… | |
… | |
142 | |
142 | |
143 | int psiconv_unicode_write_char(const psiconv_config config, |
143 | int psiconv_unicode_write_char(const psiconv_config config, |
144 | psiconv_buffer buf, |
144 | psiconv_buffer buf, |
145 | int lev, psiconv_ucs2 value) |
145 | int lev, psiconv_ucs2 value) |
146 | { |
146 | { |
147 | psiconv_u8 byte; |
|
|
148 | int i; |
147 | int i; |
149 | int res=0; |
148 | int res=0; |
150 | |
149 | |
151 | if (config->unicode) { |
150 | if (config->unicode) { |
152 | if (value < 0x80) { |
151 | if (value < 0x80) { |
… | |
… | |
224 | if (result) |
223 | if (result) |
225 | result[0] = 0; |
224 | result[0] = 0; |
226 | return result; |
225 | return result; |
227 | } |
226 | } |
228 | |
227 | |
|
|
228 | |
|
|
229 | psiconv_ucs2 *psiconv_unicode_from_list(psiconv_list input) |
|
|
230 | { |
|
|
231 | psiconv_ucs2 *result; |
|
|
232 | int i; |
|
|
233 | psiconv_ucs2 *character; |
|
|
234 | |
|
|
235 | if (!(result = malloc(sizeof(psiconv_ucs2) * (psiconv_list_length(input)+1)))) |
|
|
236 | goto ERROR1; |
|
|
237 | for (i = 0; i < psiconv_list_length(input); i++) { |
|
|
238 | if (!(character = psiconv_list_get(input,i))) |
|
|
239 | goto ERROR2; |
|
|
240 | result[i] = *character; |
|
|
241 | } |
|
|
242 | result[i] = 0; |
|
|
243 | return result; |
|
|
244 | |
|
|
245 | ERROR2: |
|
|
246 | free(result); |
|
|
247 | ERROR1: |
|
|
248 | return NULL; |
|
|
249 | } |
|
|
250 | |
|
|
251 | |
|
|
252 | psiconv_ucs2 *psiconv_unicode_strstr(const psiconv_ucs2 *haystack, |
|
|
253 | const psiconv_ucs2 *needle) |
|
|
254 | { |
|
|
255 | int i,j,haystack_len,needle_len; |
|
|
256 | haystack_len = psiconv_unicode_strlen(haystack); |
|
|
257 | needle_len = psiconv_unicode_strlen(needle); |
|
|
258 | |
|
|
259 | |
|
|
260 | |
|
|
261 | for (i = 0; i < haystack_len - needle_len + 1; i++) { |
|
|
262 | for (j = 0; j < needle_len; j++) |
|
|
263 | if (haystack[i+j] != needle[j]) |
|
|
264 | break; |
|
|
265 | if (j == needle_len) |
|
|
266 | return (psiconv_ucs2 *) haystack+i; |
|
|
267 | } |
|
|
268 | return NULL; |
|
|
269 | } |