diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-14 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-15 23:55:04 +0500 |
commit | fc662341e6f85da78ada0e443f6116b978f79f22 (patch) | |
tree | 1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Common/MyXml.cpp | |
parent | 5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff) | |
download | 7zip-24.05.tar.gz 7zip-24.05.tar.bz2 7zip-24.05.zip |
24.0524.05
Diffstat (limited to 'CPP/Common/MyXml.cpp')
-rw-r--r-- | CPP/Common/MyXml.cpp | 117 |
1 files changed, 103 insertions, 14 deletions
diff --git a/CPP/Common/MyXml.cpp b/CPP/Common/MyXml.cpp index a879d34..cc891fc 100644 --- a/CPP/Common/MyXml.cpp +++ b/CPP/Common/MyXml.cpp | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "StdAfx.h" | 3 | #include "StdAfx.h" |
4 | 4 | ||
5 | #include "MyXml.h" | 5 | #include "MyXml.h" |
6 | #include "StringToInt.h" | ||
6 | 7 | ||
7 | static bool IsValidChar(char c) | 8 | static bool IsValidChar(char c) |
8 | { | 9 | { |
@@ -30,7 +31,7 @@ int CXmlItem::FindProp(const char *propName) const throw() | |||
30 | 31 | ||
31 | AString CXmlItem::GetPropVal(const char *propName) const | 32 | AString CXmlItem::GetPropVal(const char *propName) const |
32 | { | 33 | { |
33 | int index = FindProp(propName); | 34 | const int index = FindProp(propName); |
34 | if (index >= 0) | 35 | if (index >= 0) |
35 | return Props[(unsigned)index].Value; | 36 | return Props[(unsigned)index].Value; |
36 | return AString(); | 37 | return AString(); |
@@ -49,6 +50,17 @@ int CXmlItem::FindSubTag(const char *tag) const throw() | |||
49 | return -1; | 50 | return -1; |
50 | } | 51 | } |
51 | 52 | ||
53 | const CXmlItem *CXmlItem::FindSubTag_GetPtr(const char *tag) const throw() | ||
54 | { | ||
55 | FOR_VECTOR (i, SubItems) | ||
56 | { | ||
57 | const CXmlItem *p = &SubItems[i]; | ||
58 | if (p->IsTagged(tag)) | ||
59 | return p; | ||
60 | } | ||
61 | return NULL; | ||
62 | } | ||
63 | |||
52 | AString CXmlItem::GetSubString() const | 64 | AString CXmlItem::GetSubString() const |
53 | { | 65 | { |
54 | if (SubItems.Size() == 1) | 66 | if (SubItems.Size() == 1) |
@@ -73,9 +85,9 @@ const AString * CXmlItem::GetSubStringPtr() const throw() | |||
73 | 85 | ||
74 | AString CXmlItem::GetSubStringForTag(const char *tag) const | 86 | AString CXmlItem::GetSubStringForTag(const char *tag) const |
75 | { | 87 | { |
76 | int index = FindSubTag(tag); | 88 | const CXmlItem *item = FindSubTag_GetPtr(tag); |
77 | if (index >= 0) | 89 | if (item) |
78 | return SubItems[(unsigned)index].GetSubString(); | 90 | return item->GetSubString(); |
79 | return AString(); | 91 | return AString(); |
80 | } | 92 | } |
81 | 93 | ||
@@ -92,11 +104,14 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
92 | } | 104 | } |
93 | if (*s == 0) | 105 | if (*s == 0) |
94 | return NULL; | 106 | return NULL; |
95 | if (s != beg) | ||
96 | { | 107 | { |
97 | IsTag = false; | 108 | const size_t num = (size_t)(s - beg); |
98 | Name.SetFrom(beg, (unsigned)(s - beg)); | 109 | if (num) |
99 | return s; | 110 | { |
111 | IsTag = false; | ||
112 | Name.SetFrom_Chars_SizeT(beg, num); | ||
113 | return s; | ||
114 | } | ||
100 | } | 115 | } |
101 | 116 | ||
102 | IsTag = true; | 117 | IsTag = true; |
@@ -110,7 +125,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
110 | break; | 125 | break; |
111 | if (s == beg || *s == 0) | 126 | if (s == beg || *s == 0) |
112 | return NULL; | 127 | return NULL; |
113 | Name.SetFrom(beg, (unsigned)(s - beg)); | 128 | Name.SetFrom_Chars_SizeT(beg, (size_t)(s - beg)); |
114 | 129 | ||
115 | for (;;) | 130 | for (;;) |
116 | { | 131 | { |
@@ -142,11 +157,12 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
142 | } | 157 | } |
143 | 158 | ||
144 | s += 2; | 159 | s += 2; |
145 | unsigned len = Name.Len(); | 160 | const unsigned len = Name.Len(); |
161 | const char *name = Name.Ptr(); | ||
146 | for (unsigned i = 0; i < len; i++) | 162 | for (unsigned i = 0; i < len; i++) |
147 | if (s[i] != Name[i]) | 163 | if (*s++ != *name++) |
148 | return NULL; | 164 | return NULL; |
149 | s += len; | 165 | // s += len; |
150 | if (s[0] != '>') | 166 | if (s[0] != '>') |
151 | return NULL; | 167 | return NULL; |
152 | return s + 1; | 168 | return s + 1; |
@@ -166,7 +182,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
166 | } | 182 | } |
167 | if (s == beg) | 183 | if (s == beg) |
168 | return NULL; | 184 | return NULL; |
169 | prop.Name.SetFrom(beg, (unsigned)(s - beg)); | 185 | prop.Name.SetFrom_Chars_SizeT(beg, (size_t)(s - beg)); |
170 | 186 | ||
171 | SKIP_SPACES(s) | 187 | SKIP_SPACES(s) |
172 | if (*s != '=') | 188 | if (*s != '=') |
@@ -187,7 +203,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
187 | break; | 203 | break; |
188 | s++; | 204 | s++; |
189 | } | 205 | } |
190 | prop.Value.SetFrom(beg, (unsigned)(s - beg)); | 206 | prop.Value.SetFrom_Chars_SizeT(beg, (size_t)(s - beg)); |
191 | s++; | 207 | s++; |
192 | } | 208 | } |
193 | } | 209 | } |
@@ -258,3 +274,76 @@ void CXml::AppendTo(AString &s) const | |||
258 | Root.AppendTo(s); | 274 | Root.AppendTo(s); |
259 | } | 275 | } |
260 | */ | 276 | */ |
277 | |||
278 | |||
279 | void z7_xml_DecodeString(AString &temp) | ||
280 | { | ||
281 | char * const beg = temp.GetBuf(); | ||
282 | char *dest = beg; | ||
283 | const char *p = beg; | ||
284 | for (;;) | ||
285 | { | ||
286 | char c = *p++; | ||
287 | if (c == 0) | ||
288 | break; | ||
289 | if (c == '&') | ||
290 | { | ||
291 | if (p[0] == '#') | ||
292 | { | ||
293 | const char *end; | ||
294 | const UInt32 number = ConvertStringToUInt32(p + 1, &end); | ||
295 | if (*end == ';' && number != 0 && number <= 127) | ||
296 | { | ||
297 | p = end + 1; | ||
298 | c = (char)number; | ||
299 | } | ||
300 | } | ||
301 | else if ( | ||
302 | p[0] == 'a' && | ||
303 | p[1] == 'm' && | ||
304 | p[2] == 'p' && | ||
305 | p[3] == ';') | ||
306 | { | ||
307 | p += 4; | ||
308 | } | ||
309 | else if ( | ||
310 | p[0] == 'l' && | ||
311 | p[1] == 't' && | ||
312 | p[2] == ';') | ||
313 | { | ||
314 | p += 3; | ||
315 | c = '<'; | ||
316 | } | ||
317 | else if ( | ||
318 | p[0] == 'g' && | ||
319 | p[1] == 't' && | ||
320 | p[2] == ';') | ||
321 | { | ||
322 | p += 3; | ||
323 | c = '>'; | ||
324 | } | ||
325 | else if ( | ||
326 | p[0] == 'a' && | ||
327 | p[1] == 'p' && | ||
328 | p[2] == 'o' && | ||
329 | p[3] == 's' && | ||
330 | p[4] == ';') | ||
331 | { | ||
332 | p += 5; | ||
333 | c = '\''; | ||
334 | } | ||
335 | else if ( | ||
336 | p[0] == 'q' && | ||
337 | p[1] == 'u' && | ||
338 | p[2] == 'o' && | ||
339 | p[3] == 't' && | ||
340 | p[4] == ';') | ||
341 | { | ||
342 | p += 5; | ||
343 | c = '\"'; | ||
344 | } | ||
345 | } | ||
346 | *dest++ = c; | ||
347 | } | ||
348 | temp.ReleaseBuf_SetEnd((unsigned)(dest - beg)); | ||
349 | } | ||