diff options
Diffstat (limited to '')
-rw-r--r-- | CPP/Common/Lang.cpp | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/CPP/Common/Lang.cpp b/CPP/Common/Lang.cpp index 35d3752..b0b4342 100644 --- a/CPP/Common/Lang.cpp +++ b/CPP/Common/Lang.cpp | |||
@@ -12,85 +12,95 @@ void CLang::Clear() throw() | |||
12 | { | 12 | { |
13 | _ids.Clear(); | 13 | _ids.Clear(); |
14 | _offsets.Clear(); | 14 | _offsets.Clear(); |
15 | Comments.Clear(); | ||
15 | delete []_text; | 16 | delete []_text; |
16 | _text = 0; | 17 | _text = NULL; |
17 | } | 18 | } |
18 | 19 | ||
19 | static const char * const kLangSignature = ";!@Lang2@!UTF-8!"; | 20 | static const char * const kLangSignature = ";!@Lang2@!UTF-8!\n"; |
20 | 21 | ||
21 | bool CLang::OpenFromString(const AString &s2) | 22 | bool CLang::OpenFromString(const AString &s2) |
22 | { | 23 | { |
23 | UString s; | 24 | UString su; |
24 | if (!ConvertUTF8ToUnicode(s2, s)) | 25 | if (!ConvertUTF8ToUnicode(s2, su)) |
25 | return false; | 26 | return false; |
26 | unsigned i = 0; | 27 | if (su.IsEmpty()) |
27 | if (s.IsEmpty()) | ||
28 | return false; | 28 | return false; |
29 | if (s[0] == 0xFEFF) | 29 | const wchar_t *s = su; |
30 | i++; | 30 | const wchar_t *sLim = s + su.Len(); |
31 | 31 | if (*s == 0xFEFF) | |
32 | for (const char *p = kLangSignature;; i++) | 32 | s++; |
33 | for (const char *p = kLangSignature;; s++) | ||
33 | { | 34 | { |
34 | Byte c = (Byte)(*p++); | 35 | const Byte c = (Byte)(*p++); |
35 | if (c == 0) | 36 | if (c == 0) |
36 | break; | 37 | break; |
37 | if (s[i] != c) | 38 | if (*s != c) |
38 | return false; | 39 | return false; |
39 | } | 40 | } |
40 | 41 | ||
41 | _text = new wchar_t[s.Len() - i + 1]; | 42 | wchar_t *text = new wchar_t[(size_t)(sLim - s) + 1]; |
42 | wchar_t *text = _text; | 43 | _text = text; |
43 | 44 | ||
44 | Int32 id = -100; | 45 | UString comment; |
45 | UInt32 pos = 0; | 46 | Int32 id = -1024; |
47 | unsigned pos = 0; | ||
46 | 48 | ||
47 | while (i < s.Len()) | 49 | while (s != sLim) |
48 | { | 50 | { |
49 | unsigned start = pos; | 51 | const unsigned start = pos; |
50 | do | 52 | do |
51 | { | 53 | { |
52 | wchar_t c = s[i++]; | 54 | wchar_t c = *s++; |
53 | if (c == '\n') | 55 | if (c == '\n') |
54 | break; | 56 | break; |
55 | if (c == '\\') | 57 | if (c == '\\') |
56 | { | 58 | { |
57 | if (i == s.Len()) | 59 | if (s == sLim) |
58 | return false; | 60 | return false; |
59 | c = s[i++]; | 61 | c = *s++; |
60 | switch (c) | 62 | switch (c) |
61 | { | 63 | { |
62 | case '\n': return false; | 64 | case '\n': return false; |
63 | case 'n': c = '\n'; break; | 65 | case 'n': c = '\n'; break; |
64 | case 't': c = '\t'; break; | 66 | case 't': c = '\t'; break; |
65 | case '\\': c = '\\'; break; | 67 | case '\\': /* c = '\\'; */ break; |
66 | default: text[pos++] = L'\\'; break; | 68 | default: text[pos++] = L'\\'; break; |
67 | } | 69 | } |
68 | } | 70 | } |
69 | text[pos++] = c; | 71 | text[pos++] = c; |
70 | } | 72 | } |
71 | while (i < s.Len()); | 73 | while (s != sLim); |
72 | 74 | ||
73 | { | 75 | { |
74 | unsigned j = start; | 76 | unsigned j = start; |
75 | for (; j < pos; j++) | 77 | for (; j < pos; j++) |
76 | if (text[j] != ' ') | 78 | if (text[j] != ' ' && text[j] != '\t') |
77 | break; | 79 | break; |
78 | if (j == pos) | 80 | if (j == pos) |
79 | { | 81 | { |
80 | id++; | 82 | id++; |
83 | pos = start; | ||
81 | continue; | 84 | continue; |
82 | } | 85 | } |
83 | } | 86 | } |
87 | |||
88 | // start != pos | ||
89 | text[pos++] = 0; | ||
90 | |||
84 | if (text[start] == ';') | 91 | if (text[start] == ';') |
85 | { | 92 | { |
86 | pos = start; | 93 | comment = text + start; |
94 | comment.TrimRight(); | ||
95 | if (comment.Len() != 1) | ||
96 | Comments.Add(comment); | ||
87 | id++; | 97 | id++; |
98 | pos = start; | ||
88 | continue; | 99 | continue; |
89 | } | 100 | } |
90 | 101 | ||
91 | text[pos++] = 0; | ||
92 | const wchar_t *end; | 102 | const wchar_t *end; |
93 | UInt32 id32 = ConvertStringToUInt32(text + start, &end); | 103 | const UInt32 id32 = ConvertStringToUInt32(text + start, &end); |
94 | if (*end == 0) | 104 | if (*end == 0) |
95 | { | 105 | { |
96 | if (id32 > ((UInt32)1 << 30) || (Int32)id32 < id) | 106 | if (id32 > ((UInt32)1 << 30) || (Int32)id32 < id) |
@@ -134,7 +144,7 @@ bool CLang::Open(CFSTR fileName, const char *id) | |||
134 | char *p2 = p; | 144 | char *p2 = p; |
135 | for (unsigned i = 0; i < len; i++) | 145 | for (unsigned i = 0; i < len; i++) |
136 | { | 146 | { |
137 | char c = p[i]; | 147 | const char c = p[i]; |
138 | if (c == 0) | 148 | if (c == 0) |
139 | break; | 149 | break; |
140 | if (c != 0x0D) | 150 | if (c != 0x0D) |
@@ -156,7 +166,7 @@ bool CLang::Open(CFSTR fileName, const char *id) | |||
156 | 166 | ||
157 | const wchar_t *CLang::Get(UInt32 id) const throw() | 167 | const wchar_t *CLang::Get(UInt32 id) const throw() |
158 | { | 168 | { |
159 | int index = _ids.FindInSorted(id); | 169 | const int index = _ids.FindInSorted(id); |
160 | if (index < 0) | 170 | if (index < 0) |
161 | return NULL; | 171 | return NULL; |
162 | return _text + (size_t)_offsets[(unsigned)index]; | 172 | return _text + (size_t)_offsets[(unsigned)index]; |