From: Christian P. <cp...@us...> - 2005-04-26 12:16:15
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26729/include/pclasses/Unicode Modified Files: Char.h String.h uctype.h ustring.h Log Message: - More work on unicode support Index: Char.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Char.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Char.h 24 Jan 2005 01:19:26 -0000 1.2 +++ Char.h 26 Apr 2005 12:16:02 -0000 1.3 @@ -23,13 +23,14 @@ #include <pclasses/Export.h> #include <pclasses/BasicTypes.h> +#include <pclasses/Unicode/uctype.h> #include <cwchar> namespace P { namespace Unicode { -//! UNICODE 4.0 Compliant character class +//! UNICODE 4.0 compliant character class class PUNICODE_EXPORT Char { public: //! General category @@ -146,14 +147,9 @@ Combining_IotaSubscript = 240 }; - Char(uint32_t ch = 0); - Char(char ch); - Char(wchar_t ch); + Char(uchar_t ch = 0); Char(const Char& ch); - char latin1() const; - wchar_t ucs2() const; - bool isLetter() const; bool isSymbol() const; @@ -176,9 +172,7 @@ Decomposition decompTag() const; CombiningClass combiningClass() const; - Char& operator=(uint32_t ch); - Char& operator=(char ch); - Char& operator=(wchar_t ch); + Char& operator=(uchar_t ch); Char& operator=(const Char& ch); bool operator==(const Char& ch) const; @@ -195,7 +189,7 @@ static const Char& cr(); private: - uint32_t _char; + uchar_t _char; }; Index: ustring.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/ustring.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ustring.h 24 Jan 2005 01:20:09 -0000 1.2 +++ ustring.h 26 Apr 2005 12:16:02 -0000 1.3 @@ -20,7 +20,7 @@ #ifndef P_Unicode_ustring_h #define P_Unicode_ustring_h - + #include <pclasses/Export.h> #include <pclasses/Unicode/uctype.h> #include <string> @@ -100,16 +100,14 @@ } -namespace P { +namespace P { namespace Unicode { -typedef std::basic_string<uchar_t, - std::char_traits<uchar_t>, +typedef std::basic_string<uchar_t, + std::char_traits<uchar_t>, std::allocator<uchar_t> > ustring; -PUNICODE_EXPORT ustring str(const char* str); - } // !namespace Unicode } // !namespace P Index: uctype.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/uctype.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- uctype.h 24 Jan 2005 01:19:26 -0000 1.2 +++ uctype.h 26 Apr 2005 12:16:02 -0000 1.3 @@ -42,7 +42,6 @@ PUNICODE_EXPORT int isuspace(uchar_t c); PUNICODE_EXPORT int isuupper(uchar_t c); -PUNICODE_EXPORT uchar_t touchar(char c); PUNICODE_EXPORT uchar_t toulower(uchar_t c); PUNICODE_EXPORT uchar_t touupper(uchar_t c); Index: String.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/String.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- String.h 24 Jan 2005 01:19:26 -0000 1.3 +++ String.h 26 Apr 2005 12:16:02 -0000 1.4 @@ -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 * @@ -24,9 +24,8 @@ #include <pclasses/Export.h> #include <pclasses/BasicTypes.h> #include <pclasses/Alloc.h> -#include <pclasses/SharedPtr.h> -#include <pclasses/ScopedArrayPtr.h> #include <pclasses/Unicode/Char.h> +#include <pclasses/Unicode/ustring.h> #include <string> @@ -34,112 +33,47 @@ namespace Unicode { +//! UNICODE 4.0 compliant string class class PUNICODE_EXPORT String { public: enum { npos = (size_t)-1 }; - - String(size_t reserve = 8) throw(OutOfMemory); - String(const String& str) throw(OutOfMemory); - String(const char* str, size_t count = npos) throw(OutOfMemory); - String(const wchar_t* str, size_t count = npos) throw(OutOfMemory); + + String(); + String(const String& str); + String(const ustring& str); + String(const std::string& str); + String(const char* str, size_t count = npos); + ~String() throw(); void swap(String& b); size_t size() const throw(); - void resize(size_t sz) throw(OutOfMemory); - - size_t length() const throw(); const Char& at(size_t index) const throw(OutOfBounds); - Char& at(size_t index) throw(OutOfMemory, OutOfBounds); - - String part(size_t offset, size_t length) const - throw(OutOfMemory, OutOfBounds); - - String left(size_t length) const throw(OutOfMemory, OutOfBounds); - String right(size_t length) const throw(OutOfMemory, OutOfBounds); - - class PUNICODE_EXPORT Iterator { - public: - Iterator(Char* current); - Iterator(const Iterator& iter); - ~Iterator(); - - Char& operator*() const; - - Iterator& operator++(); - Iterator operator++(int); - - Iterator& operator--(); - Iterator operator--(int); - - Iterator& operator=(const Iterator& iter); - - bool operator==(const Iterator& iter) const; - bool operator!=(const Iterator& iter) const; - - private: - Char* _current; - }; - - class PUNICODE_EXPORT ConstIterator { - public: - ConstIterator(const Char* current); - ConstIterator(const ConstIterator& iter); - ~ConstIterator(); - - const Char& operator*() const; - - ConstIterator& operator++(); - ConstIterator operator++(int); - - ConstIterator& operator--(); - ConstIterator operator--(int); - - ConstIterator& operator=(const ConstIterator& iter); - - bool operator==(const ConstIterator& iter) const; - bool operator!=(const ConstIterator& iter) const; - - private: - const Char* _current; - }; - - Iterator begin(); - ConstIterator begin() const; - - Iterator end(); - ConstIterator end() const; - - void insert(const Iterator& pos, const Char& ch); - void insert(size_t pos, const Char& ch); - - void insert(const Iterator& pos, const String& str); - void insert(size_t pos, const String& str); - - void erase(const Iterator& pos); - void erase(size_t pos); + Char& at(size_t index) throw(OutOfBounds); - void append(const Char& ch); - void append(const String& str); + String substr(size_t offset = 0, size_t length = npos) const + throw(OutOfBounds); - void prepend(const Char& ch); - void prepend(const String& str); + String left(size_t length) const throw(OutOfBounds); + String right(size_t length) const throw(OutOfBounds); - std::string utf8() const; + String& append(const String& str); - String deepCopy() const; + Char& operator[](size_t pos) throw(OutOfBounds); + const Char& operator[](size_t pos) const throw(OutOfBounds); String& operator=(const String& str); + String& operator=(const ustring& str); + String& operator=(const char* str); - String& operator=(const wchar_t* str); String& operator=(const std::string& str); - Char& operator[](ptrdiff_t pos) throw(OutOfMemory, OutOfBounds); + String& operator+=(const String& str); bool operator==(const String& str) const throw(); bool operator!=(const String& str) const throw(); @@ -150,29 +84,30 @@ bool operator<=(const String& str) const throw(); bool operator>=(const String& str) const throw(); - static String fromLatin1(const char* str, size_t count = npos) - throw(OutOfMemory); + //! Returns the string in local encoding + std::string local() const; - static String fromUcs2(const wchar_t* str, size_t count = npos) - throw(OutOfMemory); + //! Returns the string in latin1 encoding + std::string latin1() const; - private: + //! Returns the string in utf8 encoding + std::string utf8() const; - //! Private string-data structure - struct Data { - Char* str; - size_t size; - }; + std::string toCharset(const char* charset) const; - String(const String& str, size_t offset, size_t length) throw(OutOfMemory); + static String fromLocal(const char* str, size_t count = npos); - Char* data() const throw(); + static String fromLatin1(const char* str, size_t count = npos); - void resize(size_t sz, size_t holeOffset, size_t holeLen) throw(OutOfMemory); + static String fromUtf8(const char* str, size_t count = npos); - mutable size_t _offset; - mutable size_t _length; - mutable SharedPtr<Data> _data; + static String fromUcs2(const char* str, size_t count); + + static String fromCharset(const char* charset, const char* str, + size_t count); + + private: + ustring _str; }; } // !namespace Unicode |