Do not call directly - these are not part of the public API.
| 118 | |
| 119 | // Do not call directly - these are not part of the public API. |
| 120 | string CatPieces(std::initializer_list<StringPiece> pieces) { |
| 121 | string result; |
| 122 | size_t total_size = 0; |
| 123 | for (const StringPiece piece : pieces) total_size += piece.size(); |
| 124 | gtl::STLStringResizeUninitialized(&result, total_size); |
| 125 | |
| 126 | char *const begin = &*result.begin(); |
| 127 | char *out = begin; |
| 128 | for (const StringPiece piece : pieces) { |
| 129 | const size_t this_size = piece.size(); |
| 130 | memcpy(out, piece.data(), this_size); |
| 131 | out += this_size; |
| 132 | } |
| 133 | DCHECK_EQ(out, begin + result.size()); |
| 134 | return result; |
| 135 | } |
| 136 | |
| 137 | // It's possible to call StrAppend with a StringPiece that is itself a fragment |
| 138 | // of the string we're appending to. However the results of this are random. |
no test coverage detected