--- psiconv/trunk/lib/psiconv/unicode.c 2004/02/22 22:24:39 217 +++ psiconv/trunk/lib/psiconv/unicode.c 2014/10/22 19:53:40 351 @@ -1,6 +1,6 @@ /* unicode.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 2003-2004 Frodo Looijaard + Copyright (c) 2003-2014 Frodo Looijaard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include "generate_routines.h" #include +#include #ifdef DMALLOC #include @@ -144,7 +145,6 @@ psiconv_buffer buf, int lev, psiconv_ucs2 value) { - psiconv_u8 byte; int i; int res=0; @@ -226,3 +226,45 @@ return result; } + +psiconv_ucs2 *psiconv_unicode_from_list(psiconv_list input) +{ + psiconv_ucs2 *result; + int i; + psiconv_ucs2 *character; + + if (!(result = malloc(sizeof(psiconv_ucs2) * (psiconv_list_length(input)+1)))) + goto ERROR1; + for (i = 0; i < psiconv_list_length(input); i++) { + if (!(character = psiconv_list_get(input,i))) + goto ERROR2; + result[i] = *character; + } + result[i] = 0; + return result; + +ERROR2: + free(result); +ERROR1: + return NULL; +} + + +psiconv_ucs2 *psiconv_unicode_strstr(const psiconv_ucs2 *haystack, + const psiconv_ucs2 *needle) +{ + int i,j,haystack_len,needle_len; + haystack_len = psiconv_unicode_strlen(haystack); + needle_len = psiconv_unicode_strlen(needle); + + + + for (i = 0; i < haystack_len - needle_len + 1; i++) { + for (j = 0; j < needle_len; j++) + if (haystack[i+j] != needle[j]) + break; + if (j == needle_len) + return (psiconv_ucs2 *) haystack+i; + } + return NULL; +}