MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / appendReplaceMultiple

Method appendReplaceMultiple

Tools/SC-build/BuildWriter.h:47–62  ·  view source on GitHub ↗

@brief Appends source to destination buffer, replacing multiple substitutions pairs @param source The StringView to be appended @param substitutions For each substitution in the span, the first is searched and replaced with the second. @return `true` if append succeeded Example: @snippet Tests/Libraries/Build/BuildTest.cpp stringBuilderTestAppendReplaceMultipleSnippet

Source from the content-addressed store, hash-verified

45 /// Example:
46 /// @snippet Tests/Libraries/Build/BuildTest.cpp stringBuilderTestAppendReplaceMultipleSnippet
47 [[nodiscard]] static bool appendReplaceMultiple(StringBuilder& builder, StringView source,
48 Span<const ReplacePair> substitutions)
49 {
50 String tempBuffer, other;
51 SC_TRY(tempBuffer.assign(source));
52 for (auto it : substitutions)
53 {
54 if (it.searchFor == it.replaceWith)
55 continue;
56 auto sb = StringBuilder::create(other);
57 SC_TRY(sb.appendReplaceAll(tempBuffer.view(), it.searchFor, it.replaceWith));
58 sb.finalize();
59 swap(other, tempBuffer);
60 }
61 return builder.append(tempBuffer.view());
62 }
63
64 private:
65 struct WriterXCode;

Callers

nothing calls this directly

Calls 6

createFunction · 0.85
swapFunction · 0.85
assignMethod · 0.45
viewMethod · 0.45
finalizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected