103 SECTION(
"stringTo<int>") {
104 std::optional<int> NOK;
105 using OK = std::optional<int>;
108 CHECK(StringOp::stringTo<int>(
"") == NOK);
111 CHECK(StringOp::stringTo<int>(
"0") == OK(0));
112 CHECK(StringOp::stringTo<int>(
"03") == OK(3));
113 CHECK(StringOp::stringTo<int>(
"097") == OK(97));
114 CHECK(StringOp::stringTo<int>(
"12") == OK(12));
116 CHECK(StringOp::stringTo<int>(
"-0") == OK(0));
117 CHECK(StringOp::stringTo<int>(
"-11") == OK(-11));
120 CHECK(StringOp::stringTo<int>(
"-") == NOK);
121 CHECK(StringOp::stringTo<int>(
"zz") == NOK);
122 CHECK(StringOp::stringTo<int>(
"+") == NOK);
123 CHECK(StringOp::stringTo<int>(
"+12") == NOK);
126 CHECK(StringOp::stringTo<int>(
" 14") == NOK);
127 CHECK(StringOp::stringTo<int>(
"15 ") == NOK);
128 CHECK(StringOp::stringTo<int>(
"15bar") == NOK);
131 CHECK(StringOp::stringTo<int>(
"0x1a") == OK(26));
132 CHECK(StringOp::stringTo<int>(
"0x1B") == OK(27));
133 CHECK(StringOp::stringTo<int>(
"0X1c") == OK(28));
134 CHECK(StringOp::stringTo<int>(
"0X1D") == OK(29));
135 CHECK(StringOp::stringTo<int>(
"-0x100") == OK(-256));
136 CHECK(StringOp::stringTo<int>(
"0x") == NOK);
137 CHECK(StringOp::stringTo<int>(
"0x12g") == NOK);
138 CHECK(StringOp::stringTo<int>(
"0x-123") == NOK);
141 CHECK(StringOp::stringTo<int>(
"0b") == NOK);
142 CHECK(StringOp::stringTo<int>(
"0b2") == NOK);
143 CHECK(StringOp::stringTo<int>(
"0b100") == OK(4));
144 CHECK(StringOp::stringTo<int>(
"-0B1001") == OK(-9));
145 CHECK(StringOp::stringTo<int>(
"0b-11") == NOK);
148 CHECK(StringOp::stringTo<int>(
"-2147483649") == NOK);
149 CHECK(StringOp::stringTo<int>(
"2147483648") == NOK);
150 CHECK(StringOp::stringTo<int>(
"999999999999999") == NOK);
151 CHECK(StringOp::stringTo<int>(
"-999999999999999") == NOK);
153 CHECK(StringOp::stringTo<int>(
"-2147483648") == OK(-2147483648));
154 CHECK(StringOp::stringTo<int>(
"2147483647") == OK(2147483647));
155 CHECK(StringOp::stringTo<int>(
"-0x80000000") == OK(-2147483648));
156 CHECK(StringOp::stringTo<int>(
"0x7fffffff") == OK(2147483647));
158 SECTION(
"stringTo<unsigned>") {
159 std::optional<unsigned> NOK;
160 using OK = std::optional<unsigned>;
163 CHECK(StringOp::stringTo<unsigned>(
"") == NOK);
166 CHECK(StringOp::stringTo<unsigned>(
"0") == OK(0));
167 CHECK(StringOp::stringTo<unsigned>(
"08") == OK(8));
168 CHECK(StringOp::stringTo<unsigned>(
"0123") == OK(123));
169 CHECK(StringOp::stringTo<unsigned>(
"13") == OK(13));
171 CHECK(StringOp::stringTo<unsigned>(
"-0") == NOK);
172 CHECK(StringOp::stringTo<unsigned>(
"-12") == NOK);
175 CHECK(StringOp::stringTo<unsigned>(
"-") == NOK);
176 CHECK(StringOp::stringTo<unsigned>(
"zz") == NOK);
177 CHECK(StringOp::stringTo<unsigned>(
"+") == NOK);
178 CHECK(StringOp::stringTo<unsigned>(
"+12") == NOK);
181 CHECK(StringOp::stringTo<unsigned>(
" 16") == NOK);
182 CHECK(StringOp::stringTo<unsigned>(
"17 ") == NOK);
183 CHECK(StringOp::stringTo<unsigned>(
"17qux") == NOK);
186 CHECK(StringOp::stringTo<unsigned>(
"0x2a") == OK(42));
187 CHECK(StringOp::stringTo<unsigned>(
"0x2B") == OK(43));
188 CHECK(StringOp::stringTo<unsigned>(
"0X2c") == OK(44));
189 CHECK(StringOp::stringTo<unsigned>(
"0X2D") == OK(45));
190 CHECK(StringOp::stringTo<unsigned>(
"0x") == NOK);
191 CHECK(StringOp::stringTo<unsigned>(
"-0x456") == NOK);
192 CHECK(StringOp::stringTo<unsigned>(
"0x-123") == NOK);
195 CHECK(StringOp::stringTo<unsigned>(
"0b1100") == OK(12));
196 CHECK(StringOp::stringTo<unsigned>(
"0B1010") == OK(10));
197 CHECK(StringOp::stringTo<unsigned>(
"0b") == NOK);
198 CHECK(StringOp::stringTo<unsigned>(
"-0b101") == NOK);
199 CHECK(StringOp::stringTo<unsigned>(
"0b2") == NOK);
200 CHECK(StringOp::stringTo<unsigned>(
"0b-11") == NOK);
203 CHECK(StringOp::stringTo<unsigned>(
"4294967296") == NOK);
204 CHECK(StringOp::stringTo<unsigned>(
"999999999999999") == NOK);
206 CHECK(StringOp::stringTo<unsigned>(
"4294967295") == OK(4294967295));
207 CHECK(StringOp::stringTo<unsigned>(
"0xffffffff") == OK(4294967295));
210 SECTION(
"stringToBool") {
236 SECTION(
"trimRight") {
237 checkTrimRight(
"",
' ',
"");
238 checkTrimRight(
" ",
' ',
"");
239 checkTrimRight(
"foo",
' ',
"foo");
240 checkTrimRight(
" foo",
' ',
" foo");
241 checkTrimRight(
"foo ",
' ',
"foo");
243 checkTrimRight(
"",
"o ",
"");
244 checkTrimRight(
" o ",
"o ",
"");
245 checkTrimRight(
"foobar",
"o ",
"foobar");
246 checkTrimRight(
" foobar",
"o ",
" foobar");
247 checkTrimRight(
"foo ",
"o ",
"f");
249 SECTION(
"trimLeft") {
250 checkTrimLeft(
"",
' ',
"");
251 checkTrimLeft(
" ",
' ',
"");
252 checkTrimLeft(
"foo",
' ',
"foo");
253 checkTrimLeft(
"foo ",
' ',
"foo ");
254 checkTrimLeft(
" foo",
' ',
"foo");
256 checkTrimLeft(
"",
"f ",
"");
257 checkTrimLeft(
" f ",
"f ",
"");
258 checkTrimLeft(
"foo",
"f ",
"oo");
259 checkTrimLeft(
"barfoo ",
"f ",
"barfoo ");
260 checkTrimLeft(
" foo",
"f ",
"oo");
262 SECTION(
"splitOnFirst") {
263 checkSplitOnFirst(
"",
"",
"");
264 checkSplitOnFirst(
"-",
"",
"");
265 checkSplitOnFirst(
"foo-",
"foo",
"");
266 checkSplitOnFirst(
"-foo",
"",
"foo");
267 checkSplitOnFirst(
"foo-bar",
"foo",
"bar");
268 checkSplitOnFirst(
"foo-bar-qux",
"foo",
"bar-qux");
269 checkSplitOnFirst(
"-bar-qux",
"",
"bar-qux");
270 checkSplitOnFirst(
"foo-bar-",
"foo",
"bar-");
272 SECTION(
"splitOnLast") {
273 checkSplitOnLast(
"",
"",
"");
274 checkSplitOnLast(
"-",
"",
"");
275 checkSplitOnLast(
"foo-",
"foo",
"");
276 checkSplitOnLast(
"-foo",
"",
"foo");
277 checkSplitOnLast(
"foo-bar",
"foo",
"bar");
278 checkSplitOnLast(
"foo-bar-qux",
"foo-bar",
"qux");
279 checkSplitOnLast(
"-bar-qux",
"-bar",
"qux");
280 checkSplitOnLast(
"foo-bar-",
"foo-bar",
"");
284 checkSplit<KEEP>(
'-',
"", {});
285 checkSplit<KEEP>(
'-',
"-", {
""});
286 checkSplit<KEEP>(
'-',
"foo-", {
"foo"});
287 checkSplit<KEEP>(
'-',
"-foo", {
"",
"foo"});
288 checkSplit<KEEP>(
'-',
"foo-bar", {
"foo",
"bar"});
289 checkSplit<KEEP>(
'-',
"foo-bar-qux", {
"foo",
"bar",
"qux"});
290 checkSplit<KEEP>(
'-',
"-bar-qux", {
"",
"bar",
"qux"});
291 checkSplit<KEEP>(
'-',
"foo-bar-", {
"foo",
"bar"});
292 checkSplit<KEEP>(
'-',
"foo--bar", {
"foo",
"",
"bar"});
293 checkSplit<KEEP>(
'-',
"--foo--bar--", {
"",
"",
"foo",
"",
"bar",
""});
294 checkSplit<KEEP>(
" \t",
"foo\t\t bar", {
"foo",
"",
"",
"",
"bar"});
296 checkSplit<REMOVE>(
'-',
"", {});
297 checkSplit<REMOVE>(
'-',
"-", {});
298 checkSplit<REMOVE>(
'-',
"foo-", {
"foo"});
299 checkSplit<REMOVE>(
'-',
"-foo", {
"foo"});
300 checkSplit<REMOVE>(
'-',
"foo-bar", {
"foo",
"bar"});
301 checkSplit<REMOVE>(
'-',
"foo-bar-qux", {
"foo",
"bar",
"qux"});
302 checkSplit<REMOVE>(
'-',
"-bar-qux", {
"bar",
"qux"});
303 checkSplit<REMOVE>(
'-',
"foo-bar-", {
"foo",
"bar"});
304 checkSplit<REMOVE>(
'-',
"foo--bar", {
"foo",
"bar"});
305 checkSplit<REMOVE>(
'-',
"--foo--bar--", {
"foo",
"bar"});
306 checkSplit<REMOVE>(
" \t",
"foo\t\t bar", {
"foo",
"bar"});
308 SECTION(
"parseRange") {
309 checkParseRange(
"", {});
310 checkParseRange(
"5", {5});
311 checkParseRange(
"5,8", {5,8});
312 checkParseRange(
"5,5", {5});
313 checkParseRange(
"5-7", {5,6,7});
314 checkParseRange(
"7-5", {5,6,7});
315 checkParseRange(
"5-7,19", {5,6,7,19});
316 checkParseRange(
"15,5-7", {5,6,7,15});
317 checkParseRange(
"6,5-7", {5,6,7});
318 checkParseRange(
"5-8,10-12", {5,6,7,8,10,11,12});
319 checkParseRange(
"5-9,6-10", {5,6,7,8,9,10});
326 SECTION(
"caseless") {
328 CHECK( op(
"abc",
"xyz"));
329 CHECK(!op(
"xyz",
"abc"));
330 CHECK(!op(
"abc",
"abc"));
331 CHECK( op(
"ABC",
"xyz"));
332 CHECK(!op(
"xyz",
"ABC"));
333 CHECK(!op(
"ABC",
"abc"));
334 CHECK( op(
"aBC",
"Xyz"));
335 CHECK(!op(
"xYz",
"AbC"));
336 CHECK(!op(
"ABc",
"abC"));
338 CHECK( op(
"abc",
"ABCdef"));
339 CHECK(!op(
"AbcDef",
"AbC"));
343 CHECK( op(
"abc",
"abc"));
344 CHECK( op(
"abc",
"ABC"));
345 CHECK(!op(
"abc",
"xyz"));
346 CHECK(!op(
"ab",
"abc"));
347 CHECK(!op(
"ab",
"ABC"));
348 CHECK(!op(
"abc",
"ab"));
349 CHECK(!op(
"abc",
"AB"));
351 SECTION(
"containsCaseInsensitive") {