COMMON: Add append function to BaseString which takes a pointer range

This allows to add efficiently a substring to another
This commit is contained in:
Le Philousophe 2023-08-18 14:20:57 +02:00 committed by Eugene Sandulenko
parent 11d7381c3f
commit 0edfc8f6dd
2 changed files with 22 additions and 0 deletions

View File

@ -788,6 +788,25 @@ TEMPLATE void BASESTRING::trim() {
}
#endif
TEMPLATE void BASESTRING::append(const value_type *beginP, const value_type *endP) {
assert(endP >= beginP);
size_t len = endP - beginP;
if (len == 0)
return;
// Don't test endP as it must be in the same buffer
if (pointerInOwnBuffer(beginP)) {
assignAppend(BaseString(beginP, endP));
return;
}
ensureCapacity(_size + len, true);
memcpy(_str + _size, beginP, len * sizeof(value_type));
_size += len;
_str[_size] = 0;
}
TEMPLATE void BASESTRING::assignAppend(value_type c) {
if (c == 0) {
#ifndef SCUMMVM_UTIL

View File

@ -201,6 +201,9 @@ public:
size_t find(const value_type *s, uint32 pos = 0) const;
uint32 find(const BaseString &str, uint32 pos = 0) const;
/** Appends a string containing the characters between beginP (including) and endP (excluding). */
void append(const value_type *begin, const value_type *end);
/**
* Wraps the text in the string to the given line maximum. Lines will be
* broken at any whitespace character. New lines are assumed to be