From: Christian P. <cp...@us...> - 2005-05-24 02:33:09
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26681/include/pclasses/Unicode Modified Files: Char.h Makefile.am String.h Added Files: Converter.h UnicodeError.h Log Message: - Added Unicode::Converter, Unicode::UnicodeError - More work on Unicode support Index: Char.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Char.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Char.h 20 May 2005 14:11:32 -0000 1.6 +++ Char.h 24 May 2005 02:32:59 -0000 1.7 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004 by Christian Prochnow * + * Copyright (C) 2004,2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -23,7 +23,7 @@ #include <pclasses/Export.h> #include <pclasses/BasicTypes.h> -#include <pclasses/Exception.h> +#include <pclasses/Unicode/UnicodeError.h> namespace P { @@ -32,16 +32,10 @@ typedef uint16_t uchar16_t; typedef int32_t uchar32_t; -class InvalidCharError: public RuntimeError { - public: - InvalidCharError(const char* what, const SourceInfo& si) throw(); - ~InvalidCharError() throw(); -}; - //! UNICODE 4.0 compliant character class class PUNICODE_EXPORT Char { public: - Char(uchar32_t ch = 0) throw(InvalidCharError); + Char(uchar32_t ch = 0) throw(UnicodeError); Char(const Char& ch) throw(); bool isDefined() const throw(); @@ -73,7 +67,7 @@ operator const uchar32_t& () const throw(); - Char& operator=(uchar32_t ch) throw(InvalidCharError); + Char& operator=(uchar32_t ch) throw(UnicodeError); Char& operator=(const Char& ch) throw(); bool operator==(const Char& ch) const throw(); --- NEW FILE: UnicodeError.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Unicode_UnicodeError_h #define P_Unicode_UnicodeError_h #include <pclasses/Export.h> #include <pclasses/Exception.h> namespace P { namespace Unicode { class PUNICODE_EXPORT UnicodeError: public RuntimeError { public: UnicodeError(int errorNo, const char* what, const SourceInfo& si) throw(); ~UnicodeError() throw(); int errorNo() const throw(); private: int _errorNo; }; } // !namespace Unicode } // !namespace P #endif // !P_Unicode_UnicodeError_h Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Makefile.am 20 May 2005 14:10:45 -0000 1.4 +++ Makefile.am 24 May 2005 02:32:59 -0000 1.5 @@ -2,4 +2,5 @@ INCLUDES = METASOURCES = AUTO -pclasses_unicode_include_HEADERS = Char.h String.h TextStream.h +pclasses_unicode_include_HEADERS = Char.h String.h Converter.h UnicodeError.h \ + TextStream.h Index: String.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/String.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- String.h 20 May 2005 14:11:32 -0000 1.6 +++ String.h 24 May 2005 02:32:59 -0000 1.7 @@ -25,14 +25,18 @@ #include <pclasses/BasicTypes.h> #include <pclasses/Alloc.h> #include <pclasses/SharedPtr.h> +#include <pclasses/Unicode/UnicodeError.h> #include <pclasses/Unicode/Char.h> +#include <exception> #include <string> namespace P { namespace Unicode { +class Converter; + //! UNICODE 4.0 compliant string class class PUNICODE_EXPORT String { public: @@ -48,21 +52,35 @@ typedef Iterator iterator; typedef ConstIterator const_iterator; - String(); - String(size_t sz); + //! Constructs an empty string that is null + String() throw(); - String(const String& str); + //! Construct an empty string with given size + String(size_t sz) throw(OutOfMemory); + + //! Copy-construct a String + String(const String& str) throw(); String(const String& str, size_t offset, size_t count = npos); - String(const Char* str, size_t count = npos); + //! Construct a String from a stl-string encoded with given codepage + String(const std::string& str, const char* codepage = 0) + throw(OutOfMemory, UnicodeError); - String(const std::string& str); - String(const char* str, size_t count = npos); + //! Construct a String from a c-string encoded with given codepage + String(const char* str, size_t count = npos, const char* codepage = 0) + throw(OutOfMemory, UnicodeError); ~String() throw(); void swap(String& b); + //! Test if the String is NULL + bool null() const throw(); + + //! Set the String to NULL + void setNull() throw(); + + //! Test if the String is empty bool empty() const throw(); size_t size() const throw(); @@ -76,7 +94,12 @@ String left(size_t length) const; String right(size_t length) const; + String lowerCase(const char* locale = 0) const throw(UnicodeError); + String upperCase(const char* locale = 0) const throw(UnicodeError); + String foldCase() const throw(UnicodeError); + int compare(const String& str) const throw(); + int caseCompare(const String& str) const throw(UnicodeError); String& append(const String& str); String& append(const Char& ch); @@ -118,28 +141,34 @@ bool operator<=(const String& str) const throw(); bool operator>=(const String& str) const throw(); - //! Returns the string in local encoding - std::string local() const; + //! Returns the string in ASCII encoding + std::string ascii() const throw(OutOfMemory); - //! Returns the string in utf8 encoding - std::string utf8() const; + static String fromAscii(const char* str, size_t count = npos) + throw(OutOfMemory); - std::string toCharset(const char* charset) const; + //! Returns the string in UTF8 encoding + std::string utf8() const throw(OutOfMemory, UnicodeError); - static String fromLocal(const char* str, size_t count = npos); + static String fromUtf8(const char* str, size_t count = npos) + throw(OutOfMemory, UnicodeError); - static String fromUtf8(const char* str, size_t count = npos); + std::string toCodepage(const char* codepage = 0) const + throw(OutOfMemory, UnicodeError); - static String fromUcs2(const char* str, size_t count); + static String fromCodepage(const char* str, size_t count = npos, + const char* codepage = 0) throw(OutOfMemory, UnicodeError); - static String fromCharset(const char* charset, const char* str, - size_t count); + void acquire(uchar16_t* str, size_t size, size_t length) + throw(OutOfMemory); + + const uchar16_t* data() const throw(); private: struct Data; - static Data* alloc(size_t size); - void deepCopy(); + static Data* alloc(size_t size) throw(OutOfMemory); + void deepCopy() throw(OutOfMemory); SharedPtr<Data> _data; }; --- NEW FILE: Converter.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Unicode_Converter_h #define P_Unicode_Converter_h #include <pclasses/Export.h> #include <pclasses/Unicode/String.h> #include <pclasses/Unicode/UnicodeError.h> #include <string> namespace P { namespace Unicode { class PUNICODE_EXPORT Converter { public: Converter(const char* name) throw(UnicodeError); ~Converter() throw(); String toUnicode(const std::string& str) throw(UnicodeError); String toUnicode(const char* str, size_t count = String::npos) throw(UnicodeError); std::string fromUnicode(const String& str) throw(UnicodeError); private: void* _private; }; } // !namespace Unicode } // !namespace P #endif |