mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-23 12:44:02 +00:00
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:
parent
11d7381c3f
commit
0edfc8f6dd
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user