src/Utility/String.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 //
00033 // Extended string
00034 //
00035 
00036 #ifndef UTILITY_STRING_H
00037 #define UTILITY_STRING_H
00038 
00039 #include <string>
00040 #include <vector>
00041 #include <stdarg.h>
00042 #include <boost/tokenizer.hpp>
00043 
00044 namespace Onikiri
00045 {
00046     class String : public std::string
00047     {
00048         typedef std::string t_string;
00049 
00050     public:
00051         String();
00052         String(const t_string &str, size_type pos = 0, size_type n = npos);
00053         String(const char* str);
00054         String& format_arg(const char* fmt, va_list& arg);
00055 
00056         // 'printf' style format
00057         String& format(const char* fmt, ... );
00058 
00059         operator const char*() const {  return c_str(); };
00060 
00061         template<class T> String& operator=(const T& rhs)
00062         {
00063             assign(rhs);
00064             return *this;
00065         }
00066 
00067         template<class T> String operator+(const T& rhs)
00068         {
00069             String tmp(*this);
00070             tmp.append(rhs);
00071             return tmp;
00072         }
00073 
00074         String& operator=(const t_string& rhs)
00075         {
00076             assign(rhs);
00077             return *this;
00078         }
00079 
00080         String operator+(const t_string& rhs)
00081         {
00082             String tmp(*this);
00083             tmp.append(rhs);
00084             return tmp;
00085         }
00086 
00087         String& operator+=(const t_string& rhs)
00088         {
00089             append(rhs);
00090             return *this;
00091         }
00092 
00093         template<class T> String& operator+=(const T& rhs)
00094         {
00095             append(rhs);
00096             return *this;
00097         }
00098 
00099         String& operator+=(const char rhs)
00100         {
00101             append(&rhs, 1);
00102             return *this;
00103         }
00104 
00105         void find_and_replace( const String& from, const String& to )
00106         {
00107             while( true ){
00108                 std::string::size_type i = find( from ); 
00109 
00110                 if( i == std::string::npos ){
00111                     break;
00112                 }
00113 
00114                 std::string::replace( i, from.length(), to );
00115             }
00116         }
00117 
00118         // sepStr     : delimiter 
00119         // sepKeepStr : delimitericj
00120         // ",/"C',''/'delimiter
00121         std::vector<String> split(
00122             const char* delimiter, 
00123             const char* delimiterKeep = NULL) const;
00124 
00125         template <class T> T to()
00126         {
00127             return boost::lexical_cast<T>(*this);
00128         }
00129     };
00130 }
00131 
00132 #endif

Onikiri2に対してTue Jun 18 14:34:27 2013に生成されました。  doxygen 1.4.7