1 #include "util_string.h"
2 #include "util_const.h"
3 #include "util_random.h"
4 #include "util_splitter.h"
11 #include <boost/regex.hpp>
12 #include <boost/regex/pattern_except.hpp>
13 #include <boost/algorithm/string.hpp>
23 UIConv::UIConv (const char* in, const char* out) {
24 cd = iconv_open (in, out);
25 if (cd == ICONV_ERR) {
26 throw (ustring (in).append (CharConst (", ")).append (ustring (out)).append (CharConst (": unknown encoding.")));
30 ustring UIConv::cv (const ustring& text) {
33 if (cd != ICONV_ERR) {
34 char* buf = new char[4096];
37 size_t isize, osize, rsize;
39 ibuf = text.begin ().base ();
45 rsize = ::iconv (cd, (char**)&ibuf, &isize, &obuf, &osize);
47 rsize = ::iconv (cd, &ibuf, &isize, &obuf, &osize);
50 if (errno == EILSEQ) {
53 ans.append (CharConst ("_"));
54 } else if (errno == EINVAL) {
55 } else if (errno == E2BIG) {
61 ans.append (buf, obuf - buf);
68 ustring c3 (const ustring& str) {
70 static uregex re ("^[0-9]+");
76 if (str[0] == '-' || str[0] == '+') {
80 if (usearch (b, e, m, re)) {
81 int n = m[0].second - m[0].first;
82 int l = str.size () + n / 3;
87 ans.append (1, str[0]);
89 for (; b != m[0].second; b ++) {
91 if (n > 1 && n % 3 == 1) {
92 ans.append (CharConst (","));
96 for (; b != e; b ++) {
105 ustring to_ustring (double val) {
107 return ustring (b, snprintf (b, 32, "%.*g", DBL_DIG, val));
110 static int hex (char c) {
111 if ('0' <= c && c <= '9') {
113 } else if ('a' <= c && c <= 'f') {
114 return (c - 'a' + 10);
115 } else if ('A' <= c && c <= 'F') {
116 return (c - 'A' + 10);
122 static int hex (char c1, char c2) {
123 return (hex (c1) * 16 + hex (c2));
126 static char hexchar (int c) {
127 if (0 <= c && c <= 9)
129 else if (10 <= c <= 15)
135 static char hexchar_c (int c) {
136 if (0 <= c && c <= 9)
138 else if (10 <= c <= 15)
144 static ustring percentHex (int c) {
145 ustring ans (3, '%');
147 ans[1] = hexchar ((c >> 4) & 0x0f);
148 ans[2] = hexchar (c & 0x0f);
152 ustring percentHEX (int c) {
153 ustring ans (3, '%');
155 ans[1] = hexchar_c ((c >> 4) & 0x0f);
156 ans[2] = hexchar_c (c & 0x0f);
160 ustring urldecode_nonul (const ustring& str) {
162 static uregex re ("(\\+)|%([0-9a-fA-F][0-9a-fA-F])|\\x00");
166 ans.reserve (str.size ());
169 while (usearch (b, e, m, re)) {
170 if (b != m[0].first) {
171 ans.append (b, m[0].first);
175 } else if (m[2].matched) {
176 int v = hex (*(m[2].first), *(m[2].first + 1));
190 ustring omitPattern (const ustring& text, uregex& re) {
191 Splitter sp (text, re);
196 ans.reserve (text.length ());
197 if (sp.begin () != sp.end ())
198 ans.append (sp.begin (), sp.end ());
200 if (sp.begin () != sp.end ())
201 ans.append (sp.begin (), sp.end ());
212 ustring omitCtrl (const ustring& str) {
213 static uregex re ("[\\x00-\\x1f\\x7f]+");
214 return omitPattern (str, re);
217 ustring omitCtrlX (const ustring& str) {
218 static uregex re ("[^\\x09\\x0a\\x20-\\x7e\\x80-\\xff]+");
219 return omitPattern (str, re);
222 ustring omitNul (const ustring& str) {
223 static uregex re ("[\\x00]+");
224 return omitPattern (str, re);
227 ustring omitNL (const ustring& str) {
228 return omitPattern (str, re_nl);
231 ustring omitNonAscii (const ustring& str) {
232 static uregex re ("[^ -\\x7e]+");
233 return omitPattern (str, re);
236 ustring omitNonAsciiWord (const ustring& str) {
237 static uregex re ("[^\\x21-\\x7e]+");
238 return omitPattern (str, re);
241 static ustring percentEncode (uiterator b, uiterator e, const uregex& re) {
247 while (b < e && usearch (b, e, m, re)) {
249 ans.append (b, m[0].first);
251 ans.append (uUScore);
252 } else if (m[2].matched) {
253 ans.append (percentHEX (*m[2].first));
265 ustring percentEncode (uiterator b, uiterator e) {
266 static uregex re ("(\\x00)|([^A-Za-z0-9_.~-])");
268 return percentEncode (b, e, re);
271 ustring percentEncode_path (uiterator b, uiterator e) {
272 static uregex re ("(\\x00)|([^A-Za-z0-9_/.~-])");
274 return percentEncode (b, e, re);
277 ustring percentEncode (const ustring& str) {
278 return percentEncode (str.begin (), str.end ());
281 ustring percentEncode_path (const ustring& str) {
282 return percentEncode_path (str.begin (), str.end ());
286 ustring percentEncode_path (uiterator b, uiterator e) {
290 for (i = b; i < e; i ++) {
293 ans.append (percentEncode (b, i));
299 ans.append (percentEncode (b, e));
304 ustring percentEncode_path (const ustring& str) {
305 return percentEncode_path (str.begin (), str.end ());
309 ustring percentDecode (const ustring& str) {
311 static uregex re ("%([0-9a-fA-F][0-9a-fA-F])|\\x00");
317 while (usearch (b, e, m, re)) {
318 if (b != m[0].first) {
319 ans.append (b, m[0].first);
322 int v = hex (*(m[1].first), *(m[1].first + 1));
333 return fixUTF8 (ans);
336 ustring cookieencode (const ustring& text) {
337 static uregex re ("([\\x00-\\x1f\\x7f])|([ ,;%\\x80-\\xff])");
339 return percentEncode (text.begin (), text.end (), re);
342 ustring cookiedecode (const ustring& text) {
347 static uregex re ("%([0-9a-fA-F])([0-9a-fA-F])");
351 while (usearch (b, e, m, re)) {
353 ans.append (ustring (b, m[0].first));
354 a = hex (*m[1].first, *m[2].first);
359 ans.append (ustring (b, e));
364 ustring clipColon (const ustring& text) {
368 for (i = 0; i < ans.size (); i ++) {
375 ustring dirPart (const ustring& path) {
376 ustring::size_type s = path.rfind ('/', path.size ());
378 if (s == ustring::npos) {
382 return ustring (path.begin (), path.begin () + s);
386 ustring filePart_osSafe (const ustring& path) {
388 static uregex re ("[^\\\\/]+$");
390 if (usearch (path, m, re)) {
391 return ustring (m[0].first, m[0].second);
397 void split (uiterator b, uiterator e, uregex& re, std::vector<ustring>& ans) {
398 Splitter sp (b, e, re);
401 ans.push_back (sp.cur ());
405 void splitE (uiterator b, uiterator e, uregex& re, std::vector<ustring>& ans) {
406 Splitter sp (b, e, re);
409 while (sp.nextSep ()) {
410 ans.push_back (sp.cur ());
412 ans.push_back (ustring (sp.begin (), sp.eol ()));
416 bool splitChar (uiterator b, uiterator e, uiterator::value_type ch, uiterator& m1) {
417 for (; b < e; b ++) {
427 ustring escape_re (const ustring& text) {
428 ustring::const_iterator b, e;
433 static uregex re ("[^\\x01- !\"#%',/0-9:;<=>@A-Z_`a-z~\\x7f-\\xff-]");
437 ans.reserve (text.size () + 16);
440 while (b != e && usearch (b, e, m, re)) {
442 ans.append (b, m[0].first);
444 buf[2] = hexchar ((c >> 4) & 0x0f);
445 buf[3] = hexchar (c & 0x0f);
454 ustring slashEncode (const ustring& text) {
455 ustring::const_iterator b, e;
460 static uregex re ("([\\x00-\\x1f\\x7f])|(\\\\)|(\")");
466 while (b != e && usearch (b, e, m, re)) {
468 ans.append (b, m[0].first);
473 ans.append (CharConst ("\\t"));
476 ans.append (CharConst ("\\r"));
479 ans.append (CharConst ("\\n"));
482 buf[2] = hexchar ((c >> 4) & 0x0f);
483 buf[3] = hexchar (c & 0x0f);
486 } else if (m[2].matched) {
487 ans.append (CharConst ("\\\\"));
488 } else if (m[3].matched) {
489 ans.append (CharConst ("\\\""));
500 ustring slashDecode (const ustring& text) {
501 ustring::const_iterator b, e;
505 static uregex re ("\\\\([0-7][0-7][0-7]|[\\x00-\\x7f])");
509 while (b != e && usearch (b, e, m, re)) {
511 ans.append (b, m[0].first);
516 ans.append (CharConst ("\t"));
519 ans.append (CharConst ("\r"));
522 ans.append (CharConst ("\n"));
525 if (m[0].second - m[0].first == 4) {
531 if (0 < c && c < 0x20)
544 unsigned long strtoul (const ustring& str) {
545 return strtoul (str.c_str (), NULL, 10);
548 unsigned long strtoul (const uiterator& b) {
549 return strtoul (&*b, NULL, 10);
552 long strtol (const ustring& str) {
553 return strtol (str.c_str (), NULL, 10);
556 double strtod (const ustring& str) {
557 return strtod (str.c_str (), NULL);
560 bool passMatch (const ustring& pass, const ustring& cpass) {
561 if (pass.length () == 0 || cpass.length () == 0)
563 return (strcmp (crypt (pass.c_str (), cpass.c_str ()), cpass.c_str ()) == 0);
566 ustring passCrypt (const ustring& pass) {
567 ustring salt = makeSalt ();
568 return ustring (crypt (pass.c_str (), salt.c_str ()));
571 size_t strLength (const ustring& src) {
583 void substring (const ustring& src, size_t idx, size_t len, int flen, ustring& ans) {
589 for (i = 0; i < idx && b < e; i ++)
593 for (i = 0; i < len && t < e; i ++)
601 static bool jssafe[] = {
602 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0--15
603 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 16--31
604 1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1, // 32--47
605 1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0, // 48--63
606 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 64--79
607 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, // 80--95
608 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 96--111
609 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 112--127
612 ustring jsEncode (const ustring& str) {
619 ans.reserve (u.size () * 3);
622 for (i = 0; i < u.size (); i += 2) {
625 if (c == 0 && 0 < d && d < 127 && jssafe[d]) {
628 b[2] = hexchar ((c >> 4) & 0x0f);
629 b[3] = hexchar (c & 0x0f);
630 b[4] = hexchar ((d >> 4) & 0x0f);
631 b[5] = hexchar (d & 0x0f);
638 ustring filenameEncode (const ustring& text) {
639 static uregex re ("([\\x00-\\x1f\\x7f])|([^a-zA-Z0-9._-])|(^\\.+)");
640 Splitter sp (text, re);
644 if (text.length () == 0) {
645 throw (ustring (text).append (uErrorBadName));
647 ans.reserve (text.length () + 16);
649 if (sp.begin () < sp.end ())
650 ans.append (sp.begin (), sp.end ());
652 } else if (sp.match (2)) {
653 c = *sp.matchBegin (2);
655 ans.append (1, hexchar ((c >> 4) & 0x0f));
656 ans.append (1, hexchar (c & 0x0f));
657 } else if (sp.match (3)) {
658 for (c = sp.matchEnd (3) - sp.matchBegin (3); c > 0; c --) {
659 ans.append (CharConst (":2e"));
663 if (ans.length () > 250)
668 ustring filenameDecode (const ustring& text) {
669 static uregex re (":([0-9a-fA-F][0-9a-fA-F])");
670 Splitter sp (text, re);
674 ans.reserve (text.length ());
676 if (sp.begin () < sp.end ())
677 ans.append (sp.begin (), sp.end ());
679 c = hex (*(sp.matchBegin (1))) * 16 + hex (*(sp.matchBegin (1) + 1));
680 if (32 <= c && c < 256)
687 bool matchSkip (uiterator& b, uiterator e, const char* t, size_t s) {
688 if (e - b >= s && memcmp (t, &b[0], s) == 0) {
696 bool matchHead (uiterator& b, uiterator e, const char* t, size_t s) {
697 if (e - b >= s && memcmp (t, &b[0], s) == 0) {
704 bool matchHead (const ustring& str, const char* t, size_t s) {
705 if (str.length () >= s && memcmp (t, &*str.begin (), s) == 0) {
712 bool matchHead (const ustring& str, const ustring& head) {
713 if (str.length () >= head.length () && memcmp (&*str.begin (), &*head.begin (), head.length ()) == 0) {
720 bool match (uiterator b, uiterator e, const char* t, size_t s) {
721 if (e - b == s && memcmp (t, &b[0], s) == 0) {
728 bool match (const ustring& str, const char* t, size_t s) {
729 if (str.length () == s && memcmp (t, str.data (), s) == 0) {
736 bool match (uiterator b, uiterator e, const ustring& str) {
737 if (e - b == str.length () && memcmp (str.data (), &b[0], str.length ()) == 0) {
744 bool match (const ustring& str, const char* t, size_t s, const char* t2, size_t s2) {
745 if (match (str, t, s) || match (str, t2, s2)) {
752 ustring clipWhite (uiterator b, uiterator e) {
760 if (isblank (*(e - 1))) {
765 return ustring (b, e);
767 ustring clipWhite (const ustring& str) {
768 return clipWhite (str.begin (), str.end ());
771 ustring getenvString (const char* key) {
772 char* e = getenv (key);
780 ustring zeroPad (int n, const ustring& src) {
783 n = std::min (32, n);
784 m = n - src.length ();
796 bool wsearch (const ustring& text, boost::wsmatch& m, const ustring& reg, boost::wregex::flag_type reg_flags, boost::match_flag_type search_flags) {
798 std::wstring wtext = utow (text);
799 std::wstring wreg = utow (reg);
800 boost::wregex wre (wreg, reg_flags);
801 return regex_search (wtext, m, wre, search_flags);
802 } catch (boost::regex_error& err) {
803 throw (uErrorRegexp);
807 bool wsearch_env (MlEnv* mlenv, const ustring& text, const ustring& reg, boost::wregex::flag_type reg_flags, boost::match_flag_type search_flags) {
809 mlenv->regtext = utow (text);
810 std::wstring wreg = utow (reg);
811 boost::wregex wre (wreg, reg_flags);
812 return regex_search (mlenv->regtext, mlenv->regmatch, wre, search_flags);
813 } catch (boost::regex_error& err) {
814 throw (uErrorRegexp);
818 ustring wreplace (const ustring& text, const ustring& reg, const ustring& fmt, boost::wregex::flag_type reg_flags, boost::match_flag_type match_flags) {
820 std::wstring wtext = utow (text);
821 std::wstring wreg = utow (reg);
822 std::wstring wfmt = utow (fmt);
823 boost::wregex wre (wreg, reg_flags);
824 std::wstring ans = regex_replace (wtext, wre, wfmt, match_flags);
826 } catch (boost::regex_error& err) {
827 throw (uErrorRegexp);
831 ustring padEmpty (const ustring& name) {
833 return ustring (CharConst ("(null)"));
838 uint32_t hextoul (uiterator b, uiterator e) {
842 for (n = 0; n < 8 && b != e; n ++, b ++) {
843 ans = (ans << 4) + hex (*b);
848 ustring toCRLF (const ustring& str) {
849 uiterator b = str.begin ();
850 uiterator e = str.end ();
854 while (usearch (b, e, m, re_lf)) {
855 ans.append (b, m[0].first).append (uCRLF);
862 void skipSpace (uiterator& b, uiterator e) {
863 while (b < e && *b == ' ') {
868 static ustring::value_type toLower_ustring_value (ustring::value_type v) {
869 if ('A' <= v && v <= 'Z') {
870 return v - 'A' + 'a';
876 ustring toLower (uiterator b, uiterator e) {
881 for (; b < e; b ++, i++) {
882 *i = toLower_ustring_value (*b);
887 static void format_hex (ustring& ans, MNode* a, std::vector<ustring>& par, bool fcap) {
894 if (par.size () > 0) {
895 int p = strtol (par[0]);
901 ans.append (buf, snprintf (buf, 32, "%.*X", p, v));
903 ans.append (buf, snprintf (buf, 32, "%.*x", p, v));
906 ans.append (buf, snprintf (buf, 32, "%X", v));
908 ans.append (buf, snprintf (buf, 32, "%x", v));
912 static void format_hex (ustring& ans, MNode* a, std::vector<ustring>& par) {
913 format_hex (ans, a, par, false);
916 static void format_HEX (ustring& ans, MNode* a, std::vector<ustring>& par) {
917 format_hex (ans, a, par, true);
920 static void format_int_sub (ustring& ans, MNode* a, std::vector<ustring>& par, bool pad0 = false) {
928 if (par.size () > 0) {
932 if (match (par[0], CharConst ("comma")) || match (par[0], CharConst ("c"))) {
933 ans.append (c3 (to_ustring (v)));
935 int p = strtol (par[0]);
940 for (int i = 1; i < par.size (); i ++) {
941 if (match (par[i], CharConst ("clip"))) {
943 } else if (match (par[i], CharConst ("0"))) {
945 } else if (match (par[i], CharConst ("comma")) || match (par[i], CharConst ("c"))) {
948 throw (par[i] + uErrorBadParam);
952 s = snprintf (buf, 32, "%.*d", p, v);
954 s = snprintf (buf, 32, "%*d", p, v);
956 ans.append (buf + s - p, p);
957 else if (! fclip && fc3)
958 ans.append (c3 (ustring (buf, s)));
963 ans.append (to_ustring (v));
967 static void format_int (ustring& ans, MNode* a, std::vector<ustring>& par) {
968 format_int_sub (ans, a, par);
971 static void format_int0 (ustring& ans, MNode* a, std::vector<ustring>& par) {
972 format_int_sub (ans, a, par, true);
975 static void format_int (ustring& ans, MNode* a, int c, bool pad0 = false) {
987 s = snprintf (buf, 32, "%.*d", c, v);
989 s = snprintf (buf, 32, "%*d", c, v);
991 ans.append (buf + s - c, c);
995 ans.append (to_ustring (v));
999 static void format_float (ustring& ans, MNode* a, std::vector<ustring>& par) {
1004 if (par.size () > 0)
1005 p1 = strtol (par[0]);
1006 if (par.size () > 1)
1007 p2 = strtol (par[1]);
1016 ans.append (buf, snprintf (buf, 32, "%*.*lf", p1, p2, to_double (a)));
1019 static void format_string (ustring& ans, MNode* a, std::vector<ustring>& par) {
1021 bool fright = false;
1022 ustring u = to_string (a);
1024 if (par.size () > 0)
1025 p = strtol (par[0]);
1028 if (par.size () > 1) {
1029 if (match (par[1], CharConst ("right")) || match (par[1], CharConst ("r")))
1032 throw (par[1] + uErrorBadParam);
1036 ans.append (p - u.size (), ' ').append (u);
1041 ans.append (u).append (p - u.size (), ' ');
1047 static void format_literal (ustring& ans, MNode* a, const char* list[], int offset, size_t size) {
1051 v = to_int (a) - offset;
1052 if (0 <= v && v < size)
1053 ans.append (list[v]);
1057 static const char* mstr_a[] = {
1058 "Jan", "Feb", "Mar", "Apr",
1059 "May", "Jun", "Jul", "Aug",
1060 "Sep", "Oct", "Nov", "Dec"
1062 static const char* mstr[] = {
1063 "January", "February", "March", "April",
1064 "May", "June", "July", "August",
1065 "September", "October", "November", "December"
1067 static void format_month (ustring& ans, MNode* a, std::vector<ustring>& par) {
1068 format_literal (ans, a, mstr_a, 1, 12);
1071 static void format_Month (ustring& ans, MNode* a, std::vector<ustring>& par) {
1072 format_literal (ans, a, mstr, 1, 12);
1075 static const char* WStr_a[] = {
1076 "Sun", "Mon", "Tue", "Wed",
1080 static const char* WStr[] = {
1081 "Sunday", "Monday", "Tuesday", "Wednesday",
1082 "Thursday", "Friday", "Saturday"
1085 static void format_week (ustring& ans, MNode* a, std::vector<ustring>& par) {
1086 format_literal (ans, a, WStr_a, 0, 7);
1089 static void format_Week (ustring& ans, MNode* a, std::vector<ustring>& par) {
1090 format_literal (ans, a, WStr, 0, 7);
1093 ustring formatString (const ustring& format, boost::ptr_vector<MNodePtr>& par) {
1099 static uregex re ("\\$\\{([1-9][0-9]*)(:([a-zA-Z][a-zA-Z0-9]*)(:([0-9a-z.:]+))?)?\\}");
1103 void (*fn)(ustring& ans, MNode* a, std::vector<ustring>& par);
1105 {CharConst ("hex"), format_hex},
1106 {CharConst ("HEX"), format_HEX},
1107 {CharConst ("int"), format_int},
1108 {CharConst ("int0"), format_int0},
1109 {CharConst ("float"), format_float},
1110 {CharConst ("string"), format_string},
1111 {CharConst ("month"), format_month},
1112 {CharConst ("Month"), format_Month},
1113 {CharConst ("week"), format_week},
1114 {CharConst ("Week"), format_Week},
1118 b = format.begin ();
1120 while (usearch (b, e, m, re)) {
1121 ans.append (b, m[0].first);
1123 i = strtoul (ustring (m[1].first, m[1].second)) - 1;
1124 if (i < par.size ()) {
1129 if (! m[2].matched) {
1131 ans.append (to_string (a));
1133 std::vector<ustring> fpar;
1136 split (m[5].first, m[5].second, re_colon, fpar);
1137 for (i = 0; formatFunc[i].name; i ++) {
1138 if (match (m[3].first, m[3].second, formatFunc[i].name, formatFunc[i].namelen)) {
1139 (*formatFunc[i].fn) (ans, a, fpar);
1143 ans.append (m[0].first, m[0].second);
1152 static ustring colpad0 (int n, const ustring& src) {
1156 n = std::min (32, n);
1157 m = n - src.length ();
1161 ans.append (m, '0');
1164 } else if (m == 0) {
1167 return ustring (src.end () - n, src.end ());
1176 ${M:2}, ${M}, ${M:name}, ${M:ab}
1184 //ustring formatDateString (const ustring& format, time_t tm) {
1185 ustring formatDateString (const ustring& format, struct tm& v) {
1191 // static uregex re ("\\$\\{([YMDhmsWw])(:([0-9]))?\\}");
1192 static uregex re ("\\$\\{(([YMDhmsWwo])(:([0-9]))?|M:((name)|(ab)|(abname)))\\}");
1193 std::vector<ustring> fpar;
1195 // localtime_r (&tm, &v);
1196 b = format.begin ();
1198 while (usearch (b, e, m, re)) {
1199 ans.append (b, m[0].first);
1202 if (m[6].matched) { // name
1203 ans.append (mstr[v.tm_mon]);
1204 } else if (m[7].matched || m[8].matched) { // abname
1205 ans.append (mstr_a[v.tm_mon]);
1208 // if (m[2].matched) {
1210 // pc = strtol (ustring (m[3].first, m[3].second));
1211 pc = strtol (ustring (m[4].first, m[4].second));
1215 // switch (*m[1].first) {
1216 switch (*m[2].first) {
1218 ans.append (colpad0 (pc, to_ustring (v.tm_year + 1900)));
1221 ans.append (colpad0 (pc, to_ustring (v.tm_mon + 1)));
1224 ans.append (colpad0 (pc, to_ustring (v.tm_mday)));
1227 ans.append (colpad0 (pc, to_ustring (v.tm_hour)));
1230 ans.append (colpad0 (pc, to_ustring (v.tm_min)));
1233 ans.append (colpad0 (pc, to_ustring (v.tm_sec)));
1236 ans.append (WStr [v.tm_wday]);
1239 ans.append (WStr_a [v.tm_wday]);
1244 if (v.tm_gmtoff < 0) {
1245 h = - v.tm_gmtoff / 60;
1248 ans.append (CharConst ("-")).append (colpad0 (4, to_ustring (h * 100 + m)));
1250 h = v.tm_gmtoff / 60;
1253 ans.append (CharConst ("+")).append (colpad0 (4, to_ustring (h * 100 + m)));
1265 ustring toLower (const ustring& str) {
1266 return boost::to_lower_copy (str);
1269 ustring toUpper (const ustring& str) {
1270 return boost::to_upper_copy (str);
1273 ustring hexEncode (const ustring& data) {
1277 ans.reserve (data.length () * 2);
1280 for (; b < e; b ++) {
1281 ans.append (1, hexchar ((*b >> 4) & 0x0f));
1282 ans.append (1, hexchar (*b & 0x0f));