String.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006-2011, SRI International (R)
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as published by
00006  * the Free Software Foundation, either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include <algorithm>
00019 #include <string>
00020 #include <limits>
00021 
00022 #include <OpenKarto/String.h>
00023 
00024 namespace karto
00025 {
00026 
00030 
00031 #ifndef _DEBUG
00032   struct StringPrivate
00033   {
00034     std::string m_String;
00035   };
00036 #endif
00037 
00038   String::String()
00039     : m_pStringPrivate(new StringPrivate())
00040   {
00041   }
00042 
00043   String::String(char c)
00044     : m_pStringPrivate(new StringPrivate())
00045   {
00046     m_pStringPrivate->m_String = c;
00047   }
00048 
00049   String::String(const char* pString)
00050     : m_pStringPrivate(new StringPrivate())
00051   {
00052     m_pStringPrivate->m_String = pString;
00053   }
00054 
00055   String::String(const char* pString, kt_int32u size)
00056     : m_pStringPrivate(new StringPrivate())
00057   {
00058     m_pStringPrivate->m_String = std::string(pString, size);
00059   }
00060 
00061   String::String(const String& rOther)
00062     : m_pStringPrivate(new StringPrivate())
00063   {
00064     m_pStringPrivate->m_String = rOther.m_pStringPrivate->m_String;
00065   }
00066 
00067   String::~String()
00068   {
00069     delete m_pStringPrivate;
00070   }
00071 
00072   const char* String::ToCString() const
00073   {
00074     return m_pStringPrivate->m_String.c_str();
00075   }
00076 
00077   kt_size_t String::Size() const
00078   {
00079     return m_pStringPrivate->m_String.size();
00080   }
00081 
00082   void String::Append(const String& rString)
00083   {
00084     m_pStringPrivate->m_String.append(rString.ToCString());
00085   }
00086 
00087   String String::SubString(kt_size_t index) const
00088   {
00089     return String(m_pStringPrivate->m_String.substr(index).c_str());
00090   }
00091 
00092   String String::SubString(kt_size_t index, kt_size_t length) const
00093   {
00094     return String(m_pStringPrivate->m_String.substr(index, length).c_str());
00095   }
00096 
00097   kt_size_t String::Find(const String& rValue) const
00098   {
00099     return m_pStringPrivate->m_String.find(rValue.ToCString());
00100   }
00101 
00102   kt_size_t String::FindFirstOf(const String& rValue) const
00103   {
00104     return m_pStringPrivate->m_String.find_first_of(rValue.ToCString());
00105   }
00106 
00107   kt_size_t String::FindLastOf(const String& rValue) const
00108   {
00109     return m_pStringPrivate->m_String.find_last_of(rValue.ToCString());
00110   }
00111 
00112   void String::Erase(kt_size_t index, kt_size_t length)
00113   {
00114     m_pStringPrivate->m_String.erase(index, length);
00115   }
00116 
00117   karto::String String::NewLine()
00118   {
00119     return String('\n');
00120   }
00121 
00122   void String::Clear()
00123   {
00124     m_pStringPrivate->m_String.clear();
00125   }
00126 
00127   //String::operator const char *() const
00128   //{
00129   //  return m_pStringPrivate->m_String.c_str();
00130   //}
00131 
00132   String& String::operator=(const String& rOther)
00133   {
00134     if (&rOther != this)
00135     {
00136       m_pStringPrivate->m_String = rOther.m_pStringPrivate->m_String;
00137     }
00138 
00139     return *this;
00140   }
00141 
00142   kt_bool String::operator==(const String& rOther) const
00143   {
00144     return m_pStringPrivate->m_String == rOther.m_pStringPrivate->m_String;
00145   }
00146 
00147   kt_bool String::operator!=(const String& rOther) const
00148   {
00149     return m_pStringPrivate->m_String != rOther.m_pStringPrivate->m_String;
00150   }
00151 
00152   kt_bool String::operator<( const String& rOther ) const
00153   {
00154     return m_pStringPrivate->m_String < rOther.m_pStringPrivate->m_String;
00155   }
00156 
00157   kt_bool String::operator>( const String& rOther ) const
00158   {
00159     return m_pStringPrivate->m_String > rOther.m_pStringPrivate->m_String;
00160   }
00161 
00162   String String::operator+(const String& rOther)
00163   {
00164     return (m_pStringPrivate->m_String + rOther.m_pStringPrivate->m_String).c_str();
00165   }
00166 
00167   karto::String String::operator+(const char* pChar)
00168   {
00169     return (m_pStringPrivate->m_String + std::string(pChar)).c_str();
00170   }
00171 
00172   int String::operator[]( kt_int32u index ) const
00173   {
00174     return m_pStringPrivate->m_String[index];
00175   }
00176 
00177 }


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Thu Aug 27 2015 14:07:25