tools

various tools
git clone git://deadbeef.fr/tools.git
Log | Files | Refs | README | LICENSE

string.hpp (2474B)


      1 // Copyright (c) 2020 Morel BĂ©renger
      2 // 
      3 // This software is provided 'as-is', without any express or implied
      4 // warranty. In no event will the authors be held liable for any damages
      5 // arising from the use of this software.
      6 // 
      7 // Permission is granted to anyone to use this software for any purpose,
      8 // including commercial applications, and to alter it and redistribute it
      9 // freely, subject to the following restrictions:
     10 // 
     11 // 1. The origin of this software must not be misrepresented; you must not
     12 //    claim that you wrote the original software. If you use this software
     13 //    in a product, an acknowledgment in the product documentation would be
     14 //    appreciated but is not required.
     15 // 2. Altered source versions must be plainly marked as such, and must not be
     16 //    misrepresented as being the original software.
     17 // 3. This notice may not be removed or altered from any source distribution.
     18 
     19 // this file defines a set of operators and helpers to use
     20 // vector's data as a string, which means allowing the use
     21 // of SL's algorithms in a less surprising way than
     22 // std::string.
     23 // It's really only contains a typedef, plus functions for
     24 // concatenation, string creation and conversion.
     25 // Other features I think really necessaryare *already* in
     26 // vector or algorithm, anyway.
     27 // Be warned that this container still sucks, and still do
     28 // not handle strings which contains characters of various
     29 // size like UTF-8 (for that, a proper container without
     30 // random access would be needed).
     31 
     32 #ifndef STRING_HPP
     33 #define STRING_HPP
     34 
     35 typedef vector<char> string;
     36 
     37 string make_string( char const* str );
     38 string make_string( wchar_t const* str );
     39 
     40 string to_string( int32_t i );
     41 string to_string( uint32_t i );
     42 
     43 string& operator+=( string& lhs, char const* rhs );
     44 string& operator+=( string& lhs, char rhs );
     45 string& operator+=( string& lhs, string const& rhs );
     46 string& operator+=( string& lhs, string && rhs );
     47 
     48 //TODO: make a template
     49 template <typename T>
     50 string operator+( string const& lhs, T rhs )
     51 {
     52 	string ret( lhs );
     53 	ret += rhs;
     54 	return ret;
     55 }
     56 
     57 string operator+( char const* lhs, string const& rhs );
     58 
     59 bool operator==( string const& str1, string const& str2 );
     60 bool operator==( string const& str1, char const* str2 );
     61 bool operator==( char const* str1, string const& str2 );
     62 
     63 bool operator!=( string const& str1, string const& str2 );
     64 bool operator!=( string const& str1, char const* str2 );
     65 bool operator!=( char const* str1, string const& str2 );
     66 
     67 #endif