blob: a25a7776169bde11d81e6f9760fc6af530264322 [file] [log] [blame]
Gary Morrisonced8c6f2020-02-27 19:35:59 +00001/*
2 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "string_ops.hpp"
9
10using namespace std;
11
12// Replace first occurrence of find_str within orig of replace_str:
13size_t find_replace_1st (const string &find_str, const string &replace_str,
14 string &orig) {
15 size_t where = 0;
16 where = orig.find(find_str, where);
17 if (where != string::npos) {
18 orig.replace(where, find_str.length(), replace_str);
19 }
20 return where;
21}
22
23// Replace all occurrences of find_str in "this" string, with replace_str:
24size_t find_replace_all (const string &find_str, const string &replace_str,
25 string &orig) {
26 size_t where = 0;
27 do {
28 where = orig.find(find_str, where);
29 if (where != string::npos) {
30 orig.replace(where, find_str.length(), replace_str);
31 }
32 } while (where != string::npos);
33 return where;
34}