OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 if (size == 0) return; | 107 if (size == 0) return; |
108 | 108 |
109 // Build the string. | 109 // Build the string. |
110 int original_size = output->size(); | 110 int original_size = output->size(); |
111 STLStringResizeUninitialized(output, original_size + size); | 111 STLStringResizeUninitialized(output, original_size + size); |
112 char* target = string_as_array(output) + original_size; | 112 char* target = string_as_array(output) + original_size; |
113 for (int i = 0; format[i] != '\0'; i++) { | 113 for (int i = 0; format[i] != '\0'; i++) { |
114 if (format[i] == '$') { | 114 if (format[i] == '$') { |
115 if (ascii_isdigit(format[i+1])) { | 115 if (ascii_isdigit(format[i+1])) { |
116 const SubstituteArg* src = args_array[format[i+1] - '0']; | 116 unsigned int index = format[i+1] - '0'; |
| 117 assert(index < 10); |
| 118 const SubstituteArg* src = args_array[index]; |
117 memcpy(target, src->data(), src->size()); | 119 memcpy(target, src->data(), src->size()); |
118 target += src->size(); | 120 target += src->size(); |
119 ++i; // Skip next char. | 121 ++i; // Skip next char. |
120 } else if (format[i+1] == '$') { | 122 } else if (format[i+1] == '$') { |
121 *target++ = '$'; | 123 *target++ = '$'; |
122 ++i; // Skip next char. | 124 ++i; // Skip next char. |
123 } | 125 } |
124 } else { | 126 } else { |
125 *target++ = format[i]; | 127 *target++ = format[i]; |
126 } | 128 } |
127 } | 129 } |
128 | 130 |
129 GOOGLE_DCHECK_EQ(target - output->data(), output->size()); | 131 GOOGLE_DCHECK_EQ(target - output->data(), output->size()); |
130 } | 132 } |
131 | 133 |
132 } // namespace strings | 134 } // namespace strings |
133 } // namespace protobuf | 135 } // namespace protobuf |
134 } // namespace google | 136 } // namespace google |
OLD | NEW |