| 27 | |
| 28 | namespace internal { |
| 29 | int SubstitutedSize(StringPiece format, |
| 30 | const SubstituteArg* const* args_array) { |
| 31 | int size = 0; |
| 32 | for (int i = 0; i < format.size(); i++) { |
| 33 | if (format[i] == '$') { |
| 34 | if (i+1 >= format.size()) { |
| 35 | LOG(DFATAL) << "Invalid strings::Substitute() format string: \"" |
| 36 | << CEscape(format) << "\"."; |
| 37 | return 0; |
| 38 | } else if (ascii_isdigit(format[i+1])) { |
| 39 | int index = format[i+1] - '0'; |
| 40 | if (args_array[index]->size() == -1) { |
| 41 | LOG(DFATAL) |
| 42 | << "strings::Substitute format string invalid: asked for \"$" |
| 43 | << index << "\", but only " << CountSubstituteArgs(args_array) |
| 44 | << " args were given. Full format string was: \"" |
| 45 | << CEscape(format) << "\"."; |
| 46 | return 0; |
| 47 | } |
| 48 | size += args_array[index]->size(); |
| 49 | ++i; // Skip next char. |
| 50 | } else if (format[i+1] == '$') { |
| 51 | ++size; |
| 52 | ++i; // Skip next char. |
| 53 | } else { |
| 54 | LOG(DFATAL) << "Invalid strings::Substitute() format string: \"" |
| 55 | << CEscape(format) << "\"."; |
| 56 | return 0; |
| 57 | } |
| 58 | } else { |
| 59 | ++size; |
| 60 | } |
| 61 | } |
| 62 | return size; |
| 63 | } |
| 64 | |
| 65 | char* SubstituteToBuffer(StringPiece format, |
| 66 | const SubstituteArg* const* args_array, |
no test coverage detected