149 |
static char* |
static char* |
150 |
check_multibyte_string(char const *buf, size_t size) |
check_multibyte_string(char const *buf, size_t size) |
151 |
{ |
{ |
|
static char const *precalc_buf = NULL; |
|
|
static size_t precalc_size = 0; |
|
|
static char *precalc_mb_properties = NULL; |
|
152 |
char *mb_properties = xmalloc(size); |
char *mb_properties = xmalloc(size); |
153 |
mbstate_t cur_state; |
mbstate_t cur_state; |
154 |
int i; |
int i; |
155 |
|
|
|
if (!size || |
|
|
buf >= precalc_buf && (buf + size) <= (precalc_buf + precalc_size)) |
|
|
{ |
|
|
memcpy(mb_properties, precalc_mb_properties + (buf - precalc_buf), size); |
|
|
return mb_properties; |
|
|
} |
|
|
|
|
|
precalc_mb_properties = xrealloc(precalc_mb_properties, size); |
|
|
precalc_buf = buf; |
|
|
precalc_size = size; |
|
156 |
memset(&cur_state, 0, sizeof(mbstate_t)); |
memset(&cur_state, 0, sizeof(mbstate_t)); |
157 |
memset(mb_properties, 0, sizeof(char)*size); |
memset(mb_properties, 0, sizeof(char)*size); |
158 |
for (i = 0; i < size ;) |
for (i = 0; i < size ;) |
170 |
i += mbclen; |
i += mbclen; |
171 |
} |
} |
172 |
|
|
|
memcpy(precalc_mb_properties, mb_properties, size); |
|
173 |
return mb_properties; |
return mb_properties; |
174 |
} |
} |
175 |
#endif |
#endif |