5 * アドレス固定のWide文字列とそれに対応するUTF-8文字列を格納する構造体
13 static BOOL g_initialized = FALSE;
14 static CRITICAL_SECTION g_msgUtilLLock;
16 // Wide文字列 - UTF-8文字列 対応Map
17 static StrPair *pStrMap = NULL;
20 static int strMapCount = 0;
23 static int strMapMaxCount = 0;
26 * staticなWide文字列に対応するUTF-8バイナリ文字列領域を確保し、その先頭アドレスを返す
28 const char* const MessageUtil_GetUTF8StaticBinaryBlock(const wchar_t* const ws, size_t ws_area_length)
33 const char *pResult = NULL;
36 InitializeCriticalSection(&g_msgUtilLLock);
39 EnterCriticalSection(&g_msgUtilLLock);
40 for (i = 0; i < strMapCount; i++)
42 if (pStrMap[i].ws == ws)
44 pResult = pStrMap[i].u8s;
50 if (strMapMaxCount < strMapCount + 1)
53 if (strMapMaxCount == 0)
56 pStrMap = (StrPair*)malloc(sizeof(StrPair) * strMapMaxCount);
60 strMapMaxCount += 100;
61 pStrMap = (StrPair*)realloc(pStrMap, sizeof(StrPair) * strMapMaxCount);
64 newSize = WideCharToMultiByte(CP_UTF8, 0, ws, ws_area_length, 0, 0, NULL, NULL);
67 int index = strMapCount;
71 pStrMap[index].ws = ws;
72 pStrMap[index].u8size = newSize;
73 beginPos = (char*)malloc(newSize);
74 pStrMap[index].u8s = beginPos;
75 postSize = WideCharToMultiByte(CP_UTF8, 0, ws, ws_area_length, beginPos, newSize, NULL, NULL);
80 static char sEmpty[] = "";
84 LeaveCriticalSection(&g_msgUtilLLock);
89 * MessageUtil_GetUTF8StaticBinaryBlock() で確保した領域をすべて破棄する
91 void MessageUtil_FreeUTF8StaticBinaryBlocks()
96 InitializeCriticalSection(&g_msgUtilLLock);
99 EnterCriticalSection(&g_msgUtilLLock);
100 for (i = 0; i < strMapCount; i++)
102 free(pStrMap[i].u8s);
107 pStrMap = (StrPair*)NULL;
109 LeaveCriticalSection(&g_msgUtilLLock);