21 #include <boost/algorithm/string.hpp> 22 #include <boost/algorithm/string/trim.hpp> 23 #include <boost/format.hpp> 24 #include <boost/lexical_cast.hpp> 48 #if defined(_MSC_VER) && _MSC_VER < 1900 50 _set_output_format(_TWO_DIGIT_EXPONENT);
51 #elif defined(_MSC_VER) && _MSC_VER >= 1900 52 #pragma message("StTemp2DigitExponents class can be removed.") 59 #if defined(_MSC_VER) && _MSC_VER < 1900 71 unsigned int count = 0;
72 std::string::size_type size = str.size();
74 for (std::string::size_type pos = 0; pos < size; ++pos) {
89 std::stringstream ss(copy);
94 return (!ss.fail() && ss.eof());
104 bool check_numeric ) {
109 return (str.find_first_of(
"eE") != std::string::npos);
118 const char *look_up[] = {
127 unsigned int src = to_extended ? 1 : 0;
128 unsigned int dst = to_extended ? 0 : 1;
130 for (; look_up[src] !=
nullptr; src += 2, dst += 2) {
131 stReplace(str, look_up[src], look_up[dst]);
145 std::string::size_type pos = source.find(a_delimiter);
146 std::vector<std::string> exploded;
148 if (pos != std::string::npos) {
149 size_t delim_len = a_delimiter.size();
151 exploded.push_back(source.substr(0, pos));
153 while (pos != std::string::npos) {
154 std::string::size_type pos2 = source.find(a_delimiter, pos + 1);
155 std::string::size_type length = pos2 - pos - delim_len;
157 if (pos2 == std::string::npos) {
158 length = std::string::npos;
161 exploded.push_back(source.substr(pos + delim_len, length));
166 if (!source.empty()) {
167 exploded.push_back(source);
183 const std::string &a_delimiterList ,
184 bool a_delimiterCompressOn ) {
185 std::string trimmed =
stTrimCopy(a_source, a_delimiterList);
187 if (a_delimiterCompressOn) {
188 boost::split(elems, trimmed, boost::is_any_of(a_delimiterList),
189 boost::token_compress_on);
194 std::vector<char> temp(a_source.size());
196 for (
size_t i = 0; i < a_source.size(); ++i) {
197 if (a_delimiterList.find(a_source[i]) != std::string::npos) {
198 elems.push_back(std::string(&temp[0], end));
201 temp[end++] = a_source[i];
204 if (a_delimiterList.find(a_source.back()) != std::string::npos) {
216 std::string
stImplode(
const std::vector<std::string> &source,
217 const std::string &delim) {
218 std::string imploded;
220 if (!source.empty()) {
221 size_t size = source.size() - 1;
222 for (
size_t i = 0; i < size; ++i) {
223 imploded += source[i];
227 imploded += source[size];
241 for (
int i = 0; i < static_cast<int>(a_container.size()); i++) {
242 if (a_container[i] == str) {
259 const std::string &delim ) {
260 std::string temp(str);
262 return stTrim(temp, delim);
271 const std::string &delim ) {
272 std::string::size_type pos = str.find_first_not_of(delim);
274 if (pos != std::string::npos) {
289 const std::string &delim ) {
290 std::string::size_type pos = str.find_last_not_of(delim);
292 if (pos != std::string::npos) {
306 std::string &
stTrim(std::string &str,
const std::string &delim ) {
319 std::string replaced(str);
331 std::string
stReplaceCopy(
const std::string &str,
const std::string &source,
332 const std::string &dest) {
333 std::string replaced(str);
345 std::string &
stReplace(std::string &str,
char source,
char dest) {
346 if (source == dest) {
350 size_t pos = str.find(source);
352 while (pos != std::string::npos) {
354 pos = str.find(source, pos + 1);
367 std::string &
stReplace(std::string &str,
const std::string &source,
368 const std::string &dest) {
369 if (source == dest) {
373 std::string::size_type pos = str.find(source);
374 std::string::size_type source_len = source.size();
375 std::string::size_type dest_len = dest.size();
377 while (pos != std::string::npos) {
378 str.erase(pos, source_len);
379 str.insert(pos, dest);
380 pos = str.find(source, pos + dest_len);
393 std::string copy(str);
403 std::string &
stRemove(std::string &str,
char source) {
404 str.erase(std::remove(str.begin(), str.end(), source), str.end());
413 std::string copy(str);
422 std::transform<std::string::iterator, std::string::iterator, int (*)(int)>(
423 str.begin(), str.end(), str.begin(), std::tolower);
433 std::string copy(str);
442 std::transform<std::string::iterator, std::string::iterator, int (*)(int)>(
443 str.begin(), str.end(), str.begin(), std::toupper);
452 std::string
stLeftCopy(
const std::string &a_source,
size_t const a_length) {
455 XM_ASSERT(a_length == std::string::npos || a_length < (
size_t)-1 - 1000);
457 std::string copy(a_source);
458 return stLeft(copy, a_length);
466 std::string &
stLeft(std::string &a_source,
size_t const a_length) {
469 XM_ASSERT(a_length == std::string::npos || a_length < (
size_t)-1 - 1000);
471 if (a_length == std::string::npos)
474 a_source = a_source.substr(0, a_length);
484 std::string
stRightCopy(
const std::string &a_source,
size_t const a_length) {
487 XM_ASSERT(a_length == std::string::npos || a_length < (
size_t)-1 - 1000);
489 std::string copy(a_source);
490 return stRight(copy, a_length);
498 std::string modified = std::regex_replace(str, std::regex(
"\\s+"),
" ");
499 modified = boost::trim_copy(modified);
509 bool stContains(
const std::string &a_container,
const std::string &a_substr) {
510 std::string container = boost::to_upper_copy(a_container);
511 std::string substr = boost::to_upper_copy(a_substr);
516 if (container.find(substr) != std::string::npos)
528 return (std::find(a_container.begin(), a_container.end(), str) !=
537 std::string &
stRight(std::string &a_source,
size_t const a_length) {
540 XM_ASSERT(a_length == std::string::npos || a_length < (
size_t)-1 - 1000);
542 if (a_length >= a_source.size()) {
545 a_source = a_source.substr(a_source.size() - a_length);
555 return boost::iequals(a, b);
572 bool stMakeUnique(
const std::set<std::string> &set_str, std::string &str) {
573 if (set_str.find(str) == set_str.end()) {
581 std::string::size_type pos1, pos2;
583 pos1 = str.find(
'(');
584 pos2 = str.find(
')');
586 if ((pos1 != std::string::npos) && (pos2 != std::string::npos) &&
589 std::string::size_type diff;
590 std::stringstream ss;
596 ss.str(str.substr(pos1, diff));
600 if (!ss.fail() && ss.eof()) {
604 str.replace(pos1, diff, ss.str(), 0, ss.str().length());
611 }
while (set_str.find(str) != set_str.end());
628 i = std::stoi(s, &bad, base);
629 if (bad < s.size()) {
632 }
catch (std::exception) {
649 d = std::stod(s, &bad);
650 if (bad < s.size()) {
653 }
catch (std::exception) {
677 if (!std::isfinite(value))
681 const int MAXFLOATDIGITS(7);
682 const int MAXDOUBLEDIGITS(14);
691 short ilength, flength;
694 bool isFraction =
false;
709 max = pow(10.0, (
double)(length - 3));
710 const double min = 1e-5;
723 if (
GT_EPS(fabs(value), max, DBL_EPSILON) ||
724 EQ_EPS(fabs(value), max, DBL_EPSILON) ||
726 (
GT_EPS(fabs(value), 0.0, DBL_EPSILON) &&
727 LT_EPS(fabs(value), min, DBL_EPSILON))) {
746 istring = (boost::format(
"%1.6e") % value).str();
748 istring = (boost::format(
"%1.15e") % value).str();
750 charptr = istring.find(
'.');
751 istring = istring.substr(0, charptr);
752 charptr = fstring.find(
'.');
753 if (charptr != std::string::npos) {
755 fstring = fstring.substr(charptr);
757 charptr = fstring.find(
'e');
758 fstring = fstring.substr(0, charptr);
769 theval = (boost::format(
"%1.6e") % value).str();
771 theval = (boost::format(
"%1.13e") % value).str();
774 ipart = boost::numeric_cast<int64_t>(i);
776 istring = (boost::format(
"%d") % ipart).str();
777 ilength = (short)istring.size();
782 theval.erase(0, ilength);
784 size_t indx = theval.find(
"e");
785 theval.erase(indx, theval.size() - indx);
791 ipart = boost::numeric_cast<int64_t>(i);
792 istring = (boost::format(
"%d") % ipart).str();
794 fstring = (boost::format(
"%Lg") % f).str();
797 if (fstring.find(
"e") != std::string::npos ||
798 fstring.find(
"E") != std::string::npos) {
800 f2 = std::stod(fstring);
801 fstring = (boost::format(
"%.16lf") % f2).str();
803 charptr = fstring.find(
'.');
804 if (charptr != std::string::npos) {
806 fstring = fstring.substr(charptr);
811 ipart = boost::numeric_cast<int64_t>(i);
812 istring = (boost::format(
"%d") % ipart).str();
813 ilength = (short)istring.size();
819 maxDigits = MAXFLOATDIGITS;
821 maxDigits = MAXDOUBLEDIGITS;
822 if (ipart == 0 && value != 0.0) {
824 modf(log10(fabs(value)), &i);
825 int digits = maxDigits -
Round(i);
827 ilength = (short)(digits + 2);
829 ilength = (short)(digits + 3);
831 (boost::format(
"%s%d.%d%s") %
"%" % ilength % digits %
"f").str();
833 format = (boost::format(
"%s%d.%d%s") %
"%" % ilength %
834 Miabs(maxDigits - ilength) %
"f")
838 fstring = (boost::format(format) % value).str();
840 charptr = fstring.find(
'.');
841 if (charptr != std::string::npos) {
843 fstring = fstring.substr(charptr);
848 ilength = (short)istring.size();
849 flength = (short)fstring.size();
862 prec = MAXFLOATDIGITS - ilength - 1;
864 prec = MAXDOUBLEDIGITS - ilength - 1;
866 if (ilength == 1 && ipart == 0) {
869 if (prec >= flength) {
872 for (; prec >= 0; prec--) {
873 if (fstring.at(prec) !=
'0')
903 if (flags & STR_SCIENTIFIC) {
904 maxdigits = (short)(length - 8);
910 if (!
LT_EPS(fabs(value), testval, DBL_EPSILON)) {
914 }
while (!
LT_EPS(fabs(value), testval, DBL_EPSILON));
917 if (!(value < 0.0)) {
930 if (prec > maxdigits) {
939 if ((
int)fstring.size() > prec && fstring.at(prec - 1) ==
'0') {
940 std::stringstream ss;
941 ss << fstring.at(prec);
945 fstring.at(prec - 1) =
'1';
947 for (; prec >= 1; prec--) {
948 if (fstring.at(prec - 1) !=
'0') {
995 std::string
STRstd(
double a_value,
int a_n ,
int width ,
1007 #if BOOST_OS_WINDOWS 1008 if (!_finite(a_value)) {
1009 switch (_fpclass(a_value)) {
1023 if (!std::isfinite(a_value)) {
1024 switch (std::fpclassify(a_value)) {
1026 if (std::signbit(a_value))
1044 if ((flags & STR_USEMAXPREC) &&
LT_TOL(fabs(a_value), 1e-4, DBL_EPSILON)) {
1045 a_value *= pow(10.0, a_n);
1046 a_value = floor(a_value + 0.5);
1047 a_value /= pow(10.0, a_n);
1052 }
catch (std::exception &) {
1057 if ((flags & STR_USEMAXPREC) && prec > a_n) {
1069 format = (boost::format(
"%%.%de") %
Miabs(prec)).str();
1074 format = (boost::format(
"%%.%dlf") %
Miabs(prec)).str();
1079 str = (boost::format(format) % a_value).str();
1082 std::locale loc(
"");
1083 str = (boost::format(format, loc) % a_value).str();
1089 if ((a_n == -1) || (flags & STR_USEMAXPREC)) {
1091 size_t index = str.find(
'.');
1092 if (index != std::string::npos) {
1093 if ((index = str.find_first_of(
"eE")) != std::string::npos) {
1096 while (index > 0 && str.at(index) ==
'0' && str.at(index - 1) !=
'.') {
1097 str.erase(index, 1);
1104 if (str[str.size() - 1] ==
'.') {
1114 int len = (int)str.size();
1115 int diff = width - len;
1117 std::string str1, str2;
1118 for (
size_t i = 0; i < diff; i++)
1126 if (str ==
"-0.0") {
1168 std::string
STRstd(
float value,
int n ,
int width ,
1170 return STRstd((
double)value, n, width, flags);
1178 std::string
STRstd(std::string value) {
return value; }
1227 void GetVectorsFromArray(std::vector<ValStr> a_array,
xms::VecDbl &a_vals,
1235 for (
int i = 0; i < a_array.size(); ++i) {
1236 a_vals.push_back(a_array[i].val);
1237 a_ns.push_back(a_array[i].n);
1238 a_widths.push_back(a_array[i].width);
1239 a_flags.push_back(a_array[i].flag);
1240 a_strs.push_back(a_array[i].str);
1248 TS_ASSERT_EQUALS(a_values.size(), a_flags.size());
1249 TS_ASSERT_EQUALS(a_values.size(), a_precs.size());
1255 for (
int i = 0; i < (int)a_values.size(); ++i) {
1267 TS_ASSERT_EQUALS(a_vals.size(), a_ns.size());
1268 TS_ASSERT_EQUALS(a_vals.size(), a_widths.size());
1269 TS_ASSERT_EQUALS(a_vals.size(), a_flags.size());
1270 TS_ASSERT_EQUALS(a_vals.size(), a_strs.size());
1275 for (
int i = 0; i < (int)a_vals.size(); ++i) {
1277 xms::STRstd(a_vals.at(i), a_ns.at(i), a_widths.at(i), a_flags.at(i));
1294 std::string str1(
"test\xb2");
1295 std::string str2(
"test\xb3");
1296 std::string str3(
"\xb0test");
1298 xms::stChangeExtendedAscii(str1,
false);
1299 xms::stChangeExtendedAscii(str2,
false);
1300 xms::stChangeExtendedAscii(str3,
false);
1302 TS_ASSERT_EQUALS(
"test^2", str1);
1303 TS_ASSERT_EQUALS(
"test^3", str2);
1304 TS_ASSERT_EQUALS(
"deg_test", str3);
1306 xms::stChangeExtendedAscii(str1,
true);
1307 xms::stChangeExtendedAscii(str2,
true);
1308 xms::stChangeExtendedAscii(str3,
true);
1310 TS_ASSERT_EQUALS(
"test\xb2", str1);
1311 TS_ASSERT_EQUALS(
"test\xb3", str2);
1312 TS_ASSERT_EQUALS(
"\xb0test", str3);
1318 std::vector<std::string> values;
1320 values.push_back(
"test");
1321 values.push_back(
"test2");
1322 values.push_back(
"test3");
1323 values.push_back(
"test4");
1325 std::string result = xms::stImplode(values,
"stuff");
1327 TS_ASSERT_EQUALS(
"teststufftest2stufftest3stufftest4", result);
1329 std::vector<std::string> result2;
1330 result2 = xms::stExplode(result,
"stuff");
1334 result = xms::stImplode(values,
"stuff");
1335 TS_ASSERT_EQUALS(
"", result);
1337 result2 = xms::stExplode(result,
"stuff");
1340 values.push_back(
"test");
1341 result = xms::stImplode(values,
"stuff");
1342 TS_ASSERT_EQUALS(
"test", result);
1344 result2 = xms::stExplode(result,
"stuff");
1347 result = xms::stImplode(values,
" ");
1348 result2 = xms::stExplode(result,
" ");
1349 std::vector<std::string> expected = {
"test",
"test2",
"test3",
"test4"};
1358 xms::VecStr container = {
"me",
"you",
"they",
"we",
"Us"};
1359 int test1 = xms::stIndexOfElem(container,
"us");
1360 TS_ASSERT_EQUALS(expected, test1);
1363 int test2 = xms::stIndexOfElem(container,
"they");
1364 TS_ASSERT_EQUALS(expected, test2);
1370 std::string s =
" 1 2 3\t4\t\t5 \t6 ";
1371 std::vector<std::string> expected;
1372 std::vector<std::string> r;
1374 r = xms::stSplit(s);
1375 expected = {
"1",
"2",
"3",
"4",
"5",
"6"};
1378 r = xms::stSplit(s,
" ");
1379 expected = {
"1",
"2",
"3\t4\t\t5",
"\t6"};
1382 r = xms::stSplit(s,
"\t");
1383 expected = {
" 1 2 3",
"4",
"5 ",
"6 "};
1386 r = xms::stSplit(s,
" \t");
1387 expected = {
"1",
"2",
"3",
"4",
"5",
"6"};
1390 r = xms::stSplit(
",,A,B,,C,,,",
",",
false);
1391 expected = {
"",
"",
"A",
"B",
"",
"C",
"",
"",
""};
1398 const std::string expected1(
"make");
1399 const std::string expected2(
"make (2)");
1400 const std::string expected3(
"make (10)");
1402 std::set<std::string> set_str;
1403 std::string str(
"make");
1405 set_str.insert(
"test");
1406 set_str.insert(
"stuff");
1407 set_str.insert(
"yup");
1409 TS_ASSERT(!xms::stMakeUnique(set_str, str));
1410 TS_ASSERT_EQUALS(expected1, str);
1412 set_str.insert(
"make");
1413 set_str.insert(
"make (3)");
1415 TS_ASSERT(xms::stMakeUnique(set_str, str));
1416 TS_ASSERT_EQUALS(expected2, str);
1418 set_str.insert(
"make (2)");
1419 set_str.insert(
"make (4)");
1420 set_str.insert(
"make (5)");
1421 set_str.insert(
"make (6)");
1422 set_str.insert(
"make (7)");
1423 set_str.insert(
"make (8)");
1424 set_str.insert(
"make (9)");
1426 TS_ASSERT(xms::stMakeUnique(set_str, str));
1427 TS_ASSERT_EQUALS(expected3, str);
1435 std::string test(
"\f this has white space\t \n \r \v");
1437 TS_ASSERT_EQUALS(
"this has white space", test);
1440 std::string test(
" ");
1445 TS_ASSERT_EQUALS(
"", test);
1448 std::string test(
" , * ");
1449 xms::stTrim(test,
" ,*");
1450 TS_ASSERT_EQUALS(
"", test);
1457 std::string test(
"this has a few spaces");
1459 xms::stReplace(test,
' ',
'_');
1460 TS_ASSERT_EQUALS(
"this_has_a_few_spaces", test);
1462 std::string test_copy(xms::stReplaceCopy(test,
'_',
' '));
1463 TS_ASSERT_EQUALS(
"this has a few spaces", test_copy);
1464 TS_ASSERT_EQUALS(
"this_has_a_few_spaces", test);
1466 xms::stReplace(test,
"a_few",
"zero");
1467 TS_ASSERT_EQUALS(
"this_has_zero_spaces", test);
1469 xms::stReplace(test,
"_",
"");
1470 TS_ASSERT_EQUALS(
"thishaszerospaces", test);
1476 std::string test(
"how much wood would a woodchuck chuck if a woodchuck could" 1479 TS_ASSERT_EQUALS(11, xms::stCountChar(test,
'o'));
1485 std::string test(
"-123e+201");
1487 TS_ASSERT(xms::stNumeric(test));
1488 TS_ASSERT(xms::stScientificNotation(test));
1492 TS_ASSERT(xms::stNumeric(test));
1493 TS_ASSERT(!xms::stScientificNotation(test));
1495 test =
"muffin monster";
1497 TS_ASSERT(!xms::stNumeric(test));
1498 TS_ASSERT(!xms::stScientificNotation(test));
1502 TS_ASSERT(xms::stScientificNotation(test,
false));
1508 std::string str(
"aBcD");
1509 TS_ASSERT_EQUALS(
"ABCD", xms::stToUpper(str));
1511 const std::string str_const(
"aBcD");
1514 TS_ASSERT_EQUALS(
"ABCD", xms::stToUpperCopy(str_const));
1524 const int TEST_NONE = -1;
1530 rv = xms::stStringToInt(str, i);
1531 TS_ASSERT_EQUALS(i, TEST_NONE);
1532 TS_ASSERT_EQUALS(rv,
false);
1536 rv = xms::stStringToInt(str, i);
1537 TS_ASSERT_EQUALS(i, TEST_NONE);
1538 TS_ASSERT_EQUALS(rv,
false);
1542 rv = xms::stStringToInt(str, i);
1543 TS_ASSERT_EQUALS(i, 1);
1544 TS_ASSERT_EQUALS(rv,
false);
1548 rv = xms::stStringToInt(str, i);
1549 TS_ASSERT_EQUALS(i, 1);
1550 TS_ASSERT_EQUALS(rv,
true);
1554 rv = xms::stStringToInt(str, i);
1555 TS_ASSERT_EQUALS(i, -1);
1556 TS_ASSERT_EQUALS(rv,
true);
1560 rv = xms::stStringToInt(str, i);
1561 TS_ASSERT_EQUALS(i, 0);
1562 TS_ASSERT_EQUALS(rv,
true);
1566 rv = xms::stStringToInt(str, i);
1567 TS_ASSERT_EQUALS(i, 1);
1568 TS_ASSERT_EQUALS(rv,
false);
1572 rv = xms::stStringToInt(str, i);
1573 TS_ASSERT_EQUALS(i, 1);
1574 TS_ASSERT_EQUALS(rv,
false);
1583 std::string s1 =
"abcdefg";
1584 const std::string s2 = s1;
1590 TS_ASSERT_EQUALS(
"", s1);
1593 TS_ASSERT_EQUALS(
"a", s1);
1596 TS_ASSERT_EQUALS(
"ab", s1);
1599 TS_ASSERT_EQUALS(
"abcdefg", s1);
1602 TS_ASSERT_EQUALS(
"abcdefg", s1);
1607 s3 = xms::stLeftCopy(s2, 0);
1608 TS_ASSERT_EQUALS(
"abcdefg", s2);
1609 TS_ASSERT_EQUALS(
"", s3);
1610 s3 = xms::stLeftCopy(s2, 1);
1611 TS_ASSERT_EQUALS(
"abcdefg", s2);
1612 TS_ASSERT_EQUALS(
"a", s3);
1613 s3 = xms::stLeftCopy(s2, 2);
1614 TS_ASSERT_EQUALS(
"abcdefg", s2);
1615 TS_ASSERT_EQUALS(
"ab", s3);
1616 s3 = xms::stLeftCopy(s2, 7);
1617 TS_ASSERT_EQUALS(
"abcdefg", s2);
1618 TS_ASSERT_EQUALS(
"abcdefg", s3);
1619 s3 = xms::stLeftCopy(s2, 8);
1620 TS_ASSERT_EQUALS(
"abcdefg", s2);
1621 TS_ASSERT_EQUALS(
"abcdefg", s3);
1625 xms::stRight(s1, 0);
1626 TS_ASSERT_EQUALS(
"", s1);
1628 xms::stRight(s1, 1);
1629 TS_ASSERT_EQUALS(
"g", s1);
1631 xms::stRight(s1, 2);
1632 TS_ASSERT_EQUALS(
"fg", s1);
1634 xms::stRight(s1, 7);
1635 TS_ASSERT_EQUALS(
"abcdefg", s1);
1637 xms::stRight(s1, 8);
1638 TS_ASSERT_EQUALS(
"abcdefg", s1);
1643 s3 = xms::stRightCopy(s2, 0);
1644 TS_ASSERT_EQUALS(
"abcdefg", s2);
1645 TS_ASSERT_EQUALS(
"", s3);
1646 s3 = xms::stRightCopy(s2, 1);
1647 TS_ASSERT_EQUALS(
"abcdefg", s2);
1648 TS_ASSERT_EQUALS(
"g", s3);
1649 s3 = xms::stRightCopy(s2, 2);
1650 TS_ASSERT_EQUALS(
"abcdefg", s2);
1651 TS_ASSERT_EQUALS(
"fg", s3);
1652 s3 = xms::stRightCopy(s2, 7);
1653 TS_ASSERT_EQUALS(
"abcdefg", s2);
1654 TS_ASSERT_EQUALS(
"abcdefg", s3);
1655 s3 = xms::stRightCopy(s2, 8);
1656 TS_ASSERT_EQUALS(
"abcdefg", s2);
1657 TS_ASSERT_EQUALS(
"abcdefg", s3);
1661 TS_ASSERT_EQUALS(
true, xms::stEqualNoCase(
"ABC",
"abc"));
1662 TS_ASSERT_EQUALS(
true, xms::stEqualNoCase(
"abc",
"ABC"));
1663 TS_ASSERT_EQUALS(
false, xms::stEqualNoCase(
"ABC",
"ABCD"));
1664 TS_ASSERT_EQUALS(
false, xms::stEqualNoCase(
"abc",
"abcd"));
1665 TS_ASSERT_EQUALS(
false, xms::stEqualNoCase(
"BCD",
"ABCD"));
1666 TS_ASSERT_EQUALS(
false, xms::stEqualNoCase(
"bcd",
"abcd"));
1667 TS_ASSERT_EQUALS(
false, xms::stEqualNoCase(
"ABC",
"DEFG"));
1671 std::string s7 =
"abcd abcd abcd";
1672 const std::string s8 = s7;
1675 xms::stRemove(s7,
' ');
1676 TS_ASSERT_EQUALS(
"abcdabcdabcd", s7);
1678 xms::stRemove(s7,
'g');
1679 TS_ASSERT_EQUALS(
"abcd abcd abcd", s7);
1681 xms::stRemove(s7,
'c');
1682 TS_ASSERT_EQUALS(
"abd abd abd", s7);
1685 s9 = xms::stRemoveCopy(s8,
' ');
1686 TS_ASSERT_EQUALS(
"abcd abcd abcd", s8);
1687 TS_ASSERT_EQUALS(
"abcdabcdabcd", s9);
1688 s9 = xms::stRemoveCopy(s8,
'g');
1689 TS_ASSERT_EQUALS(
"abcd abcd abcd", s8);
1690 TS_ASSERT_EQUALS(
"abcd abcd abcd", s9);
1691 s9 = xms::stRemoveCopy(s8,
'c');
1692 TS_ASSERT_EQUALS(
"abcd abcd abcd", s8);
1693 TS_ASSERT_EQUALS(
"abd abd abd", s9);
1700 double d1 = 123456.0123;
1701 double d2 = 0.123456789;
1703 std::stringstream ss;
1705 ss.imbue(commaLocale);
1706 ss << d1 <<
" " << d2 <<
" " << i;
1707 std::string s(ss.str());
1708 std::string expected =
"123,456 0.123457 123,456,789";
1709 TS_ASSERT_EQUALS(expected, s);
1715 std::string s =
"\t Testing \rextra \nspace \t \n\t";
1716 std::string expected =
"Testing extra space";
1717 std::string modified = xms::stSimplified(s);
1718 TS_ASSERT_EQUALS(expected, modified);
1724 std::string container =
"Isn't ThiS a Lovely day?";
1725 std::string str1 =
"DAY";
1726 std::string str2 =
"these a";
1727 bool expectedT =
true;
1728 bool expectedF =
false;
1730 bool test1 = xms::stContains(container, str1);
1731 TS_ASSERT_EQUALS(expectedT, test1);
1733 bool test2 = xms::stContains(container, str2);
1734 TS_ASSERT_EQUALS(expectedF, test2);
1736 bool test3 = xms::stContains(container,
"THis");
1737 TS_ASSERT_EQUALS(expectedT, test3)
1743 bool expectedT =
true;
1744 bool expectedF =
false;
1745 xms::VecStr container = {
"me",
"you",
"they",
"we",
"Us"};
1747 bool test1 = xms::stVectorContainsString(container,
"we");
1748 TS_ASSERT_EQUALS(expectedT, test1);
1750 bool test2 = xms::stVectorContainsString(container,
"she");
1751 TS_ASSERT_EQUALS(expectedF, test2);
1758 xms::STRstd(0.0, 15, 15, xms::STR_FULLWIDTH | xms::STR_USEMAXPREC);
1759 std::string base =
" 0.0";
1760 TS_ASSERT_EQUALS(base, out);
1774 xms::VecDbl vec_values{0.0, 1e-30, 1e-15, 1e-6, 1e-5, 1e11, 1e12, 1e13};
1778 RunPrec(vec_values, vec_flags, vec_precs);
1793 std::vector<ValStr> arr{
1796 {0.0, -1, 15, 0,
"0.0"},
1797 {1e-30, -1, 15, 0,
"1.0e-30"},
1798 {1e-15, -1, 15, 0,
"1.0e-15"},
1799 {1e-6, -1, 15, 0,
"1.0e-06"},
1800 {1e-5, -1, 15, 0,
"0.00001"},
1801 {1e11, -1, 15, 0,
"100000000000.0"},
1802 {1e12, -1, 15, 0,
"1.0e+12"},
1803 {1e13, -1, 15, 0,
"1.0e+13"}
1807 {0.0, -1, 15, xms::STR_USEMAXPREC,
"0.0"},
1808 {1e-30, -1, 15, xms::STR_USEMAXPREC,
"0.0"},
1809 {1e-15, -1, 15, xms::STR_USEMAXPREC,
"0.0"},
1810 {1e-6, -1, 15, xms::STR_USEMAXPREC,
"0.0"},
1811 {1e-5, -1, 15, xms::STR_USEMAXPREC,
"0.0"},
1812 {1e11, -1, 15, xms::STR_USEMAXPREC,
"100000000000.0"},
1813 {1e12, -1, 15, xms::STR_USEMAXPREC,
"1.0e+12"},
1814 {1e13, -1, 15, xms::STR_USEMAXPREC,
"1.0e+13"}
1818 {0.0, 3, 15, 0,
"0.000"},
1819 {1e-30, 3, 15, 0,
"0.000"},
1820 {1e-15, 3, 15, 0,
"0.000"},
1821 {1e-6, 3, 15, 0,
"0.000"},
1822 {1e-5, 3, 15, 0,
"0.000"},
1823 {1e11, 3, 15, 0,
"100000000000.000"},
1824 {1e12, 3, 15, 0,
"1000000000000.000"},
1825 {1e13, 3, 15, 0,
"10000000000000.000"}
1829 {0.0, 30, 15, xms::STR_USEMAXPREC,
"0.0"},
1830 {1e-30, 30, 15, xms::STR_USEMAXPREC,
"1.0e-30"},
1831 {1e-15, 30, 15, xms::STR_USEMAXPREC,
"1.0e-15"},
1832 {1e-6, 30, 15, xms::STR_USEMAXPREC,
"1.0e-06"},
1833 {1e-5, 30, 15, xms::STR_USEMAXPREC,
"0.00001"},
1834 {1e11, 30, 15, xms::STR_USEMAXPREC,
"100000000000.0"},
1835 {1e12, 30, 15, xms::STR_USEMAXPREC,
"1.0e+12"},
1836 {1e13, 30, 15, xms::STR_USEMAXPREC,
"1.0e+13"}
1840 {-999999.0, -1, 8, xms::STR_FLOAT | xms::STR_SCIENTIFIC,
"-1.0e+06"}
1846 GetVectorsFromArray(arr, vals, ns, widths, flags, strs);
1848 RunSTR(vals, ns, widths, flags, strs);
void testExtendedASCII()
Test stChangeExtendedAscii.
int m_oldOutputFormat
Saved output format to restore to orignal value.
std::vector< int > VecInt
short rename
std::string stRemoveCopy(const std::string &str, char source)
Returns a copy of str with all instances of char source removed.
std::string & stTrimLeft(std::string &str, const std::string &delim)
Trims the leading delim characters from a string.
bool LT_EPS(_T A, _U B, _V epsilon)
Returns true if A < B equal within an epsilon (DBL EPS).
std::string & stLeft(std::string &a_source, size_t const a_length)
Modifies a_source to contain the first (leftmost) a_length characters.
std::string & stToUpper(std::string &str)
Modifies str to be all uppercase.
bool GT_EPS(_T A, _U B, _V epsilon)
Returns true if A > B equal within an epsilon (DBL EPS).
int stPrecision(double value, int &flags, int length)
Returns precision, or the number of digits to the right of the decimal needed to display the [value]...
void testSuIcontains()
Tests stContains.
_T Miabs(_T a)
Integer absolute value.
void testXmCommaNumpunct()
Tests StCommaNumpunct.
std::string STRstd(double a_value, int a_n, int width, int flags)
Get a properly formatted string from a double.
void test_STRstd()
Tests stVectorContainsString.
std::vector< double > VecDbl
short rename
std::string & stTrim(std::string &str, const std::string &delim)
Trim the leading and trailing delim characters from a string.
bool stScientificNotation(const std::string &str, bool check_numeric)
Determines whether the given string is a number in scientific notation.
std::string stReplaceCopy(const std::string &str, char source, char dest)
Returns a copy of str with every instance of source replaced with dest.
void testNumAndSciNot()
Test stNumeric and stScientificNotation.
std::string stToLowerCopy(const std::string &str)
Returns a new string that is str with all characters lowercase.
bool stVectorContainsString(const VecStr &a_container, const std::string &str)
Checks if a vec of strings contains a string. Case sensitive.
std::vector< std::string > VecStr
short rename
std::string stToUpperCopy(const std::string &str)
Returns a new string that is str with all characters uppercase.
std::string & stRight(std::string &a_source, size_t const a_length)
Modifies a_source to contain the last (rightmost) a_length characters.
bool stStringToDouble(const std::string &s, double &d)
Convert a string to an double.
StTemp2DigitExponents()
Temporarily output 2-digit exponents for floating point numbers to match C++ standard. Should be able to remove all instances of this class upon moving to Visual Studio 2015.
std::string stLeftCopy(const std::string &a_source, size_t const a_length)
Extracts first (leftmost) a_length characters from a_source returning a copy.
std::string stSimplified(const std::string &str)
Removes all white space from the passed string.
void testMakeUnique()
Test stMakeUnique.
Used to format numbers with comma separators.
void testSplit()
Test stSplit.
int stIndexOfElem(const VecStr &a_container, const std::string &str)
Iterates through a vec of strings and looks for the string. Case sensitive.
When constructed std::cout will temporarily output 2-digit exponents for floating point numbers...
bool stFindNoCase(const std::string &a, const std::string &b)
Returns true if a contains b while ignoring capitalization.
void testToUpper()
test stToUpper
virtual char do_thousands_sep() const
Returns the character used to separate numbers by thousands.
std::string & stReplace(std::string &str, char source, char dest)
Returns a reference to str, and replaces every instance of source replaced with dest.
std::string stImplode(const std::vector< std::string > &source, const std::string &delim)
Joins the vector, inserting delim between each item.
void test_str2int()
test stStringToInt
std::string & stToLower(std::string &str)
Modifies str to be all lowercase.
std::string stTrimCopy(const std::string &str, const std::string &delim)
Trims the white space from a string. This involves creating a copy of the string (twice I believe)...
~StTemp2DigitExponents()
Revert back to 3-digit exponents for pre-Visual Studio 2015.
std::string stRightCopy(const std::string &a_source, size_t const a_length)
Extracts last (rightmost) a_length characters from a_source returning a copy.
void testPrec()
Test the Prec utility.
void testSuIndexOfElem()
Test stIndexOfElem()
std::string & stTrimRight(std::string &str, const std::string &delim)
Trims the trailing delim characters from a string.
void testCountChar()
Test stCountChar.
bool stMakeUnique(const std::set< std::string > &set_str, std::string &str)
Changes str to "str (2)" etc. if it is in set of set_str.
void testSuSimplified()
Tests stSimplified.
VecStr stExplode(const std::string &source, const std::string &a_delimiter)
Breaks the string into a vector of strings based on the delimiter.
bool stNumeric(const std::string &str)
Determines whether the given string is a valid number.
#define XM_ASSERT(x)
Does a regular ASSERT if xmAsserting, otherwise does nothing.
void testSuVecContainsStr()
Tests stVectorContainsString.
VecStr stSplit(const std::string &a_source, const std::string &a_delimiterList, bool a_delimiterCompressOn)
Breaks string into vector of strings based on one or more delimiters.
bool stEqualNoCase(const std::string &a, const std::string &b)
Returns true if a and b are equal while ignoring capitalization.
bool LT_TOL(_T A, _U B, _V tolerance)
Returns true if A < B equal within a tolerance.
bool stContains(const std::string &a_container, const std::string &a_substr)
Checks if first string contains second. Case insensitive.
Vector types for convenience.
void stChangeExtendedAscii(std::string &str, bool to_extended)
Replaces the Windows Latin-1 extended ASCII characters with standard ASCII and vice-versa.
std::string STRstd(T a_value, int a_n=0, int width=0, int flags=0)
Functions and macros for assertion and checking for errors.
unsigned int stCountChar(const std::string &str, char c)
Counts the number of a given character in a string.
virtual std::string do_grouping() const
Returns the string defining how many numbers between separators.
void testSTR()
Test the STR utility.
std::string & stRemove(std::string &str, char source)
Removes all instances of char source from str and returns a reference to str.
void testMisc()
test various string utility functions.
bool stStringToInt(const std::string &s, int &i, int base)
Convert a string to an int.
void testImplodeExplode()
Test stImplode.
bool EQ_EPS(_T A, _U B, _V epsilon)
Returns true if A == B within an epsilon (DBL EPS).
void testReplace()
Test stReplace.
void testTrim()
Test stTrim.