From: Christian P. <cp...@us...> - 2004-12-23 04:32:30
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14702/src/Unicode Modified Files: Makefile.am unicodedata.awk Added Files: Char.cpp String.cpp TextStream.cpp Log Message: Moved IODevice, IOError into P::IO namespace. Moved Char, String, TextStream into P::Unicode namespace. Index: unicodedata.awk =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/unicodedata.awk,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- unicodedata.awk 22 Dec 2004 17:54:37 -0000 1.1.1.1 +++ unicodedata.awk 23 Dec 2004 04:32:18 -0000 1.2 @@ -2,12 +2,12 @@ FS=";" print "/* Automatically generated by P::Classes unicodedata.awk */" > "unicodedata_extra.h" - print "namespace P { namespace unicode {" >> "unicodedata_extra.h" + print "namespace P { namespace Unicode {" >> "unicodedata_extra.h" print "struct letterExtraData { uint32_t upper, lower, title; };" >> "unicodedata_extra.h" print "struct decimalDigitExtraData { int num; };" >> "unicodedata_extra.h" print "/* Automatically generated by P::Classes unicodedata.awk */" - print "namespace P { namespace unicode {" + print "namespace P { namespace Unicode {" print "struct codePointData {" print " uint32_t codePoint;" print " char category;" --- NEW FILE: String.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/Unicode/String.h" #include "pclasses/ScopedPtr.h" #include "pclasses/ScopedArrayPtr.h" #include "pclasses/Algorithm.h" #include <cstring> namespace P { namespace Unicode { String::String(size_t reserve) throw(OutOfMemory) : _offset(0), _length(0) { ScopedPtr<Data> d(new Data); d->str = (Char*)new char[sizeof(Char) * reserve]; d->size = reserve; _data = d.release(); } String::String(const String& str) throw(OutOfMemory) : _offset(str._offset), _length(str._length), _data(str._data) { } String::String(const char* str, size_t count) throw(OutOfMemory) { *this = fromLatin1(str, count); } String::String(const wchar_t* str, size_t count) throw(OutOfMemory) { *this = fromUcs2(str, count); } String::String(const String& str, size_t offset, size_t length) throw(OutOfMemory) : _offset(str._offset + offset), _length(length), _data(str._data) { } String::~String() throw() { } void String::swap(String& b) { SharedPtr<Data> tmp = _data; _data = b._data; b._data = tmp; } size_t String::size() const throw() { return _data->size; } void String::resize(size_t sz) throw(OutOfMemory) { resize(sz, 0, 0); } void String::resize(size_t sz, size_t holeOffset, size_t holeLen) throw(OutOfMemory) { SharedPtr<Data> newData(new Data); char* newStr = 0; size_t newLength = 0; size_t length = sz >= _length ? _length : sz; if(holeLen == 0 || holeOffset >= length) { size_t reserve = sz - length; newStr = new char[sizeof(Char) * sz]; copy_construct((Char*)newStr, data(), length); construct((Char*)newStr + length, reserve); newLength = length; } else { size_t len1; } newData->str = (Char*)newStr; newData->size = sz; _data = newData; _offset = 0; _length = newLength; } size_t String::length() const throw() { return _length; } String String::part(size_t offset, size_t length) const throw(OutOfMemory, OutOfBounds) { if(offset + length > _length) throw OutOfBounds("Offset and/or length is out of bounds", P_SOURCEINFO); return String(*this, offset, length); } String String::left(size_t length) const throw(OutOfMemory, OutOfBounds) { return part(0, length); } String String::right(size_t length) const throw(OutOfMemory, OutOfBounds) { return part(_length - length, length); } void String::makeUnique() const throw(OutOfMemory) { if(_data.useCount() > 1) { // allocate new data structure SharedPtr<Data> newData(new Data); // allocate and copy-construct string data char* newStr = new char[sizeof(Char) * (_length + 8)]; copy_construct((Char*)newStr, data(), _length); // set the copied string data newData->str = (Char*)newStr; newData->size = _length + 8; _data = newData; _offset = 0; _length = _length; } } const Char& String::at(size_t pos) const throw(OutOfBounds) { if(_offset + pos >= _length) throw OutOfBounds("Index is out of bounds", P_SOURCEINFO); return *(data() + pos); } Char& String::at(size_t pos) throw(OutOfMemory, OutOfBounds) { return operator[](pos); } Char& String::operator[](ptrdiff_t pos) throw(OutOfMemory, OutOfBounds) { if(pos >= _length) throw OutOfBounds("Index is out of bounds", P_SOURCEINFO); makeUnique(); // construct Char's that were not yet constructed, but allocated /*if(pos >= _length) size_t ccount = pos - _length; construct(_data->str + _length, ccount); _length += pos + 1; }*/ return *(_data->str + _offset + pos); } String& String::operator=(const String& str) { if(this != &str) { if(_data != str._data) _data = str._data; _offset = str._offset; _length = str._length; } return *this; } String& String::operator=(const char* str) { *this = fromLatin1(str); return *this; } String& String::operator=(const wchar_t* str) { *this = fromUcs2(str); return *this; } bool String::operator==(const String& str) const throw() { if(&str == this || (str.data() == data() && str._length == _length)) return true; if(str._length == _length) { Char* lhsBegin = data(); Char* lhsEnd = data() + _length; Char* rhsBegin = str.data(); while(lhsBegin != lhsEnd) { if(*lhsBegin != *rhsBegin) return false; ++lhsBegin, ++rhsBegin; } return true; } return false; } bool String::operator!=(const String& str) const throw() { return !operator==(str); } bool String::operator<(const String& str) const throw() { //@todo String::operator< } bool String::operator>(const String& str) const throw() { //@todo String::operator> } bool String::operator<=(const String& str) const throw() { return (operator<(str) || operator==(str)); } bool String::operator>=(const String& str) const throw() { return (operator>(str) || operator==(str)); } Char* String::data() const throw() { return _data->str + _offset; } String String::fromLatin1(const char* str, size_t count) throw(OutOfMemory) { if(count == npos) count = strlen(str); Char ch; String str2(count + 8); const char* end = str + count; Char* mystr = str2.data(); while(str != end) { ch = *(str++); copy_construct(mystr++, &ch, 1); } str2._length = count; return str2; } String String::fromUcs2(const wchar_t* str, size_t count) throw(OutOfMemory) { if(count == npos) count = wcslen(str); Char ch; String str2(count + 8); const wchar_t* end = str + count; Char* mystr = str2.data(); while(str != end) { ch = *(str++); copy_construct(mystr++, &ch, 1); } str2._length = count; return str2; } String::Iterator String::begin() { makeUnique(); return Iterator(data()); } String::Iterator String::end() { makeUnique(); return Iterator(data() + _length); } void String::insert(const Iterator& pos, const Char& ch) { /* if(_data.useCount() > 1 || _length + 1 > _data->size) resize(_data->size + 8);*/ } void String::insert(const Iterator& pos, const String& str) { } void String::insert(size_t pos, const Char& ch) { insert(Iterator(data() + pos), ch); } void String::insert(size_t pos, const String& str) { insert(Iterator(data() + pos), str); } void String::append(const Char& ch) { insert(end(), ch); } void String::append(const String& str) { insert(end(), str); } void String::prepend(const Char& ch) { insert(begin(), ch); } void String::prepend(const String& str) { insert(begin(), str); } void String::erase(const Iterator& pos) { } void String::erase(size_t pos) { erase(Iterator(data() + pos)); } String::Iterator::Iterator(const String::Iterator& iter) : _current(iter._current) { } String::Iterator::Iterator(Char* current) : _current(current) { } String::Iterator::~Iterator() { } Char& String::Iterator::operator*() const { return *_current; } String::Iterator& String::Iterator::operator++() { ++_current; return *this; } String::Iterator String::Iterator::operator++(int) { Iterator tmp = *this; ++_current; return tmp; } String::Iterator& String::Iterator::operator--() { --_current; return *this; } String::Iterator String::Iterator::operator--(int) { Iterator tmp = *this; --_current; return tmp; } String::Iterator& String::Iterator::operator=(const String::Iterator& iter) { _current = iter._current; return *this; } bool String::Iterator::operator==(const String::Iterator& iter) const { return (_current == iter._current); } bool String::Iterator::operator!=(const String::Iterator& iter) const { return (_current != iter._current); } } // !namespace Unicode } // !namespace P Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.am 22 Dec 2004 17:54:37 -0000 1.1.1.1 +++ Makefile.am 23 Dec 2004 04:32:18 -0000 1.2 @@ -8,5 +8,13 @@ unicodedata.h unicodedata_extra.h: wget --passive-ftp http://www.unicode.org/Public/UNIDATA/UnicodeData.txt - awk -f $(top_srcdir)/src/unicode/unicodedata.awk UnicodeData.txt >unicodedata.h + awk -f $(top_srcdir)/src/Unicode/unicodedata.awk UnicodeData.txt >unicodedata.h rm -f UnicodeData.txt + +INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_builddir)/src/Unicode $(all_includes) +METASOURCES = AUTO + +lib_LTLIBRARIES = libpclasses_unicode.la +libpclasses_unicode_la_SOURCES = Char.cpp String.cpp TextStream.cpp +libpclasses_unicode_la_LIBADD = $(top_builddir)/src/libpclasses.la +libpclasses_unicode_la_DEPENDENCIES = $(top_builddir)/src/libpclasses.la $(noinst_HEADERS) --- NEW FILE: TextStream.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/Unicode/TextStream.h" namespace P { namespace Unicode { TextStream::TextStream() : _fmt(Dec), _width(0), _prec(0), _fillCh(' ') { } TextStream::~TextStream() { } void TextStream::setFormat(Format fmt) throw() { _fmt = fmt; } void TextStream::setWidth(unsigned int width) throw() { _width = width; } void TextStream::setPrecision(unsigned int prec) throw() { _prec = prec; } void TextStream::setFill(Char ch) throw() { _fillCh = ch; } TextStream& TextStream::operator<<(const Char& ch) { write(ch); return *this; } TextStream& TextStream::operator<<(const String& str) { write(str); return *this; } TextStream& TextStream::operator<<(Int8 val) { } TextStream& TextStream::operator<<(UInt8 val) { } TextStream& TextStream::operator<<(Int16 val) { } TextStream& TextStream::operator<<(UInt16 val) { } TextStream& TextStream::operator<<(Int32 val) { } TextStream& TextStream::operator<<(UInt32 val) { } #ifdef PCLASSES_HAVE_64BIT_INT TextStream& TextStream::operator<<(Int64 val) { } TextStream& TextStream::operator<<(UInt64 val) { } #endif TextStream& TextStream::operator<<(float val) { } TextStream& TextStream::operator<<(double val) { } #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& TextStream::operator<<(long double val) { } #endif TextStream& TextStream::operator<<(TextStream& (*__pfn)(TextStream& strm)) { (*__pfn)(*this); return *this; } void TextStream::write(const Char& ch) { } void TextStream::write(const String& str) { } void TextStream::flush() { } TextStream& endl(TextStream& strm) { #ifdef PCLASSES_WITH_CR_LINEFEED strm.write(Char::cr()); #endif strm.write(Char::nl()); return strm; } TextStream& dec(TextStream& strm) { strm.setFormat(TextStream::Dec); return strm; } TextStream& hex(TextStream& strm) { strm.setFormat(TextStream::Hex); return strm; } TextStream& oct(TextStream& strm) { strm.setFormat(TextStream::Oct); return strm; } } // !namespace Unicode } // !namespace P --- NEW FILE: Char.cpp --- /* * P::Classes - Portable C++ Application Framework * Copyright (C) 2000-2004 Christian Prochnow <cp...@se...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "pclasses/Unicode/Char.h" #include "unicodedata_extra.h" // UNICODE extra character data #include "unicodedata.h" // UNICODE character data namespace P { namespace Unicode { const codePointData* lookupCodePoint(uint32_t codePoint) { unsigned int i = 0; while(codePoints[i].codePoint != (uint32_t)-1) { if(codePoints[i].codePoint == codePoint) return &codePoints[i]; ++i; } return 0; } Char::Char(uint32_t ch) : _char(ch) { } Char::Char(char ch) : _char(ch) { } Char::Char(wchar_t ch) : _char(ch) { } Char::Char(const Char& ch) : _char(ch._char) { } char Char::latin1() const { if(_char < 0x7f) return _char; return '?'; } wchar_t Char::ucs2() const { //@todo return '?'; } bool Char::isNumber() const { bool ret = false; switch(category()) { case Number_DecimalDigit: case Number_Letter: case Number_Other: ret = true; break; default: break; } return ret; } bool Char::isSymbol() const { bool ret = false; switch(category()) { case Symbol_Math: case Symbol_Currency: case Symbol_Modifier: case Symbol_Other: ret = true; default: break; } return ret; } bool Char::isMark() const { bool ret = false; switch(category()) { case Mark_NonSpacing: case Mark_SpacingCombining: case Mark_Enclosing: ret = true; default: break; } return ret; } bool Char::isPunct() const { bool ret = false; switch(category()) { case Punctuation_Connector: case Punctuation_Dash: case Punctuation_Open: case Punctuation_Close: case Punctuation_InitialQuote: case Punctuation_FinalQuote: case Punctuation_Other: ret = true; default: break; } return ret; } bool Char::isLetter() const { bool ret = false; switch(category()) { case Letter_Uppercase: case Letter_Lowercase: case Letter_Titlecase: case Letter_Modifier: case Letter_Other: ret = true; default: break; } return ret; } int Char::toNumber() const { int ret = 0; const codePointData* data = lookupCodePoint(_char); if(data) { switch(category()) { case Number_DecimalDigit: case Number_Letter: { const decimalDigitExtraData* extraData = (const decimalDigitExtraData*)data->extra; ret = extraData->num; } break; case Number_Other: break; default: break; } } return ret; } bool Char::isLower() const { return category() == Letter_Lowercase; } Char Char::toLower() const { const codePointData* data = lookupCodePoint(_char); if(data && data->extra) { const letterExtraData* extraData = (const letterExtraData*)data->extra; return Char(extraData->lower); } return *this; } bool Char::isUpper() const { return category() == Letter_Uppercase; } Char Char::toUpper() const { const codePointData* data = lookupCodePoint(_char); if(data && data->extra) { const letterExtraData* extraData = (const letterExtraData*)data->extra; return Char(extraData->upper); } return *this; } bool Char::isMirrored() const { const codePointData* data = lookupCodePoint(_char); return data->mirrored == 1 ? true : false; } Char::Category Char::category() const { const codePointData* data = lookupCodePoint(_char); return (Char::Category)data->category; } Char::BidiClass Char::bidiClass() const { const codePointData* data = lookupCodePoint(_char); return (Char::BidiClass)data->bidi; } Char::Decomposition Char::decompTag() const { const codePointData* data = lookupCodePoint(_char); return (Char::Decomposition)data->decomp; } Char::CombiningClass Char::combiningClass() const { const codePointData* data = lookupCodePoint(_char); return (Char::CombiningClass)data->combining; } Char& Char::operator=(uint32_t ch) { _char = ch; return *this; } Char& Char::operator=(char ch) { _char = ch; return *this; } Char& Char::operator=(wchar_t ch) { _char = ch; return *this; } Char& Char::operator=(const Char& ch) { _char = ch._char; return *this; } bool Char::operator==(const Char& ch) const { return _char == ch._char; } bool Char::operator!=(const Char& ch) const { return _char != ch._char; } bool Char::operator<(const Char& ch) const { //@todo Char::operator< } bool Char::operator>(const Char& ch) const { //@todo Char::operator> } bool Char::operator<=(const Char& ch) const { return (operator<(ch) || operator==(ch)); } bool Char::operator>=(const Char& ch) const { return (operator>(ch) || operator==(ch)); } const Char& Char::eof() { static Char _eof((char)0); return _eof; } const Char& Char::nl() { static Char _nl('\n'); return _nl; } const Char& Char::cr() { static Char _cr('\r'); return _cr; } } // !namespace Unicode } // !namespace P |