Go to the documentation of this file.
22 #include <unordered_map>
23 #include <unordered_set>
37 void stripLeading(::std::string& s,
const char& c =
' ');
51 void strip(::std::string& s,
const char& c =
' ');
66 ::std::string
stripLeading(const ::std::string& s,
const char& c =
' ');
74 ::std::string
stripTrailing(const ::std::string& s,
const char& c =
' ');
82 ::std::string
strip(const ::std::string& s,
const char& c =
' ');
100 ::std::string
removePrefix(const ::std::string& str, const ::std::string& prefix,
bool* hadPrefix =
nullptr);
110 ::std::string
removeSuffix(const ::std::string& str, const ::std::string& suffix,
bool* hadSuffix =
nullptr);
118 ::std::string
prependIfNonEmpty(const ::std::string& str, const ::std::string& prefix);
126 ::std::string
appendIfNonEmpty(const ::std::string& str, const ::std::string& suffix);
134 bool startsWith(const ::std::string& str, const ::std::string& prefix);
142 bool endsWith(const ::std::string& str, const ::std::string& suffix);
167 ::std::string
replace(const ::std::string& str, const ::std::string& from, const ::std::string& to,
177 void replace(::std::string& str, const ::std::string& from, const ::std::string& to,
186 bool contains(const ::std::string& str,
char c);
194 bool contains(const ::std::string& str, const ::std::string& needle);
203 ::std::vector<::std::string>
split(const ::std::string& str, const ::std::string& delimiter,
int maxSplits = -1);
211 ::std::string
toUpper(const ::std::string& str);
219 ::std::string
toLower(const ::std::string& str);
230 constexpr
size_t BUF_LEN = 1024u;
234 ::va_copy(argsCopy,
args);
236 const auto len = ::vsnprintf(buf, BUF_LEN,
format,
args);
238 ::std::string result;
241 throw ::std::runtime_error(::std::string(
"Error formatting string '") +
format +
"': " + ::strerror(errno));
243 else if (len < BUF_LEN)
249 char* buf2 =
new char[len + 1];
250 ::vsnprintf(buf2, len + 1,
format, argsCopy);
306 template<
typename T, ::std::enable_if_t<!::cras::is_
string<::std::decay_t<T>>::value,
bool> = true>
318 template<
typename T, ::std::enable_if_t<::cras::is_
string<::std::decay_t<T>>::value,
bool> = true>
321 return "\"" +
s +
"\"";
343 inline decltype(
static_cast<::std::string
>(::std::declval<T>()))
to_string(const T& value)
345 return static_cast<::std::string
>(value);
349 template<
typename T>
using ToStringFn = ::std::function<::std::string(
const T&)>;
361 inline ::std::string
to_string(
const long double& value)
383 inline ::std::string
to_string(
char value[I])
390 return value ?
"True" :
"False";
393 inline ::std::string
to_string(const ::std::string& value)
400 #if __has_include(<Eigen/Core>)
404 #if __has_include(<tf2/LinearMath/Vector3.h>)
408 #if __has_include(<ros/ros.h>)
412 #if __has_include(<xmlrpcpp/XmlRpcValue.h>)
420 template<
typename K,
typename V>
421 inline ::std::string
to_string(const ::std::map<K, V>& value);
423 template<
typename K,
typename V>
424 inline ::std::string
to_string(const ::std::unordered_map<K, V>& value);
426 #define DECLARE_TO_STRING_VECTOR(vectorType, prefix, suffix) \
427 template<typename T> \
428 inline ::std::string to_string(const vectorType<T>& value) \
430 ::std::stringstream ss; \
433 for (const auto& v : value) \
435 ss << ::cras::quoteIfStringType(::cras::to_string(v), v); \
436 if (i + 1 < value.size()) \
447 DECLARE_TO_STRING_VECTOR(::std::unordered_set, "{
", "}
")
449 template<typename T, size_t N>
450 inline ::std::string to_string(const ::std::array<T, N>& value)
452 ::std::stringstream ss;
455 for (const auto& v : value)
457 ss << ::cras::quoteIfStringType(::cras::to_string(v), v);
458 if (i + 1 < value.size())ss << ",
";
465 #define DECLARE_TO_STRING_MAP(mapType) \
466 template<typename K, typename V> \
467 inline ::std::string to_string(const mapType<K, V>& value) \
469 ::std::stringstream ss; \
472 for (const auto& pair : value) \
474 ss << ::cras::quoteIfStringType(::cras::to_string(pair.first), pair.first) \
476 << ::cras::quoteIfStringType(::cras::to_string(pair.second), pair.second); \
477 if (i + 1 < value.size()) \
485 DECLARE_TO_STRING_MAP(::std::map)
486 DECLARE_TO_STRING_MAP(::std::unordered_map)
496 ::std::string join(const T& strings, const ::std::string& delimiter)
498 const auto numStrings = strings.size();
502 ::std::stringstream ss;
504 for (const auto& s : strings)
506 ss << ::cras::to_string(s);
507 if (i < numStrings - 1)
523 int8_t parseInt8(const std::string& string);
534 int8_t parseInt8(const std::string& string, uint8_t base);
544 inline int8_t parseInt8(const char* string)
546 return ::cras::parseInt8(::std::string(string));
558 inline int8_t parseInt8(const char* string, const uint8_t base)
560 return ::cras::parseInt8(::std::string(string), base);
571 uint8_t parseUInt8(const std::string& string);
582 uint8_t parseUInt8(const std::string& string, uint8_t base);
592 inline uint8_t parseUInt8(const char* string)
594 return ::cras::parseUInt8(::std::string(string));
606 inline uint8_t parseUInt8(const char* string, const uint8_t base)
608 return ::cras::parseUInt8(::std::string(string), base);
619 int16_t parseInt16(const std::string& string);
630 int16_t parseInt16(const std::string& string, uint8_t base);
640 inline int16_t parseInt16(const char* string)
642 return ::cras::parseInt16(::std::string(string));
654 inline int16_t parseInt16(const char* string, const uint8_t base)
656 return ::cras::parseInt16(::std::string(string), base);
667 uint16_t parseUInt16(const std::string& string);
678 uint16_t parseUInt16(const std::string& string, uint8_t base);
688 inline uint16_t parseUInt16(const char* string)
690 return ::cras::parseUInt16(::std::string(string));
702 inline uint16_t parseUInt16(const char* string, const uint8_t base)
704 return ::cras::parseUInt16(::std::string(string), base);
715 int32_t parseInt32(const std::string& string);
726 int32_t parseInt32(const std::string& string, uint8_t base);
736 inline int32_t parseInt32(const char* string)
738 return ::cras::parseInt32(::std::string(string));
750 inline int32_t parseInt32(const char* string, const uint8_t base)
752 return ::cras::parseInt32(::std::string(string), base);
763 uint32_t parseUInt32(const std::string& string);
774 uint32_t parseUInt32(const std::string& string, uint8_t base);
784 inline uint32_t parseUInt32(const char* string)
786 return ::cras::parseUInt32(::std::string(string));
798 inline uint32_t parseUInt32(const char* string, const uint8_t base)
800 return ::cras::parseUInt32(::std::string(string), base);
811 int64_t parseInt64(const std::string& string);
822 int64_t parseInt64(const std::string& string, uint8_t base);
832 inline int64_t parseInt64(const char* string)
834 return ::cras::parseInt64(::std::string(string));
846 inline int64_t parseInt64(const char* string, const uint8_t base)
848 return ::cras::parseInt64(::std::string(string), base);
859 uint64_t parseUInt64(const std::string& string);
870 uint64_t parseUInt64(const std::string& string, uint8_t base);
880 inline uint64_t parseUInt64(const char* string)
882 return ::cras::parseUInt64(::std::string(string));
894 inline uint64_t parseUInt64(const char* string, const uint8_t base)
896 return ::cras::parseUInt64(::std::string(string), base);
906 float parseFloat(const ::std::string& string);
915 inline float parseFloat(const char* string)
917 return ::cras::parseFloat(::std::string(string));
927 double parseDouble(const ::std::string& string);
936 inline double parseDouble(const char* string)
938 return ::cras::parseDouble(::std::string(string));
946 bool isLegalName(const ::std::string& name);
954 bool isLegalBaseName(const ::std::string& name);
970 TempLocale(int category, const char* newLocale);
974 int category; //!< The category of the locale.
975 const char* oldLocale; //!< The previous locale.
993 ::std::string iconvConvert(
994 const ::std::string& toEncoding, const ::std::string& fromEncoding, const ::std::string& inText,
995 bool translit = false, bool ignore = false, double initialOutbufSizeScale = 1.0, double outbufEnlargeCoef = 2.0,
996 const ::cras::optional<::std::string>& localeName = ::cras::nullopt);
1003 ::std::string transliterateToAscii(const ::std::string& text);
1016 ::std::string toValidRosName(const ::std::string& text, bool baseName = true,
1017 const ::cras::optional<::std::string>& fallbackName = ::cras::nullopt);
Specializations of cras::to_string() for ROS types and messages. Parsing of dates.
::std::string prependIfNonEmpty(const ::std::string &str, const ::std::string &prefix)
If str is nonempty, returns prefix + str, otherwise empty string.
bool contains(const ::std::string &str, char c)
Check whether str contains character c.
void stripLeadingSlash(::std::string &s, bool warn=false)
Strip leading slash from the given string (if there is one).
::std::string toUpper(const ::std::string &str)
Convert all characters in the given string to upper case.
void stripTrailing(::std::string &s, const char &c=' ')
Strip c from the end of the given string (if there is one).
void stripLeading(::std::string &s, const char &c=' ')
Strip c from the start of the given string (if there is one).
ReplacePosition
Specifies where a replace operation should act.
bool endsWith(const ::std::string &str, const ::std::string &suffix)
Check whether suffix is a suffix of str.
::std::function<::std::string(const T &)> ToStringFn
Type of function that converts anything to a string.
inline ::std::string format(::std::string format,...)
::std::string toLower(const ::std::string &str)
Convert all characters in the given string to lower case.
void strip(::std::string &s, const char &c=' ')
Strip c from the beginning and end of the given string (if it is there).
__attribute__((format(printf, 1, 0))) inline
bool startsWith(const ::std::string &str, const ::std::string &prefix)
Check whether prefix is a prefix of str.
Specializations of cras::to_string() for TF2 types.
inline ::std::string to_string(const ::std::array< T, N > &value)
Specializations of cras::to_string() for XmlRpcValue values.
::std::string removeSuffix(const ::std::string &str, const ::std::string &suffix, bool *hadSuffix=nullptr)
Remove suffix from end of str if it contains it, otherwise return str unchanged.
::std::vector<::std::string > split(const ::std::string &str, const ::std::string &delimiter, int maxSplits=-1)
Split the given string by the given delimiter.
::std::string removePrefix(const ::std::string &str, const ::std::string &prefix, bool *hadPrefix=nullptr)
Remove prefix from start of str if it contains it, otherwise return str unchanged.
Specializations of cras::to_string() for Eigen types.
#define DECLARE_TO_STRING_VECTOR(vectorType, prefix, suffix)
inline ::std::string quoteIfStringType(const ::std::string &s, const T &)
Put s in double quotes if T is a string type (std::string or char*).
@ EVERYWHERE
Act in the whole string.
Useful C++ string traits.
@ END
Act only on the end of the string.
::std::string appendIfNonEmpty(const ::std::string &str, const ::std::string &suffix)
If str is nonempty, returns str + suffix, otherwise empty string.
inline ::std::string to_string(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &value)
inline ::std::string format(::std::string format, ::va_list args)
@ START
Act only on the beginning of the string.
::std::string replace(const ::std::string &str, const ::std::string &from, const ::std::string &to, const ::cras::ReplacePosition &where=::cras::ReplacePosition::EVERYWHERE)
Replace all occurrences of from in str with to.
A C++11 shim for std::optional. Uses std::optional when used in C++17 mode.
cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04