MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / replace

Method replace

source/core/StarString.cpp:410–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408}
409
410String String::replace(String const& rplc, String const& val, CaseSensitivity cs) const {
411 size_t index;
412 size_t sz = size();
413 size_t rsz = rplc.size();
414 String ret;
415 ret.reserve(m_string.length());
416
417 if (rplc.empty())
418 return *this;
419
420 index = find(rplc, 0, cs);
421 if (index == NPos)
422 return *this;
423
424 auto it = begin();
425 for (size_t i = 0; i < index; ++i)
426 ret.append(*it++);
427
428 while (index < sz) {
429 ret.append(val);
430 index += rsz;
431 for (size_t i = 0; i < rsz; ++i)
432 ++it;
433
434 size_t nindex = find(rplc, index, cs);
435 for (size_t i = index; i < nindex && i < sz; ++i)
436 ret.append(*it++);
437
438 index = nindex;
439 }
440 return ret;
441}
442
443String String::trimEnd(String const& pattern) const {
444 size_t end;

Callers

nothing calls this directly

Calls 8

sizeFunction · 0.85
findFunction · 0.85
beginFunction · 0.85
sizeMethod · 0.45
reserveMethod · 0.45
lengthMethod · 0.45
emptyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected