1 | /*
|
---|
2 | stdHelpers.cpp
|
---|
3 |
|
---|
4 | Copyright (C) 2002-2004 René Nyffenegger
|
---|
5 |
|
---|
6 | This source code is provided 'as-is', without any express or implied
|
---|
7 | warranty. In no event will the author be held liable for any damages
|
---|
8 | arising from the use of this software.
|
---|
9 |
|
---|
10 | Permission is granted to anyone to use this software for any purpose,
|
---|
11 | including commercial applications, and to alter it and redistribute it
|
---|
12 | freely, subject to the following restrictions:
|
---|
13 |
|
---|
14 | 1. The origin of this source code must not be misrepresented; you must not
|
---|
15 | claim that you wrote the original source code. If you use this source code
|
---|
16 | in a product, an acknowledgment in the product documentation would be
|
---|
17 | appreciated but is not required.
|
---|
18 |
|
---|
19 | 2. Altered source versions must be plainly marked as such, and must not be
|
---|
20 | misrepresented as being the original source code.
|
---|
21 |
|
---|
22 | 3. This notice may not be removed or altered from any source distribution.
|
---|
23 |
|
---|
24 | René Nyffenegger [email protected]
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include "stdHelpers.h"
|
---|
28 | #include <algorithm>
|
---|
29 | #include <cctype>
|
---|
30 |
|
---|
31 | std::string ReplaceInStr(const std::string& in, const std::string& search_for, const std::string& replace_with)
|
---|
32 | {
|
---|
33 |
|
---|
34 | std::string ret = in;
|
---|
35 |
|
---|
36 | std::string::size_type pos = ret.find(search_for);
|
---|
37 |
|
---|
38 | while (pos != std::string::npos)
|
---|
39 | {
|
---|
40 | ret = ret.replace(pos, search_for.size(), replace_with);
|
---|
41 |
|
---|
42 | pos = pos - search_for.size() + replace_with.size() + 1;
|
---|
43 |
|
---|
44 | pos = ret.find(search_for, pos);
|
---|
45 | }
|
---|
46 |
|
---|
47 | return ret;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void ToUpper(std::string& s)
|
---|
51 | {
|
---|
52 | std::transform(s.begin(), s.end(), s.begin(), std::toupper);
|
---|
53 | }
|
---|
54 |
|
---|
55 | void ToLower(std::string& s)
|
---|
56 | {
|
---|
57 | std::transform(s.begin(), s.end(), s.begin(), std::tolower);
|
---|
58 | }
|
---|