| 22 | namespace json2pb { |
| 23 | |
| 24 | inline int match_pattern(const std::string& str, int index) { |
| 25 | //pattern: _Zxxx_ |
| 26 | const char digit = '0'; |
| 27 | const int pattern_length = 6; |
| 28 | |
| 29 | int length = str.size(); |
| 30 | if (length <= index || length - index < pattern_length) { |
| 31 | return -1; |
| 32 | } |
| 33 | if (str[index] != '_' || |
| 34 | str[index + 1] != 'Z' || |
| 35 | str[index + 5] != '_' || |
| 36 | !isdigit(str[index + 2]) || |
| 37 | !isdigit(str[index + 3]) || |
| 38 | !isdigit(str[index + 4])) { |
| 39 | return -1; |
| 40 | } |
| 41 | int sum = (str[index + 2] - digit) * 100 + (str[index + 3] - digit) * 10 + (str[index + 4] - digit); |
| 42 | return sum < 256 ? sum : -1; |
| 43 | } |
| 44 | |
| 45 | bool encode_name(const std::string& content, std::string& encoded_content) { |
| 46 | int index = 0; |