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 static 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 static 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 omitNul (const ustring& str) {
218 static uregex re ("[\\x00]+");
219 return omitPattern (str, re);
222 ustring omitNL (const ustring& str) {
223 return omitPattern (str, re_nl);
226 ustring omitNonAscii (const ustring& str) {
227 static uregex re ("[^ -\\x7e]+");
228 return omitPattern (str, re);
231 ustring omitNonAsciiWord (const ustring& str) {
232 static uregex re ("[^\\x21-\\x7e]+");
233 return omitPattern (str, re);
236 bool to_bool (const ustring& v) {
237 if (v.length () == 0 || (v.length () == 1 && v[0] == '0')) {
245 static ustring percentEncode (const ustring& text, uregex& re) {
255 if (b != e && usearch (b, e, m, re)) {
256 if (b != m[0].first) {
257 ans.append (ustring (b, m[0].first));
260 ans.append (uUScore);
261 } else if (m[2].matched) {
262 ans.append (percentHex (*m[2].first));
267 while (b != e && usearch (b, e, m, re)) {
268 if (b != m[0].first) {
269 ans.append (ustring (b, m[0].first));
272 ans.append (uUScore);
273 } else if (m[2].matched) {
274 ans.append (percentHex (*m[2].first));
281 ans.append (ustring (b, e));
290 static ustring percentEncode (uiterator b, uiterator e, const uregex& re) {
296 while (b < e && usearch (b, e, m, re)) {
298 ans.append (b, m[0].first);
300 ans.append (uUScore);
301 } else if (m[2].matched) {
302 ans.append (percentHEX (*m[2].first));
315 ustring urlencode (const ustring& url) {
316 static uregex re ("(\\x00)|([^a-zA-Z0-9_.,/\x80-\xff-])");
318 return percentEncode (url, re);
322 ustring percentEncode (uiterator b, uiterator e) {
323 static uregex re ("(\\x00)|([^A-Za-z0-9_.~-])");
325 return percentEncode (b, e, re);
328 ustring percentEncode (const ustring& str) {
329 return percentEncode (str.begin (), str.end ());
332 ustring percentEncode_path (uiterator b, uiterator e) {
336 for (i = b; i < e; i ++) {
339 ans.append (percentEncode (b, i));
340 ans.append (CharConst ("/"));
345 ans.append (percentEncode (b, e));
350 ustring percentEncode_path (const ustring& str) {
351 return percentEncode_path (str.begin (), str.end ());
354 ustring percentDecode (const ustring& str) {
356 static uregex re ("%([0-9a-fA-F][0-9a-fA-F])|\\x00");
362 while (usearch (b, e, m, re)) {
363 if (b != m[0].first) {
364 ans.append (b, m[0].first);
367 int v = hex (*(m[1].first), *(m[1].first + 1));
378 return fixUTF8 (ans);
381 ustring cookieencode (const ustring& text) {
382 static uregex re ("([\\x00-\\x1f\\x7f])|([ ,;%\\x80-\\xff])");
384 return percentEncode (text.begin (), text.end (), re);
387 ustring cookiedecode (const ustring& text) {
392 static uregex re ("%([0-9a-fA-F])([0-9a-fA-F])");
396 while (usearch (b, e, m, re)) {
398 ans.append (ustring (b, m[0].first));
399 a = hex (*m[1].first, *m[2].first);
404 ans.append (ustring (b, e));
409 ustring clipColon (const ustring& text) {
413 for (i = 0; i < ans.size (); i ++) {
420 ustring dirPart (char* path) {
421 char* e = rindex (path, '/');
423 if (e && e != path) {
424 return ustring (path, e - path);
430 ustring dirPart (const ustring& path) {
431 ustring::size_type s = path.rfind ('/', path.size ());
433 if (s == ustring::npos) {
436 return ustring (path.begin (), path.begin () + s);
440 ustring filePart_osSafe (const ustring& path) {
442 static uregex re ("[^\\\\/]+$");
444 if (usearch (path, m, re)) {
445 return ustring (m[0].first, m[0].second);
451 void split (uiterator b, uiterator e, uregex& re, std::vector<ustring>& ans) {
452 Splitter sp (b, e, re);
455 ans.push_back (sp.cur ());
459 void splitE (uiterator b, uiterator e, uregex& re, std::vector<ustring>& ans) {
460 Splitter sp (b, e, re);
463 while (sp.nextSep ()) {
464 ans.push_back (sp.cur ());
466 ans.push_back (ustring (sp.begin (), sp.eol ()));
470 bool splitChar (uiterator b, uiterator e, uiterator::value_type ch, uiterator& m1) {
471 for (; b < e; b ++) {
481 ustring escape_re (const ustring& text) {
482 ustring::const_iterator b, e;
487 static uregex re ("[^\\x01- !\"#%',/0-9:;<=>@A-Z_`a-z~\\x7f-\\xff-]");
491 ans.reserve (text.size () + 16);
494 while (b != e && usearch (b, e, m, re)) {
496 ans.append (b, m[0].first);
498 buf[2] = hexchar ((c >> 4) & 0x0f);
499 buf[3] = hexchar (c & 0x0f);
508 ustring slashEncode (const ustring& text) {
509 ustring::const_iterator b, e;
514 static uregex re ("([\\x00-\\x1f\\x7f])|(\\\\)|(\")");
520 while (b != e && usearch (b, e, m, re)) {
522 ans.append (b, m[0].first);
527 ans.append (CharConst ("\\t"));
530 ans.append (CharConst ("\\r"));
533 ans.append (CharConst ("\\n"));
536 buf[2] = hexchar ((c >> 4) & 0x0f);
537 buf[3] = hexchar (c & 0x0f);
540 } else if (m[2].matched) {
541 ans.append (CharConst ("\\\\"));
542 } else if (m[3].matched) {
543 ans.append (CharConst ("\\\""));
554 ustring slashDecode (const ustring& text) {
555 ustring::const_iterator b, e;
559 static uregex re ("\\\\([0-7][0-7][0-7]|[\\x00-\\x7f])");
563 while (b != e && usearch (b, e, m, re)) {
565 ans.append (b, m[0].first);
570 ans.append (CharConst ("\t"));
573 ans.append (CharConst ("\r"));
576 ans.append (CharConst ("\n"));
579 if (m[0].second - m[0].first == 4) {
585 if (0 < c && c < 0x20)
598 unsigned long strtoul (const ustring& str) {
599 return strtoul (str.c_str (), NULL, 10);
602 unsigned long strtoul (const uiterator& b) {
603 return strtoul (&*b, NULL, 10);
606 long strtol (const ustring& str) {
607 return strtol (str.c_str (), NULL, 10);
610 double strtod (const ustring& str) {
611 return strtod (str.c_str (), NULL);
614 bool passMatch (const ustring& pass, const ustring& cpass) {
615 if (pass.length () == 0 || cpass.length () == 0)
617 return (strcmp (crypt (pass.c_str (), cpass.c_str ()), cpass.c_str ()) == 0);
620 ustring passCrypt (const ustring& pass) {
621 ustring salt = makeSalt ();
622 return ustring (crypt (pass.c_str (), salt.c_str ()));
625 size_t strLength (const ustring& src) {
637 void substring (const ustring& src, size_t idx, size_t len, int flen, ustring& ans) {
643 for (i = 0; i < idx && b < e; i ++)
647 for (i = 0; i < len && t < e; i ++)
655 static bool jssafe[] = {
656 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0--15
657 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 16--31
658 1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1, // 32--47
659 1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0, // 48--63
660 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 64--79
661 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, // 80--95
662 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 96--111
663 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 112--127
666 ustring jsEncode (const ustring& str) {
673 ans.reserve (u.size () * 3);
676 for (i = 0; i < u.size (); i += 2) {
679 if (c == 0 && 0 < d && d < 127 && jssafe[d]) {
682 b[2] = hexchar ((c >> 4) & 0x0f);
683 b[3] = hexchar (c & 0x0f);
684 b[4] = hexchar ((d >> 4) & 0x0f);
685 b[5] = hexchar (d & 0x0f);
692 ustring filenameEncode (const ustring& text) {
693 static uregex re ("([\\x00-\\x1f\\x7f])|([^a-zA-Z0-9._-])|(^\\.+)");
694 Splitter sp (text, re);
698 if (text.length () == 0) {
699 throw (ustring (text).append (uErrorBadName));
701 ans.reserve (text.length () + 16);
703 if (sp.begin () < sp.end ())
704 ans.append (sp.begin (), sp.end ());
706 } else if (sp.match (2)) {
707 c = *sp.matchBegin (2);
709 ans.append (1, hexchar ((c >> 4) & 0x0f));
710 ans.append (1, hexchar (c & 0x0f));
711 } else if (sp.match (3)) {
712 for (c = sp.matchEnd (3) - sp.matchBegin (3); c > 0; c --) {
713 ans.append (CharConst (":2e"));
717 if (ans.length () > 250)
722 ustring filenameDecode (const ustring& text) {
723 static uregex re (":([0-9a-fA-F][0-9a-fA-F])");
724 Splitter sp (text, re);
728 ans.reserve (text.length ());
730 if (sp.begin () < sp.end ())
731 ans.append (sp.begin (), sp.end ());
733 c = hex (*(sp.matchBegin (1))) * 16 + hex (*(sp.matchBegin (1) + 1));
734 if (32 <= c && c < 256)
741 bool matchSkip (uiterator& b, uiterator e, const char* t, size_t s) {
742 if (e - b >= s && memcmp (t, &b[0], s) == 0) {
750 bool matchHead (uiterator& b, uiterator e, const char* t, size_t s) {
751 if (e - b >= s && memcmp (t, &b[0], s) == 0) {
758 bool matchHead (const ustring& str, const char* t, size_t s) {
759 if (str.length () >= s && memcmp (t, &*str.begin (), s) == 0) {
766 bool matchHead (const ustring& str, const ustring& head) {
767 if (str.length () >= head.length () && memcmp (&*str.begin (), &*head.begin (), head.length ()) == 0) {
774 bool match (uiterator b, uiterator e, const char* t, size_t s) {
775 if (e - b == s && memcmp (t, &b[0], s) == 0) {
782 bool match (const ustring& str, const char* t, size_t s) {
783 if (str.length () == s && memcmp (t, str.data (), s) == 0) {
790 bool match (uiterator b, uiterator e, const ustring& str) {
791 if (e - b == str.length () && memcmp (str.data (), &b[0], str.length ()) == 0) {
798 bool match (const ustring& str, const char* t, size_t s, const char* t2, size_t s2) {
799 if (match (str, t, s) || match (str, t2, s2)) {
806 ustring clipWhite (uiterator b, uiterator e) {
814 if (isblank (*(e - 1))) {
819 return ustring (b, e);
821 ustring clipWhite (const ustring& str) {
822 return clipWhite (str.begin (), str.end ());
825 ustring getenvString (const char* key) {
826 char* e = getenv (key);
834 ustring zeroPad (int n, const ustring& src) {
837 n = std::min (32, n);
838 m = n - src.length ();
850 bool wsearch (const ustring& text, boost::wsmatch& m, const ustring& reg, boost::wregex::flag_type reg_flags, boost::match_flag_type search_flags) {
852 std::wstring wtext = utow (text);
853 std::wstring wreg = utow (reg);
854 boost::wregex wre (wreg, reg_flags);
855 return regex_search (wtext, m, wre, search_flags);
856 } catch (boost::regex_error& err) {
857 throw (uErrorRegexp);
861 bool wsearch_env (MlEnv* mlenv, const ustring& text, const ustring& reg, boost::wregex::flag_type reg_flags, boost::match_flag_type search_flags) {
863 mlenv->regtext = utow (text);
864 std::wstring wreg = utow (reg);
865 boost::wregex wre (wreg, reg_flags);
866 return regex_search (mlenv->regtext, mlenv->regmatch, wre, search_flags);
867 } catch (boost::regex_error& err) {
868 throw (uErrorRegexp);
872 ustring wreplace (const ustring& text, const ustring& reg, const ustring& fmt, boost::wregex::flag_type reg_flags, boost::match_flag_type match_flags) {
874 std::wstring wtext = utow (text);
875 std::wstring wreg = utow (reg);
876 std::wstring wfmt = utow (fmt);
877 boost::wregex wre (wreg, reg_flags);
878 std::wstring ans = regex_replace (wtext, wre, wfmt, match_flags);
880 } catch (boost::regex_error& err) {
881 throw (uErrorRegexp);
885 ustring padEmpty (const ustring& name) {
887 return ustring (CharConst ("(null)"));
892 uint32_t hextoul (uiterator b, uiterator e) {
896 for (n = 0; n < 8 && b != e; n ++, b ++) {
897 ans = (ans << 4) + hex (*b);
902 ustring toCRLF (const ustring& str) {
903 uiterator b = str.begin ();
904 uiterator e = str.end ();
908 while (usearch (b, e, m, re_lf)) {
909 ans.append (b, m[0].first).append (uCRLF);
916 void skipSpace (uiterator& b, uiterator e) {
917 while (b < e && *b == ' ') {
922 static ustring::value_type toLower_ustring_value (ustring::value_type v) {
923 if ('A' <= v && v <= 'Z') {
924 return v - 'A' + 'a';
931 void toLower (ustring::iterator* b, ustring::iterator* e) {
932 transform (*b, *e, *b, toLower_ustring_value);
936 ustring toLower (uiterator b, uiterator e) {
941 for (; b < e; b ++, i++) {
942 *i = toLower_ustring_value (*b);
947 static void format_hex (ustring& ans, MNode* a, std::vector<ustring>& par, bool fcap) {
954 if (par.size () > 0) {
955 int p = strtol (par[0]);
961 ans.append (buf, snprintf (buf, 32, "%.*X", p, v));
963 ans.append (buf, snprintf (buf, 32, "%.*x", p, v));
966 ans.append (buf, snprintf (buf, 32, "%X", v));
968 ans.append (buf, snprintf (buf, 32, "%x", v));
972 static void format_hex (ustring& ans, MNode* a, std::vector<ustring>& par) {
973 format_hex (ans, a, par, false);
976 static void format_HEX (ustring& ans, MNode* a, std::vector<ustring>& par) {
977 format_hex (ans, a, par, true);
980 static void format_int_sub (ustring& ans, MNode* a, std::vector<ustring>& par, bool pad0 = false) {
988 if (par.size () > 0) {
992 if (match (par[0], CharConst ("comma")) || match (par[0], CharConst ("c"))) {
993 ans.append (c3 (to_ustring (v)));
995 int p = strtol (par[0]);
1000 for (int i = 1; i < par.size (); i ++) {
1001 if (match (par[i], CharConst ("clip"))) {
1003 } else if (match (par[i], CharConst ("0"))) {
1005 } else if (match (par[i], CharConst ("comma")) || match (par[i], CharConst ("c"))) {
1008 throw (par[i] + uErrorBadParam);
1012 s = snprintf (buf, 32, "%.*d", p, v);
1014 s = snprintf (buf, 32, "%*d", p, v);
1016 ans.append (buf + s - p, p);
1017 else if (! fclip && fc3)
1018 ans.append (c3 (ustring (buf, s)));
1020 ans.append (buf, s);
1023 ans.append (to_ustring (v));
1027 static void format_int (ustring& ans, MNode* a, std::vector<ustring>& par) {
1028 format_int_sub (ans, a, par);
1031 static void format_int0 (ustring& ans, MNode* a, std::vector<ustring>& par) {
1032 format_int_sub (ans, a, par, true);
1035 static void format_int (ustring& ans, MNode* a, int c, bool pad0 = false) {
1047 s = snprintf (buf, 32, "%.*d", c, v);
1049 s = snprintf (buf, 32, "%*d", c, v);
1051 ans.append (buf + s - c, c);
1053 ans.append (buf, s);
1055 ans.append (to_ustring (v));
1059 static void format_float (ustring& ans, MNode* a, std::vector<ustring>& par) {
1064 if (par.size () > 0)
1065 p1 = strtol (par[0]);
1066 if (par.size () > 1)
1067 p2 = strtol (par[1]);
1076 ans.append (buf, snprintf (buf, 32, "%*.*lf", p1, p2, to_double (a)));
1079 static void format_string (ustring& ans, MNode* a, std::vector<ustring>& par) {
1081 bool fright = false;
1082 ustring u = to_string (a);
1084 if (par.size () > 0)
1085 p = strtol (par[0]);
1088 if (par.size () > 1) {
1089 if (match (par[1], CharConst ("right")) || match (par[1], CharConst ("r")))
1092 throw (par[1] + uErrorBadParam);
1096 ans.append (p - u.size (), ' ').append (u);
1101 ans.append (u).append (p - u.size (), ' ');
1107 static void format_literal (ustring& ans, MNode* a, const char* list[], int offset, size_t size) {
1111 v = to_int (a) - offset;
1112 if (0 <= v && v < size)
1113 ans.append (list[v]);
1117 static const char* mstr_a[] = {
1118 "Jan", "Feb", "Mar", "Apr",
1119 "May", "Jun", "Jul", "Aug",
1120 "Sep", "Oct", "Nov", "Dec"
1122 static const char* mstr[] = {
1123 "January", "February", "March", "April",
1124 "May", "June", "July", "August",
1125 "September", "October", "November", "December"
1127 static void format_month (ustring& ans, MNode* a, std::vector<ustring>& par) {
1128 format_literal (ans, a, mstr_a, 1, 12);
1131 static void format_Month (ustring& ans, MNode* a, std::vector<ustring>& par) {
1132 format_literal (ans, a, mstr, 1, 12);
1135 static const char* WStr_a[] = {
1136 "Sun", "Mon", "Tue", "Wed",
1140 static const char* WStr[] = {
1141 "Sunday", "Monday", "Tuesday", "Wednesday",
1142 "Thursday", "Friday", "Saturday"
1145 static void format_week (ustring& ans, MNode* a, std::vector<ustring>& par) {
1146 format_literal (ans, a, WStr_a, 0, 7);
1149 static void format_Week (ustring& ans, MNode* a, std::vector<ustring>& par) {
1150 format_literal (ans, a, WStr, 0, 7);
1153 ustring formatString (const ustring& format, boost::ptr_vector<MNodePtr>& par) {
1159 static uregex re ("\\$\\{([1-9][0-9]*)(:([a-zA-Z][a-zA-Z0-9]*)(:([0-9a-z.:]+))?)?\\}");
1163 void (*fn)(ustring& ans, MNode* a, std::vector<ustring>& par);
1165 {CharConst ("hex"), format_hex},
1166 {CharConst ("HEX"), format_HEX},
1167 {CharConst ("int"), format_int},
1168 {CharConst ("int0"), format_int0},
1169 {CharConst ("float"), format_float},
1170 {CharConst ("string"), format_string},
1171 {CharConst ("month"), format_month},
1172 {CharConst ("Month"), format_Month},
1173 {CharConst ("week"), format_week},
1174 {CharConst ("Week"), format_Week},
1178 b = format.begin ();
1180 while (usearch (b, e, m, re)) {
1181 ans.append (b, m[0].first);
1183 i = strtoul (ustring (m[1].first, m[1].second)) - 1;
1184 if (i < par.size ()) {
1189 if (! m[2].matched) {
1191 ans.append (to_string (a));
1193 std::vector<ustring> fpar;
1196 split (m[5].first, m[5].second, re_colon, fpar);
1197 for (i = 0; formatFunc[i].name; i ++) {
1198 if (match (m[3].first, m[3].second, formatFunc[i].name, formatFunc[i].namelen)) {
1199 (*formatFunc[i].fn) (ans, a, fpar);
1203 ans.append (m[0].first, m[0].second);
1212 static ustring colpad0 (int n, const ustring& src) {
1216 n = std::min (32, n);
1217 m = n - src.length ();
1221 ans.append (m, '0');
1224 } else if (m == 0) {
1227 return ustring (src.end () - n, src.end ());
1236 ${M:2}, ${M}, ${M:name}, ${M:ab}
1244 ustring formatDateString (const ustring& format, time_t tm) {
1250 // static uregex re ("\\$\\{([YMDhmsWw])(:([0-9]))?\\}");
1251 static uregex re ("\\$\\{(([YMDhmsWwo])(:([0-9]))?|M:((name)|(ab)|(abname)))\\}");
1252 std::vector<ustring> fpar;
1254 localtime_r (&tm, &v);
1255 b = format.begin ();
1257 while (usearch (b, e, m, re)) {
1258 ans.append (b, m[0].first);
1261 if (m[6].matched) { // name
1262 ans.append (mstr[v.tm_mon]);
1263 } else if (m[7].matched || m[8].matched) { // abname
1264 ans.append (mstr_a[v.tm_mon]);
1267 // if (m[2].matched) {
1269 // pc = strtol (ustring (m[3].first, m[3].second));
1270 pc = strtol (ustring (m[4].first, m[4].second));
1274 // switch (*m[1].first) {
1275 switch (*m[2].first) {
1277 ans.append (colpad0 (pc, to_ustring (v.tm_year + 1900)));
1280 ans.append (colpad0 (pc, to_ustring (v.tm_mon + 1)));
1283 ans.append (colpad0 (pc, to_ustring (v.tm_mday)));
1286 ans.append (colpad0 (pc, to_ustring (v.tm_hour)));
1289 ans.append (colpad0 (pc, to_ustring (v.tm_min)));
1292 ans.append (colpad0 (pc, to_ustring (v.tm_sec)));
1295 ans.append (WStr [v.tm_wday]);
1298 ans.append (WStr_a [v.tm_wday]);
1303 if (v.tm_gmtoff < 0) {
1304 h = - v.tm_gmtoff / 60;
1307 ans.append (CharConst ("-")).append (colpad0 (4, to_ustring (h * 100 + m)));
1309 h = v.tm_gmtoff / 60;
1312 ans.append (CharConst ("+")).append (colpad0 (4, to_ustring (h * 100 + m)));
1324 ustring toLower (const ustring& str) {
1325 return boost::to_lower_copy (str);
1328 ustring toUpper (const ustring& str) {
1329 return boost::to_upper_copy (str);