1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
//$$FILE$$
//$$VERSION$$
//$$DATE$$
//$$LICENSE$$
#ifndef GENSTRING_H
#define GENSTRING_H
#include <string>
#include <functional>
/**
** \class Char
**
** \brief Generic character class that contains character related methods.
**
** This class is a static class that contains generic character related utility
** methods.
*/
class Char
{
public:
enum eCompareType
{
eCASE_SENSITIVE = 0,
eCASE_INSENSITIVE,
eWS_INSENSITIVE, // But case-sensitive
eAS_INTEGER
};
static char ToLower(const char c);
static char ToUpper(const char c);
static bool IsCiLess(const char c1, const char c2);
static bool IsWhiteSpace(const char c);
static bool IsDigit(const char c);
};
/**
** \class CharLess
**
** \brief Public class that encapsulates character comparison.
**
** This class encapsulates character comparison. It supports the following
** compare types: case-sensitive and case-insensitive.
*/
class CharLess
{
public:
CharLess(Char::eCompareType compareType = Char::eCASE_SENSITIVE);
CharLess& operator=(const CharLess& in);
bool operator()(const char c1, const char c2) const;
inline Char::eCompareType GetCompareType();
private:
Char::eCompareType _compareType;
};
/**
** \class CharEqualTo
**
** \brief Public class that encapsulates generic character equal_to functor.
**
** This class is equal_to functor for generic character. It supports the
** following compare types: case-sensitive and case-insensitive.
*/
class CharEqualTo : public std::binary_function<char, char, bool>
{
public:
CharEqualTo(Char::eCompareType compareType = Char::eCASE_SENSITIVE);
CharEqualTo& operator=(const CharEqualTo& in);
bool operator()(const char c1, const char c2) const;
inline Char::eCompareType GetCompareType();
private:
Char::eCompareType _compareType;
};
class WhiteSpace : public std::unary_function<char, bool>
{
public:
bool operator()(const char c) const;
bool operator()(const char c1, const char c2) const;
};
/**
** \class StringLess
**
** \brief Public class that encapsulates string comparison.
**
** This class encapsulates string comparison. It supports the following
** compare types: case-sensitive, case-insensitive and as-integer.
*/
class StringLess
{
public:
StringLess(Char::eCompareType compareType = Char::eCASE_SENSITIVE);
StringLess& operator=(const StringLess& in);
bool operator()(const std::string& s1, const std::string& s2) const;
inline Char::eCompareType GetCompareType();
private:
Char::eCompareType _compareType;
};
/**
** \class StringEqualTo
**
** \brief Public class that encapsulates generic string equal_to functor.
**
** This class is equal_to functor for generic strings. It supports the
** following compare types: case-sensitive, case-insensitive and as-integer.
*/
class StringEqualTo : public std::binary_function<std::string, std::string,
bool>
{
public:
StringEqualTo(Char::eCompareType compareType = Char::eCASE_SENSITIVE);
StringEqualTo& operator=(const StringEqualTo& in);
bool operator()(const std::string& s1, const std::string& s2) const;
inline Char::eCompareType GetCompareType();
private:
Char::eCompareType _compareType;
};
/**
** \class String
**
** \brief Generic string class that contains string related utility methods.
**
** This class is a static class that contains generic string related utility
** methods, such as: converting string to uppercase/lowercase, removing
** whitespaces, converting strings to/from integers/real numbers, determining
** if string a number, determining whether strings are equal, escaping and
** unescaping.
*/
class String
{
public:
static void LowerCase(const std::string& inString, std::string& outString);
static void LowerCase(std::string& inOutString);
static void UpperCase(const std::string& inString, std::string& outString);
static void UpperCase(std::string& inOutString);
static void RemoveWhiteSpace(const std::string& inString,
std::string& outString);
static std::string IntToString(int inInteger);
static std::string DoubleToString(double inDouble);
static int StringToInt(const std::string& inString);
static double StringToDouble(const std::string& inString);
static bool IsScientific(const std::string& number);
static void ToFixedFormat(std::string& fixedFormat,
const std::string& number);
static bool StringToBoolean(const std::string& inString);
static bool IsNumber(const std::string& inString);
static bool IsCiEqual(const std::string& firstString,
const std::string& secondString);
static bool IsEqual(const std::string& firstString,
const std::string& secondString,
const Char::eCompareType compareType);
static void StripLeadingWs(std::string& resString);
static void StripTrailingWs(std::string& resString);
static void StripAndCompressWs(std::string& resString);
static void rcsb_clean_string(std::string& theString);
static void UnEscape(std::string& outStr, const std::string& inStr);
static void Replace(std::string& resString, const std::string& fromStr,
const std::string& toStr);
private:
static std::string::const_iterator GetExpValue(int& expValue,
const std::string::const_iterator& beg,
const std::string::const_iterator& end);
static void GetMantissa(std::string& mantissa, int& addExpValue,
const std::string::const_iterator& beg,
const std::string::const_iterator& end);
static void ScientificNumberToFixed(std::string& fixed,
const bool isPositive, const std::string& mantissa, const int exponent);
};
inline Char::eCompareType StringLess::GetCompareType()
{
return (_compareType);
}
inline Char::eCompareType StringEqualTo::GetCompareType()
{
return (_compareType);
}
#endif
|