• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_Win32LocaleString.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (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 General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
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 /* 0 == zero-terminate */);
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     // The returned pointer is valid until the next non-const
00085     // operation. You will _always_ get a legal pointer back,
00086     // even if to an empty (0) string.
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 /* UT_WIN32LOCALESTRING_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1