62 falses.append(
"false");
70 bool foundMatch =
false;
72 QListIterator<QString> truesIterator(trues);
73 while (!foundMatch && truesIterator.hasNext()) {
74 foundMatch = (
string.compare(truesIterator.next(), Qt::CaseInsensitive) == 0);
80 QListIterator<QString> falsesIterator(falses);
81 while (!foundMatch && falsesIterator.hasNext()) {
82 foundMatch = (
string.compare(falsesIterator.next(), Qt::CaseInsensitive) == 0);
89 QString message = QObject::tr(
"Failed to convert string [%1] to a boolean. "
90 "Please specify one of [%2] for true, or one of [%3] for false.")
91 .arg(
string).arg(trues.join(
", ")).arg(falses.join(
", "));
110 int result =
string.toInt(&ok);
113 QString message = QObject::tr(
"Failed to convert string [%1] to an integer").arg(
string);
134 s <<
string.toStdString();
135 s.seekg(0, std::ios::beg);
137 std::ios::iostate state = s.rdstate();
138 if((state & std::ios::failbit) || (state & std::ios::badbit) ||
139 (!(state & std::ios::eofbit))) {
144 QString message = QObject::tr(
"Failed to convert string [%1] to a big integer").arg(
string);
166 if (
string.startsWith(
"16#") &&
string.endsWith(
"#")) {
169 s <<
string.mid(3,
string.size() - 3);
170 s.seekg(0, ios::beg);
173 unsigned int intData;
177 s >> hex >> raw.intData;
179 ios::iostate state = s.rdstate();
180 if((state & ios::failbit) || (state & ios::badbit)) {
184 result = raw.floatData;
187 QString message = QObject::tr(
"Failed to convert HEX string [%1] to a "
188 "double").arg(
string);
194 if (knownStrings.isEmpty()) {
196 knownStrings[
"1.79769313486232e+308"] = DBL_MAX;
197 knownStrings[
"-1.79769313486232e+308"] = -DBL_MAX;
201 if (!knownStrings.contains(
string)) {
202 result =
string.toDouble(&ok);
205 result = knownStrings[string];
209 QString message = QObject::tr(
"Failed to convert string [%1] to a double").arg(
string);
226 return boolToConvert?
"Yes" :
"No";
240 result += QChar(charToConvert);
252 return QString::number(intToConvert);
262 QString
toString(
const unsigned int &intToConvert) {
263 return QString::number(intToConvert);
274 return QString::number(intToConvert);
291 QString
toString(
double doubleToConvert,
int precision) {
296 if(doubleToConvert == 0.0) {
299 else if(isnan(doubleToConvert)) {
303 if(doubleToConvert > DBL_MAX) {
304 doubleToConvert = DBL_MAX;
307 if(doubleToConvert < -DBL_MAX) {
308 doubleToConvert = -DBL_MAX;
317 double temp = qAbs(doubleToConvert);
318 int pre = (int)(log10(temp)) + 1;
333 char doubleString[23];
335 if((log10(temp) > 13.0) || (log10(temp) < -3.0)) {
336 char format[8], buffer[8];
337 snprintf(buffer, 8,
"%de", precision);
338 strcpy(format,
"%21.");
339 strcat(format, buffer);
340 snprintf(doubleString, 23, format, doubleToConvert);
342 char *e = strchr(doubleString,
'e');
345 while(*sptr ==
'0') {
358 e = strchr(doubleString,
'e');
361 for(sptr = e + 2; *sptr; sptr++) {
380 int post = precision - pre;
382 char tempStr[3], format[8];
383 strcpy(format,
"%17.");
384 snprintf(tempStr, 3,
"%d", post);
385 strcat(format, tempStr);
388 snprintf(doubleString, 23, format, doubleToConvert);
391 char *sptr = doubleString + strlen(doubleString) - 1;
392 while((*sptr ==
'0') && (*(sptr - 1) !=
'.')) {
399 while(doubleString[0] ==
' ') {
400 for(
unsigned int i = 0; i < strlen(doubleString); i++) {
401 doubleString[i] = doubleString[i + 1];
405 result = QString(doubleString);
417 IString::IString() : string() {
509 *
this =
toString(num, piPrecision).toStdString();
519 assign(str.toStdString());
558 std::string
IString::Trim(
const std::string &chars,
const std::string &str) {
573 *
this = replace(0, find_first_not_of(chars),
"");
589 result.replace(0, str.find_first_not_of(chars),
"");
602 *
this = erase(find_last_not_of(chars) + 1);
620 result.erase(str.find_last_not_of(chars) + 1);
648 transform(str.begin(), str.end(), sOut.begin(), (int ( *)(int)) toupper);
675 transform(str.begin(), str.end(), sOut.begin(), (int ( *)(int))tolower);
692 return(toupper(c1) == toupper(c2));
706 return Equal(str, temp);
720 if(str1.size() != str2.size())
return(
false);
721 return(std::equal(str1.begin(), str1.end(), str2.begin(),
nocase_compare));
750 s.seekg(0, ios::beg);
752 ios::iostate state = s.rdstate();
753 if((state & ios::failbit) || (state & ios::badbit) ||
754 (!(state & ios::eofbit))) {
759 string message =
"Failed to convert string [" + str +
"] to an integer";
790 s.seekg(0, ios::beg);
792 ios::iostate state = s.rdstate();
793 if((state & ios::failbit) || (state & ios::badbit) ||
794 (!(state & ios::eofbit))) {
799 string message =
"Failed to convert string [" + str +
"] to a big "
831 if(str.substr(0, 3) ==
"16#" && str.substr(str.length() - 1, 1) ==
"#") {
834 s << str.substr(3, str.find_last_of(
"#") - 3);
835 s.seekg(0, ios::beg);
844 ios::iostate state = s.rdstate();
845 if((state & ios::failbit) || (state & ios::badbit)) {
851 string message =
"Failed to convert HEX string [" + str +
"] to a "
861 s.seekg(0, ios::beg);
863 ios::iostate state = s.rdstate();
864 if((state & ios::failbit) || (state & ios::badbit) ||
865 (!(state & ios::eofbit))) {
870 string message =
"Failed to convert string [" + str +
"] to a double";
884 return QString::fromStdString(*
this);
895 return(QString::fromStdString(s));
914 for(
unsigned int i = 0; i < size(); i++) {
915 for(
unsigned int sep = 0; sep < separator.size(); sep++) {
916 if(separator[sep] == at(i)) {
917 retstr = substr(0, i);
918 replace(0, i + 1,
"");
926 replace(0, size(),
"");
955 std::vector<std::string> &tokens,
956 bool allowEmptyEntries) {
957 string::size_type idx(0), idx2(0);
958 unsigned int ksize = str.size();
962 if(str[idx] == separator) idx++;
963 while((idx2 = str.find(separator, idx)) != string::npos) {
965 if(allowEmptyEntries) tokens.push_back(
"");
968 string::size_type len(idx2 - idx);
969 tokens.push_back(str.substr(idx, len));
973 if(idx < ksize) tokens.push_back(str.substr(idx));
975 return(tokens.size());
989 *
this =
Compress((
string) *
this, force);
1006 if(force ==
false) {
1008 int leftquote = result.find_first_of(
"\"\'");
1009 while((spaces = result.find(
" ", spaces)) >= 0) {
1010 int rightquote = result.find_first_of(
"\"\'", leftquote + 1);
1011 if(spaces < leftquote) {
1012 result.erase(spaces, 1);
1013 leftquote = result.find_first_of(
"\"\'", spaces);
1015 else if((spaces > leftquote) && (spaces < rightquote)) {
1016 spaces = rightquote + 1;
1017 leftquote = result.find_first_of(
"\"\'", rightquote + 1);
1019 else if(leftquote == (
int)npos) {
1020 result.erase(spaces, 1);
1023 leftquote = result.find_first_of(
"\"\'", rightquote + 1);
1030 while((spaces = result.find(
" ", spaces)) >= 0) {
1031 result.erase(spaces, 1);
1052 int maxReplaceCount) {
1053 *
this =
IString(
Replace((
string) *
this, from, to, maxReplaceCount));
1106 const std::string &to,
int maxReplaceCount) {
1107 if(str.empty())
return(str);
1108 if(from.empty())
return(str);
1110 string::size_type pos;
1112 while((nReplaced < maxReplaceCount) &&
1113 (pos = sRet.find(from)) != string::npos) {
1114 sRet.replace(pos, from.size(), to);
1139 *
this =
Replace((
string) *
this, from, to, honorquotes);
1162 const std::string &to ,
bool honorquotes) {
1164 string result = str;
1165 if(honorquotes ==
true) {
1167 int quote = result.find_first_of(
"\"\'");
1168 while((instances = result.find(from, instances)) >= 0) {
1170 int nextquote = result.find_first_of(
"\"\'", quote + 1);
1171 if(instances < quote) {
1172 result.replace(instances, from.length(), to);
1173 quote = result.find_first_of(
"\"\'", instances);
1175 else if((instances > quote) && (instances < nextquote)) {
1176 instances = nextquote + 1;
1177 quote = result.find_first_of(
"\"\'", nextquote);
1179 else if(quote == (
int)npos) {
1180 result.replace(instances, from.length(), to);
1183 quote = result.find_first_of(
"\"\'", nextquote);
1190 while((instances = result.find(from, instances)) >= 0) {
1191 result.replace(instances, from.length(), to);
1211 *
this =
Convert((
string) *
this, listofchars, to);
1232 std::string::size_type pos = 0;
1233 string result = str;
1236 while((pos = result.find_first_of(listofchars, pos)) != npos) {
1237 result.replace(pos, 1, tmp);
1267 return Convert(str,
"\n\r\t\f\v\b",
' ');
1281 std::string::size_type pos;
1282 while((pos = find_first_of(del)) != npos) this->erase(pos, 1);
1300 string::size_type pos;
1302 while((pos = result.find_first_of(del)) != npos) result.erase(pos, 1);
1348 return(str.toStdString());
1362 for(
unsigned int i = 0 ; i < sl.size() ; i++) {
1378 std::vector<std::string> Stdsl;
1379 for(
int i = 0 ; i < sl.size() ; i++) {
1380 Stdsl.push_back(
ToStd(sl.at(i)));
1398 std::ostream &
operator<<(std::ostream &outputStream,
const QString &
string) {
1399 return (outputStream <<
string.toAscii().data());
1414 std::ostream &
operator<<(std::ostream &outputStream,
const QStringRef &
string) {
1415 return (outputStream <<
string.
toString().toAscii().data());