diff --git a/src/Mayaqua/Internat.c b/src/Mayaqua/Internat.c index a32591ac..aeff5364 100644 --- a/src/Mayaqua/Internat.c +++ b/src/Mayaqua/Internat.c @@ -191,22 +191,6 @@ BUF *UniStrToBin(wchar_t *str) return ret; } -// Generate a sequence of specified characters -wchar_t *UniMakeCharArray(wchar_t c, UINT count) -{ - UINT i; - wchar_t *ret = Malloc(sizeof(wchar_t) * (count + 1)); - - for (i = 0;i < count;i++) - { - ret[i] = c; - } - - ret[count] = 0; - - return ret; -} - // Check whether the character is safe bool UniIsSafeChar(wchar_t c) { @@ -228,26 +212,6 @@ bool UniIsSafeChar(wchar_t c) return false; } -// Convert the token list to a string list -LIST *UniTokenListToList(UNI_TOKEN_LIST *t) -{ - UINT i; - LIST *o; - // Validate arguments - if (t == NULL) - { - return NULL; - } - - o = NewListFast(NULL); - for (i = 0;i < t->NumTokens;i++) - { - Insert(o, UniCopyStr(t->Token[i])); - } - - return o; -} - // Convert a string list to a token list UNI_TOKEN_LIST *UniListToTokenList(LIST *o) { @@ -289,71 +253,6 @@ void UniFreeStrList(LIST *o) ReleaseList(o); } -// Convert the string list to a string -BUF *UniStrListToStr(LIST *o) -{ - BUF *b; - UINT i; - wchar_t c; - // Validate arguments - if (o == NULL) - { - return NULL; - } - b = NewBuf(); - - for (i = 0;i < LIST_NUM(o);i++) - { - wchar_t *s = LIST_DATA(o, i); - WriteBuf(b, s, UniStrSize(s)); - } - - c = 0; - WriteBuf(b, &c, sizeof(c)); - - SeekBuf(b, 0, 0); - - return b; -} - -// Convert a (NULL delimited) string to list -LIST *UniStrToStrList(wchar_t *str, UINT size) -{ - LIST *o; - wchar_t *tmp; - UINT tmp_size; - UINT i; - // Validate arguments - if (str == NULL) - { - return NULL; - } - - o = NewListFast(NULL); - - i = 0; - while (true) - { - if (i >= size) - { - break; - } - if (*str == 0) - { - break; - } - - tmp_size = UniStrSize(str); - tmp = ZeroMalloc(tmp_size); - UniStrCpy(tmp, tmp_size, str); - Add(o, tmp); - str += UniStrLen(str) + 1; - i++; - } - - return o; -} - // Normalize the line breaks wchar_t *UniNormalizeCrlf(wchar_t *str) { @@ -819,51 +718,6 @@ UINT UniStrWidth(wchar_t *str) return ret; } -// Display a dump of Unicode string -void DumpUniStr(wchar_t *str) -{ - UINT i, len; - char *s; - // Validate arguments - if (str == NULL) - { - return; - } - - s = CopyUniToStr(str); - - Print("DumpUniStr: %s\n ", s); - - len = UniStrLen(str); - for (i = 0;i < len;i++) - { - Print("0x%04X ", str[i]); - } - Print("\n"); - - Free(s); -} - -// Display the dump of the string -void DumpStr(char *str) -{ - UINT i, len; - // Validate arguments - if (str == NULL) - { - return; - } - - Print("DumpStr: %s\n ", str); - - len = StrLen(str); - for (i = 0;i < len;i++) - { - Print("0x%02X ", str[i]); - } - Print("\n"); -} - // Convert string of 2 byte/character to wchar_t of 4 byte/character wchar_t *Utf16ToWide(USHORT *str) { @@ -1266,12 +1120,6 @@ UNI_TOKEN_LIST *UniNullToken() return ret; } -// Empty Unicode token list (Alias) -UNI_TOKEN_LIST *NullUniToken() -{ - return UniNullToken(); -} - // Convert the token list to Unicode token list UNI_TOKEN_LIST *TokenListToUniTokenList(TOKEN_LIST *src) { @@ -1486,81 +1334,6 @@ UINT64 UniToInt64(wchar_t *str) return ToInt64(tmp); } -// Convert a 64-bit integer to a Unicode string -void UniToStr64(wchar_t *str, UINT64 value) -{ - char tmp[MAX_SIZE]; - // Validate arguments - if (str == NULL) - { - return; - } - - ToStr64(tmp, value); - - StrToUni(str, 0, tmp); -} - -// Convert an ANSI string to UTF -UINT StrToUtf(char *utfstr, UINT size, char *str) -{ - char *tmp; - // Validate arguments - if (utfstr == NULL || str == NULL) - { - StrCpy(utfstr, size, ""); - return 0; - } - - tmp = CopyStrToUtf(str); - - StrCpy(utfstr, size, tmp); - - Free(tmp); - - return StrLen(utfstr); -} - -// Convert an UTF string to an ANSI string -UINT UtfToStr(char *str, UINT size, char *utfstr) -{ - char *tmp; - // Validate arguments - if (str == NULL || utfstr == NULL) - { - StrCpy(str, size, ""); - return 0; - } - - tmp = CopyUtfToStr(utfstr); - - StrCpy(str, size, tmp); - - Free(tmp); - - return StrLen(str); -} - -// Convert the Unicode string to the UTF string -UINT UniToUtf(char *utfstr, UINT size, wchar_t *unistr) -{ - char *tmp; - // Validate arguments - if (utfstr == NULL || unistr == NULL) - { - StrCpy(utfstr, size, ""); - return 0; - } - - tmp = CopyUniToStr(unistr); - - StrCpy(utfstr, size, tmp); - - Free(tmp); - - return StrLen(utfstr); -} - // Convert the UTF string to a Unicode string UINT UtfToUni(wchar_t *unistr, UINT size, char *utfstr) { @@ -1602,30 +1375,6 @@ wchar_t *CopyUtfToUni(char *utfstr) return ret; } -// Copy the UTF8 string to the ANSI string -char *CopyUtfToStr(char *utfstr) -{ - wchar_t *uni; - char *ret; - // Validate arguments - if (utfstr == NULL) - { - return NULL; - } - - uni = CopyUtfToUni(utfstr); - if (uni == NULL) - { - return CopyStr(""); - } - - ret = CopyUniToStr(uni); - - Free(uni); - - return ret; -} - // Copy a Unicode string to ANSI string char *CopyUniToStr(wchar_t *unistr) { @@ -1689,30 +1438,6 @@ char *CopyUniToUtf(wchar_t *unistr) return ret; } -// Copy ANSI string to UTF8 string -char *CopyStrToUtf(char *str) -{ - wchar_t *unistr; - char *ret; - // Validate arguments - if (str == NULL) - { - return NULL; - } - - unistr = CopyStrToUni(str); - if (unistr == NULL) - { - return CopyStr(""); - } - - ret = CopyUniToUtf(unistr); - - Free(unistr); - - return ret; -} - // Copy the Unicode string wchar_t *CopyUniStr(wchar_t *str) { @@ -1784,65 +1509,6 @@ bool IsSafeUniChar(wchar_t c) return false; } -// Convert an UTF-8 string to an ANSI string -UINT Utf8ToStr(char *str, UINT str_size, BYTE *u, UINT size) -{ - UINT ret, uni_size; - wchar_t *tmp; - // Validate arguments - if (u == NULL || str == NULL) - { - return 0; - } - - // Convert to Unicode - uni_size = CalcUtf8ToUni(u, size); - if (uni_size == 0) - { - if (str_size >= 1) - { - StrCpy(str, 0, ""); - return 0; - } - } - tmp = Malloc(uni_size); - Utf8ToUni(tmp, uni_size, u, size); - - // Convert to ANSI - ret = UniToStr(str, str_size, tmp); - Free(tmp); - - return ret; -} - -// Convert an ANSI string to UTF-8 string -UINT StrToUtf8(BYTE *u, UINT size, char *str) -{ - UINT ret, uni_size; - wchar_t *tmp; - // Validate arguments - if (u == NULL || str == NULL) - { - return 0; - } - - // Convert to Unicode - uni_size = CalcStrToUni(str); - if (uni_size == 0) - { - return 0; - } - tmp = Malloc(uni_size); - StrToUni(tmp, uni_size, str); - - // Convert to UTF-8 - ret = UniToUtf8(u, size, tmp); - - Free(tmp); - - return ret; -} - // Convert Unicode string to ANSI string UINT UniToStr(char *str, UINT size, wchar_t *s) { @@ -2275,12 +1941,6 @@ UINT GetUniType(wchar_t c) return 3; } -// String replacing (case-insensitive) -UINT UniReplaceStri(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword) -{ - return UniReplaceStrEx(dst, size, string, old_keyword, new_keyword, false); -} - // String replacing (case-sensitive) UINT UniReplaceStr(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword) { @@ -2383,12 +2043,6 @@ UINT UniSearchStr(wchar_t *string, wchar_t *keyword, UINT start) return UniSearchStrEx(string, keyword, start, true); } -// Search for a string (Don't distinguish between upper / lower case) -UINT UniSearchStri(wchar_t *string, wchar_t *keyword, UINT start) -{ - return UniSearchStrEx(string, keyword, start, false); -} - // Return the position of the first found of the keyword in the string // (Found in first character: returns 0, Not found: returns INFINITE) UINT UniSearchStrEx(wchar_t *string, wchar_t *keyword, UINT start, bool case_sensitive) @@ -2806,18 +2460,6 @@ void UniTrimLeft(wchar_t *str) Free(buf); } -// Convert an integer to a hexadecimal string (8-digit fixed) -void UniToStrx8(wchar_t *str, UINT i) -{ - UniFormat(str, 0, L"0x%08x", i); -} - -// Convert an integer to a hexadecimal string -void UniToStrx(wchar_t *str, UINT i) -{ - UniFormat(str, 0, L"0x%02x", i); -} - // Convert a signed integer to a string void UniToStri(wchar_t *str, int i) { @@ -2830,21 +2472,6 @@ void UniToStru(wchar_t *str, UINT i) UniFormat(str, 0, L"%u", i); } -// Convert the string to signed integer -int UniToInti(wchar_t *str) -{ - char tmp[128]; - // Validate arguments - if (str == NULL) - { - return 0; - } - - UniToStrForSingleChars(tmp, sizeof(tmp), str); - - return ToInt(tmp); -} - // Convert a string to an integer UINT UniToInt(wchar_t *str) { @@ -2892,82 +2519,6 @@ void UniToStrForSingleChars(char *dst, UINT dst_size, wchar_t *src) } } -// Format string replacement for 64-bit -wchar_t *UniReplaceFormatStringFor64(wchar_t *fmt) -{ - wchar_t *tmp; - wchar_t *ret; - UINT tmp_size; - // Validate arguments - if (fmt == NULL) - { - return NULL; - } - - tmp_size = UniStrSize(fmt) * 2; - tmp = ZeroMalloc(tmp_size); - -#ifdef OS_WIN32 - UniReplaceStrEx(tmp, tmp_size, fmt, L"%ll", L"%I64", false); -#else // OS_WIN32 - UniReplaceStrEx(tmp, tmp_size, fmt, L"%I64", L"%ll", false); - - if (1) - { - UINT i, len; - bool f = false; - len = UniStrLen(tmp); - for (i = 0;i < len;i++) - { - if (tmp[i] == L'%') - { - f = true; - } - - if (f) - { - switch (tmp[i]) - { - case L'c': - case L'C': - case L'd': - case L'i': - case L'o': - case L'u': - case L'x': - case L'X': - case L'e': - case L'E': - case L'f': - case L'g': - case L'G': - case L'n': - case L'p': - case L's': - case L'S': - if (tmp[i] == L's') - { - tmp[i] = L'S'; - } - else if (tmp[i] == L'S') - { - tmp[i] = L's'; - } - f = false; - break; - } - } - } - } - -#endif // OS_WIN32 - - ret = CopyUniStr(tmp); - Free(tmp); - - return ret; -} - // Get lines from a string UNI_TOKEN_LIST *UniGetLines(wchar_t *str) { @@ -3387,22 +2938,6 @@ UINT UniStrCat(wchar_t *dst, UINT size, wchar_t *src) return len1 + len2; } -UINT UniStrCatLeft(wchar_t *dst, UINT size, wchar_t *src) -{ - wchar_t *s; - // Validate arguments - if (dst == NULL || src == NULL) - { - return 0; - } - - s = UniCopyStr(dst); - UniStrCpy(dst, size, s); - UniStrCat(dst, size, src); - Free(s); - - return UniStrLen(dst); -} // String copy UINT UniStrCpy(wchar_t *dst, UINT size, wchar_t *src) @@ -3455,43 +2990,6 @@ UINT UniStrCpy(wchar_t *dst, UINT size, wchar_t *src) return len; } -// Check whether the character is within specified buffer size -bool UniCheckStrSize(wchar_t *str, UINT size) -{ - // Validate arguments - if (str == NULL || size <= 1) - { - return false; - } - - return UniCheckStrLen(str, size / sizeof(wchar_t) - 1); -} - -// Check whether the number of characters is within specified length -bool UniCheckStrLen(wchar_t *str, UINT len) -{ - UINT count = 0; - UINT i; - // Validate arguments - if (str == NULL) - { - return false; - } - - for (i = 0;;i++) - { - if (str[i] == 0) - { - return true; - } - count++; - if (count > len) - { - return false; - } - } -} - // Get the buffer size needed to store the string UINT UniStrSize(wchar_t *str) { diff --git a/src/Mayaqua/Internat.h b/src/Mayaqua/Internat.h index 7e881860..149e8245 100644 --- a/src/Mayaqua/Internat.h +++ b/src/Mayaqua/Internat.h @@ -124,10 +124,7 @@ struct UNI_TOKEN_LIST UINT UniStrLen(wchar_t *str); UINT UniStrSize(wchar_t *str); UINT UniStrCpy(wchar_t *dst, UINT size, wchar_t *src); -bool UniCheckStrSize(wchar_t *str, UINT size); -bool UniCheckStrLen(wchar_t *str, UINT len); UINT UniStrCat(wchar_t *dst, UINT size, wchar_t *src); -UINT UniStrCatLeft(wchar_t *dst, UINT size, wchar_t *src); wchar_t UniToLower(wchar_t c); wchar_t UniToUpper(wchar_t c); void UniStrLower(wchar_t *str); @@ -143,11 +140,8 @@ void UniDebug(wchar_t *fmt, ...); void UniPrint(wchar_t *fmt, ...); void UniPrintArgs(wchar_t *fmt, va_list args); void UniPrintStr(wchar_t *string); -void UniToStrx8(wchar_t *str, UINT i); -void UniToStrx(wchar_t *str, UINT i); void UniToStri(wchar_t *str, int i); void UniToStru(wchar_t *str, UINT i); -int UniToInti(wchar_t *str); UINT UniToInt(wchar_t *str); void UniToStrForSingleChars(char *dst, UINT dst_size, wchar_t *src); void UniTrim(wchar_t *str); @@ -160,11 +154,9 @@ bool UniGetLineUnix(wchar_t *str, UINT size); void UniFreeToken(UNI_TOKEN_LIST *tokens); UNI_TOKEN_LIST *UniParseToken(wchar_t *src, wchar_t *separator); UINT UniSearchStrEx(wchar_t *string, wchar_t *keyword, UINT start, bool case_sensitive); -UINT UniSearchStri(wchar_t *string, wchar_t *keyword, UINT start); UINT UniSearchStr(wchar_t *string, wchar_t *keyword, UINT start); UINT UniCalcReplaceStrEx(wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword, bool case_sensitive); UINT UniReplaceStrEx(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword, bool case_sensitive); -UINT UniReplaceStri(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword); UINT UniReplaceStr(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword); UINT GetUniType(wchar_t c); UINT GetUtf8Type(BYTE *s, UINT size, UINT offset); @@ -177,23 +169,14 @@ UINT CalcStrToUni(char *str); UINT StrToUni(wchar_t *s, UINT size, char *str); UINT CalcUniToStr(wchar_t *s); UINT UniToStr(char *str, UINT size, wchar_t *s); -UINT StrToUtf8(BYTE *u, UINT size, char *str); -UINT Utf8ToStr(char *str, UINT str_size, BYTE *u, UINT size); bool IsSafeUniStr(wchar_t *str); bool IsSafeUniChar(wchar_t c); wchar_t *CopyUniStr(wchar_t *str); wchar_t *CopyStrToUni(char *str); -UINT StrToUtf(char *utfstr, UINT size, char *str); -UINT UtfToStr(char *str, UINT size, char *utfstr); -UINT UniToUtf(char *utfstr, UINT size, wchar_t *unistr); UINT UtfToUni(wchar_t *unistr, UINT size, char *utfstr); char *CopyUniToUtf(wchar_t *unistr); -char *CopyStrToUtf(char *str); char *CopyUniToStr(wchar_t *unistr); wchar_t *CopyUtfToUni(char *utfstr); -char *CopyUtfToStr(char *utfstr); -wchar_t *UniReplaceFormatStringFor64(wchar_t *fmt); -void UniToStr64(wchar_t *str, UINT64 value); UINT64 UniToInt64(wchar_t *str); UNI_TOKEN_LIST *UniParseCmdLine(wchar_t *str); UNI_TOKEN_LIST *UniCopyToken(UNI_TOKEN_LIST *src); @@ -201,7 +184,6 @@ wchar_t *UniCopyStr(wchar_t *str); TOKEN_LIST *UniTokenListToTokenList(UNI_TOKEN_LIST *src); UNI_TOKEN_LIST *TokenListToUniTokenList(TOKEN_LIST *src); UNI_TOKEN_LIST *UniNullToken(); -UNI_TOKEN_LIST *NullUniToken(); bool UniIsNum(wchar_t *str); bool IsEmptyUniStr(wchar_t *str); bool UniIsEmptyStr(wchar_t *str); @@ -209,8 +191,6 @@ void InitInternational(); void FreeInternational(); USHORT *WideToUtf16(wchar_t *str); wchar_t *Utf16ToWide(USHORT *str); -void DumpUniStr(wchar_t *str); -void DumpStr(char *str); wchar_t *InternalFormatArgs(wchar_t *fmt, va_list args, bool ansi_mode); UINT UniStrWidth(wchar_t *str); UNI_TOKEN_LIST *UnixUniParseToken(wchar_t *src, wchar_t *separator); @@ -218,13 +198,9 @@ void UniToStr3(wchar_t *str, UINT size, UINT64 value); bool UniEndWith(wchar_t *str, wchar_t *key); bool UniStartWith(wchar_t *str, wchar_t *key); wchar_t *UniNormalizeCrlf(wchar_t *str); -LIST *UniStrToStrList(wchar_t *str, UINT size); -BUF *UniStrListToStr(LIST *o); void UniFreeStrList(LIST *o); UNI_TOKEN_LIST *UniListToTokenList(LIST *o); -LIST *UniTokenListToList(UNI_TOKEN_LIST *t); bool UniIsSafeChar(wchar_t c); -wchar_t *UniMakeCharArray(wchar_t c, UINT count); BUF *UniStrToBin(wchar_t *str); bool UniInStr(wchar_t *str, wchar_t *keyword); bool UniInStrEx(wchar_t *str, wchar_t *keyword, bool case_sensitive);