1 // Common/TextConfig.cpp
\r
5 #include "TextConfig.h"
\r
8 #include "UTFConvert.h"
\r
10 static bool IsDelimitChar(char c)
\r
12 return (c == ' ' || c == 0x0A || c == 0x0D ||
\r
13 c == '\0' || c == '\t');
\r
16 static AString GetIDString(const char *string, int &finishPos)
\r
19 for (finishPos = 0; ; finishPos++)
\r
21 char c = string[finishPos];
\r
22 if (IsDelimitChar(c) || c == '=')
\r
29 static bool WaitNextLine(const AString &string, int &pos)
\r
31 for (;pos < string.Length(); pos++)
\r
32 if (string[pos] == 0x0A)
\r
37 static bool SkipSpaces(const AString &string, int &pos)
\r
39 for (;pos < string.Length(); pos++)
\r
41 char c = string[pos];
\r
42 if (!IsDelimitChar(c))
\r
46 if (!WaitNextLine(string, pos))
\r
53 bool GetTextConfig(const AString &string, CObjectVector<CTextConfigPair> &pairs)
\r
58 /////////////////////
\r
63 if (!SkipSpaces(string, pos))
\r
65 CTextConfigPair pair;
\r
67 AString temp = GetIDString(((const char *)string) + pos, finishPos);
\r
68 if (!ConvertUTF8ToUnicode(temp, pair.ID))
\r
73 if (!SkipSpaces(string, pos))
\r
75 if (string[pos] != '=')
\r
78 if (!SkipSpaces(string, pos))
\r
80 if (string[pos] != '\"')
\r
86 if (pos >= string.Length())
\r
88 char c = string[pos++];
\r
93 char c = string[pos++];
\r
117 if (!ConvertUTF8ToUnicode(message, pair.String))
\r
124 int FindTextConfigItem(const CObjectVector<CTextConfigPair> &pairs, const UString &id)
\r
126 for (int i = 0; i < pairs.Size(); i++)
\r
127 if (pairs[i].ID.Compare(id) == 0)
\r
132 UString GetTextConfigValue(const CObjectVector<CTextConfigPair> &pairs, const UString &id)
\r
134 int index = FindTextConfigItem(pairs, id);
\r
137 return pairs[index].String;
\r