Isis 3.0
Back | Home
IString.h
Go to the documentation of this file.
1 #ifndef IString_h
2 #define IString_h
3 
25 #include <string>
26 #include <vector>
27 
28 #include <QString>
29 #include <QStringList>
30 
31 #include "Constants.h"
32 
33 namespace Isis {
34  class IString;
35 
36  bool toBool(const QString &);
37  int toInt(const QString &);
38  BigInt toBigInt(const QString &);
39  double toDouble(const QString &);
40 
41  QString toString(bool);
42  QString toString(char);
43  QString toString(const int &);
44  QString toString(const unsigned int &);
45  QString toString(const BigInt &);
46  QString toString(double, int precision = 14);
47 
179  class IString : public std::string {
180  public:
181  IString();
182 
183  IString(const std::string &str);
184  IString(const IString &str);
185  IString(const char *str);
186  IString(const int &num);
187  IString(const double &num, const int piPrecision = 14);
188  IString(const BigInt &num);
189  IString(const QString &str);
190 
191  ~IString();
192 
193  IString Trim(const std::string &chars);
194  static std::string Trim(const std::string &chars, const std::string &str);
195 
196  IString TrimHead(const std::string &chars);
197  static std::string TrimHead(const std::string &chars, const std::string &str);
198 
199  IString TrimTail(const std::string &chars);
200  static std::string TrimTail(const std::string &chars, const std::string &str);
201 
202  IString UpCase();
203  static std::string UpCase(const std::string &str);
204 
205  IString DownCase();
206  static std::string DownCase(const std::string &str);
207 
208  int ToInteger() const;
209  static int ToInteger(const std::string &str);
210 
211  BigInt ToBigInteger() const;
212  static BigInt ToBigInteger(const std::string &str);
213 
214  double ToDouble() const;
215  static double ToDouble(const std::string &str);
216 
217  QString ToQt() const;
218  static QString ToQt(const std::string &str);
219 
220  IString Token(const IString &separator);
221  static int Split(const char separator, const std::string &instr,
222  std::vector<std::string> &tokens,
223  bool allowEmptyEntries = true);
224 
225  IString Compress(bool force = false);
226  static std::string Compress(const std::string &str, bool force = false);
227 
228  IString Replace(const std::string &from, const std::string &to,
229  int maxReplaceCount = 20);
230  static std::string Replace(const std::string &str,
231  const std::string &from,
232  const std::string &to,
233  int maxReplacementCount = 20);
234 
235  IString Replace(const std::string &from, const std::string &to , bool honorquotes);
236  static IString Replace(const std::string &str, const std::string &from,
237  const std::string &to , bool honorquotes);
238 
239  IString Convert(const std::string &listofchars, const char &to);
240  static std::string Convert(const std::string &str,
241  const std::string &listofchars,
242  const char &to);
243 
245  static std::string ConvertWhiteSpace(const std::string &str);
246 
247  IString Remove(const std::string &del);
248  static std::string Remove(const std::string &del, const std::string &str);
249 
255  operator int() const {
256  return ToInteger();
257  };
258 
265  operator BigInt() const {
266  return ToBigInteger();
267  };
268 
274  operator double() const {
275  return ToDouble();
276  };
277 
283 #if 0
284  operator IString() const {
285  return ToQt();
286  };
287 #endif
288 
289  IString &operator= (const int &value);
290 
291  IString &operator= (const BigInt &value);
292 
300  IString &operator= (const double &value) {
301  SetDouble(value);
302  return *this;
303  }
304 
305  bool Equal(const std::string &str) const;
306  static bool Equal(const std::string &str1, const std::string &str2);
307 
308  static std::string ToStd(const QString &str);
309 
310  static QStringList ToQt(const std::vector<std::string> &sl);
311  static std::vector<std::string> ToStd(const QStringList &sl);
312 
313  private:
314  void SetDouble(const double &value, const int piPrecision = 14);
315  };
316 
317  std::ostream &operator<<(std::ostream &os, const QString &string);
318  std::ostream &operator<<(std::ostream &os, const QStringRef &string);
319 }
320 
321 #endif
long long int BigInt
Definition: Constants.h:63
IString()
Constructs an empty IString object.
Definition: IString.cpp:418
BigInt ToBigInteger() const
Returns the BigInt representation of the object IString.
Definition: IString.cpp:773
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:884
bool Equal(const std::string &str) const
Compare a string to the object IString.
Definition: IString.cpp:705
double ToDouble() const
Returns the floating point value the IString represents.
Definition: IString.cpp:814
static std::string ToStd(const QString &str)
Converts a Qt string into a std::string.
Definition: IString.cpp:1348
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
IString & operator=(const int &value)
Attempts to convert the stirng to a QStirng (Qt) and return that IString.
Definition: IString.cpp:1316
IString TrimHead(const std::string &chars)
Trims The input characters from the beginning of the object IString.
Definition: IString.cpp:573
int ToInteger() const
Returns the object string as an integer.
Definition: IString.cpp:733
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
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:955
BigInt toBigInt(const QString &string)
Global function to convert from a string to a &quot;big&quot; integer.
Definition: IString.cpp:130
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
IString Compress(bool force=false)
Collapses multiple spaces into single spaces.
Definition: IString.cpp:989
IString Token(const IString &separator)
Returns the first token in the IString.
Definition: IString.cpp:912
IString Convert(const std::string &listofchars, const char &to)
Returns the string with all occurrences of any character in the &quot;from&quot; argument converted to the &quot;to&quot;...
Definition: IString.cpp:1211
IString Remove(const std::string &del)
Remove all instances of any character in the string from the IString.
Definition: IString.cpp:1281
~IString()
Destructor.
Definition: IString.cpp:528
IString DownCase()
Converts all upper case letters in the object IString into lower case characters. ...
Definition: IString.cpp:659
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
Definition: IString.cpp:53
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:1052
Adds specific functionality to C++ strings.
Definition: IString.h:179
IString ConvertWhiteSpace()
Returns the string with all &quot;new lines&quot;, &quot;carriage returns&quot;, &quot;tabs&quot;, &quot;form feeds&quot;, &quot;vertical tabs&quot; and &quot;back spaces&quot; converted to single spaces.
Definition: IString.cpp:1253
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Definition: Hillshade.cpp:308
IString UpCase()
Converst any lower case characters in the object IString with uppercase characters.
Definition: IString.cpp:632
IString TrimTail(const std::string &chars)
Trims the input characters from the end of the object IString.
Definition: IString.cpp:602
IString Trim(const std::string &chars)
Removes characters from the beginning and end of the IString.
Definition: IString.cpp:540

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:19:54