Skip to content

Commit 2da8e85

Browse files
committed
Url decode/encode and JSON escaped chars go to/from local charset in ASL_ANSI mode
1 parent 38a0990 commit 2da8e85

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

include/asl/String.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,9 @@ int ASL_API utf8toUtf16(const char* u, wchar_t* p, int);
753753
int ASL_API utf32toUtf8(const int* p, char* u, int);
754754
int ASL_API utf8toUtf32(const char* u, int* p, int);
755755
String ASL_API localToString(const String& a);
756+
String ASL_API stringToLocal(const String& a);
757+
String ASL_API localToUtf8(const String& a);
758+
String ASL_API utf8ToLocal(const String& a);
756759
}
757760

758761
#ifdef QSTRING_H

src/Http.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ String Url::decode(const String& q0)
3333
else
3434
q << c;
3535
}
36+
#ifdef ASL_ANSI
37+
return utf8ToLocal(q);
38+
#else
3639
return q;
40+
#endif
3741
}
3842

3943
inline bool isanyof(char c, const char* chars)
@@ -51,8 +55,14 @@ inline char hexNibble(int x)
5155
return h[x];
5256
}
5357

54-
String Url::encode(const String& q0, bool component)
58+
String Url::encode(const String& q0_, bool component)
5559
{
60+
#ifdef ASL_ANSI
61+
String q0 = localToUtf8(q0_);
62+
#else
63+
const String& q0 = q0_;
64+
#endif
65+
5666
String q(q0.length(), 0);
5767
for (int i = 0; i < q0.length(); i++)
5868
{

src/String.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,31 @@ String localToString(const String& a)
211211
return String(ws.ptr());
212212
}
213213

214+
String stringToLocal(const String& a)
215+
{
216+
Array<char> s(a.length() + 1);
217+
utf16toLocal8((const wchar_t*)a, s.ptr(), a.length() + 1);
218+
return String(s.ptr());
219+
}
220+
221+
String localToUtf8(const String& a)
222+
{
223+
Array<wchar_t> ws(a.length() + 1);
224+
local8toUtf16(a, ws.ptr(), a.length() + 1);
225+
String u(a.length() * 3, 0);
226+
int n = utf16toUtf8(ws.ptr(), u.data(), a.length() * 3);
227+
return u.fix(n);
228+
}
229+
230+
String utf8ToLocal(const String& a)
231+
{
232+
Array<char> s(a.length() + 1);
233+
Array<wchar_t> ws(a.length() + 1);
234+
int n = utf8toUtf16(*a, ws.ptr(), a.length());
235+
utf16toLocal8(ws.ptr(), s.ptr(), a.length() + 1);
236+
return String(s.ptr());
237+
}
238+
214239
int String::Enumerator::operator*()
215240
{
216241
#ifdef ASL_ANSI

src/Xdl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,11 @@ void XdlParser::parse(const char* s)
559559
wchar_t u16[3] = { _wchar, wchar, 0 };
560560
char ch[9];
561561
utf16toUtf8(u16, ch, 2);
562+
#ifdef ASL_ANSI
563+
_buffer << utf8ToLocal(ch);
564+
#else
562565
_buffer << ch;
566+
#endif
563567
_unicodeCount = 0;
564568
}
565569
else if (_unicodeCount == 4) // first code
@@ -569,7 +573,11 @@ void XdlParser::parse(const char* s)
569573
wchar_t u16[2] = { wchar, 0 };
570574
char ch[8];
571575
utf16toUtf8(u16, ch, 1);
576+
#ifdef ASL_ANSI
577+
_buffer << utf8ToLocal(ch);
578+
#else
572579
_buffer << ch;
580+
#endif
573581
_unicodeCount = 0;
574582
}
575583
else

0 commit comments

Comments
 (0)