string_data16.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Harry Storbacka
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "../api_core.h"
00036 #include <string>
00037 
00038 class CL_StringRef16;
00039 
00043 class CL_API_CORE CL_StringData16
00044 {
00045 public:
00046         typedef unsigned int size_type;
00047         static const size_type npos; // = 0xffffffff;
00048         typedef wchar_t char_type;
00049         typedef wchar_t *iterator;
00050         typedef const wchar_t *const_iterator;
00051 
00052         CL_StringData16();
00053 
00058         CL_StringData16(const wchar_t *ptr, size_type length);
00059 
00063         iterator begin() { return (iterator) data_ptr; }
00064 
00068         iterator end() { return begin() + data_length; }
00069 
00073         const_iterator begin() const { return (const_iterator) data_ptr; }
00074 
00078         const_iterator end() const { return begin() + data_length; }
00079 
00080 //      reverse_iterator rbegin();
00081 //      reverse_iterator rend();
00082 //      const_reverse_iterator rbegin() const;
00083 //      const_reverse_iterator rend() const;
00084 
00085         const wchar_t &operator[](size_type n) const { return *(data_ptr + n); }
00086         wchar_t &operator[](size_type n) { return *(data_ptr + n); }
00087 
00088         const wchar_t *data() const { return data_ptr; }
00089 
00093         wchar_t *data() { return data_ptr; }
00094 
00098         operator std::wstring() const;
00099 
00103         operator CL_StringRef16() const;
00104 
00108         size_type size() const { return data_length; }
00109 
00113         size_type length() const { return data_length; }
00114 
00118         bool empty() const { return data_length == 0; }
00119 
00126         size_type find(const CL_StringData16 &s, size_type pos = 0) const;
00127 
00135         size_type find(const wchar_t *s, size_type pos, size_type n) const;
00136 
00143         size_type find(const wchar_t *s, size_type pos = 0) const;
00144 
00151         size_type find(wchar_t c, size_type pos = 0) const;
00152 
00159         size_type rfind(const CL_StringData16 &s, size_type pos = npos) const;
00160 
00168         size_type rfind(const wchar_t *s, size_type pos, size_type n) const;
00169 
00176         size_type rfind(const wchar_t *s, size_type pos = npos) const;
00177 
00184         size_type rfind(wchar_t c, size_type pos = npos) const;
00185 
00192         size_type find_first_of(const CL_StringData16 &s, size_type pos = 0) const;
00193 
00201         size_type find_first_of(const wchar_t *s, size_type pos, size_type n) const;
00202 
00209         size_type find_first_of(const wchar_t *s, size_type pos = 0) const;
00210 
00217         size_type find_first_of(wchar_t c, size_type pos = 0) const;
00218 
00225         size_type find_first_not_of(const CL_StringData16 &s, size_type pos = 0) const;
00226 
00234         size_type find_first_not_of(const wchar_t *s, size_type pos, size_type n) const;
00235 
00242         size_type find_first_not_of(const wchar_t *s, size_type pos = 0) const;
00243 
00250         size_type find_first_not_of(wchar_t c, size_type pos = 0) const;
00251 
00258         size_type find_last_of(const CL_StringData16 &s, size_type pos = npos) const;
00259 
00267         size_type find_last_of(const wchar_t *s, size_type pos, size_type n) const;
00268 
00275         size_type find_last_of(const wchar_t *s, size_type pos = npos) const;
00276 
00283         size_type find_last_of(wchar_t c, size_type pos = npos) const;
00284 
00291         size_type find_last_not_of(const CL_StringData16 &s, size_type pos = npos) const;
00292 
00300         size_type find_last_not_of(const wchar_t *s, size_type pos, size_type n) const;
00301 
00308         size_type find_last_not_of(const wchar_t *s, size_type pos = npos) const;
00309 
00316         size_type find_last_not_of(wchar_t c, size_type pos = npos) const;
00317 
00324         CL_StringRef16 substr(size_type pos = 0, size_type n = npos) const;
00325 
00331         int compare(const CL_StringData16 &s) const;
00332 
00340         int compare(size_type pos, size_type n, const CL_StringData16 &s) const;
00341 
00351         int compare(size_type pos, size_type n, const CL_StringData16 &s, size_type pos1, size_type n1) const;
00352 
00358         int compare(const wchar_t *s) const;
00359 
00368         int compare(size_type pos, size_type n, const wchar_t *s, size_type len = npos) const;
00369 
00370 protected:
00371         mutable wchar_t *data_ptr;
00372         mutable size_type data_length;
00373 };
00374 
00375 CL_API_CORE bool operator==(const CL_StringData16 &s1, const CL_StringData16 &s2);
00376 CL_API_CORE bool operator==(const wchar_t *s1, const CL_StringData16 &s2);
00377 CL_API_CORE bool operator==(const CL_StringData16 &s1, const wchar_t *s2);
00378 CL_API_CORE bool operator!=(const CL_StringData16 &s1, const CL_StringData16 &s2);
00379 CL_API_CORE bool operator!=(const wchar_t *s1, const CL_StringData16 &s2);
00380 CL_API_CORE bool operator!=(const CL_StringData16 &s1, const wchar_t *s2);
00381 CL_API_CORE bool operator<(const CL_StringData16 &s1, const CL_StringData16 &s2);
00382 CL_API_CORE bool operator<(const wchar_t *s1, const CL_StringData16 &s2);
00383 CL_API_CORE bool operator<(const CL_StringData16 &s1, const wchar_t *s2);
00384 CL_API_CORE bool operator>(const CL_StringData16 &s1, const CL_StringData16 &s2);
00385 CL_API_CORE bool operator>(const wchar_t *s1, const CL_StringData16 &s2);
00386 CL_API_CORE bool operator>(const CL_StringData16 &s1, const wchar_t *s2);
00387