349d72c19c
function old new delta unzip_main 2726 2792 +66 printable_string2 - 57 +57 identify 4329 4336 +7 expmeta 659 663 +4 add_interface 99 103 +4 beep_main 286 289 +3 changepath 192 194 +2 builtin_type 115 117 +2 devmem_main 469 470 +1 input_tab 1076 1074 -2 create_J 1821 1819 -2 poplocalvars 314 311 -3 doCommands 2222 2214 -8 do_load 918 902 -16 printable_string 57 9 -48 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 8/6 up/down: 146/-79) Total: 67 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
63 lines
1.1 KiB
C
63 lines
1.1 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* Unicode support routines.
|
|
*
|
|
* Copyright (C) 2010 Denys Vlasenko
|
|
*
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
|
*/
|
|
#include "libbb.h"
|
|
#include "unicode.h"
|
|
|
|
const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str)
|
|
{
|
|
char *dst;
|
|
const char *s;
|
|
|
|
s = str;
|
|
while (1) {
|
|
unsigned char c = *s;
|
|
if (c == '\0') {
|
|
/* 99+% of inputs do not need conversion */
|
|
if (stats) {
|
|
stats->byte_count = (s - str);
|
|
stats->unicode_count = (s - str);
|
|
stats->unicode_width = (s - str);
|
|
}
|
|
return str;
|
|
}
|
|
if (c < ' ')
|
|
break;
|
|
if (c >= 0x7f)
|
|
break;
|
|
s++;
|
|
}
|
|
|
|
#if ENABLE_UNICODE_SUPPORT
|
|
dst = unicode_conv_to_printable(stats, str);
|
|
#else
|
|
{
|
|
char *d = dst = xstrdup(str);
|
|
while (1) {
|
|
unsigned char c = *d;
|
|
if (c == '\0')
|
|
break;
|
|
if (c < ' ' || c >= 0x7f)
|
|
*d = '?';
|
|
d++;
|
|
}
|
|
if (stats) {
|
|
stats->byte_count = (d - dst);
|
|
stats->unicode_count = (d - dst);
|
|
stats->unicode_width = (d - dst);
|
|
}
|
|
}
|
|
#endif
|
|
return auto_string(dst);
|
|
}
|
|
|
|
const char* FAST_FUNC printable_string(const char *str)
|
|
{
|
|
return printable_string2(NULL, str);
|
|
}
|