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 unsigned int index = format[i+1] - '0'; | 116 const SubstituteArg* src = args_array[format[i+1] - '0']; |
117 assert(index < 10); | |
118 const SubstituteArg* src = args_array[index]; | |
119 memcpy(target, src->data(), src->size()); | 117 memcpy(target, src->data(), src->size()); |
120 target += src->size(); | 118 target += src->size(); |
121 ++i; // Skip next char. | 119 ++i; // Skip next char. |
122 } else if (format[i+1] == '$') { | 120 } else if (format[i+1] == '$') { |
123 *target++ = '$'; | 121 *target++ = '$'; |
124 ++i; // Skip next char. | 122 ++i; // Skip next char. |
125 } | 123 } |
126 } else { | 124 } else { |
127 *target++ = format[i]; | 125 *target++ = format[i]; |
128 } | 126 } |
129 } | 127 } |
130 | 128 |
131 GOOGLE_DCHECK_EQ(target - output->data(), output->size()); | 129 GOOGLE_DCHECK_EQ(target - output->data(), output->size()); |
132 } | 130 } |
133 | 131 |
134 } // namespace strings | 132 } // namespace strings |
135 } // namespace protobuf | 133 } // namespace protobuf |
136 } // namespace google | 134 } // namespace google |
OLD | NEW |