From: Christian P. <cp...@us...> - 2004-12-23 04:32:27
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14702/include/pclasses/Unicode Added Files: Char.h Makefile.am String.h TextStream.h Log Message: Moved IODevice, IOError into P::IO namespace. Moved Char, String, TextStream into P::Unicode namespace. --- NEW FILE: Char.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * 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_Char_h #define P_Unicode_Char_h #include <pclasses/BasicTypes.h> #include <cwchar> namespace P { namespace Unicode { //! UNICODE 4.0 Compliant character class class Char { public: //! General category enum Category { Mark_NonSpacing, // Mn Mark_SpacingCombining, // Mc Mark_Enclosing, // Me Number_DecimalDigit, // Nd Number_Letter, // Nl Number_Other, // No Separator_Space, // Zs Separator_Line, // Zl Separator_Paragraph, // Zp Other_Control, // Cc Other_Format, // Cf Other_Surrogate, // Cs Other_PrivateUse, // Co Other_NotAssigned, // Cn Letter_Uppercase, // Lu Letter_Lowercase, // Ll Letter_Titlecase, // Lt Letter_Modifier, // Lm Letter_Other, // Lo Punctuation_Connector, // Pc Punctuation_Dash, // Pd Punctuation_Open, // Ps Punctuation_Close, // Pe Punctuation_InitialQuote, // Pi Punctuation_FinalQuote, // Pf Punctuation_Other, // Po Symbol_Math, // Sm Symbol_Currency, // Sc Symbol_Modifier, // Sk Symbol_Other // So }; //! Bidirectional Class enum BidiClass { LeftToRight, // L LeftToRightEmbedding, // LRE LeftToRightOverride, // LRO RightToLeft, // R RightToLeftArabic, // AL RightToLeftEmbedding, // RLE RightToLeftOverride, // RLO PopDirectionalFormat, // PDF EuropeanNumber, // EN EuropeanNumberSeparator, // ES EuropeanNumberTerminator, // ET ArabicNumber, // AN CommonNumberSeparator, // CS NonSpacingMark, // NSM BoundaryNeutral, // BN ParagraphSeparator, // B SegmentSeparator, // S Whitespace, // WS OtherNeutrals // ON }; //! Character Decomposition Tag enum Decomposition { NoDecomposition, Font, // <font> NoBreak, // <noBreak> Initial, // <initial> Medial, // <medial> Final, // <final> Isolated, // <isolated> Encircled, // <circle> Superscript, // <super> Subscript, // <sub> Vertical, // <vertical> Wide, // <wide> Narrow, // <narrow> Small, // <small> Square, // <square> Fraction, // <fraction> Compat // <compat> }; //! Canonical Combining Class enum CombiningClass { Combining_Spacing = 0, Combining_Overlays = 1, Combining_Nuktas = 7, Combining_VoicingMarks = 8, Combining_Viramas = 9, Combining_FixedStart = 10, Combining_FixedEnd = 199, Combining_BelowLeftAttached = 200, Combining_BelowAttached = 202, Combining_BelowRightAttached = 204, Combining_LeftAttached = 208, Combining_RightAttached = 210, Combining_AboveLeftAttached = 212, Combining_AboveAttached = 214, Combining_AboveRightAttached = 216, Combining_BelowLeft = 218, Combining_Below = 220, Combining_BelowRight = 222, Combining_Left = 224, Combining_Right = 226, Combining_AboveLeft = 228, Combining_Above = 230, Combining_AboveRight = 232, Combining_DoubleBelow = 233, Combining_DoubleAbove = 234, Combining_IotaSubscript = 240 }; Char(uint32_t ch = 0); Char(char ch); Char(wchar_t ch); Char(const Char& ch); char latin1() const; wchar_t ucs2() const; bool isLetter() const; bool isSymbol() const; bool isPunct() const; bool isMark() const; bool isNumber() const; int toNumber() const; bool isLower() const; Char toLower() const; bool isUpper() const; Char toUpper() const; bool isMirrored() const; Category category() const; BidiClass bidiClass() const; Decomposition decompTag() const; CombiningClass combiningClass() const; Char& operator=(uint32_t ch); Char& operator=(char ch); Char& operator=(wchar_t ch); Char& operator=(const Char& ch); bool operator==(const Char& ch) const; bool operator!=(const Char& ch) const; bool operator<(const Char& ch) const; bool operator>(const Char& ch) const; bool operator<=(const Char& ch) const; bool operator>=(const Char& ch) const; static const Char& eof(); static const Char& nl(); static const Char& cr(); private: uint32_t _char; }; } // !namespace Unicode } // !namespace P #endif --- NEW FILE: Makefile.am --- INCLUDES = METASOURCES = AUTO pkginclude_HEADERS = Char.h String.h TextStream.h --- NEW FILE: String.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * 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_String_h #define P_Unicode_String_h #include <pclasses/BasicTypes.h> #include <pclasses/Alloc.h> #include <pclasses/SharedPtr.h> #include <pclasses/ScopedArrayPtr.h> #include <pclasses/Unicode/Char.h> namespace P { namespace Unicode { class 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() 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 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; }; Iterator begin(); Iterator end(); 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); void append(const Char& ch); void append(const String& str); void prepend(const Char& ch); void prepend(const String& str); String& operator=(const String& str); String& operator=(const char* str); String& operator=(const wchar_t* str); Char& operator[](ptrdiff_t pos) throw(OutOfMemory, OutOfBounds); bool operator==(const String& str) const throw(); bool operator!=(const String& str) const throw(); bool operator<(const String& str) const throw(); bool operator>(const String& str) const throw(); 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); static String fromUcs2(const wchar_t* str, size_t count = npos) throw(OutOfMemory); private: //! Private string-data structure struct Data { Char* str; size_t size; }; String(const String& str, size_t offset, size_t length) throw(OutOfMemory); //! Make string unique (not shared) void makeUnique() const throw(OutOfMemory); Char* data() const throw(); void resize(size_t sz, size_t holeOffset, size_t holeLen) throw(OutOfMemory); mutable size_t _offset; mutable size_t _length; mutable SharedPtr<Data> _data; }; } // !namespace Unicode } // !namespace P #endif --- NEW FILE: TextStream.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * 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_TextStream_h #define P_Unicode_TextStream_h #include <pclasses/IntTypes.h> #include <pclasses/CircularQueue.h> #include <pclasses/Unicode/String.h> namespace P { namespace Unicode { class TextStreamBuffer { public: TextStreamBuffer(); ~TextStreamBuffer(); }; class TextStream { public: //! Number format enum Format { Hex, /*!< Print numbers in hexadecimal format */ Dec, /*!< Print numbers in decimal format */ Oct /*!< Print numbers in octal fomat */ }; TextStream(); ~TextStream(); //! Set number-format void setFormat(Format fmt) throw(); //! Set width of numbers void setWidth(unsigned int width) throw(); //! Set floating-point precision void setPrecision(unsigned int prec) throw(); //! Set fill-character void setFill(Char ch) throw(); TextStream& operator<<(const Char& ch); TextStream& operator<<(const String& str); TextStream& operator<<(Int8 val); TextStream& operator<<(UInt8 val); TextStream& operator<<(Int16 val); TextStream& operator<<(UInt16 val); TextStream& operator<<(Int32 val); TextStream& operator<<(UInt32 val); #ifdef PCLASSES_HAVE_64BIT_INT TextStream& operator<<(Int64 val); TextStream& operator<<(UInt64 val); #endif TextStream& operator<<(float val); TextStream& operator<<(double val); #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& operator<<(long double val); #endif TextStream& operator<<(TextStream& (*pfn)(TextStream& strm)); //! Write character into stream-buffer void write(const Char& ch); //! Write string into stream-buffer void write(const String& str); //! Flush streams output-buffer void flush(); private: Format _fmt; unsigned int _width, _prec; Char _fillCh; }; TextStream& endl(TextStream& strm); TextStream& dec(TextStream& strm); TextStream& hex(TextStream& strm); TextStream& oct(TextStream& strm); } // !namespace Unicode } // !namespace P #endif |