00001 /******************************************************************* 00002 * File: StringUtil.h 00003 * Description: Some common utility functions for strings. 00004 * Author: Subhasis Ray 00005 * E-mail: ray.subhasis@gmail.com 00006 * Created: 2007-09-25 12:08:00 00007 ********************************************************************/ 00008 #ifndef _STRINGUTIL_H 00009 #define _STRINGUTIL_H 00010 #include <string> 00011 #include <vector> 00013 static const char* const DELIMITERS=" \t\r\n"; 00015 void tokenize( 00016 const std::string& str, 00017 const std::string& delimiters, 00018 std::vector< std::string >& tokens ); 00020 std::string trim(const std::string myString, const std::string& delimiters=" \t\r\n"); 00021 00023 std::string fix(const std::string myString, const std::string& delimiters=" \t\r\n"); 00024 00025 std::string& clean_type_name(std::string& arg); 00026 bool endswith(const std::string& full, const std::string& ending); 00027 // TODO: other std::string utilities to add 00028 // /** Trim leading and trailing whitespace and replace convert any two or more consecutive whitespace inside the std::string by a single 'blank' character. */ 00029 // std::string fulltrim(std::string& myString) const; 00030 // /** Convert to uppercase */ 00031 // std::string upcase(std::string& myString) const; 00032 // /** Convert to lowercase */ 00033 // std::string downcase(std::string & myString); 00034 // Maybe a implement regular expression search - reinventing wheel - but no standard way without using some bloated library. 00035 #endif //_STRINGUTIL_H