@@ -5,10 +5,10 @@ void FB_escHTML(String& s) {
55 out.reserve (s.length ());
66 for (uint16_t i = 0 ; i < s.length (); i++) {
77 switch (s[i]) {
8- case ' <' : out += F (" <" ); break ;
9- case ' >' : out += F (" >" ); break ;
10- case ' &' : out += F (" &" ); break ;
11- default : out += s[i]; break ;
8+ case ' <' : out += F (" <" ); break ;
9+ case ' >' : out += F (" >" ); break ;
10+ case ' &' : out += F (" &" ); break ;
11+ default : out += s[i]; break ;
1212 }
1313 }
1414 s = out;
@@ -26,11 +26,21 @@ void FB_escMarkdown(String& s) {
2626 s = out;
2727}
2828
29- int64_t FB_str64 (const String & s) {
29+ int64_t FB_str64 (const String& s) {
3030 return atoll (s.c_str ());
3131}
3232String FB_64str (int64_t id) {
33- return String (id);
33+ bool neg = 0 ;
34+ if (id < 0 ) id = -id, neg = 1 ;
35+ char str[21 ];
36+ char * p = str + 21 ;
37+ *--p = 0 ;
38+ do {
39+ *--p = id % 10 + ' 0' ;
40+ id /= 10 ;
41+ } while (id);
42+ if (neg) *--p = ' -' ;
43+ return p;
3444}
3545
3646// упрощённый urlencode (до 38 ASCII + space)
@@ -45,14 +55,13 @@ void FB_urlencode(const String& s, String& dest) {
4555 dest += ' %' ;
4656 dest += (char )((c >> 4 ) + (((c >> 4 ) > 9 ) ? 87 : 48 ));
4757 dest += (char )((c & 0xF ) + (((c & 0xF ) > 9 ) ? 87 : 48 ));
48- }
49- else dest += c;
58+ } else dest += c;
5059 }
5160}
5261
5362// разработано Глебом Жуковым, допилено AlexGyver
5463// https://vk.com/wall-97877471_783011
55- void FB_unicode (String & uStr) {
64+ void FB_unicode (String& uStr) {
5665 if (!uStr.length ()) return ;
5766 String out;
5867 out.reserve (uStr.length () / 3 );
@@ -62,36 +71,36 @@ void FB_unicode(String &uStr) {
6271 if (uStr[i] != ' \\ ' ) out += uStr[i];
6372 else {
6473 switch (uStr[++i]) {
65- case ' 0' : break ;
66- case ' n' : out += ' \n ' ; break ;
67- case ' r' : out += ' \r ' ; break ;
68- case ' t' : out += ' \t ' ; break ;
69- case ' u' :
70- uBytes = strtol (uStr.substring (i + 1 , i + 5 ).c_str (), NULL , HEX);
71- i += 4 ;
72- if ((uBytes >= 0xD800 ) && (uBytes <= 0xDBFF )) buf = uBytes;
73- else if ((uBytes >= 0xDC00 ) && (uBytes <= 0xDFFF )) {
74- uBytes = (0x10000 + ((buf - 0xD800 ) * 0x0400 ) + (uBytes - 0xDC00 ));
75- out += (char )(0b11110000 | ((uBytes >> 18 ) & 0b111 ));
76- out += x0;
77- out += (char )(0b10000000 | ((uBytes >> 12 ) & 0b111111 ));
78- out += x0;
79- out += (char )(0b10000000 | ((uBytes >> 6 ) & 0b111111 ));
80- out += x0;
81- out += (char )(0b10000000 | (uBytes & 0b111111 ));
82- } else if (uBytes < 0x800 ) {
83- out += (char )(0b11000000 | ((uBytes >> 6 ) & 0b11111 ));
84- out += x0;
85- out += (char )(0b10000000 | (uBytes & 0b111111 ));
86- } else if (uBytes >= 0x800 ) {
87- out += (char )(0b11100000 | ((uBytes >> 12 ) & 0b1111 ));
88- out += x0;
89- out += (char )(0b10000000 | ((uBytes >> 6 ) & 0b111111 ));
90- out += x0;
91- out += (char )(0b10000000 | (uBytes & 0b111111 ));
92- }
93- break ;
94- default : out += uStr[i]; break ;
74+ case ' 0' : break ;
75+ case ' n' : out += ' \n ' ; break ;
76+ case ' r' : out += ' \r ' ; break ;
77+ case ' t' : out += ' \t ' ; break ;
78+ case ' u' :
79+ uBytes = strtol (uStr.substring (i + 1 , i + 5 ).c_str (), NULL , HEX);
80+ i += 4 ;
81+ if ((uBytes >= 0xD800 ) && (uBytes <= 0xDBFF )) buf = uBytes;
82+ else if ((uBytes >= 0xDC00 ) && (uBytes <= 0xDFFF )) {
83+ uBytes = (0x10000 + ((buf - 0xD800 ) * 0x0400 ) + (uBytes - 0xDC00 ));
84+ out += (char )(0b11110000 | ((uBytes >> 18 ) & 0b111 ));
85+ out += x0;
86+ out += (char )(0b10000000 | ((uBytes >> 12 ) & 0b111111 ));
87+ out += x0;
88+ out += (char )(0b10000000 | ((uBytes >> 6 ) & 0b111111 ));
89+ out += x0;
90+ out += (char )(0b10000000 | (uBytes & 0b111111 ));
91+ } else if (uBytes < 0x800 ) {
92+ out += (char )(0b11000000 | ((uBytes >> 6 ) & 0b11111 ));
93+ out += x0;
94+ out += (char )(0b10000000 | (uBytes & 0b111111 ));
95+ } else if (uBytes >= 0x800 ) {
96+ out += (char )(0b11100000 | ((uBytes >> 12 ) & 0b1111 ));
97+ out += x0;
98+ out += (char )(0b10000000 | ((uBytes >> 6 ) & 0b111111 ));
99+ out += x0;
100+ out += (char )(0b10000000 | (uBytes & 0b111111 ));
101+ }
102+ break ;
103+ default : out += uStr[i]; break ;
95104 }
96105 }
97106 }
0 commit comments