cxWidgets 1.0
cxStringUtils.h
Go to the documentation of this file.
1// Copyright (c) 2026 E. Oulashin
2#ifndef __CXSTRINGUTILS_H__
3#define __CXSTRINGUTILS_H__
4
5/* cxStringUtils.h - String utility functions
6 *
7 * Copyright (c) 2004-2007 Michael H. Kinney
8 */
9
10#include <regex.h>
11#include <cctype> // For isdigit(), isalpha, etc.
12#include <string>
13#include <vector>
14#include <list>
15#include <sstream>
16
17#include "cxReturnCodes.h"
18#include "cxKeyDefines.h"
19#include "cxInputOptions.h"
20#include "cxBorderStyles.h"
21
28namespace cxStringUtils
29{
36 void SplitStringRegex(const std::string& input, const std::string& regex,
37 std::vector<std::string>& resultContainer);
38
50 bool Find(const std::string& input, const std::string& regex, bool useBasicRegex = false);
51
58 void Find(const std::string& input, const std::string& regex, std::string& output);
59
71 bool Replace(std::string& srcStr, const std::string& regexStr, const std::string& replacementStr);
72
79 std::string replace(const std::string& input, const std::string& search, const std::string& replace);
80
86 int stringTo(const std::string& s);
87 long stringToLong(const std::string& s);
88 unsigned stringToUnsigned(const std::string& s);
89 double stringToDouble(const std::string& s);
90 long double stringToLongDouble(const std::string& s);
91 std::string stringToString(const std::string& s);
92
93 void test_stringTo();
94
106 std::string toString(const int& x);
107 std::string toString(const long& x);
108 std::string toString(const double& x);
109 std::string toString(const long double& x);
110 std::string toString(const unsigned& x);
111 std::string toString(const unsigned long& x);
112 std::string toString(const cx::eReturnCode& x);
113 std::string toString(const cx::eInputOptions& x);
114 std::string toString(const cx::eBorderStyle& x);
115 std::string toString(const void* x);
116
117 void test_toString();
118
124 bool startsWithNumber(const std::string& pStr);
125
136 bool isPrintable(const int& pKey);
137
145 int indexOfLastCap(const std::string& pStr);
146
152 void toUpper(std::string& theString);
153
162 std::string stripNewlines(const std::string& pStr);
163
172 std::string replaceNewlines(const std::string& pStr, const char& pChar);
173
185 void insertUnderline(std::string& pStr, char pChar, bool pAll = false);
186
195 std::string removeChar(const std::string& pString, const int pPos);
196
204 std::string strToUpper(const std::string& theString);
205
213 std::string strToLower(const std::string& theString);
214
221 void TrimSpaces(std::string& str);
222
229 void splitStringOnNewlines(const std::string& pStr, std::list<std::string>& pStrings);
230
231} // End of stringUtils namespace
232
233#endif
Defines an enumeration for different input options (editable and.
String utility functions.
std::string strToLower(const std::string &theString)
conver the string to lower case
std::string stripNewlines(const std::string &pStr)
Strips newlines characters from a string and returns.
bool startsWithNumber(const std::string &pStr)
bool isPrintable(const int &pKey)
Returns whether or not a key is printable. This should be used.
Definition cxStringUtils.cpp:463
long stringToLong(const std::string &s)
Definition cxStringUtils.cpp:261
void test_toString()
Definition cxStringUtils.cpp:395
std::string strToUpper(const std::string &theString)
conver the string to upper case
std::string removeChar(const std::string &pString, const int pPos)
Removes a character from a string.
void insertUnderline(std::string &pStr, char pChar, bool pAll=false)
Inserts an underline character into.
void test_stringTo()
Definition cxStringUtils.cpp:298
void toUpper(std::string &theString)
Converts a string to upper-case.
bool Replace(std::string &srcStr, const std::string &regexStr, const std::string &replacementStr)
std::string replaceNewlines(const std::string &pStr, const char &pChar)
Replaces newlines in a string with another character.
void TrimSpaces(std::string &str)
Trims leading & trailing spaces from a string.
int indexOfLastCap(const std::string &pStr)
Returns the index of the last capital letter in a string. Returns -1 if there are no capital letters.
std::string toString(const int &x)
Converts an object to a string, i.e.:
Definition cxStringUtils.cpp:325
long double stringToLongDouble(const std::string &s)
Definition cxStringUtils.cpp:285
double stringToDouble(const std::string &s)
Definition cxStringUtils.cpp:277
std::string stringToString(const std::string &s)
Definition cxStringUtils.cpp:293
void SplitStringRegex(const std::string &input, const std::string &regex, std::vector< std::string > &resultContainer)
unsigned stringToUnsigned(const std::string &s)
Definition cxStringUtils.cpp:269
std::string replace(const std::string &input, const std::string &search, const std::string &replace)
Replaces substrings of a string with another string.
bool Find(const std::string &input, const std::string &regex, bool useBasicRegex=false)
void splitStringOnNewlines(const std::string &pStr, std::list< std::string > &pStrings)
Splits a string on newlines.
int stringTo(const std::string &s)
Converts a string to another type.
Definition cxStringUtils.cpp:253
eInputOptions
Definition cxInputOptions.h:20
eBorderStyle
Definition cxBorderStyles.h:26
eReturnCode
Definition cxReturnCodes.h:27