Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <cob_utilities/StrUtil.h>
00019 #include <algorithm>
00020
00021 std::string StringToUpper(std::string strToConvert) {
00022 for(unsigned int i=0;i<strToConvert.length();i++)
00023 {
00024 strToConvert[i] = toupper(strToConvert[i]);
00025 }
00026 return strToConvert;
00027 }
00028
00029 std::string StringToLower(std::string strToConvert) {
00030 for(unsigned int i=0;i<strToConvert.length();i++)
00031 {
00032 strToConvert[i] = tolower(strToConvert[i]);
00033 }
00034 return strToConvert;
00035 }
00036
00037 std::string NumToString(const int n) {
00038 std::stringstream ss;
00039 ss << n;
00040 return ss.str();
00041 }
00042
00043 std::string NumToString(const unsigned int n) {
00044 std::stringstream ss;
00045 ss << n;
00046 return ss.str();
00047 }
00048
00049 std::string NumToString(const long l) {
00050 std::stringstream ss;
00051 ss << l;
00052 return ss.str();
00053 }
00054
00055 std::string NumToString(const float f, unsigned int width, unsigned int precise) {
00056 std::stringstream ss;
00057 ss << std::setw(width) << std::setprecision(precise) << f;
00058 return ss.str();
00059 }
00060
00061 std::string NumToString(const double d, unsigned int width, unsigned int precise) {
00062 std::stringstream ss;
00063 ss << std::setw(width) << std::setprecision(precise) << d;
00064 return ss.str();
00065 }
00066
00070 char* itoa( int value, char* result, int base )
00071 {
00072
00073 if (base < 2 || base > 16) {
00074 *result = 0; return result;
00075 }
00076
00077 char* out = result;
00078 int quotient = value;
00079
00080 do {
00081 *out = "0123456789abcdef"[ std::abs( quotient % base ) ];
00082 ++out;
00083 quotient /= base;
00084 } while ( quotient );
00085
00086
00087 if ( value < 0 && base == 10) *out++ = '-';
00088
00089 std::reverse( result, out );
00090 *out = 0;
00091 return result;
00092 }
00093
00097 std::string itoa(int value, int base)
00098 {
00099 enum { kMaxDigits = 35 };
00100 std::string buf;
00101
00102 buf.reserve( kMaxDigits );
00103
00104
00105 if (base < 2 || base > 16) return buf;
00106
00107 int quotient = value;
00108
00109
00110 do {
00111 buf += "0123456789abcdef"[ std::abs( quotient % base ) ];
00112 quotient /= base;
00113 } while ( quotient );
00114
00115
00116 if ( value < 0 && base == 10) buf += '-';
00117 std::reverse( buf.begin(), buf.end() );
00118 return buf;
00119 }
00120