"Fossies" - the Fresh Open Source Software Archive 
Member "ansifilter-2.18-x64/src/stringtools.cpp" (30 Jan 2021, 2897 Bytes) of package /windows/misc/ansifilter-2.18-x64.zip:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "stringtools.cpp":
2.13_vs_2.14.
1 /***************************************************************************
2 stringtools.cpp - description
3 -------------------
4 begin : Mon Dec 10 2001
5 copyright : (C) 2001 by Andre Simon
6 email : a.simon@mailbox.org
7 ***************************************************************************/
8
9 /*
10 This file is part of ANSIFilter.
11
12 ANSIFilter is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 ANSIFilter is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with ANSIFilter. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26 #include "stringtools.h"
27
28 // Avoid problems with isspace and UTF-8 characters, use iswspace
29 #include <wctype.h>
30
31
32 using namespace std;
33
34 namespace StringTools
35 {
36
37 string lowerCase(const string& s)
38 {
39 char* buf = new char[s.length()];
40 s.copy(buf, s.length());
41 for(unsigned int i = 0; i < s.length(); i++)
42 buf[i] = tolower(buf[i]);
43 string r(buf, s.length());
44 delete[] buf;
45 return r;
46 }
47
48 // TODO only one function to change case
49 string upperCase(const string& s)
50 {
51 char* buf = new char[s.length()];
52 s.copy(buf, s.length());
53 for(unsigned int i = 0; i < s.length(); i++)
54 buf[i] = toupper(buf[i]);
55 string r(buf, s.length());
56 delete[] buf;
57 return r;
58 }
59
60 string trimRight(const string &value)
61 {
62 string::size_type where = value.find_last_not_of(" \t\r");
63
64 if (where == string::npos)
65 // string has nothing but space
66 return string();
67
68 if (where == (value.length() - 1))
69 // string has no trailing space, don't copy its contents
70 return value;
71
72 return value.substr(0, where + 1);
73 }
74
75 string getParantheseVal(const string &s)
76 {
77 string::size_type openPos=s.find('(');
78 string::size_type closePos=s.rfind(')');
79 if (openPos ==string::npos || closePos==string::npos) {
80 return string();
81 }
82 return s.substr(openPos+1, closePos-openPos-1);
83 }
84
85 vector<string> splitString(const string& s, unsigned char delim)
86 {
87 string::size_type pos=s.find(delim), oldPos=0;
88 vector <string> results;
89
90 if (pos ==string::npos) {
91 if (!s.empty())results.push_back(s);
92 return results;
93 }
94
95 do {
96 if (oldPos-pos) results.push_back (s.substr(oldPos, pos-oldPos));
97 oldPos=pos+1;
98 pos=s.find(delim, pos+1);
99 } while (pos!=string::npos);
100 results.push_back (s.substr(oldPos));
101
102 return results;
103 }
104
105 }