8 #ifndef META_OCEAN_BASE_STRING_H
9 #define META_OCEAN_BASE_STRING_H
39 static std::string
toAString(
const unsigned char value);
47 static std::string
toAString(
const double value,
const unsigned int precision = 5u);
55 static std::string
toAString(
const float value,
const unsigned int precision = 5u);
85 static std::string
toAString(
const unsigned int value);
99 static std::string
toAString(
const long long value);
106 static std::string
toAString(
const unsigned long long value);
113 static std::string
toAString(
const long unsigned int value);
127 static std::string
toAString(
const unsigned short value);
136 static std::string
toAString(
const unsigned int value,
const unsigned int minimalChars);
144 static std::string
toAStringHex(
const char value,
const bool upperCases =
true);
152 static std::string
toAStringHex(
const unsigned char value,
const bool upperCases =
true);
160 static std::string
toAStringHex(
const double value,
const bool upperCases =
true);
168 static std::string
toAStringHex(
const float value,
const bool upperCases =
true);
176 static std::string
toAStringHex(
const int value,
const bool upperCases =
true);
184 static std::string
toAStringHex(
const unsigned int value,
const bool upperCases =
true);
192 static std::string
toAStringHex(
const long long value,
const bool upperCases =
true);
200 static std::string
toAStringHex(
const unsigned long long value,
const bool upperCases =
true);
208 static std::string
toAStringHex(
const long unsigned int value,
const bool upperCases =
true);
216 static std::string
toAStringHex(
const short value,
const bool upperCases =
true);
224 static std::string
toAStringHex(
const unsigned short value,
const bool upperCases =
true);
233 static std::string
toAStringHex(
const uint8_t* data,
const size_t size,
const bool upperCases =
true);
242 static std::string
toAStringHexReverse(
const uint8_t* data,
const size_t size,
const bool upperCases =
true);
249 static std::string
toLower(
const std::string& value);
256 static std::string
toUpper(
const std::string& value);
264 static std::string
trimFront(
const std::string& value,
const char character =
' ');
272 static std::string
trimBack(
const std::string& value,
const char character =
' ');
280 static std::string
trim(
const std::string& value,
const char character =
' ');
290 static std::string
replace(std::string&& value,
const std::string& oldString,
const std::string& newString,
const bool onlyFirstOccurrence);
300 static std::string
replaceCharacters(
const std::string& value,
const char oldCharacter,
const char newCharacter);
310 static std::string
exchangeCharacters(
const std::string& value,
const char character0,
const char character1);
332 template <
typename TChar>
333 static std::basic_string<TChar> insertCharacter(
const std::basic_string<TChar>& value,
const TChar& character,
size_t interval,
bool startAtFront);
345 static bool isBoolean(
const std::string& stringValue,
const bool matchCase =
true,
const bool acceptInteger =
false,
bool* value =
nullptr);
355 static bool isInteger32(
const std::string& stringValue, int32_t* value =
nullptr);
377 static bool isHexValue64(
const char* hexString,
size_t length,
const bool needPrefix =
false,
unsigned long long* value =
nullptr);
387 static bool isNumber(
const std::string& stringValue,
const bool acceptInteger =
false,
double* value =
nullptr);
422 static std::string
toAString(
const std::wstring& value);
450 static std::wstring
toWString(
const unsigned short* value);
457 static std::wstring
toWString(
const unsigned char value);
465 static std::wstring
toWString(
const double value,
const unsigned int precision = 5u);
473 static std::wstring
toWString(
const float value,
const unsigned int precision = 5u);
503 static std::wstring
toWString(
const unsigned int value);
524 static std::wstring
toWString(
const unsigned long long value);
538 static std::wstring
toWString(
const unsigned short value);
545 static std::wstring
toWString(
const long unsigned int value);
561 static std::wstring
toWString(
const unsigned int value,
const unsigned int minimalChars);
568 static std::wstring
toWString(
const std::string& value);
575 static std::wstring
toWString(
const std::wstring& value);
583 static std::wstring
trimFront(
const std::wstring& value,
const wchar_t character = L
' ');
591 static std::wstring
trimBack(
const std::wstring& value,
const wchar_t character = L
' ');
599 static std::wstring
trim(
const std::wstring& value,
const wchar_t character = L
' ');
645 static std::wstring
replaceCharacters(
const std::wstring& value,
const wchar_t oldCharacter,
const wchar_t newCharacter);
655 static std::wstring
exchangeCharacters(
const std::wstring& value,
const wchar_t character0,
const wchar_t character1);
675 template <
typename TChar,
typename T>
676 static std::basic_string<TChar>
toString(
const T& value);
694 template <
typename TChar>
701 return value ? std::string(
"true") : std::string(
"false");
707 return value ? std::wstring(L
"true") : std::wstring(L
"false");
710 template <
typename TChar>
711 std::basic_string<TChar>
String::insertCharacter(
const std::basic_string<TChar>& value,
const TChar& character,
size_t interval,
bool startAtFront)
713 ocean_assert(interval != 0);
715 std::basic_string<TChar> result(value);
719 size_t position = interval;
721 while (position < result.length())
723 result.insert(position, 1, character);
724 position += interval + 1;
729 std::ptrdiff_t position = std::ptrdiff_t(result.length()) - std::ptrdiff_t(interval);
731 while (position >= 1)
733 result.insert(position, 1, character);
734 position -= std::ptrdiff_t(interval);
741 template <
typename TChar,
typename T>
744 std::basic_ostringstream<TChar> stream;
This class provides string convert functionalities.
Definition: String.h:24
static std::string trimBack(const std::string &value, const char character=' ')
Trims the back of a string.
static std::string removeCharacters(const std::string &value, const char character)
Removes characters with a specified value from a string.
static std::wstring toWStringScientific(const double value, const unsigned int precision=5u)
Converts a value to a wstring using a scientific notation.
static std::wstring toWString(const std::wstring &value)
Converts a value to a wstring.
static std::basic_string< TChar > insertCharacter(const std::basic_string< TChar > &value, const TChar &character, size_t interval, bool startAtFront)
Inserts a specified character into a string in regular intervals.
Definition: String.h:711
static std::string toAStringHex(const long unsigned int value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string toAStringScientific(const double value, const unsigned int precision=5u)
Converts a value to a string with 8bit character using a scientific notation.
static std::string toAString(const long long value)
Converts a value to a string with 8bit character.
static std::string trimFront(const std::string &value, const char character=' ')
Trims the front of a string.
static std::string toAString(const char value)
Converts a value to a string with 8bit character.
static std::string toAStringHex(const double value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::wstring toWString(const unsigned int value, const unsigned int minimalChars)
Converts a value to a wstring with a minimal number of characters.
static std::wstring toWString(const short value)
Converts a value to a wstring.
static bool isBoolean(const std::string &stringValue, const bool matchCase=true, const bool acceptInteger=false, bool *value=nullptr)
Returns whether a given string stores a boolean value.
static std::string toLower(const std::string &value)
Converts a string to a string with lower characters only.
static std::wstring toWString(const double value, const unsigned int precision=5u)
Converts a value to a wstring using a fixed notation.
static std::string trimWhitespace(const std::string &text)
Returns the specified text with all whitespace characters removed from the left and right side.
static std::string toAString(const char *value)
Converts a value to a string with 8bit character.
static std::string replaceCharacters(const std::string &value, const char oldCharacter, const char newCharacter)
Replaces characters with a specified value by a new character.
static std::string toAString(const std::string &value)
Converts a value to a string with 8bit character.
static std::wstring toWStringScientific(const float value, const unsigned int precision=5u)
Converts a value to a wstring using a scientific notation.
static bool isInteger32(const std::string &stringValue, int32_t *value=nullptr)
Returns whether a given string stores a 32bit integer value.
static std::wstring trim(const std::wstring &value, const wchar_t character=L' ')
Trims the front and the back of a string.
static bool isNumber(const std::string &stringValue, const bool acceptInteger=false, double *value=nullptr)
Returns whether a given string stores a number value.
static std::string toAString(const unsigned short value)
Converts a value to a string with 8bit character.
static std::wstring replaceCharacters(const std::wstring &value, const wchar_t oldCharacter, const wchar_t newCharacter)
Replaces characters with a specified value by a new character.
static std::string trim(const std::string &value, const char character=' ')
Trims the front and the back of a string.
static std::wstring toWString(const unsigned short *value)
Converts a value to a wstring.
static std::string toAStringHex(const char value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string toAStringHex(const unsigned long long value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::wstring toWString(const unsigned char value)
Converts a value to a wstring.
static bool isHexValue64(const char *hexString, size_t length, const bool needPrefix=false, unsigned long long *value=nullptr)
Returns whether a given string stores an hexadecimal value with up to 64 bits.
static std::basic_string< TChar > toString(const T &value)
Converts a value of an arbitrary primitive type into a string (supported types are: ordinal types,...
Definition: String.h:742
static std::string toAString(const wchar_t value)
Converts a value to a string with 8bit character.
static bool isUnsignedInteger64(const std::string &stringValue, uint64_t *value=nullptr)
Returns whether a given string stores an unsigned 64bit integer value.
static std::string toAString(const float value, const unsigned int precision=5u)
Converts a value to a string with 8bit character using a fixed notation.
static std::string toAStringHex(const long long value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string toAString(const unsigned int value)
Converts a value to a string with 8bit character.
static std::wstring toWString(const long value)
Converts a value to a wstring.
static std::string toAStringHex(const short value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string toAString(const unsigned long long value)
Converts a value to a string with 8bit character.
static std::wstring toWString(const unsigned int value)
Converts a value to a wstring.
static std::wstring toWString(const unsigned short value)
Converts a value to a wstring.
static std::string toAString(const unsigned int value, const unsigned int minimalChars)
Converts a value to a string with a minimal number of characters.
static std::string toAString(const short value)
Converts a value to a string with 8bit character.
static std::wstring toWString(const wchar_t value)
Converts a value to a wstring.
static std::wstring toWString(const char *value)
Converts a value to a wstring.
static std::string toAStringHex(const int value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string replace(std::string &&value, const std::string &oldString, const std::string &newString, const bool onlyFirstOccurrence)
Replaces a sub-string inside a string with a different string.
static std::string toAStringHex(const uint8_t *data, const size_t size, const bool upperCases=true)
Converts memory to a string with hexadecimal notation.
static std::wstring trimBack(const std::wstring &value, const wchar_t character=L' ')
Trims the back of a string.
static std::basic_string< TChar > trimWhitespaceString(const std::basic_string< TChar > &text)
Returns the specified text with all whitespace characters removed from the left and right side.
static std::wstring removeCharacters(const std::wstring &value, const wchar_t character)
Removes characters with a specified value from a string.
static std::string toAStringHex(const float value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string toUpper(const std::string &value)
Converts a string to a string with upper characters only.
static std::string toAStringHex(const unsigned char value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string toAString(const double value, const unsigned int precision=5u)
Converts a value to a string with 8bit character using a fixed notation.
static std::string toAString(const long value)
Converts a value to a string with 8bit character.
static std::string toAString(const wchar_t *value)
Converts a value to a string with 8bit character.
static std::wstring toWString(const long long value)
Converts a value to a wstring.
static std::string toAString(const unsigned char value)
Converts a value to a string with 8bit character.
static std::string toAStringHex(const unsigned short value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::string toAStringHexReverse(const uint8_t *data, const size_t size, const bool upperCases=true)
Converts memory to a string with hexadecimal notation in a reverse order.
static std::string exchangeCharacters(const std::string &value, const char character0, const char character1)
Exchanges two characters within a string.
static std::string toAStringHex(const unsigned int value, const bool upperCases=true)
Converts a value to a string with 8bit character as hexadecimal notation.
static std::wstring toWString(const long unsigned int value)
Converts a value to a wstring.
static std::wstring toWString(const float value, const unsigned int precision=5u)
Converts a value to a wstring using a fixed notation.
static std::wstring toWString(const wchar_t *value)
Converts a value to a wstring.
static std::wstring toWString(const char value)
Converts a value to a wstring.
static std::string toAString(const long unsigned int value)
Converts a value to a string with 8bit character.
static std::string toAString(const int value)
Converts a value to a string with 8bit character.
static std::wstring toWString(const std::string &value)
Converts a value to a wstring.
static std::wstring exchangeCharacters(const std::wstring &value, const wchar_t character0, const wchar_t character1)
Exchanges two characters within a string.
static std::wstring toWString(const int value)
Converts a value to a wstring.
static std::wstring trimWhitespace(const std::wstring &text)
Returns the specified text with all whitespace characters removed from the left and right side.
static std::string toAStringScientific(const float value, const unsigned int precision=5u)
Converts a value to a string with 8bit character using a scientific notation.
static std::string toAString(const std::wstring &value)
Converts a value to a string with 8bit character.
static std::wstring toWString(const unsigned long long value)
Converts a value to a wstring.
static std::wstring trimFront(const std::wstring &value, const wchar_t character=L' ')
Trims the front of a string.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15