GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/*************************************** |
||
2 |
Auteur : Pierre Aubert |
||
3 |
Mail : pierre.aubert@lapp.in2p3.fr |
||
4 |
Licence : CeCILL-C |
||
5 |
****************************************/ |
||
6 |
|||
7 |
|||
8 |
#include "string_lower_upper.h" |
||
9 |
|||
10 |
///Tels if the character is a number or not |
||
11 |
/** @param ch : character to be analysed |
||
12 |
* @return true if it is a number, false otherwise |
||
13 |
*/ |
||
14 |
80 |
bool isCharNumber(char ch){ |
|
15 |
✓✓✓✓ |
80 |
return (ch >= 48 && ch <= 57); |
16 |
} |
||
17 |
|||
18 |
///Tels if std::string contains figures |
||
19 |
/** @param str : std::string to be tested |
||
20 |
* @return true if std::string contains only figures |
||
21 |
*/ |
||
22 |
10 |
bool isStrNumber(const std::string & str){ |
|
23 |
✓✓ | 10 |
if(str.size() == 0lu){return false;} |
24 |
9 |
bool isMatch(true); |
|
25 |
9 |
long unsigned int i(0lu); |
|
26 |
✓✓✓✓ ✓✓ |
25 |
while(i < str.size() && isMatch){ |
27 |
16 |
isMatch = isCharNumber(str[i]); |
|
28 |
16 |
++i; |
|
29 |
} |
||
30 |
9 |
return isMatch; |
|
31 |
} |
||
32 |
|||
33 |
///Say if the list of std::string contains a number |
||
34 |
/** @param listStr : list of std::strings to be checked |
||
35 |
* @return true if the list of std::string contains number, false if not |
||
36 |
*/ |
||
37 |
4 |
bool isListStrNumber(const std::list<std::string> & listStr){ |
|
38 |
✓✓ | 4 |
if(listStr.size() == 0lu){return false;} |
39 |
3 |
bool isMatch(true); |
|
40 |
3 |
std::list<std::string>::const_iterator it(listStr.begin()); |
|
41 |
✓✓✓✓ ✓✓ |
9 |
while(isMatch && it != listStr.end()){ |
42 |
✓ | 6 |
isMatch &= isStrNumber(*it); |
43 |
6 |
++it; |
|
44 |
} |
||
45 |
3 |
return isMatch; |
|
46 |
} |
||
47 |
|||
48 |
///Tels if the character is a number or a '.' |
||
49 |
/** @param ch : character to be analysed |
||
50 |
* @return true if it is a number or '.', false otherwise |
||
51 |
*/ |
||
52 |
8 |
bool isCharNumberOrDot(char ch){ |
|
53 |
✓✓✓✓ ✓✓ |
8 |
return ((ch >= 48 && ch <= 57) || ch == '.'); |
54 |
} |
||
55 |
|||
56 |
///Tels if the character is a figure, a '.', a -, +, e or E |
||
57 |
/** @param ch : character to be analysed |
||
58 |
* @return true if the current char is a part of a number, false otherwise |
||
59 |
*/ |
||
60 |
18 |
bool isCharNumberDotMinusPlusE(char ch){ |
|
61 |
✓✓✓✓ ✓✓✓✓ ✓✓✓✓ ✗✓ |
18 |
return ((ch >= 48 && ch <= 57) || ch == '.' || ch == '-' || ch == '+' || ch == 'e' || ch == 'E'); |
62 |
} |
||
63 |
|||
64 |
///Tels if std::string contains figures or dots |
||
65 |
/** @param str : std::string to be tested |
||
66 |
* @return true if std::string contains only figures or dots |
||
67 |
*/ |
||
68 |
4 |
bool isStrNumberOrDot(const std::string & str){ |
|
69 |
✓✓ | 4 |
if(str.size() == 0l){return false;} |
70 |
3 |
bool isMatch(true); |
|
71 |
3 |
long unsigned int i(0lu); |
|
72 |
✓✓✓✓ ✓✓ |
10 |
while(i < str.size() && isMatch){ |
73 |
7 |
isMatch = isCharNumberOrDot(str[i]); |
|
74 |
7 |
++i; |
|
75 |
} |
||
76 |
3 |
return isMatch; |
|
77 |
} |
||
78 |
|||
79 |
///Tels if std::string std::string contains figures, '.', -, +, e or E |
||
80 |
/** @param str : std::string to be tested |
||
81 |
* @return true if std::string contains only figures, '.', -, +, e or E |
||
82 |
*/ |
||
83 |
6 |
bool isStrNumberDotMinusPlusE(const std::string & str){ |
|
84 |
✓✓ | 6 |
if(str.size() == 0lu){return false;} |
85 |
5 |
bool isMatch(true); |
|
86 |
5 |
long unsigned int i(0lu); |
|
87 |
✓✓✓✓ ✓✓ |
23 |
while(i < str.size() && isMatch){ |
88 |
18 |
isMatch = isCharNumberDotMinusPlusE(str[i]); |
|
89 |
18 |
++i; |
|
90 |
} |
||
91 |
5 |
return isMatch; |
|
92 |
} |
||
93 |
|||
94 |
///Tels if the character is a letter or '_' |
||
95 |
/** @param ch : character to be analysed |
||
96 |
* @return true si c'est une lettre ou un _ , false otherwise |
||
97 |
*/ |
||
98 |
64 |
bool isCharLetter(char ch){ |
|
99 |
✓✓✓✓ ✓✓✗✓ ✗✓ |
64 |
return (((int)ch >= 65 && (int)ch <= 90) || ((int)ch >= 97 && (int)ch <= 122) || ((int)ch == 95)); |
100 |
} |
||
101 |
|||
102 |
///Tels if the character is letter, figure or '_' |
||
103 |
/** @param ch : character to be analysed |
||
104 |
* @return true if character is a letter, figure or '_', false otherwise |
||
105 |
*/ |
||
106 |
64 |
bool isCharNumberOrLetter(char ch){ |
|
107 |
✓✓✓✓ ✓✓✗✓ ✓✗✓✓ ✓✗ |
64 |
return ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || (ch == 95) || (ch >= 48 && ch <= 57)); |
108 |
} |
||
109 |
|||
110 |
///Tels if the character is a letter, number, '.' or '_' |
||
111 |
/** @param ch : character to be analysed |
||
112 |
* @return true if it is a letter, number, '.' or '_', false otherwise |
||
113 |
*/ |
||
114 |
64 |
bool isCharNumberOrLetterOrDot(char ch){ |
|
115 |
✓✓✓✓ ✓✓✗✓ ✓✗✓✓ ✗✓✓✓ |
64 |
return ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || (ch == 95) || (ch >= 48 && ch <= 57) || (ch == '.')); |
116 |
} |
||
117 |
|||
118 |
///Tels if the character is number or star |
||
119 |
/** @param ch : character to be analysed |
||
120 |
* @return true if it is a number or star, false otherwise |
||
121 |
*/ |
||
122 |
64 |
bool isCharNumberOrStar(char ch){ |
|
123 |
✓✓✓✓ ✓✓ |
64 |
return ((ch >= 48 && ch <= 57) || ch == '*'); |
124 |
} |
||
125 |
|||
126 |
///Tels if the character is letter, star or '_' |
||
127 |
/** @param ch : character to be analysed |
||
128 |
* @return true is letter, star or '_', false otherwise |
||
129 |
*/ |
||
130 |
64 |
bool isCharLetterOrStar(char ch){ |
|
131 |
✓✓✓✓ ✓✓✗✓ ✓✗✓✓ |
64 |
return (((int)ch >= 65 && (int)ch <= 90) || ((int)ch >= 97 && (int)ch <= 122) || ((int)ch == 95) || ch == '*'); |
132 |
} |
||
133 |
|||
134 |
///Tels if the character is letter, number, star or '_' |
||
135 |
/** @param ch : character to be analysed |
||
136 |
* @return true if it is letter, number, star or '_', false otherwise |
||
137 |
*/ |
||
138 |
64 |
bool isCharNumberOrLetterOrStar(char ch){ |
|
139 |
✓✓✓✓ ✓✓✗✓ ✓✗✓✓ ✗✓✓✓ |
64 |
return ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || (ch == 95) || (ch >= 48 && ch <= 57) || ch == '*'); |
140 |
} |
||
141 |
|||
142 |
///Tels if the character is upper case letter |
||
143 |
/** @param ch : caractère à tester |
||
144 |
* @return true if character is upper case letter, false otherwise |
||
145 |
*/ |
||
146 |
134 |
bool isCharUpperCase(char ch){ |
|
147 |
✓✓✓✓ |
134 |
return (ch >= 65 && ch <= 90); |
148 |
} |
||
149 |
|||
150 |
///Tels if the character is lower case letter |
||
151 |
/** @param ch : caractère à tester |
||
152 |
* @return true if the character is lower case letter, false otherwise |
||
153 |
*/ |
||
154 |
114 |
bool isCharLowerCase(char ch){ |
|
155 |
✓✓✓✗ |
114 |
return (ch >= 97 && ch <= 122); |
156 |
} |
||
157 |
|||
158 |
///Say if the given std::string is in uppercase |
||
159 |
/** @param str : std::string to be checked |
||
160 |
* @return true if the std::string is in uppercase, false if not |
||
161 |
*/ |
||
162 |
1 |
bool isStrUpperCase(const std::string & str){ |
|
163 |
1 |
bool isUpper(true); |
|
164 |
1 |
size_t i(0lu); |
|
165 |
✓✓✓✗ ✓✓ |
5 |
while(i < str.size() && isUpper){ |
166 |
4 |
isUpper = isCharUpperCase(str[i]); |
|
167 |
4 |
++i; |
|
168 |
} |
||
169 |
1 |
return isUpper; |
|
170 |
} |
||
171 |
|||
172 |
///Say if the given std::string is in lowercase |
||
173 |
/** @param str : std::string to be checked |
||
174 |
* @return true if the std::string is in lowercase, false if not |
||
175 |
*/ |
||
176 |
1 |
bool isStrLowerCase(const std::string & str){ |
|
177 |
1 |
bool isLower(true); |
|
178 |
1 |
size_t i(0lu); |
|
179 |
✓✓✓✗ ✓✓ |
5 |
while(i < str.size() && isLower){ |
180 |
4 |
isLower = isCharLowerCase(str[i]); |
|
181 |
4 |
++i; |
|
182 |
} |
||
183 |
1 |
return isLower; |
|
184 |
} |
||
185 |
|||
186 |
///Convert std::string in lower case |
||
187 |
/** @param str : std::string to be converted |
||
188 |
* @return lower case std::string |
||
189 |
*/ |
||
190 |
3 |
std::string strToLower(const std::string & str){ |
|
191 |
✓ | 3 |
std::string strOut(""); |
192 |
char currentChar; |
||
193 |
3 |
long unsigned int size(str.size()); |
|
194 |
✓✓ | 45 |
for(long unsigned int i(0lu); i < size; ++i){ |
195 |
42 |
currentChar = str[i]; |
|
196 |
✓✓✓ | 42 |
if(isCharUpperCase(currentChar)){ |
197 |
✓ | 32 |
strOut += currentChar + (char)32; |
198 |
}else{ |
||
199 |
✓ | 10 |
strOut += currentChar; |
200 |
} |
||
201 |
} |
||
202 |
3 |
return strOut; |
|
203 |
} |
||
204 |
|||
205 |
///Convert std::string in upper case |
||
206 |
/** @param str : std::string to be converted |
||
207 |
* @return lower case std::string |
||
208 |
*/ |
||
209 |
3 |
std::string strToUpper(const std::string & str){ |
|
210 |
✓ | 3 |
std::string strOut(""); |
211 |
char currentChar; |
||
212 |
3 |
long unsigned int size(str.size()); |
|
213 |
✓✓ | 45 |
for(long unsigned int i(0); i < size; ++i){ |
214 |
42 |
currentChar = str[i]; |
|
215 |
✓✓✓ | 42 |
if(isCharLowerCase(currentChar)){ |
216 |
✓ | 32 |
strOut += currentChar - (char)32; |
217 |
}else{ |
||
218 |
✓ | 10 |
strOut += currentChar; |
219 |
} |
||
220 |
} |
||
221 |
3 |
return strOut; |
|
222 |
} |
||
223 |
|||
224 |
///Convert std::string in lower case and space in '_' |
||
225 |
/** @param str : std::string to be converted |
||
226 |
* @return std::string in lower case and space in '_' |
||
227 |
*/ |
||
228 |
2 |
std::string strToLowerUnderscore(const std::string & str){ |
|
229 |
✓ | 2 |
std::string strOut(""); |
230 |
char currentChar; |
||
231 |
2 |
long unsigned int size(str.size()); |
|
232 |
✓✓ | 23 |
for(long unsigned int i(0lu); i < size; ++i){ |
233 |
21 |
currentChar = str[i]; |
|
234 |
✓✓✓ | 21 |
if(isCharUpperCase(currentChar)){ |
235 |
✓ | 4 |
strOut += currentChar + (char)32; |
236 |
}else{ |
||
237 |
✓✓✓ | 17 |
if(currentChar == ' ') strOut += '_'; |
238 |
✓ | 16 |
else strOut += currentChar; |
239 |
} |
||
240 |
} |
||
241 |
2 |
return strOut; |
|
242 |
} |
||
243 |
|||
244 |
///Convert first letter of the std::string in upper case |
||
245 |
/** @param str : std::string to be converted |
||
246 |
* @return std::string with first letter of the std::string in upper case |
||
247 |
*/ |
||
248 |
4 |
std::string firstToUpper(const std::string & str){ |
|
249 |
✗✓✗✗ |
4 |
if(str.size() == 0lu) return ""; |
250 |
✓ | 8 |
std::string strOut(str); |
251 |
✓ | 4 |
char currentChar = strOut[0lu]; |
252 |
✓✓✓ | 4 |
if(isCharLowerCase(currentChar)){ |
253 |
✓ | 2 |
strOut[0lu] = currentChar - (char)32; |
254 |
} |
||
255 |
4 |
return strOut; |
|
256 |
} |
||
257 |
|||
258 |
///Convert first letter of the std::string in lower case |
||
259 |
/** @param str : std::string to be converted |
||
260 |
* @return std::string with first letter of the std::string in lower case |
||
261 |
*/ |
||
262 |
3 |
std::string firstToLower(const std::string & str){ |
|
263 |
✗✓✗✗ |
3 |
if(str.size() == 0lu) return ""; |
264 |
✓ | 6 |
std::string strOut(str); |
265 |
✓ | 3 |
char currentChar = strOut[0lu]; |
266 |
✓✓✓ | 3 |
if(isCharUpperCase(currentChar)){ |
267 |
✓ | 2 |
strOut[0lu] = currentChar + (char)32; |
268 |
} |
||
269 |
3 |
return strOut; |
|
270 |
} |
||
271 |
|||
272 |
|||
273 |
Generated by: GCOVR (Version 4.2) |