6 #include "TextConfig.h"
\r
8 #include "../Windows/FileIO.h"
\r
9 #include "UTFConvert.h"
\r
12 static bool HexStringToNumber(const UString &s, UInt32 &value)
\r
17 for (int i = 0; i < s.Length(); i++)
\r
21 if (c >= L'0' && c <= L'9')
\r
23 else if (c >= L'A' && c <= L'F')
\r
25 else if (c >= L'a' && c <= L'f')
\r
36 static bool WaitNextLine(const AString &s, int &pos)
\r
38 for (; pos < s.Length(); pos++)
\r
44 static int CompareLangItems(void *const *elem1, void *const *elem2, void *)
\r
46 const CLangPair &langPair1 = *(*((const CLangPair **)elem1));
\r
47 const CLangPair &langPair2 = *(*((const CLangPair **)elem2));
\r
48 return MyCompare(langPair1.Value, langPair2.Value);
\r
51 bool CLang::Open(LPCWSTR fileName)
\r
54 NWindows::NFile::NIO::CInFile file;
\r
55 if (!file.Open(fileName))
\r
58 if (!file.GetLength(length))
\r
60 if (length > (1 << 20))
\r
63 char *p = s.GetBuffer((int)length + 1);
\r
65 if (!file.Read(p, (UInt32)length, processed))
\r
67 p[(UInt32)length] = 0;
\r
71 if (s.Length() >= 3)
\r
73 if (Byte(s[0]) == 0xEF && Byte(s[1]) == 0xBB && Byte(s[2]) == 0xBF)
\r
77 /////////////////////
\r
80 AString stringID = ";!@Lang@!UTF-8!";
\r
81 if (s.Mid(pos, stringID.Length()) != stringID)
\r
83 pos += stringID.Length();
\r
85 if (!WaitNextLine(s, pos))
\r
88 CObjectVector<CTextConfigPair> pairs;
\r
89 if (!GetTextConfig(s.Mid(pos), pairs))
\r
92 _langPairs.Reserve(_langPairs.Size());
\r
93 for (int i = 0; i < pairs.Size(); i++)
\r
95 CTextConfigPair textConfigPair = pairs[i];
\r
97 if (!HexStringToNumber(textConfigPair.ID, langPair.Value))
\r
99 langPair.String = textConfigPair.String;
\r
100 _langPairs.Add(langPair);
\r
102 _langPairs.Sort(CompareLangItems, NULL);
\r
106 int CLang::FindItem(UInt32 value) const
\r
108 int left = 0, right = _langPairs.Size();
\r
109 while (left != right)
\r
111 UInt32 mid = (left + right) / 2;
\r
112 UInt32 midValue = _langPairs[mid].Value;
\r
113 if (value == midValue)
\r
115 if (value < midValue)
\r
123 bool CLang::GetMessage(UInt32 value, UString &message) const
\r
125 int index = FindItem(value);
\r
128 message = _langPairs[index].String;
\r