28 #ifndef __TERRALIB_COMMON_INTERNAL_STRINGUTILS_H
29 #define __TERRALIB_COMMON_INTERNAL_STRINGUTILS_H
40 #include <boost/cstdint.hpp>
53 char name[std::numeric_limits<boost::int16_t>::digits10 + 2];
54 sprintf(name,
"%hd", value);
65 char name[std::numeric_limits<boost::uint16_t>::digits10 + 2];
66 sprintf(name,
"%hu", value);
77 char name[std::numeric_limits<boost::int32_t>::digits10 + 2];
78 sprintf(name,
"%d", value);
89 char name[std::numeric_limits<boost::uint32_t>::digits10 + 2];
90 sprintf(name,
"%u", value);
101 char name[std::numeric_limits<boost::int64_t>::digits10 + 2];
102 sprintf(name,
"%lli", value);
113 char name[std::numeric_limits<boost::uint64_t>::digits10 + 2];
114 sprintf(name,
"%llu", value);
125 char name[std::numeric_limits<float>::digits10 + std::numeric_limits<float>::digits + 4];
126 sprintf(name,
"%f", value);
137 char name[std::numeric_limits<double>::digits10 + std::numeric_limits<double>::digits + 4];
138 sprintf(name,
"%e", value);
152 sprintf(name,
"%.*f", precision, value );
165 size_t size = value.size();
167 std::string aux(size,
' ');
169 for(
size_t i = 0; i < size; ++i)
170 aux[i] = ((value[i] >= 97) && (value[i] <= 122)) ? (value[i] - 32) : value[i];
184 size_t size = value.size();
186 for(
size_t i = 0; i < size; ++i)
187 value[i] = ((value[i] >= 97) && (value[i] <= 122)) ? (value[i] - 32) : value[i];
199 size_t size = value.size();
201 std::string aux(size,
' ');
203 for(
size_t i = 0; i < size; ++i)
204 aux[i] = ((value[i] >= 65) && (value[i] <= 90)) ? (value[i] + 32) : value[i];
217 std::vector<std::string>& tokens,
218 const std::string& delimiters =
" ")
221 size_t lastPos = str.find_first_not_of(delimiters, 0);
224 size_t pos = str.find_first_of(delimiters, lastPos);
226 while((std::string::npos != pos) ||
227 (std::string::npos != lastPos))
230 tokens.push_back(str.substr(lastPos, pos - lastPos));
233 lastPos = str.find_first_not_of(delimiters, pos);
236 pos = str.find_first_of(delimiters, lastPos);
252 std::map<std::string, std::string>& kvp,
253 const std::string& kvpDelimiter =
"&",
254 const std::string& kvDelimiter =
"=",
255 bool toUpper =
false)
261 std::vector<std::string> tokens;
263 Tokenize(kvpStr, tokens, kvpDelimiter);
266 size_t size = tokens.size();
268 for(
size_t i = 0; i < size; ++i)
270 std::vector<std::string> kv;
272 Tokenize(tokens[i], kv, kvDelimiter);
290 for(
size_t k = 1; k < kv.size(); ++k)
293 size_t pos = aux.size() - 1;
295 kvp[kv[0]] = aux.erase(pos, 1);
309 char* cs =
new char[s.length() + 1];
310 strncpy(cs, s.c_str(), s.length() + 1);
323 std::size_t ns = vs.size() ;
325 char** as =
new char*[ns + 1];
329 for(std::size_t i = 0; i< ns; ++i)
331 as[i] =
new char[vs[i]->length() + 1];
333 strncpy(as[i], vs[i]->c_str(), vs[i]->length() + 1);
348 std::size_t ns = vs.size() ;
350 char** as =
new char*[ns + 1];
354 for(std::size_t i = 0; i< ns; ++i)
356 as[i] =
new char[vs[i].length() + 1];
358 strncpy(as[i], vs[i].c_str(), vs[i].length() + 1);
367 #endif // __TERRALIB_COMMON_INTERNAL_STRINGUTILS_H
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
void ExtractKVP(const std::string &kvpStr, std::map< std::string, std::string > &kvp, const std::string &kvpDelimiter="&", const std::string &kvDelimiter="=", bool toUpper=false)
It extracts a key-value map from a string.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
void Convert2UCaseInPlace(std::string &value)
It converts a string to upper case in place (it doesn't allocate an auxiliar buffer).
char ** CreateCStringArray(const std::vector< std::string * > &vs)
It converts the C++ vector of string pointers to a C array os strings.
char * CreateCString(const std::string &s)
It converts the C++ string to a C-string.