4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #include "string_utils.h"
29 bool GetIndexAfterParens(const string
& s
, size_t indexParen
, size_t& indexNext
,
30 char cOpenParen
, char cCloseParen
) {
32 size_t index
= indexParen
;
33 string
sParenChars(" ");
34 sParenChars
[0]=cOpenParen
;
35 sParenChars
[1]=cCloseParen
;
38 /* Skip "index" ahead to after the closing parenthesis, or to the
40 index
= s
.find_first_of(sParenChars
, index
+1);
41 if(index
==string::npos
) break;
42 if(s
.at(index
)==cOpenParen
)
46 if(parenCount
==0) break;
50 /* If the end of the string is found before parenthesis parsing is
51 finished, then set the break position to the end of the string. */
52 if(index
==string::npos
) return false;
58 bool GetIndexBeforeParens(const string
& s
, size_t indexParen
, size_t& indexNext
,
59 char cOpenParen
, char cCloseParen
) {
61 size_t index
= indexParen
-1;
62 string
sParenChars(" ");
63 sParenChars
[0]=cOpenParen
;
64 sParenChars
[1]=cCloseParen
;
67 /* Skip "index" ahead to after the closing parenthesis, or to the
69 index
= s
.find_last_of(sParenChars
, index
);
70 if(index
==string::npos
) break;
71 if(s
.at(index
)==cCloseParen
)
75 if(parenCount
==0) break;
79 /* If the end of the string is found before parenthesis parsing is
80 finished, then set the break position to the end of the string. */
81 if(index
==string::npos
) return false;
87 string
ToUpper(string src
) {
88 for(string::iterator i
= src
.begin(); i
!= src
.end(); i
++) {
94 wstring
ToUpper(wstring src
) {
95 for(wstring::iterator i
= src
.begin(); i
!= src
.end(); i
++) {
101 string
ToLower(string src
) {
102 for(string::iterator i
= src
.begin(); i
!= src
.end(); i
++) {
108 wstring
ToLower(wstring src
) {
109 for(wstring::iterator i
= src
.begin(); i
!= src
.end(); i
++) {
115 string
Trim(string src
) {
116 int len
= src
.length();
119 for(begin
=0; begin
<len
; begin
++) {
120 if(!isspace(src
[begin
])) break;
122 if(begin
==len
) return "";
124 for(end
=len
-1; end
>=0; end
--) {
125 if(!isspace(src
[end
])) break;
128 return src
.substr(begin
, end
+1 - begin
);
131 wstring
Trim(wstring src
) {
132 int len
= src
.length();
135 for(begin
=0; begin
<len
; begin
++) {
136 if(!iswspace(src
[begin
])) break;
138 if(begin
==len
) return L
"";
140 for(end
=len
-1; end
>=0; end
--) {
141 if(!iswspace(src
[end
])) break;
144 return src
.substr(begin
, end
+1 - begin
);