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 #include <vector>
27 
28 #include "ebase.h"
29 
31 class EString : public std::string
32 {
33 public:
35  EString() {}
38  EString(cpStr s) : std::string(s) {}
42  EString(cpStr s, size_t n) : std::string(s,n) {}
45  EString(const std::string &s) : std::string(s) {}
48  EString(const EString &s) : std::string(s) {}
51  EString &format(cpChar pszFormat, ...);
54  EString &tolower();
57  EString &toupper();
58 
61  operator cpChar() const { return c_str(); }
62 
65  EString &operator=(cpChar s)
66  {
67  *(std::string *)this = s;
68  return *this;
69  }
72  EString &operator=(const std::string s)
73  {
74  *(std::string *)this = s;
75  return *this;
76  }
79  Int icompare(EString &str)
80  {
81  return epc_strnicmp(c_str(), str.c_str(), length() > str.length() ? length() : str.length());
82  }
85  Int icompare(cpStr str)
86  {
87  size_t len = strlen(str);
88  return epc_strnicmp(c_str(), str, length() > len ? length() : len);
89  }
90 
92  Void ltrim()
93  {
94  erase(begin(), std::find_if(begin(), end(), [](Char ch) {
95  return !std::isspace(ch);
96  }));
97  }
98 
100  Void rtrim()
101  {
102  erase(std::find_if(rbegin(), rend(), [](Char ch) {
103  return !std::isspace(ch);
104  }).base(),
105  end());
106  }
107 
109  Void trim()
110  {
111  ltrim();
112  rtrim();
113  }
114 
121  EString &replaceAll(cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen);
128  EString replaceAllCopy(cpStr srch, size_t srchlen, cpStr rplc, size_t rplclen);
129 };
130 
131 typedef std::vector<EString> EStringVec;
132 
133 #endif // #define __estring_h_included
EString(cpStr s, size_t n)
Class constructor.
Definition: estring.h:42
Void trim()
Removes leading and trailing white space.
Definition: estring.h:109
EString & operator=(cpChar s)
Assigns the specified NULL terminated strint to this string object.
Definition: estring.h:65
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
Macros for various standard C library functions and standard includes.
EString()
Default constructor.
Definition: estring.h:35
STL namespace.
std::vector< EString > EStringVec
Definition: estring.h:131
Int icompare(EString &str)
Compares this string object to the specified string object.
Definition: estring.h:79
#define epc_strnicmp(str1, str2, count)
strnicmp - strnicmp, strncasecmp
Definition: ebase.h:54
EString & toupper()
Converts this string to uppercase.
Definition: estring.cpp:72
EString & tolower()
Converts this string to lowercase.
Definition: estring.cpp:66
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(const std::string &s)
Copy constructor.
Definition: estring.h:45
Int icompare(cpStr str)
Compares this string object to the specified NULL terminated string.
Definition: estring.h:85
Void rtrim()
Removes trailing white space.
Definition: estring.h:100
EString(cpStr s)
Class constructor.
Definition: estring.h:38
EString & format(cpChar pszFormat,...)
Sets the value to the string using a "printf" style format string and arguments.
Definition: estring.cpp:38
EString(const EString &s)
Copy constructor.
Definition: estring.h:48
EString & operator=(const std::string s)
Assignment operator.
Definition: estring.h:72
String class.
Definition: estring.h:31
Void ltrim()
Removes leading white space.
Definition: estring.h:92