Isis 3 Programmer Reference
IString.h
1 #ifndef IString_h
2 #define IString_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 #include <string>
10 #include <vector>
11 
12 #include <QString>
13 #include <QStringList>
14 
15 #include "Constants.h"
16 
17 namespace Isis {
18  class IString;
19 
20  bool toBool(const QString &);
21  int toInt(const QString &);
22  BigInt toBigInt(const QString &);
23  double toDouble(const QString &);
24 
25  QString toString(bool);
26  QString toString(char);
27  QString toString(const int &);
28  QString toString(const unsigned int &);
29  QString toString(const BigInt &);
30  QString toString(double, int precision = 14);
31 
165  class IString : public std::string {
166  public:
167  IString();
168 
169  IString(const std::string &str);
170  IString(const IString &str);
171  IString(const char *str);
172  IString(const int &num);
173  IString(const double &num, const int piPrecision = 14);
174  IString(const BigInt &num);
175  IString(const QString &str);
176 
177  ~IString();
178 
179  IString Trim(const std::string &chars);
180  static std::string Trim(const std::string &chars, const std::string &str);
181 
182  IString TrimHead(const std::string &chars);
183  static std::string TrimHead(const std::string &chars, const std::string &str);
184 
185  IString TrimTail(const std::string &chars);
186  static std::string TrimTail(const std::string &chars, const std::string &str);
187 
188  IString UpCase();
189  static std::string UpCase(const std::string &str);
190 
191  IString DownCase();
192  static std::string DownCase(const std::string &str);
193 
194  int ToInteger() const;
195  static int ToInteger(const std::string &str);
196 
197  BigInt ToBigInteger() const;
198  static BigInt ToBigInteger(const std::string &str);
199 
200  double ToDouble() const;
201  static double ToDouble(const std::string &str);
202 
203  QString ToQt() const;
204  static QString ToQt(const std::string &str);
205 
206  IString Token(const IString &separator);
207  static int Split(const char separator, const std::string &instr,
208  std::vector<std::string> &tokens,
209  bool allowEmptyEntries = true);
210 
211  IString Compress(bool force = false);
212  static std::string Compress(const std::string &str, bool force = false);
213 
214  IString Replace(const std::string &from, const std::string &to,
215  int maxReplaceCount = 20);
216  static std::string Replace(const std::string &str,
217  const std::string &from,
218  const std::string &to,
219  int maxReplacementCount = 20);
220 
221  IString Replace(const std::string &from, const std::string &to , bool honorquotes);
222  static IString Replace(const std::string &str, const std::string &from,
223  const std::string &to , bool honorquotes);
224 
225  IString Convert(const std::string &listofchars, const char &to);
226  static std::string Convert(const std::string &str,
227  const std::string &listofchars,
228  const char &to);
229 
231  static std::string ConvertWhiteSpace(const std::string &str);
232 
233  IString Remove(const std::string &del);
234  static std::string Remove(const std::string &del, const std::string &str);
235 
241  operator int() const {
242  return ToInteger();
243  };
244 
251  operator BigInt() const {
252  return ToBigInteger();
253  };
254 
260  operator double() const {
261  return ToDouble();
262  };
263 
269 #if 0
270  operator IString() const {
271  return ToQt();
272  };
273 #endif
274 
275  IString &operator= (const int &value);
276 
277  IString &operator= (const BigInt &value);
278 
286  IString &operator= (const double &value) {
287  SetDouble(value);
288  return *this;
289  }
290 
291  bool Equal(const std::string &str) const;
292  static bool Equal(const std::string &str1, const std::string &str2);
293 
294  static std::string ToStd(const QString &str);
295 
296  static QStringList ToQt(const std::vector<std::string> &sl);
297  static std::vector<std::string> ToStd(const QStringList &sl);
298 
299  private:
300  void SetDouble(const double &value, const int piPrecision = 14);
301  };
302 
303  std::ostream &operator<<(std::ostream &os, const QString &string);
304  std::ostream &operator<<(std::ostream &os, const QStringRef &string);
305 }
306 
307 #endif
Isis::IString::Replace
IString Replace(const std::string &from, const std::string &to, int maxReplaceCount=20)
Replaces all instances of the first input string with the second input string.
Definition: IString.cpp:1037
Isis::IString::ToDouble
double ToDouble() const
Returns the floating point value the IString represents.
Definition: IString.cpp:799
Isis::operator<<
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Definition: Hillshade.cpp:314
Isis::IString::DownCase
IString DownCase()
Converts all upper case letters in the object IString into lower case characters.
Definition: IString.cpp:644
Isis::IString::TrimTail
IString TrimTail(const std::string &chars)
Trims the input characters from the end of the object IString.
Definition: IString.cpp:587
Isis::IString::ToStd
static std::string ToStd(const QString &str)
Converts a Qt string into a std::string.
Definition: IString.cpp:1333
Isis::IString::IString
IString()
Constructs an empty IString object.
Definition: IString.cpp:403
Isis::IString::Trim
IString Trim(const std::string &chars)
Removes characters from the beginning and end of the IString.
Definition: IString.cpp:525
Isis::IString::ConvertWhiteSpace
IString ConvertWhiteSpace()
Returns the string with all "new lines", "carriage returns", "tabs", "form feeds",...
Definition: IString.cpp:1238
Isis::IString::ToInteger
int ToInteger() const
Returns the object string as an integer.
Definition: IString.cpp:718
QStringList
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::IString::Convert
IString Convert(const std::string &listofchars, const char &to)
Returns the string with all occurrences of any character in the "from" argument converted to the "to"...
Definition: IString.cpp:1196
Isis::IString::Compress
IString Compress(bool force=false)
Collapses multiple spaces into single spaces.
Definition: IString.cpp:974
Isis::IString::UpCase
IString UpCase()
Converst any lower case characters in the object IString with uppercase characters.
Definition: IString.cpp:617
Isis::IString::ToBigInteger
BigInt ToBigInteger() const
Returns the BigInt representation of the object IString.
Definition: IString.cpp:758
Isis::toBigInt
BigInt toBigInt(const QString &string)
Global function to convert from a string to a "big" integer.
Definition: IString.cpp:115
Isis::toInt
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:93
Isis::IString::operator=
IString & operator=(const int &value)
Attempts to convert the stirng to a QStirng (Qt) and return that IString.
Definition: IString.cpp:1301
Isis::BigInt
long long int BigInt
Big int.
Definition: Constants.h:49
Isis::IString::~IString
~IString()
Destructor.
Definition: IString.cpp:513
Isis::IString::SetDouble
void SetDouble(const double &value, const int piPrecision=14)
Performs the conversion necessary to represent a floating-point value as a string.
Definition: IString.cpp:494
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
Isis::toBool
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
Definition: IString.cpp:38
Isis::IString::Split
static int Split(const char separator, const std::string &instr, std::vector< std::string > &tokens, bool allowEmptyEntries=true)
Find separators between characters and split them into strings.
Definition: IString.cpp:940
Isis::IString::Equal
bool Equal(const std::string &str) const
Compare a string to the object IString.
Definition: IString.cpp:690
Isis::IString::Token
IString Token(const IString &separator)
Returns the first token in the IString.
Definition: IString.cpp:897
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis::IString::TrimHead
IString TrimHead(const std::string &chars)
Trims The input characters from the beginning of the object IString.
Definition: IString.cpp:558
Isis::IString::Remove
IString Remove(const std::string &del)
Remove all instances of any character in the string from the IString.
Definition: IString.cpp:1266
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IString::ToQt
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:869