Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef UT_WIN32LOCALESTRING_H
00021 #define UT_WIN32LOCALESTRING_H
00022
00023 #include "ut_string_class.h"
00024 #include <windows.h>
00025 #include <wchar.h>
00026
00027
00028
00029 class UT_UCS2Stringbuf
00030 {
00031 public:
00032 typedef UT_UCS2Char char_type;
00033
00034 UT_UCS2Stringbuf();
00035 UT_UCS2Stringbuf(const UT_UCS2Stringbuf& rhs);
00036 UT_UCS2Stringbuf(const char_type* sz, size_t n);
00037 ~UT_UCS2Stringbuf();
00038
00039 void operator=(const UT_UCS2Stringbuf& rhs);
00040
00041 void assign(const char_type* sz, size_t n);
00042 void append(const char_type* sz, size_t n);
00043 void append(const UT_UCS2Stringbuf& rhs);
00044
00045 void clear();
00046
00047 bool empty() const { return m_psz == m_pEnd; }
00048 size_t size() const { return m_pEnd - m_psz; }
00049 size_t capacity() const { return m_size; }
00050 const char_type* data() const { return m_psz; }
00051 char_type* data() { return m_psz; }
00052
00053 private:
00054 void grow_nocopy(size_t n);
00055 void grow_copy(size_t n);
00056 void grow_common(size_t n, bool bCopy);
00057
00058 static void copy(char_type* pDest, const char_type* pSrc, size_t n);
00059
00060 char_type* m_psz;
00061 char_type* m_pEnd;
00062 size_t m_size;
00063 };
00064
00065
00066 class ABI_EXPORT UT_UCS2String
00067 {
00068 public:
00069 UT_UCS2String();
00070 UT_UCS2String(const UT_UCS2Char * sz, size_t n = 0 );
00071 UT_UCS2String(const UT_UCS2String& rhs);
00072 ~UT_UCS2String();
00073
00074 size_t size() const;
00075 bool empty() const;
00076 void clear() const;
00077 size_t length() { return size(); }
00078
00079 UT_UCS2String substr(size_t iStart, size_t nChars) const;
00080
00081 UT_UCS2String& operator=(const UT_UCS2String& rhs);
00082 UT_UCS2String& operator=(const UT_UCS2Char * rhs);
00083
00084
00085
00086
00087 const UT_UCS2Char* ucs2_str() const;
00088
00089 protected:
00090 class UT_UCS2Stringbuf* pimpl;
00091 };
00092
00093
00094 class ABI_EXPORT UT_Win32LocaleString : public UT_UCS2String
00095 {
00096 public:
00097
00098 UT_Win32LocaleString ();
00099
00100 void fromUCS2 (const UT_UCS2Char * szIn);
00101 void fromUCS4 (const UT_UCS4Char * szIn);
00102 void fromUTF8 (const char* szUTF8);
00103 void fromASCII (const char* szASCII, size_t size = -1);
00104 void fromLocale (const wchar_t* szLocale);
00105
00106 void appendASCII (const char* szASCII);
00107 void appendLocale (const wchar_t* szLocale);
00108 const wchar_t * c_str() const;
00109 UT_UTF8String utf8_str() const;
00110 UT_UCS4String ucs4_str() const;
00111 UT_Win32LocaleString substr(size_t iStart, size_t nChars) const;
00112
00113 wchar_t operator[](size_t iPos) const
00114 {
00115 UT_ASSERT(iPos <= size());
00116 if (iPos == size())
00117 return L'\0';
00118 return (wchar_t) pimpl->data()[iPos];
00119 }
00120
00121 wchar_t& operator[](size_t iPos)
00122 {
00123 UT_ASSERT(iPos <= size());
00124 return (wchar_t &) pimpl->data()[iPos];
00125 }
00126 };
00127
00128 bool operator==(const UT_Win32LocaleString& s1, const wchar_t* s2);
00129
00130 #endif