| 81 | } |
| 82 | |
| 83 | bool decode_name(const std::string& content, std::string& decoded_content) { |
| 84 | const int pattern_length = 6; |
| 85 | int begin = 0; |
| 86 | int second = 0; |
| 87 | bool convert = false; |
| 88 | for (std::string::const_iterator it = content.begin(); it < content.end(); ++it, ++second) { |
| 89 | if (*it != '_') { |
| 90 | continue; |
| 91 | } |
| 92 | int val = match_pattern(content, second); |
| 93 | if (val != -1) { |
| 94 | if (!convert) { |
| 95 | decoded_content.clear(); |
| 96 | decoded_content.reserve(content.size()); |
| 97 | convert = true; |
| 98 | } |
| 99 | decoded_content.append(content, begin, second - begin); |
| 100 | decoded_content.push_back(static_cast<char>(val)); |
| 101 | second += pattern_length - 1; |
| 102 | begin = second + 1; |
| 103 | it += pattern_length - 1; |
| 104 | } |
| 105 | } |
| 106 | if (!convert) { |
| 107 | return false; |
| 108 | } else { |
| 109 | decoded_content.append(content, begin, second - begin); |
| 110 | return true; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | } // namespace json2pb |