==============================================================================
| 291 | |
| 292 | //============================================================================== |
| 293 | String StringArray::joinIntoString (StringRef separator, int start, int numberToJoin) const |
| 294 | { |
| 295 | auto last = (numberToJoin < 0) ? size() |
| 296 | : jmin (size(), start + numberToJoin); |
| 297 | |
| 298 | if (start < 0) |
| 299 | start = 0; |
| 300 | |
| 301 | if (start >= last) |
| 302 | return {}; |
| 303 | |
| 304 | if (start == last - 1) |
| 305 | return strings.getReference (start); |
| 306 | |
| 307 | auto separatorBytes = separator.text.sizeInBytes() - sizeof (String::CharPointerType::CharType); |
| 308 | auto bytesNeeded = (size_t) (last - start - 1) * separatorBytes; |
| 309 | |
| 310 | for (int i = start; i < last; ++i) |
| 311 | bytesNeeded += strings.getReference(i).getCharPointer().sizeInBytes() - sizeof (String::CharPointerType::CharType); |
| 312 | |
| 313 | String result; |
| 314 | result.preallocateBytes (bytesNeeded); |
| 315 | |
| 316 | auto dest = result.getCharPointer(); |
| 317 | |
| 318 | while (start < last) |
| 319 | { |
| 320 | auto& s = strings.getReference (start); |
| 321 | |
| 322 | if (! s.isEmpty()) |
| 323 | dest.writeAll (s.getCharPointer()); |
| 324 | |
| 325 | if (++start < last && separatorBytes > 0) |
| 326 | dest.writeAll (separator.text); |
| 327 | } |
| 328 | |
| 329 | dest.writeNull(); |
| 330 | return result; |
| 331 | } |
| 332 | |
| 333 | int StringArray::addTokens (StringRef text, const bool preserveQuotedStrings) |
| 334 | { |
no test coverage detected