58 #define snprintf _snprintf
74 return (
'0' <= c && c <=
'9') ||
75 (
'a' <= c && c <=
'f') ||
76 (
'A' <= c && c <=
'F');
80 return c >= 0x20 && c <= 0x7E;
88 void StripString(
string* s,
const char* remove,
char replacewith) {
89 const char * str_start =
s->c_str();
90 const char *
str = str_start;
91 for (
str = strpbrk(
str, remove);
93 str = strpbrk(
str + 1, remove)) {
94 (*s)[
str - str_start] = replacewith;
104 const char *str_start =
s->c_str();
105 const char *
str = str_start;
106 for (
str = strpbrk(
str, remove);
108 str = strpbrk(
str + 1, remove)) {
109 (*s)[
str - str_start] = replacewith;
114 int str_length =
str->length();
122 if (
first == str_length) {
132 int last = str_length - 1;
136 if (last != (str_length - 1) && last >= 0) {
137 str->erase(last + 1, string::npos);
149 const string& newsub,
bool replace_all,
151 if (oldsub.empty()) {
156 string::size_type start_pos = 0;
157 string::size_type pos;
159 pos =
s.find(oldsub, start_pos);
160 if (pos == string::npos) {
163 res->append(
s, start_pos, pos - start_pos);
165 start_pos = pos + oldsub.size();
166 }
while (replace_all);
167 res->append(
s, start_pos,
s.length() - start_pos);
180 const string& newsub,
bool replace_all) {
194 template <
typename ITR>
200 if (delim[0] !=
'\0' && delim[1] ==
'\0') {
202 const char*
p = full.data();
203 const char*
end =
p + full.size();
209 while (++
p !=
end && *
p != c);
216 string::size_type begin_index, end_index;
217 begin_index = full.find_first_not_of(delim);
218 while (begin_index != string::npos) {
219 end_index = full.find_first_of(delim, begin_index);
220 if (end_index == string::npos) {
221 *result++ = full.substr(begin_index);
224 *result++ = full.substr(begin_index, (end_index - begin_index));
225 begin_index = full.find_first_not_of(delim, end_index);
231 std::vector<string>* result) {
232 std::back_insert_iterator< std::vector<string> >
it(*result);
247 template <
typename StringType,
typename ITR>
253 string::size_type begin_index, end_index;
256 for (
int i = 0; (
i < pieces-1) || (pieces == 0);
i++) {
257 end_index = full.find_first_of(delim, begin_index);
258 if (end_index == string::npos) {
259 *result++ = full.substr(begin_index);
262 *result++ = full.substr(begin_index, (end_index - begin_index));
263 begin_index = end_index + 1;
265 *result++ = full.substr(begin_index);
269 std::vector<string>* result) {
270 std::back_insert_iterator<std::vector<string> >
it(*result);
280 template <
class ITERATOR>
287 int delim_length = strlen(delim);
291 for (ITERATOR iter =
start; iter !=
end; ++iter) {
300 for (ITERATOR iter =
start; iter !=
end; ++iter) {
302 result->append(delim, delim_length);
304 result->append(iter->data(), iter->size());
326 #define IS_OCTAL_DIGIT(c) (((c) >= '0') && ((c) <= '7'))
330 #define LOG_STRING(LEVEL, VECTOR) GOOGLE_LOG_IF(LEVEL, false)
337 std::vector<string> *
errors) {
344 while (
p ==
d && *
p !=
'\0' && *
p !=
'\\' )
356 case 'a': *
d++ =
'\a';
break;
357 case 'b': *
d++ =
'\b';
break;
358 case 'f': *
d++ =
'\f';
break;
359 case 'n': *
d++ =
'\n';
break;
360 case 'r': *
d++ =
'\r';
break;
361 case 't': *
d++ =
'\t';
break;
362 case 'v': *
d++ =
'\v';
break;
363 case '\\': *
d++ =
'\\';
break;
364 case '?': *
d++ =
'\?';
break;
365 case '\'': *
d++ =
'\'';
break;
366 case '"': *
d++ =
'\"';
break;
367 case '0':
case '1':
case '2':
case '3':
368 case '4':
case '5':
case '6':
case '7': {
371 ch =
ch * 8 + *++
p -
'0';
373 ch =
ch * 8 + *++
p -
'0';
377 case 'x':
case 'X': {
383 "\\x cannot be followed by non-hex digit: \\" << *
p <<
p[1];
388 const char *hex_start =
p;
393 "\\" <<
string(hex_start,
p+1-hex_start) <<
" exceeds 8 bits";
397 #if 0 // TODO(kenton): Support \u and \U? Requires runetochar().
401 const char *hex_start =
p;
402 for (
int i = 0;
i < 4; ++
i) {
407 <<
"\\u must be followed by 4 hex digits: \\"
408 <<
string(hex_start,
p+1-hex_start);
412 d += runetochar(
d, &rune);
418 const char *hex_start =
p;
419 for (
int i = 0;
i < 8; ++
i) {
424 if (newrune > 0x10FFFF) {
427 <<
string(hex_start,
p + 1 - hex_start)
428 <<
" exceeds Unicode limit (0x10FFFF)";
435 <<
"\\U must be followed by 8 hex digits: \\"
436 <<
string(hex_start,
p+1-hex_start);
440 d += runetochar(
d, &rune);
473 std::vector<string> *
errors) {
474 std::unique_ptr<char[]> unescaped(
new char[
src.size() + 1]);
477 dest->assign(unescaped.get(),
len);
482 std::unique_ptr<char[]> unescaped(
new char[
src.size() + 1]);
500 int dest_len,
bool use_hex,
bool utf8_safe) {
501 const char* src_end =
src + src_len;
503 bool last_hex_escape =
false;
505 for (;
src < src_end;
src++) {
506 if (dest_len - used < 2)
509 bool is_hex_escape =
false;
511 case '\n':
dest[used++] =
'\\';
dest[used++] =
'n';
break;
512 case '\r':
dest[used++] =
'\\';
dest[used++] =
'r';
break;
513 case '\t':
dest[used++] =
'\\';
dest[used++] =
't';
break;
514 case '\"':
dest[used++] =
'\\';
dest[used++] =
'\"';
break;
515 case '\'':
dest[used++] =
'\\';
dest[used++] =
'\'';
break;
516 case '\\':
dest[used++] =
'\\';
dest[used++] =
'\\';
break;
521 if ((!utf8_safe ||
static_cast<uint8>(*
src) < 0x80) &&
524 if (dest_len - used < 4)
526 sprintf(
dest + used, (use_hex ?
"\\x%02x" :
"\\%03o"),
528 is_hex_escape = use_hex;
534 last_hex_escape = is_hex_escape;
537 if (dest_len - used < 1)
548 static char c_escaped_len[256] = {
549 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 4, 4,
550 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
551 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
552 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
553 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
554 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1,
555 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
556 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4,
557 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
558 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
559 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
560 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
561 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
562 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
563 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
564 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
567 size_t escaped_len = 0;
568 for (
int i = 0;
i <
src.size(); ++
i) {
569 unsigned char c =
static_cast<unsigned char>(
src[
i]);
570 escaped_len += c_escaped_len[c];
583 if (escaped_len ==
src.size()) {
588 size_t cur_dest_len =
dest->size();
589 dest->resize(cur_dest_len + escaped_len);
590 char* append_ptr = &(*dest)[cur_dest_len];
592 for (
int i = 0;
i <
src.size(); ++
i) {
593 unsigned char c =
static_cast<unsigned char>(
src[
i]);
595 case '\n': *append_ptr++ =
'\\'; *append_ptr++ =
'n';
break;
596 case '\r': *append_ptr++ =
'\\'; *append_ptr++ =
'r';
break;
597 case '\t': *append_ptr++ =
'\\'; *append_ptr++ =
't';
break;
598 case '\"': *append_ptr++ =
'\\'; *append_ptr++ =
'\"';
break;
599 case '\'': *append_ptr++ =
'\\'; *append_ptr++ =
'\'';
break;
600 case '\\': *append_ptr++ =
'\\'; *append_ptr++ =
'\\';
break;
603 *append_ptr++ =
'\\';
604 *append_ptr++ =
'0' + c / 64;
605 *append_ptr++ =
'0' + (c % 64) / 8;
606 *append_ptr++ =
'0' + c % 8;
624 const int dest_length =
src.size() * 4 + 1;
625 std::unique_ptr<char[]>
dest(
new char[dest_length]);
627 dest.get(), dest_length,
false,
true);
633 const int dest_length =
src.size() * 4 + 1;
634 std::unique_ptr<char[]>
dest(
new char[dest_length]);
636 dest.get(), dest_length,
true,
false);
652 const int saved_errno =
errno;
654 const long result = strtol(nptr, endptr,
base);
655 if (
errno == ERANGE && result == LONG_MIN) {
657 }
else if (
errno == ERANGE && result == LONG_MAX) {
668 return static_cast<int32>(result);
672 const int saved_errno =
errno;
674 const unsigned long result = strtoul(nptr, endptr,
base);
675 if (
errno == ERANGE && result == ULONG_MAX) {
683 return static_cast<uint32>(result);
687 bool* negative_ptr ) {
688 const char*
start = text->data();
689 const char*
end =
start + text->size();
703 *negative_ptr = (
start[0] ==
'-');
704 if (*negative_ptr ||
start[0] ==
'+') {
714 template<
typename IntType>
716 string text, IntType* value_p) {
719 const IntType vmax = std::numeric_limits<IntType>::max();
721 assert(vmax >=
base);
722 const IntType vmax_over_base = vmax /
base;
723 const char*
start = text.data();
724 const char*
end =
start + text.size();
727 unsigned char c =
static_cast<unsigned char>(
start[0]);
729 if (digit >=
base || digit < 0) {
733 if (
value > vmax_over_base) {
738 if (
value > vmax - digit) {
748 template<
typename IntType>
750 const string& text, IntType* value_p) {
753 const IntType vmin = std::numeric_limits<IntType>::min();
755 assert(vmin <= 0 -
base);
756 IntType vmin_over_base = vmin /
base;
761 if (vmin %
base > 0) {
764 const char*
start = text.data();
765 const char*
end =
start + text.size();
768 unsigned char c =
static_cast<unsigned char>(
start[0]);
770 if (digit >=
base || digit < 0) {
774 if (
value < vmin_over_base) {
779 if (
value < vmin + digit) {
789 template<
typename IntType>
803 template<
typename IntType>
909 GOOGLE_CHECK(
i >= 0) <<
"FastHexToBuffer() wants non-negative integers, not " <<
i;
911 static const char *hexdigits =
"0123456789abcdef";
915 *
p-- = hexdigits[
i & 15];
922 static const char *hexdigits =
"0123456789abcdef";
924 for (
int i = num_byte - 1;
i >= 0;
i--) {
963 {
'0',
'0'}, {
'0',
'1'}, {
'0',
'2'}, {
'0',
'3'}, {
'0',
'4'},
964 {
'0',
'5'}, {
'0',
'6'}, {
'0',
'7'}, {
'0',
'8'}, {
'0',
'9'},
965 {
'1',
'0'}, {
'1',
'1'}, {
'1',
'2'}, {
'1',
'3'}, {
'1',
'4'},
966 {
'1',
'5'}, {
'1',
'6'}, {
'1',
'7'}, {
'1',
'8'}, {
'1',
'9'},
967 {
'2',
'0'}, {
'2',
'1'}, {
'2',
'2'}, {
'2',
'3'}, {
'2',
'4'},
968 {
'2',
'5'}, {
'2',
'6'}, {
'2',
'7'}, {
'2',
'8'}, {
'2',
'9'},
969 {
'3',
'0'}, {
'3',
'1'}, {
'3',
'2'}, {
'3',
'3'}, {
'3',
'4'},
970 {
'3',
'5'}, {
'3',
'6'}, {
'3',
'7'}, {
'3',
'8'}, {
'3',
'9'},
971 {
'4',
'0'}, {
'4',
'1'}, {
'4',
'2'}, {
'4',
'3'}, {
'4',
'4'},
972 {
'4',
'5'}, {
'4',
'6'}, {
'4',
'7'}, {
'4',
'8'}, {
'4',
'9'},
973 {
'5',
'0'}, {
'5',
'1'}, {
'5',
'2'}, {
'5',
'3'}, {
'5',
'4'},
974 {
'5',
'5'}, {
'5',
'6'}, {
'5',
'7'}, {
'5',
'8'}, {
'5',
'9'},
975 {
'6',
'0'}, {
'6',
'1'}, {
'6',
'2'}, {
'6',
'3'}, {
'6',
'4'},
976 {
'6',
'5'}, {
'6',
'6'}, {
'6',
'7'}, {
'6',
'8'}, {
'6',
'9'},
977 {
'7',
'0'}, {
'7',
'1'}, {
'7',
'2'}, {
'7',
'3'}, {
'7',
'4'},
978 {
'7',
'5'}, {
'7',
'6'}, {
'7',
'7'}, {
'7',
'8'}, {
'7',
'9'},
979 {
'8',
'0'}, {
'8',
'1'}, {
'8',
'2'}, {
'8',
'3'}, {
'8',
'4'},
980 {
'8',
'5'}, {
'8',
'6'}, {
'8',
'7'}, {
'8',
'8'}, {
'8',
'9'},
981 {
'9',
'0'}, {
'9',
'1'}, {
'9',
'2'}, {
'9',
'3'}, {
'9',
'4'},
982 {
'9',
'5'}, {
'9',
'6'}, {
'9',
'7'}, {
'9',
'8'}, {
'9',
'9'}
987 const char *ASCII_digits =
nullptr;
994 if (u >= 1000000000) {
995 digits = u / 100000000;
997 buffer[0] = ASCII_digits[0];
998 buffer[1] = ASCII_digits[1];
1001 u -= digits * 100000000;
1003 digits = u / 1000000;
1005 buffer[0] = ASCII_digits[0];
1006 buffer[1] = ASCII_digits[1];
1009 u -= digits * 1000000;
1013 buffer[0] = ASCII_digits[0];
1014 buffer[1] = ASCII_digits[1];
1017 u -= digits * 10000;
1021 buffer[0] = ASCII_digits[0];
1022 buffer[1] = ASCII_digits[1];
1029 buffer[0] = ASCII_digits[0];
1030 buffer[1] = ASCII_digits[1];
1039 if (u >= 10)
goto lt100;
1040 *
buffer++ =
'0' + digits;
1044 if (u >= 1000)
goto lt10_000;
1046 *
buffer++ =
'0' + digits;
1050 if (u >= 100000)
goto lt1_000_000;
1052 *
buffer++ =
'0' + digits;
1055 if (u < 100000000) {
1056 if (u >= 10000000)
goto lt100_000_000;
1057 digits = u / 1000000;
1058 *
buffer++ =
'0' + digits;
1059 goto sublt1_000_000;
1062 digits = u / 100000000;
1063 *
buffer++ =
'0' + digits;
1064 goto sublt100_000_000;
1078 const char *ASCII_digits =
nullptr;
1083 uint64 top_11_digits = u64 / 1000000000;
1085 u = u64 - (top_11_digits * 1000000000);
1087 digits = u / 10000000;
1090 buffer[0] = ASCII_digits[0];
1091 buffer[1] = ASCII_digits[1];
1093 u -= digits * 10000000;
1094 digits = u / 100000;
1096 buffer[0] = ASCII_digits[0];
1097 buffer[1] = ASCII_digits[1];
1099 u -= digits * 100000;
1102 buffer[0] = ASCII_digits[0];
1103 buffer[1] = ASCII_digits[1];
1108 buffer[0] = ASCII_digits[0];
1109 buffer[1] = ASCII_digits[1];
1113 *
buffer++ =
'0' + digits;
1138 return (
sizeof(
i) == 4) ?
1152 return (
sizeof(
i) == 4) ?
1166 return (
sizeof(
i) == 4) ?
1230 return (
'0' <= c && c <=
'9') ||
1231 c ==
'e' || c ==
'E' ||
1232 c ==
'+' || c ==
'-';
1238 if (strchr(
buffer,
'.') !=
nullptr)
return;
1269 if (
value == std::numeric_limits<double>::infinity()) {
1272 }
else if (
value == -std::numeric_limits<double>::infinity()) {
1280 int snprintf_result =
1294 if (parsed_value !=
value) {
1295 int snprintf_result =
1307 const unsigned char *us1 =
reinterpret_cast<const unsigned char *
>(s1);
1308 const unsigned char *us2 =
reinterpret_cast<const unsigned char *
>(s2);
1310 for (
int i = 0;
i <
len;
i++ ) {
1312 static_cast<int>(
static_cast<unsigned char>(
ascii_tolower(us1[
i]))) -
1313 static_cast<int>(
static_cast<unsigned char>(
ascii_tolower(us2[
i])));
1314 if (diff != 0)
return diff;
1320 if (s1.
size() != s2.
size())
return false;
1344 #if defined(_WIN32) || defined (__hpux) // has no strtof()
1349 return *
str != 0 && *endptr == 0 &&
errno == 0;
1355 if (endptr !=
str) {
1361 return *
str !=
'\0' && *endptr ==
'\0';
1387 if (
value == std::numeric_limits<double>::infinity()) {
1390 }
else if (
value == -std::numeric_limits<double>::infinity()) {
1398 int snprintf_result =
1407 int snprintf_result =
1429 static const char hexdigits[] =
"0123456789abcdef";
1431 *--writer = hexdigits[
value & 0xF];
1434 }
while (
mask != 0);
1452 memcpy(out,
x.data(),
x.size());
1453 return out +
x.size();
1456 static char *
Append2(
char *out,
const AlphaNum &x1,
const AlphaNum &x2) {
1457 memcpy(out, x1.data(), x1.size());
1460 memcpy(out, x2.data(), x2.size());
1461 return out + x2.size();
1465 const AlphaNum &x1,
const AlphaNum &x2,
1466 const AlphaNum &x3,
const AlphaNum &x4) {
1467 memcpy(out, x1.data(), x1.size());
1470 memcpy(out, x2.data(), x2.size());
1473 memcpy(out, x3.data(), x3.size());
1476 memcpy(out, x4.data(), x4.size());
1477 return out + x4.size();
1482 result.resize(
a.size() +
b.size());
1483 char *
const begin = &*result.begin();
1489 string StrCat(
const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c) {
1491 result.resize(
a.size() +
b.size() + c.size());
1492 char *
const begin = &*result.begin();
1499 string StrCat(
const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c,
1500 const AlphaNum &d) {
1502 result.resize(
a.size() +
b.size() + c.size() +
d.size());
1503 char *
const begin = &*result.begin();
1509 string StrCat(
const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c,
1510 const AlphaNum &d,
const AlphaNum &e) {
1512 result.resize(
a.size() +
b.size() + c.size() +
d.size() + e.size());
1513 char *
const begin = &*result.begin();
1520 string StrCat(
const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c,
1521 const AlphaNum &d,
const AlphaNum &e,
const AlphaNum &
f) {
1523 result.resize(
a.size() +
b.size() + c.size() +
d.size() + e.size() +
1525 char *
const begin = &*result.begin();
1532 string StrCat(
const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c,
1533 const AlphaNum &d,
const AlphaNum &e,
const AlphaNum &
f,
1534 const AlphaNum &
g) {
1536 result.resize(
a.size() +
b.size() + c.size() +
d.size() + e.size() +
1537 f.size() +
g.size());
1538 char *
const begin = &*result.begin();
1546 string StrCat(
const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c,
1547 const AlphaNum &d,
const AlphaNum &e,
const AlphaNum &
f,
1548 const AlphaNum &
g,
const AlphaNum &
h) {
1550 result.resize(
a.size() +
b.size() + c.size() +
d.size() + e.size() +
1551 f.size() +
g.size() +
h.size());
1552 char *
const begin = &*result.begin();
1559 string StrCat(
const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c,
1560 const AlphaNum &d,
const AlphaNum &e,
const AlphaNum &
f,
1561 const AlphaNum &
g,
const AlphaNum &
h,
const AlphaNum &
i) {
1563 result.resize(
a.size() +
b.size() + c.size() +
d.size() + e.size() +
1564 f.size() +
g.size() +
h.size() +
i.size());
1565 char *
const begin = &*result.begin();
1577 #define GOOGLE_DCHECK_NO_OVERLAP(dest, src) \
1578 GOOGLE_DCHECK_GT(uintptr_t((src).data() - (dest).data()), \
1579 uintptr_t((dest).size()))
1583 result->append(
a.data(),
a.size());
1586 void StrAppend(
string *result,
const AlphaNum &
a,
const AlphaNum &
b) {
1589 string::size_type old_size = result->size();
1590 result->resize(old_size +
a.size() +
b.size());
1591 char *
const begin = &*result->begin();
1597 const AlphaNum &
a,
const AlphaNum &
b,
const AlphaNum &c) {
1601 string::size_type old_size = result->size();
1602 result->resize(old_size +
a.size() +
b.size() + c.size());
1603 char *
const begin = &*result->begin();
1610 const AlphaNum &
a,
const AlphaNum &
b,
1611 const AlphaNum &c,
const AlphaNum &d) {
1616 string::size_type old_size = result->size();
1617 result->resize(old_size +
a.size() +
b.size() + c.size() +
d.size());
1618 char *
const begin = &*result->begin();
1624 const string& replacement,
1627 if (
s->empty() || substring.empty())
1630 int num_replacements = 0;
1632 for (
int match_pos =
s->find(substring.data(), pos, substring.length());
1633 match_pos != string::npos;
1634 pos = match_pos + substring.length(),
1635 match_pos =
s->find(substring.data(), pos, substring.length())) {
1638 tmp.append(*
s, pos, match_pos - pos);
1640 tmp.append(replacement.begin(), replacement.end());
1644 if (num_replacements > 0) {
1645 tmp.append(*
s, pos,
s->length() - pos);
1648 return num_replacements;
1667 int len = (input_len / 3) * 4;
1669 if (input_len % 3 == 0) {
1674 }
else if (input_len % 3 == 1) {
1694 assert(
len >= input_len);
1728 char *
dest,
int szdest,
1729 const signed char* unbase64) {
1730 static const char kPad64Equals =
'=';
1731 static const char kPad64Dot =
'.';
1736 unsigned int ch = 0;
1737 unsigned int temp = 0;
1742 const unsigned char *
src =
reinterpret_cast<const unsigned char*
>(src_param);
1750 #define GET_INPUT(label, remain) \
1754 decode = unbase64[ch]; \
1756 if (ascii_isspace(ch) && szsrc >= remain) \
1758 state = 4 - remain; \
1774 while (szsrc >= 4) {
1784 (temp = ((
unsigned(unbase64[
src[0]]) << 18) |
1785 (
unsigned(unbase64[
src[1]]) << 12) |
1786 (
unsigned(unbase64[
src[2]]) << 6) |
1787 (
unsigned(unbase64[
src[3]])))) & 0x80000000) {
1798 temp = (temp << 6) | decode;
1800 temp = (temp << 6) | decode;
1802 temp = (temp << 6) | decode;
1815 if (destidx+3 > szdest)
return -1;
1816 dest[destidx+2] = temp;
1818 dest[destidx+1] = temp;
1820 dest[destidx] = temp;
1824 while (szsrc >= 4) {
1826 (temp = ((
unsigned(unbase64[
src[0]]) << 18) |
1827 (
unsigned(unbase64[
src[1]]) << 12) |
1828 (
unsigned(unbase64[
src[2]]) << 6) |
1829 (
unsigned(unbase64[
src[3]])))) & 0x80000000) {
1848 if (decode < 0 &&
ch !=
'\0' &&
1852 if (
ch == kPad64Equals ||
ch == kPad64Dot) {
1866 decode = unbase64[
ch];
1870 }
else if (
ch ==
'\0') {
1872 }
else if (
ch == kPad64Equals ||
ch == kPad64Dot) {
1884 temp = (temp << 6) | decode;
1890 if (destidx+3 > szdest)
return -1;
1891 dest[destidx+2] = temp;
1893 dest[destidx+1] = temp;
1895 dest[destidx] = temp;
1905 int expected_equals = 0;
1918 if (destidx+1 > szdest)
return -1;
1920 dest[destidx] = temp;
1923 expected_equals = 2;
1929 if (destidx+2 > szdest)
return -1;
1931 dest[destidx+1] = temp;
1933 dest[destidx] = temp;
1936 expected_equals = 1;
1941 GOOGLE_LOG(
FATAL) <<
"This can't happen; base64 decoder state = " << state;
1950 while (szsrc > 0 && *
src) {
1951 if (*
src == kPad64Equals || *
src == kPad64Dot)
1959 return (equals == 0 || equals == expected_equals) ? destidx : -1;
1993 -1, -1, -1, -1, -1, -1, -1, -1,
1994 -1, -1, -1, -1, -1, -1, -1, -1,
1995 -1, -1, -1, -1, -1, -1, -1, -1,
1996 -1, -1, -1, -1, -1, -1, -1, -1,
1997 -1, -1, -1, -1, -1, -1, -1, -1,
1998 -1, -1, -1, 62, -1, -1, -1, 63,
1999 52, 53, 54, 55, 56, 57, 58, 59,
2000 60, 61, -1, -1, -1, -1, -1, -1,
2001 -1, 0, 1, 2, 3, 4, 5, 6,
2002 7, 8, 9, 10, 11, 12, 13, 14,
2003 15, 16, 17, 18, 19, 20, 21, 22,
2004 23, 24, 25, -1, -1, -1, -1, -1,
2005 -1, 26, 27, 28, 29, 30, 31, 32,
2006 33, 34, 35, 36, 37, 38, 39, 40,
2007 41, 42, 43, 44, 45, 46, 47, 48,
2008 49, 50, 51, -1, -1, -1, -1, -1,
2009 -1, -1, -1, -1, -1, -1, -1, -1,
2010 -1, -1, -1, -1, -1, -1, -1, -1,
2011 -1, -1, -1, -1, -1, -1, -1, -1,
2012 -1, -1, -1, -1, -1, -1, -1, -1,
2013 -1, -1, -1, -1, -1, -1, -1, -1,
2014 -1, -1, -1, -1, -1, -1, -1, -1,
2015 -1, -1, -1, -1, -1, -1, -1, -1,
2016 -1, -1, -1, -1, -1, -1, -1, -1,
2017 -1, -1, -1, -1, -1, -1, -1, -1,
2018 -1, -1, -1, -1, -1, -1, -1, -1,
2019 -1, -1, -1, -1, -1, -1, -1, -1,
2020 -1, -1, -1, -1, -1, -1, -1, -1,
2021 -1, -1, -1, -1, -1, -1, -1, -1,
2022 -1, -1, -1, -1, -1, -1, -1, -1,
2023 -1, -1, -1, -1, -1, -1, -1, -1,
2024 -1, -1, -1, -1, -1, -1, -1, -1
2027 -1, -1, -1, -1, -1, -1, -1, -1,
2028 -1, -1, -1, -1, -1, -1, -1, -1,
2029 -1, -1, -1, -1, -1, -1, -1, -1,
2030 -1, -1, -1, -1, -1, -1, -1, -1,
2031 -1, -1, -1, -1, -1, -1, -1, -1,
2032 -1, -1, -1, -1, -1, 62, -1, -1,
2033 52, 53, 54, 55, 56, 57, 58, 59,
2034 60, 61, -1, -1, -1, -1, -1, -1,
2035 -1, 0, 1, 2, 3, 4, 5, 6,
2036 7, 8, 9, 10, 11, 12, 13, 14,
2037 15, 16, 17, 18, 19, 20, 21, 22,
2038 23, 24, 25, -1, -1, -1, -1, 63,
2039 -1, 26, 27, 28, 29, 30, 31, 32,
2040 33, 34, 35, 36, 37, 38, 39, 40,
2041 41, 42, 43, 44, 45, 46, 47, 48,
2042 49, 50, 51, -1, -1, -1, -1, -1,
2043 -1, -1, -1, -1, -1, -1, -1, -1,
2044 -1, -1, -1, -1, -1, -1, -1, -1,
2045 -1, -1, -1, -1, -1, -1, -1, -1,
2046 -1, -1, -1, -1, -1, -1, -1, -1,
2047 -1, -1, -1, -1, -1, -1, -1, -1,
2048 -1, -1, -1, -1, -1, -1, -1, -1,
2049 -1, -1, -1, -1, -1, -1, -1, -1,
2050 -1, -1, -1, -1, -1, -1, -1, -1,
2051 -1, -1, -1, -1, -1, -1, -1, -1,
2052 -1, -1, -1, -1, -1, -1, -1, -1,
2053 -1, -1, -1, -1, -1, -1, -1, -1,
2054 -1, -1, -1, -1, -1, -1, -1, -1,
2055 -1, -1, -1, -1, -1, -1, -1, -1,
2056 -1, -1, -1, -1, -1, -1, -1, -1,
2057 -1, -1, -1, -1, -1, -1, -1, -1,
2058 -1, -1, -1, -1, -1, -1, -1, -1
2066 const signed char* unbase64) {
2070 const int dest_len = 3 * (slen / 4) + (slen % 4);
2072 dest->resize(dest_len);
2077 dest_len, unbase64);
2101 static const char kPad64 =
'=';
2103 if (szsrc <= 0)
return 0;
2105 if (szsrc * 4 > szdest * 3)
return 0;
2107 char *cur_dest =
dest;
2108 const unsigned char *cur_src =
src;
2110 char *limit_dest =
dest + szdest;
2111 const unsigned char *limit_src =
src + szsrc;
2115 while (cur_src < limit_src - 3) {
2118 cur_dest[0] =
base64[in >> 18];
2120 cur_dest[1] =
base64[in >> 12];
2122 cur_dest[2] =
base64[in >> 6];
2124 cur_dest[3] =
base64[in];
2130 szdest = limit_dest - cur_dest;
2131 szsrc = limit_src - cur_src;
2141 if ((szdest -= 2) < 0)
return 0;
2143 cur_dest[0] =
base64[in >> 2];
2145 cur_dest[1] =
base64[in << 4];
2148 if ((szdest -= 2) < 0)
return 0;
2149 cur_dest[0] = kPad64;
2150 cur_dest[1] = kPad64;
2158 if ((szdest -= 3) < 0)
return 0;
2160 cur_dest[0] =
base64[in >> 10];
2162 cur_dest[1] =
base64[in >> 4];
2164 cur_dest[2] =
base64[in << 2];
2167 if ((szdest -= 1) < 0)
return 0;
2168 cur_dest[0] = kPad64;
2177 if ((szdest -= 4) < 0)
return 0;
2179 cur_dest[0] =
base64[in >> 18];
2181 cur_dest[1] =
base64[in >> 12];
2183 cur_dest[2] =
base64[in >> 6];
2185 cur_dest[3] =
base64[in];
2195 return (cur_dest -
dest);
2199 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2202 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
2208 int szdest,
bool do_padding) {
2214 string*
dest,
bool do_padding,
2216 const int calc_escaped_size =
2218 dest->resize(calc_escaped_size);
2225 dest->erase(escaped_len);
2229 string*
dest,
bool do_padding) {
2234 string *
dest,
bool do_padding) {
2258 if (code_point <= 0x7f) {
2261 }
else if (code_point <= 0x07ff) {
2263 ((code_point & 0x07c0) << 2) |
2264 (code_point & 0x003f);
2266 }
else if (code_point <= 0xffff) {
2268 ((code_point & 0xf000) << 4) |
2269 ((code_point & 0x0fc0) << 2) |
2270 (code_point & 0x003f);
2276 ((code_point & 0x1c0000) << 6) |
2277 ((code_point & 0x03f000) << 4) |
2278 ((code_point & 0x000fc0) << 2) |
2279 (code_point & 0x003f);
2283 memcpy(
output,
reinterpret_cast<const char*
>(&tmp) +
sizeof(tmp) -
len,
len);
2289 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
2290 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
2291 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
2292 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
2294 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
2295 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
2296 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,
2297 3,3,3,3,3,3,3,3, 3,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,4, 4,4,4,4,4,4,4,4
2342 bool auto_end_last_line) {
2354 ptrdiff_t output_pos = 0;
2355 bool r_seen =
false;
2356 ptrdiff_t
len =
str->size();
2358 char *
p = &(*str)[0];
2360 for (ptrdiff_t input_pos = 0; input_pos <
len;) {
2361 if (!r_seen && input_pos + 8 <
len) {
2372 #define has_less(x, n) (((x) - ~0ULL / 255 * (n)) & ~(x) & ~0ULL / 255 * 128)
2376 if (output_pos != input_pos) {
2384 string::const_reference in =
p[input_pos];
2386 if (r_seen)
p[output_pos++] =
'\n';
2388 }
else if (in ==
'\n') {
2389 if (input_pos != output_pos)
2390 p[output_pos++] =
'\n';
2395 if (r_seen)
p[output_pos++] =
'\n';
2397 if (input_pos != output_pos)
2398 p[output_pos++] = in;
2405 (auto_end_last_line && output_pos > 0 &&
p[output_pos - 1] !=
'\n')) {
2406 str->resize(output_pos + 1);
2407 str->operator[](output_pos) =
'\n';
2408 }
else if (output_pos <
len) {
2409 str->resize(output_pos);