@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
| 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; |