EpcTools
An event based multi-threaded C++ development framework.
estring.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2009-2019 Brian Waters
3 * Copyright (c) 2019 Sprint
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 
18 #ifndef __estring_h_included
19 #define __estring_h_included
20 
23 
24 #include <string>
25 #include <algorithm>
26 
27 #include "ebase.h"
28 
30 class EString : public std::string
31 {
32 public:
34  EString() {}
37  EString(cpStr s) : std::string(s) {}
40  EString(const std::string &s) : std::string(s) {}
43  EString(const EString &s) : std::string(s) {}
46  EString &format(cpChar pszFormat, ...);
49  EString &tolower();
52  EString &toupper();
53 
56  operator cpChar() { return c_str(); }
57 
60  EString &operator=(cpChar s)
61  {
62  *(std::string *)this = s;
63  return *this;
64  }
67  EString &operator=(const std::string s)
68  {
69  *(std::string *)this = s;
70  return *this;
71  }
74  Int icompare(EString &str)
75  {
76  return epc_strnicmp(c_str(), str.c_str(), length() > str.length() ? length() : str.length());
77  }
80  Int icompare(cpStr str)
81  {
82  size_t len = strlen(str);
83  return epc_strnicmp(c_str(), str, length() > len ? length() : len);
84  }
85 
87  Void ltrim()
88  {
89  erase(begin(), std::find_if(begin(), end(), [](Char ch) {
90  return !std::isspace(ch);
91  }));
92  }
93 
95  Void rtrim()
96  {
97  erase(std::find_if(rbegin(), rend(), [](Char ch) {
98  return !std::isspace(ch);
99  })
100  .base(),
101  end());
102  }
103 
105  Void trim()
106  {
107  ltrim();
108  rtrim();
109  }
110 
117  EString &replaceAll(cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen);
124  EString replaceAllCopy(cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen);
125 };
126 
127 #endif // #define __estring_h_included
EString::EString
EString()
Default constructor.
Definition: estring.h:34
EString::toupper
EString & toupper()
Converts this string to uppercase.
Definition: estring.cpp:72
EString::trim
Void trim()
Removes leading and trailing white space.
Definition: estring.h:105
ebase.h
Macros for various standard C library functions and standard includes.
EString::EString
EString(cpStr s)
Class constructor.
Definition: estring.h:37
EString::icompare
Int icompare(EString &str)
Compares this string object to the specified string object.
Definition: estring.h:74
EString::ltrim
Void ltrim()
Removes leading white space.
Definition: estring.h:87
EString::replaceAll
EString & replaceAll(cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen)
Replaces all occurances of the search string with the replacement string.
Definition: estring.cpp:78
EString::rtrim
Void rtrim()
Removes trailing white space.
Definition: estring.h:95
EString::operator=
EString & operator=(const std::string s)
Assignment operator.
Definition: estring.h:67
EString::EString
EString(const EString &s)
Copy constructor.
Definition: estring.h:43
epc_strnicmp
#define epc_strnicmp(str1, str2, count)
strnicmp - strnicmp, strncasecmp
Definition: ebase.h:54
EString::format
EString & format(cpChar pszFormat,...)
Sets the value to the string using a "printf" style format string and arguments.
Definition: estring.cpp:38
EString::replaceAllCopy
EString replaceAllCopy(cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen)
Replaces all occurances of the search string with the replacement string and returns a new string obj...
Definition: estring.cpp:83
EString
String class.
Definition: estring.h:30
EString::operator=
EString & operator=(cpChar s)
Assigns the specified NULL terminated strint to this string object.
Definition: estring.h:60
EString::EString
EString(const std::string &s)
Copy constructor.
Definition: estring.h:40
EString::tolower
EString & tolower()
Converts this string to lowercase.
Definition: estring.cpp:66
EString::icompare
Int icompare(cpStr str)
Compares this string object to the specified NULL terminated string.
Definition: estring.h:80