44 namespace string_utils
55 void CORE_LIBRARY_DLL_SHARED_API
PackStdString(std::string& line);
85 void CORE_LIBRARY_DLL_SHARED_API
SplitString(std::string& subStr1, std::string& subStr2,
86 const std::string& toSplit,
const std::string& delim,
114 template <
typename T>
118 std::ostringstream ss;
135 ss << std::setprecision(precision);
153 std::string formattedValue;
155 if (decimalPlaces < 0)
160 const T min = std::pow(T(10), T(-1) * decimalPlaces);
161 const T absVal = std::fabs(value);
163 if (absVal < std::numeric_limits<T>::epsilon())
167 else if ((absVal < min) || (absVal >= T(100000)))
177 else if (absVal < T(10))
181 else if (absVal < T(100))
185 else if (absVal < T(1000))
189 else if (absVal < T(10000))
199 return formattedValue;
210 const std::wstring& text,
const std::wstring& illegalChars = L
"~#%&*{}\\:<>?/+|\"",
211 wchar_t replacementChar = L
'_');
213 std::string CORE_LIBRARY_DLL_SHARED_API
214 RemoveIllegalChars(
const std::string& text,
const std::string& illegalChars =
"~#%&*{}\\:<>?/+|\"",
215 char replacementChar =
'_');
222 std::wstring CORE_LIBRARY_DLL_SHARED_API
StringToWString(
const std::string& text);
229 std::string CORE_LIBRARY_DLL_SHARED_API
WStringToString(
const std::wstring& text);
236 bool CORE_LIBRARY_DLL_SHARED_API
IsAlphaNumeric(
const std::wstring& text);
238 bool CORE_LIBRARY_DLL_SHARED_API
IsAlphaNumeric(
const std::string& text);
248 template <
typename Iter>
249 std::string
MakeHexString(Iter first, Iter last,
bool useUppercase,
bool insertSpaces)
251 std::ostringstream ss;
252 ss << std::hex << std::setfill(
'0');
256 ss << std::uppercase;
259 while (first != last)
261 ss << std::setw(2) << static_cast<int>(*first++);
263 if (insertSpaces && first != last)
279 std::vector<std::string> CORE_LIBRARY_DLL_SHARED_API
TokeniseString(std::string
const& text,
280 std::string
const& separator,
281 bool keepEmptyTokens =
false);
290 std::string CORE_LIBRARY_DLL_SHARED_API
291 ReplaceTokens(std::string
const& text, std::map<std::string, std::string>
const& tokenMap);
296 #endif // STRINGUTILS eFloatStringFormat
Format float options enumeration.
Definition: StringUtils.h:94
std::string AutoFormatFloatString(const T value, int decimalPlaces=1)
Convert a floating point value to a string representation using the most suitable formatting...
Definition: StringUtils.h:151
std::string FormatFloatString(const T value, const int precision=15, eFloatStringFormat formatting=eFloatStringFormat::normal)
Convert a floating point value to a formatted string representation.
Definition: StringUtils.h:115
bool CORE_LIBRARY_DLL_SHARED_API IsAlphaNumeric(const std::wstring &text)
Return a flag to indicate whether string contains only alphanumeric chars.
Definition: StringUtils.cpp:137
Trim the results, removing pre/pro-ceeding spaces.
The core_lib namespace.
Definition: AsioDefines.h:59
std::wstring CORE_LIBRARY_DLL_SHARED_API RemoveIllegalChars(const std::wstring &text, const std::wstring &illegalChars=L"~#%&*{}<>?/+|\, wchar_t replacementChar=L '_')
Return a string with any illegal chars replaced with replacement char.
Definition: StringUtils.cpp:94
eSplitStringResult
Split string options enumeration.
Definition: StringUtils.h:63
void CORE_LIBRARY_DLL_SHARED_API SplitString(std::string &subStr1, std::string &subStr2, const std::string &toSplit, const std::string &delim, eSplitStringResult option)
Split a string into two parts given delimiters.
Definition: StringUtils.cpp:61
File containing declaration of DLL import/export control defines.
std::wstring CORE_LIBRARY_DLL_SHARED_API StringToWString(const std::string &text)
Convert a std::string to std::wstring.
Definition: StringUtils.cpp:122
void CORE_LIBRARY_DLL_SHARED_API PackStdString(std::string &line)
Tidy a string obtained from getline function.
Definition: StringUtils.cpp:47
std::string CORE_LIBRARY_DLL_SHARED_API ReplaceTokens(std::string const &text, std::map< std::string, std::string > const &tokenMap)
Gieven a string containing tokens, replace tokens with specific string values.
Definition: StringUtils.cpp:173
std::string MakeHexString(Iter first, Iter last, bool useUppercase, bool insertSpaces)
Convert a range of data that is convertible to ints to a string of hex values.
Definition: StringUtils.h:249
std::vector< std::string > CORE_LIBRARY_DLL_SHARED_API TokeniseString(std::string const &text, std::string const &separator, bool keepEmptyTokens=false)
Tokenise a string separated by a separator substring and split it into tokens.
Definition: StringUtils.cpp:154
std::string CORE_LIBRARY_DLL_SHARED_API WStringToString(const std::wstring &text)
Convert a std::wstring to std::string.
Definition: StringUtils.cpp:128