20#include "../settings.hpp"
21#include "../structures.hpp"
45 return toString((
double)nNumber, _option);
73std::string
toString(
double dNumber,
int nPrecision)
75 std::ostringstream Temp;
76 Temp.precision(nPrecision);
90std::string
toString(
const std::complex<double>& dNumber,
int nPrecision)
95 std::ostringstream Temp;
96 Temp.precision(
std::rint(nPrecision / (dNumber.real() != 0.0 && dNumber.imag() != 0.0 && !
std::isnan(dNumber.imag()) ? 2 : 1)));
98 if (dNumber.real() || !dNumber.imag())
99 Temp << dNumber.real();
103 if ((dNumber.imag() > 0.0 ||
std::isnan(dNumber.imag())) && dNumber.real() != 0.0)
106 Temp << dNumber.imag() << (
std::isnan(dNumber.imag()) ||
std::isinf(dNumber.imag()) ?
" i" :
"i");
123 return toString((
long long int)nNumber);
137 return toString((
long long int)nNumber);
150std::string
toString(__time64_t tTime,
int timeStampFlags)
152 tm* ltm = _localtime64(&tTime);
159 std::ostringstream timeStream;
163 timeStream << 1900+ltm->tm_year <<
"-";
164 timeStream << std::setfill(
'0') << std::setw(2) << ltm->tm_mon + 1 <<
"-";
165 timeStream << std::setfill(
'0') << std::setw(2) << ltm->tm_mday;
175 if (
_lang.
get(
"TOOLS_TIMESTAMP_AT") ==
"TOOLS_TIMESTAMP_AT")
178 timeStream <<
_lang.
get(
"TOOLS_TIMESTAMP_AT") <<
" ";
184 timeStream << std::setfill(
'0') << std::setw(2) << ltm->tm_hour +
tz.Bias.count()/60;
186 timeStream << std::setfill(
'0') << std::setw(2) << ltm->tm_hour;
191 timeStream << std::setfill(
'0') << std::setw(2) << ltm->tm_min;
196 timeStream << std::setfill(
'0') << std::setw(2) << ltm->tm_sec;
198 return timeStream.str();
214 std::ostringstream timeStream;
219 timeStream << std::setfill(
'0') << std::setw(2) << unsigned(ltm.
m_ymd.
month()) <<
"-";
230 if (
_lang.
get(
"TOOLS_TIMESTAMP_AT") ==
"TOOLS_TIMESTAMP_AT")
233 timeStream <<
_lang.
get(
"TOOLS_TIMESTAMP_AT") <<
" ";
239 timeStream << std::setfill(
'0') << std::setw(2) << ltm.
m_hours.count() + (
tz.Bias +
tz.DayLightBias).count()/60;
241 timeStream << std::setfill(
'0') << std::setw(2) << ltm.
m_hours.count();
246 timeStream << std::setfill(
'0') << std::setw(2) << ltm.
m_minutes.count();
251 timeStream << std::setfill(
'0') << std::setw(2) << ltm.
m_seconds.count();
257 timeStream <<
"." << std::setfill(
'0') << std::setw(3) << ltm.
m_millisecs.count();
260 timeStream << std::setfill(
'0') << std::setw(3) << ltm.
m_microsecs.count();
263 return timeStream.str();
276 std::ostringstream Temp;
310 std::ostringstream Temp;
341 std::ostringstream Temp;
343 return "0x" + Temp.str();
358 std::vector<std::string> vVector;
360 if (sString ==
"{}" || !sString.length())
363 if (sString.front() ==
'{' && sString.back() ==
'}')
369 while (sString.length())
389 std::vector<int> vVector;
390 std::vector<std::string> vStrVect =
toStrVector(sString);
392 if (!vStrVect.size())
395 for (
const auto& s : vStrVect)
414 std::string sReturn = sText;
415 static std::string sToErase =
" AaEeIiOoUuÄäÖöÜüßYy";
416 for (
unsigned int i = 0; i < sReturn.length(); i++)
418 if (sToErase.find(sReturn[i]) != std::string::npos
425 || sReturn[i] == 225)
446std::string
truncString(
const std::string& sText,
size_t nMaxChars)
448 if (sText.length() <= nMaxChars)
451 return sText.substr(0, nMaxChars-3) +
"...";
465 if (!sToStrip.length())
468 sToStrip.erase(0, sToStrip.find_first_not_of(
" \t"));
470 if (sToStrip.length() && (sToStrip.back() ==
' ' || sToStrip.back() ==
'\t'))
471 sToStrip.erase(sToStrip.find_last_not_of(
" \t") + 1);
484 return atoi(sString.c_str());
497 return atof(sString.c_str());
511 if (
toLowerCase(sString) ==
"true" || sString ==
"1")
513 else if (
toLowerCase(sString) ==
"false" || sString ==
"0")
537 const char* pStart = sString.c_str();
538 const char* pEnd = pStart + sString.length();
543 while (pStart < pEnd && (*pStart ==
' ' || *pStart ==
'+'))
553 if (res.
ec == std::errc::invalid_argument)
556 while (res.
ptr < pEnd && (*res.
ptr ==
'-' || *res.
ptr ==
' ' || tolower(*res.
ptr) ==
'i'))
561 return std::complex<double>(0, *pStart ==
'-' ? -1 : 1);
569 while (res.
ptr < pEnd && *res.
ptr ==
' ')
575 if (*res.
ptr ==
'-' || *res.
ptr ==
'+')
577 oprt = *res.
ptr ==
'-' ? -1 : 1;
583 while (res.
ptr < pEnd && *res.
ptr ==
' ')
590 if (tolower(*res.
ptr) ==
'i'
592 && (res.
ptr+1 >= pEnd || tolower(*(res.
ptr+1)) !=
'n'))
593 return std::complex<double>(re, oprt);
595 if ((tolower(*res.
ptr) ==
'i' && (res.
ptr+1 >= pEnd || tolower(*(res.
ptr+1)) !=
'n')) || *res.
ptr ==
'*')
596 return std::complex<double>(0.0, re);
602 if (res.
ec == std::errc::invalid_argument)
607 while (res.
ptr < pEnd && *res.
ptr ==
' ')
610 if (tolower(*res.
ptr) !=
'i' && *res.
ptr !=
'*')
615 return std::complex<double>(re, oprt*im);
634 size_t pos = sString.find_first_not_of(
" \t");
637 timeStruct.
m_hours = std::chrono::hours::zero();
638 timeStruct.
m_minutes = std::chrono::minutes::zero();
639 timeStruct.
m_seconds = std::chrono::seconds::zero();
640 timeStruct.
m_millisecs = std::chrono::milliseconds::zero();
641 timeStruct.
m_microsecs = std::chrono::microseconds::zero();
643 const char* DIGITS =
"0123456789";
648 std::vector<std::string> toks =
split(sString,
':');
650 bool isFirst = sString.find(
':') < 3 + pos;
652 for (
size_t i = 0; i < toks.size(); i++)
657 if (i == 2 && toks[i].length() >= 3 && (toks[i][1] ==
'.' || toks[i][2] ==
'.'))
659 size_t dot = toks[i].find(
'.');
660 toks.insert(toks.begin()+i+1, toks[i].substr(dot+1));
665 if (toks[i].find_first_not_of(DIGITS) != std::string::npos)
667 if ((isFirst && i+1 != toks.size()) || (!isFirst && i))
671 toks[i].erase(toks[i].find_first_not_of(DIGITS));
673 toks[i].erase(0, toks[i].find_last_not_of(DIGITS)+1);
697 for (
size_t i = 0; i < toks.size(); i++)
702 if (toks[i].find_first_not_of(DIGITS) != std::string::npos)
710 toks[i].erase(toks[i].find_first_not_of(DIGITS));
712 toks[i].erase(0, toks[i].find_last_not_of(DIGITS)+1);
721 if (toks[i].length() > 2)
734 std::vector<std::string> toks;
742 toks =
split(sString,
'-');
743 isFirst = sString.find(
'-') < 5 + pos;
747 toks =
split(sString,
'/');
748 isFirst = sString.find(
'/') < 5 + pos;
751 for (
size_t i = 0; i < toks.size(); i++)
756 if (toks[i].find_first_not_of(DIGITS) != std::string::npos)
758 if ((isFirst && i+1 != toks.size()) || (!isFirst && i))
762 toks[i].erase(toks[i].find_first_not_of(DIGITS));
764 toks[i].erase(0, toks[i].find_last_not_of(DIGITS)+1);
769 if (toks[i].length() > 2)
817 std::string _sVer =
toString(nVersionDigits);
821 if (_sVer.length() < 3)
822 _sVer.insert(0, 3-_sVer.length(),
'0');
825 for (
size_t n = 1; n < _sVer.length(); n++)
828 _sVer.insert(n, 1,
'.');
846 if (sStr.front() ==
'"' && sStr.back() ==
'"')
847 sStr = sStr.substr(1, sStr.length()-2);
849 for (
size_t i = 0; i < sStr.length(); i++)
851 if (sStr.compare(i, 2,
"\\t") == 0
852 && sStr.compare(i, 4,
"\\tau") != 0
853 && sStr.compare(i, 6,
"\\theta") != 0
854 && sStr.compare(i, 6,
"\\times") != 0)
855 sStr.replace(i, 2,
"\t");
857 if (sStr.compare(i, 2,
"\\n") == 0
858 && sStr.compare(i, 3,
"\\nu") != 0
859 && sStr.compare(i, 4,
"\\neq") != 0)
860 sStr.replace(i, 2,
"\n");
862 if (sStr.compare(i, 2,
"\\\"") == 0)
863 sStr.replace(i, 2,
"\"");
865 if (sStr.compare(i, 2,
"\\ ") == 0)
866 sStr.replace(i, 2,
"\\");
884 return "\"" + sStr +
"\"";
898 std::string sLowerCase = sUpperCase;
899 for (
unsigned int i = 0; i < sLowerCase.length(); i++)
902 if ((
int)sLowerCase[i] >= (
int)
'A' && (
int)sLowerCase[i] <= (
int)
'Z')
905 sLowerCase[i] = (char)((
int)sLowerCase[i] + ((int)
'a' - (
int)
'A'));
907 if (sLowerCase[i] ==
'Ä')
909 else if (sLowerCase[i] ==
'Ö')
911 else if (sLowerCase[i] ==
'Ü')
913 else if (sLowerCase[i] == (
char)142)
914 sLowerCase[i] = (
char)132;
915 else if (sLowerCase[i] == (
char)153)
916 sLowerCase[i] = (
char)148;
917 else if (sLowerCase[i] == (
char)154)
918 sLowerCase[i] = (
char)129;
934 std::string sUpperCase = sLowerCase;
935 for (
unsigned int i = 0; i < sUpperCase.length(); i++)
938 if ((!i || sUpperCase[i - 1] !=
'\\') && (sUpperCase.substr(i, 2) ==
"\\n" || sUpperCase.substr(i, 2) ==
"\\t"))
943 else if (sUpperCase.substr(i, 2) ==
"\\n")
945 sUpperCase.replace(i, 2,
"N");
947 else if (sUpperCase.substr(i, 2) ==
"\\t")
949 sUpperCase.replace(i, 2,
"T");
952 if ((
int)sUpperCase[i] >= (
int)
'a' && (
int)sLowerCase[i] <= (
int)
'z')
955 sUpperCase[i] = (char)((
int)sUpperCase[i] + ((int)
'A' - (
int)
'a'));
957 if (sUpperCase[i] ==
'ä')
959 else if (sUpperCase[i] ==
'ö')
961 else if (sUpperCase[i] ==
'ü')
963 else if (sUpperCase[i] == (
char)132)
964 sUpperCase[i] = (
char)142;
965 else if (sUpperCase[i] == (
char)148)
966 sUpperCase[i] = (
char)153;
967 else if (sUpperCase[i] == (
char)129)
968 sUpperCase[i] = (
char)154;
987 && isdigit(sStr[pos-1])
988 && isdigit(sStr[pos+1])
989 && ((pos+3 < sStr.length() && sStr[pos+3] == sStr[pos])
990 || (pos+2 < sStr.length() && sStr[pos+2] == sStr[pos])
992 || (sStr[pos] ==
'.' && pos > 6 && sStr[pos-2] ==
':')))
1015 if (sStr.find_first_not_of(
" 0123456789.,eianfEIANF+-*/\t") != std::string::npos
1016 || (sStr.find_first_not_of(
"+-* .,\teE") == std::string::npos && sStr.find(
"---") == std::string::npos))
1020 if (tolower(sStr.front()) ==
'e'
1021 || tolower(sStr.front()) ==
'a'
1022 || tolower(sStr.front()) ==
'f'
1023 || tolower(sStr.back()) ==
'e')
1046 if (sStr.find_first_not_of(
" 0123456789,.:-/\tTZ") != std::string::npos
1047 || sStr.find_first_not_of(
" \t,.:-/TZ") == std::string::npos)
1051 size_t pos = sStr.find_first_not_of(
" \t");
1053 if (sStr.length() >= pos+3 && isdigit(sStr[pos]))
1055 for (
size_t i = pos; i < sStr.length()-1; i++)
1063 if (sStr[i] ==
'-' || sStr[i] ==
'.' || sStr[i] ==
'/' || sStr[i] ==
':')
1091 if (!i || !isdigit(sStr[i-1]) || !isdigit(sStr[i+1]))
1096 if ((i+3 < sStr.length() && sStr[i+3] == sStr[i])
1097 || (i+2 < sStr.length() && sStr[i+2] == sStr[i]))
1100 if ((sStr[i+3] ==
'/' && i+6 < sStr.length() && isdigit(sStr[i+6]))
1101 || (sStr[i+2] ==
'/' && i+4 < sStr.length() && isdigit(sStr[i+4])))
1124 if (!i || !isdigit(sStr[i-1]) || !isdigit(sStr[i+1]))
1129 if ((i+4 < sStr.length() && sStr[i+3] == sStr[i] && isdigit(sStr[i+4]))
1130 || (i+3 < sStr.length() && sStr[i+2] == sStr[i] && isdigit(sStr[i+3])))
1133 else if ((i+3 < sStr.length() && sStr[i+3] == sStr[i])
1134 || (i+2 < sStr.length() && sStr[i+2] == sStr[i]))
1153 if (!i || !isdigit(sStr[i-1]) || !isdigit(sStr[i+1]))
1158 if ((i+3 < sStr.length() && sStr[i+3] == sStr[i])
1159 || (i+2 < sStr.length() && sStr[i+2] == sStr[i]))
1177 if (sStr.find_first_not_of(
" 0123456789,.:-/\tTZ") != std::string::npos || sStr.find_first_not_of(
" \t") == std::string::npos)
1181 size_t pos = sStr.find_first_not_of(
" \t");
1184 if (sStr.length() >= pos+3 && isdigit(sStr[pos]))
1186 for (
size_t i = pos; i < sStr.length()-1; i++)
1190 if (sStr[i] ==
'-' || sStr[i] ==
'/')
1193 else if (sStr[i] ==
'.')
1197 else if (sStr[i] ==
':')
1205 && sStr.find(
'T') != std::string::npos
1206 && sStr.find(
'Z') != std::string::npos)
1224 std::string sReturn;
1227 char* cBuf =
new char[wStr.length() * 2 + 1];
1230 unsigned int nRet =
wcstombs(cBuf, wStr.c_str(), wStr.length() * 2 + 1);
1234 if (nRet == wStr.length() * 2 + 1)
1235 cBuf[wStr.length() * 2] =
'\0';
1269 for (
unsigned int i = 0; i < sOutput.length(); i++)
1271 if (sOutput[i] == (
char)142)
1273 else if (sOutput[i] == (
char)132)
1275 else if (sOutput[i] == (
char)153)
1277 else if (sOutput[i] == (
char)148)
1279 else if (sOutput[i] == (
char)154)
1281 else if (sOutput[i] == (
char)129)
1283 else if (sOutput[i] == (
char)225)
1285 else if (sOutput[i] == (
char)248)
1287 else if (sOutput[i] == (
char)174)
1288 sOutput[i] = (char)171;
1289 else if (sOutput[i] == (
char)175)
1290 sOutput[i] = (
char)187;
1309 std::string sReturn = sString;
1310 if (sReturn.length() < 2)
1314 for (
unsigned int i = 0; i < sReturn.length() - 1; i++)
1317 if (sReturn[i] == (
char)195)
1319 if (sReturn[i + 1] == (
char)132)
1321 sReturn.erase(i, 1);
1322 sReturn[i] = (char)142;
1324 else if (sReturn[i + 1] == (
char)164)
1326 sReturn.erase(i, 1);
1327 sReturn[i] = (char)132;
1329 else if (sReturn[i + 1] == (
char)150)
1331 sReturn.erase(i, 1);
1332 sReturn[i] = (char)153;
1334 else if (sReturn[i + 1] == (
char)182)
1336 sReturn.erase(i, 1);
1337 sReturn[i] = (char)148;
1339 else if (sReturn[i + 1] == (
char)156)
1341 sReturn.erase(i, 1);
1342 sReturn[i] = (char)154;
1344 else if (sReturn[i + 1] == (
char)188)
1346 sReturn.erase(i, 1);
1347 sReturn[i] = (char)129;
1349 else if (sReturn[i + 1] == (
char)159)
1351 sReturn.erase(i, 1);
1352 sReturn[i] = (char)225;
1355 if (sReturn[i] == (
char)194 && sReturn[i + 1] == (char)176)
1357 sReturn.erase(i, 1);
1358 sReturn[i] = (char)248;
1388std::vector<std::string>
split(
const std::string& sStr,
char cSplit)
1390 std::vector<std::string> vSplit;
1393 for (
size_t i = 1; i < sStr.length(); i++)
1395 if (sStr[i] == cSplit)
1397 vSplit.push_back(sStr.substr(lastPos, i - lastPos));
1402 if (lastPos < sStr.length())
1403 vSplit.push_back(sStr.substr(lastPos));
1420std::string
ellipsize(
const std::string& sLongString,
size_t nMaxStringLength)
1422 if (sLongString.length() > nMaxStringLength)
1423 return sLongString.substr(0, nMaxStringLength/2-2) +
"[...]" + sLongString.substr(sLongString.length()-nMaxStringLength+2);
1443void replaceAll(std::string& sToModify,
const char* sToRep,
const char* sNewValue,
size_t nStart ,
size_t nEnd )
1445 size_t nRepLength = strlen(sToRep);
1446 size_t nNewLength = strlen(sNewValue);
1447 int nOffSet = nNewLength - nRepLength;
1449 if (!sToModify.length() || !nRepLength)
1453 if ((
size_t)nStart > sToModify.length())
1456 if (nEnd == std::string::npos)
1457 nEnd = sToModify.length();
1460 for (
size_t i = nStart; i <= nEnd-nRepLength; i++)
1462 if (i >= sToModify.length())
1465 if (!sToModify.compare(i, nRepLength, sToRep))
1467 sToModify.replace(i, nRepLength, sNewValue);
1469 i += nNewLength - 1;
1490void replaceAll(std::string& sToModify,
const std::string& sToRep,
const std::string& sNewValue,
size_t nStart ,
size_t nEnd )
1492 size_t nRepLength = sToRep.length();
1493 size_t nNewLength = sNewValue.length();
1494 int nOffSet = nNewLength - nRepLength;
1496 if (!sToModify.length() || !nRepLength)
1500 if ((
size_t)nStart > sToModify.length())
1503 if (nEnd == std::string::npos)
1504 nEnd = sToModify.length();
1507 for (
size_t i = nStart; i <= nEnd-nRepLength; i++)
1509 if (i >= sToModify.length())
1512 if (!sToModify.compare(i, nRepLength, sToRep))
1514 sToModify.replace(i, nRepLength, sNewValue);
1516 i += nNewLength - 1;
1550 std::string sPath = __sPath;
1553 for (
unsigned int i = 0; i < sPath.length(); i++)
1556 if (sPath[i] ==
'\\')
1579 return str1 == str2;
const std::string sVersion
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class manages the setting values of the internal (kernel) settings of this application.
size_t getPrecision() const
Returns the precision for displaying floating numbers in the terminal. This value determines the numb...
void strip()
This member function shrinks the viewed section to remove all leading or trailing whitespace characte...
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
CONSTCD11 date::year year() const NOEXCEPT
CONSTCD11 date::day day() const NOEXCEPT
CONSTCD11 date::month month() const NOEXCEPT
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > & >(), fmt, tp), std::basic_string< CharT >{})
from_chars_result from_chars(const char *first, const char *last, T &value, chars_format fmt=chars_format::general) noexcept
bool isnan(const value_type &v)
bool isinf(const value_type &v)
value_type rint(value_type v)
This structure defines all fields necessary to create a time stamp or a formatted date.
date::year_month_day m_ymd
std::chrono::microseconds m_microsecs
std::chrono::minutes m_minutes
std::chrono::seconds m_seconds
std::chrono::hours m_hours
std::chrono::milliseconds m_millisecs
This structure defines the information for a time zone.