From: Christian P. <cp...@us...> - 2005-05-24 02:33:09
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26681/src/Unicode Modified Files: Char.cpp Makefile.am String.cpp Added Files: Converter.cpp UnicodeError.cpp Log Message: - Added Unicode::Converter, Unicode::UnicodeError - More work on Unicode support --- NEW FILE: Converter.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/ScopedArrayPtr.h" #include "pclasses/Unicode/Converter.h" #include <unicode/ucnv.h> namespace P { namespace Unicode { Converter::Converter(const char* name) throw(UnicodeError) { UErrorCode errorCode = U_ZERO_ERROR; _private = (void*)ucnv_open(name, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not open unicode converter", P_SOURCEINFO); } Converter::~Converter() throw() { ucnv_close((UConverter*)_private); } String Converter::toUnicode(const std::string& str) throw(UnicodeError) { return toUnicode(str.c_str(), str.size()); } String Converter::toUnicode(const char* str, size_t count) throw(UnicodeError) { if(count == String::npos) count = strlen(str); if(!count) return String(); UErrorCode errorCode = U_ZERO_ERROR; size_t strSize = count * 2; ScopedArrayPtr<uchar16_t> ret(new uchar16_t[strSize]); int32_t strLen = ucnv_toUChars((UConverter*)_private, ret.get(), strSize, str, count, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not convert string to unicode", P_SOURCEINFO); String retStr; retStr.acquire(ret.release(), strSize, strLen); return retStr; } std::string Converter::fromUnicode(const String& str) throw(UnicodeError) { if(str.empty()) return std::string(); UErrorCode errorCode = U_ZERO_ERROR; size_t srcLen = str.size(); size_t strSize = UCNV_GET_MAX_BYTES_FOR_STRING(srcLen, ucnv_getMaxCharSize((UConverter*)_private)) + 1; ScopedArrayPtr<char> ret(new char[strSize]); ucnv_fromUChars((UConverter*)_private, ret.get(), strSize, str.data(), srcLen, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not convert string from unicode", P_SOURCEINFO); std::string retStr; retStr = ret.get(); return retStr; } } // !namespace Unicode } // !namespace P Index: String.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/String.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- String.cpp 20 May 2005 14:14:39 -0000 1.7 +++ String.cpp 24 May 2005 02:32:59 -0000 1.8 @@ -18,13 +18,15 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/ScopedPtr.h" +#include "pclasses/ScopedArrayPtr.h" #include "pclasses/Unicode/String.h" +#include "pclasses/Unicode/Converter.h" #include <cstring> #include <sstream> #include <unicode/ustring.h> -#include <langinfo.h> #include <errno.h> namespace P { @@ -32,21 +34,37 @@ namespace Unicode { struct String::Data { + + Data(size_t sz) + : size(sz), length(0), str(new uchar16_t[sz]) + { + str[0] = 0; + } + + Data(uchar16_t* s, size_t sz, size_t len) + : size(sz), length(len), str(s) + { } + + ~Data() + { + delete[] str; + } + size_t size; // size of str counted in uchar16_t size_t length; // length of str counted in uchar16_t - uchar16_t str[1]; + uchar16_t* str; }; -String::String() +String::String() throw() { } -String::String(size_t sz) +String::String(size_t sz) throw(OutOfMemory) : _data(alloc(sz * 2)) { } -String::String(const String& str) +String::String(const String& str) throw() : _data(str._data) { } @@ -72,46 +90,61 @@ _data->length = charCount; } -String::String(const std::string& str) +String::String(const std::string& str, const char* codepage) + throw(OutOfMemory, UnicodeError) { - *this = fromLocal(str.c_str(), str.size()); + *this = fromCodepage(str.c_str(), str.size(), codepage); } -String::String(const char* str, size_t count) +String::String(const char* str, size_t count, const char* codepage) + throw(OutOfMemory, UnicodeError) { - *this = fromLocal(str, count); + *this = fromCodepage(str, count, codepage); } String::~String() throw() { } -String::Data* String::alloc(size_t size) +String::Data* String::alloc(size_t size) throw(OutOfMemory) { - Data* d = (Data*)new char[sizeof(Data) + sizeof(uchar16_t) * size]; - d->size = size; - d->length = 0; - d->str[0] = 0; + Data* d = new Data(size); return d; } -void String::deepCopy() +void String::deepCopy() throw(OutOfMemory) { if(_data.useCount() > 1) { - Data* newData = (Data*)new char[sizeof(Data) + sizeof(uchar16_t) * _data->size]; - newData->size = _data->size; + Data* newData = new Data(_data->size); newData->length = _data->length; u_strncpy(newData->str, _data->str, _data->length); _data = newData; } } +void String::acquire(uchar16_t* str, size_t size, size_t length) + throw(OutOfMemory) +{ + Data* d = new Data(str, size, length); + _data = d; +} + void String::swap(String& b) { _data.swap(b._data); } +bool String::null() const throw() +{ + return !_data; +} + +void String::setNull() throw() +{ + _data = 0; +} + bool String::empty() const throw() { if(_data) @@ -169,6 +202,75 @@ return substr(size() - length, length); } +String String::lowerCase(const char* locale) const throw(UnicodeError) +{ + UErrorCode errorCode = U_ZERO_ERROR; + int32_t strSize = u_strToLower(0, 0, _data->str, _data->length, locale, + &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to lowercase", P_SOURCEINFO); + + SharedPtr<Data> newData(alloc(strSize + 1)); + + errorCode = U_ZERO_ERROR; + newData->length = u_strToLower(newData->str, newData->size, _data->str, + _data->length, locale, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to lowercase", P_SOURCEINFO); + + String ret; + ret._data = newData; + return ret; +} + +String String::upperCase(const char* locale) const throw(UnicodeError) +{ + UErrorCode errorCode = U_ZERO_ERROR; + int32_t strSize = u_strToUpper(0, 0, _data->str, _data->length, locale, + &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to uppercase", P_SOURCEINFO); + + SharedPtr<Data> newData(alloc(strSize + 1)); + + errorCode = U_ZERO_ERROR; + newData->length = u_strToUpper(newData->str, newData->size, _data->str, + _data->length, locale, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to uppercase", P_SOURCEINFO); + + String ret; + ret._data = newData; + return ret; +} + +String String::foldCase() const throw(UnicodeError) +{ + UErrorCode errorCode = U_ZERO_ERROR; + int32_t strSize = u_strFoldCase(0, 0, _data->str, _data->length, + 0, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to foldcase", P_SOURCEINFO); + + SharedPtr<Data> newData(alloc(strSize + 1)); + + errorCode = U_ZERO_ERROR; + newData->length = u_strFoldCase(newData->str, newData->size, _data->str, + _data->length, 0, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to foldcase", P_SOURCEINFO); + + String ret; + ret._data = newData; + return ret; +} + String& String::append(const String& str) { if(!_data || _data->length == 0) @@ -208,9 +310,13 @@ size_t String::find(const String& str, size_t pos/*=0*/) const { - if(!_data || !_data->length || !str._data || !str._data->length) + if(!str._data || !str._data->length) + return 0; + + if(!_data || !_data->length) return npos; + // get the initial uchar16 offset specified by codepoint pos size_t offset = 0; getUCharOffset(_data, pos, offset); @@ -228,6 +334,7 @@ if(!_data || !_data->length) return npos; + // get the initial uchar16 offset specified by codepoint pos size_t offset = 0; getUCharOffset(_data, pos, offset); @@ -241,12 +348,17 @@ size_t String::rfind(const String& str, size_t pos/*=npos*/) const { - if(!_data || !_data->length || !str._data || !str._data->length) - return npos; - if(pos==npos) pos = size(); + if(!str._data || !str._data->length) + return pos; + + if(!_data || !_data->length) + return npos; + + // get the initial uchar16 offset specified by codepoint pos + // cause we search from the end .. the offset specifies the searchLen size_t searchLen = 0; getUCharOffset(_data, pos, searchLen); @@ -267,6 +379,8 @@ if(pos==npos) pos = size(); + // get the initial uchar16 offset specified by codepoint pos + // cause we search from the end .. the offset specifies the searchLen size_t searchLen = 0; getUCharOffset(_data, pos, searchLen); @@ -280,7 +394,35 @@ size_t String::find_first_of(const String& str, size_t pos/*=0*/) const { - return find(str, pos); + if(!str._data || !str._data->length) + return npos; + + if(!_data || !_data->length) + return npos; + + // get the initial uchar16 offset specified by codepoint pos + size_t offset1 = 0; + getUCharOffset(_data, pos, offset1); + + uchar32_t cp1, cp2; + size_t matchIndex = 0; + + while(offset1 < _data->length) + { + U16_NEXT_UNSAFE(_data->str, offset1, cp1); + + size_t offset2 = 0; + while(offset2 < str._data->length) + { + U16_NEXT_UNSAFE(str._data->str, offset2, cp2); + if(cp1 == cp2) + return matchIndex; + } + + ++matchIndex; + } + + return npos; } size_t String::find_first_of(const Char& ch, size_t pos/*=0*/) const @@ -290,17 +432,108 @@ size_t String::find_first_not_of(const String& str, size_t pos) const { - return 0; + if(!str._data || !str._data->length) + { + // strange .. but we aim for std::string compability... + if(_data && _data->length) + return 0; + } + + if(!_data || !_data->length) + return npos; + + // get the initial uchar16 offset specified by codepoint pos + size_t offset1 = 0; + getUCharOffset(_data, pos, offset1); + + uchar32_t cp1, cp2; + size_t matchIndex = 0; + + while(offset1 < _data->length) + { + U16_NEXT_UNSAFE(_data->str, offset1, cp1); + + bool matched = false; + size_t offset2 = 0; + while(offset2 < str._data->length) + { + U16_NEXT_UNSAFE(str._data->str, offset2, cp2); + if(cp1 == cp2) + { + matched = true; + break; + } + } + + // we did not match any char .. we're finished + if(!matched) + return matchIndex; + + ++matchIndex; + } + + return npos; } size_t String::find_first_not_of(const Char& ch, size_t pos) const { - return 0; + if(!_data || !_data->length) + return npos; + + // get the initial uchar16 offset specified by codepoint pos + size_t offset1 = 0; + getUCharOffset(_data, pos, offset1); + + uchar32_t cp1; + size_t matchIndex = 0; + + while(offset1 < _data->length) + { + U16_NEXT_UNSAFE(_data->str, offset1, cp1); + if(cp1 != ch) + return matchIndex; + + ++matchIndex; + } + + return npos; } size_t String::find_last_of(const String& str, size_t pos /*=npos*/) const { - return rfind(str, pos); + if(!str._data || !str._data->length) + return npos; + + if(!_data || !_data->length) + return npos; + + if(pos==npos) + pos = size(); + + // get the initial uchar16 offset specified by codepoint pos + // cause we search from the end .. the offset specifies the searchLen + size_t offset1 = 0; + getUCharOffset(_data, pos, offset1); + + uchar32_t cp1, cp2; + size_t matchIndex = pos; + + do { + + U16_PREV_UNSAFE(_data->str, offset1, cp1); + --matchIndex; + + size_t offset2 = 0; + while(offset2 < str._data->length) + { + U16_NEXT_UNSAFE(str._data->str, offset2, cp2); + if(cp1 == cp2) + return matchIndex; + } + + } while(offset1 > 0); + + return npos; } size_t String::find_last_of(const Char& ch, size_t pos /*=npos*/) const @@ -310,12 +543,76 @@ size_t String::find_last_not_of(const String& str, size_t pos) const { - return 0; + if(pos==npos) + pos = size(); + + if(!str._data || !str._data->length) + return pos - 1; + + if(!_data || !_data->length) + return npos; + + // get the initial uchar16 offset specified by codepoint pos + // cause we search from the end .. the offset specifies the searchLen + size_t offset1 = 0; + getUCharOffset(_data, pos, offset1); + + uchar32_t cp1, cp2; + size_t matchIndex = pos; + + do { + + U16_PREV_UNSAFE(_data->str, offset1, cp1); + --matchIndex; + + bool matched = false; + size_t offset2 = 0; + while(offset2 < str._data->length) + { + U16_NEXT_UNSAFE(str._data->str, offset2, cp2); + if(cp1 == cp2) + { + matched = true; + break; + } + } + + // we did not match any char .. we're finished + if(!matched) + return matchIndex; + + } while(offset1 > 0); + + return npos; } size_t String::find_last_not_of(const Char& ch, size_t pos) const { - return 0; + if(pos==npos) + pos = size(); + + if(!_data || !_data->length) + return npos; + + // get the initial uchar16 offset specified by codepoint pos + // cause we search from the end .. the offset specifies the searchLen + size_t offset1 = 0; + getUCharOffset(_data, pos, offset1); + + uchar32_t cp1; + size_t matchIndex = pos; + + do { + + U16_PREV_UNSAFE(_data->str, offset1, cp1); + --matchIndex; + + if(cp1 != ch) + return matchIndex; + + } while(offset1 > 0); + + return npos; } Char String::at(size_t pos) const @@ -332,46 +629,36 @@ if(!str._data || _data->length == 0) return 0; - return +1; + return -1; } else if(!str._data || _data->length == 0) - return -1; + return +1; - return u_strncmp(_data->str, str._data->str, - _data->length < str._data->length ? _data->length : str._data->length); + return u_strCompare(_data->str, _data->length, str._data->str, + str._data->length, true); } -std::string String::local() const +int String::caseCompare(const String& str) const throw(UnicodeError) { if(!_data || _data->length == 0) - return std::string(); - - char* ret = new char[_data->length]; - u_austrncpy(ret, _data->str, _data->length); - std::string retstr(ret); - delete[] ret; - return retstr; -} + { + if(!str._data || _data->length == 0) + return 0; -std::string String::utf8() const -{ - if(!_data || _data->length == 0) - return std::string(); + return -1; + } + else if(!str._data || _data->length == 0) + return +1; - ::int32_t resultLen = 0; UErrorCode errorCode = U_ZERO_ERROR; - // pre-flight .. get the required storage ... - u_strToUTF8(0, 0, &resultLen, _data->str, _data->length, &errorCode); + int ret = u_strCaseCompare(_data->str, _data->length, str._data->str, + str._data->length, U_COMPARE_CODE_POINT_ORDER, &errorCode); - char* ret = new char[resultLen + 1]; - ::int32_t retLen = 0; + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not case-insensitivly compare string", P_SOURCEINFO); - errorCode = U_ZERO_ERROR; - u_strToUTF8(ret, resultLen + 1, &retLen, _data->str, _data->length, &errorCode); - std::string retstr(ret); - delete[] ret; - return retstr; + return ret; } Char String::operator[](size_t pos) const @@ -387,13 +674,13 @@ String& String::operator=(const char* str) { - *this = fromLocal(str); + *this = fromCodepage(str, npos, 0); return *this; } String& String::operator=(const std::string& str) { - *this = fromLocal(str.c_str(), str.size()); + *this = fromCodepage(str.c_str(), str.size(), 0); return *this; } @@ -439,14 +726,26 @@ return (operator>(str) || operator==(str)); } -String String::fromLocal(const char* str, size_t count) +std::string String::ascii() const throw(OutOfMemory) +{ + if(!_data || _data->length == 0) + return std::string(); + + char* ret = new char[_data->length]; + u_austrncpy(ret, _data->str, _data->length); + std::string retstr(ret); + delete[] ret; + return retstr; +} + +String String::fromAscii(const char* str, size_t count) throw(OutOfMemory) { if(count == npos) count = strlen(str); SharedPtr<Data> data(alloc(count + 1)); - u_uastrncpy(data->str, str, count); + u_uastrncpy(data->str, str, count + 1); data->length = u_strlen(data->str); String ret; @@ -454,27 +753,84 @@ return ret; } +std::string String::utf8() const throw(OutOfMemory, UnicodeError) +{ + if(!_data || _data->length == 0) + return std::string(); + + ::int32_t resultLen = 0; + UErrorCode errorCode = U_ZERO_ERROR; + + // pre-flight .. get the required storage ... + u_strToUTF8(0, 0, &resultLen, _data->str, _data->length, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to UTF8", P_SOURCEINFO); + + ScopedArrayPtr<char> ret(new char[resultLen + 1]); + ::int32_t retLen = 0; + + errorCode = U_ZERO_ERROR; + u_strToUTF8(ret.get(), resultLen + 1, &retLen, _data->str, _data->length, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert string to UTF8", P_SOURCEINFO); + + std::string retstr(ret.get()); + return retstr; +} + String String::fromUtf8(const char* str, size_t count) + throw(OutOfMemory, UnicodeError) { if(count == npos) count = strlen(str); - return fromCharset("UTF8", str, count); + UErrorCode errorCode = U_ZERO_ERROR; + int32_t destLen = 0; + + u_strFromUTF8(0, 0, &destLen, str, count, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert UTF8 string to unicode", P_SOURCEINFO); + + SharedPtr<Data> data(alloc(destLen + 1)); + + errorCode = U_ZERO_ERROR; + u_strFromUTF8(data->str, data->size, &destLen, str, count, &errorCode); + data->length = destLen; + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not convert UTF8 string to unicode", P_SOURCEINFO); + + String ret; + ret._data = data; + return ret; } -String String::fromUcs2(const char* str, size_t count) +std::string String::toCodepage(const char* codepage) const + throw(OutOfMemory, UnicodeError) { - return fromCharset("UCS2", (const char*)str, count); + ScopedPtr<Converter> cvt(new Converter(codepage)); + return cvt->fromUnicode(*this); } -String String::fromCharset(const char* charset, const char* str, size_t count) +String String::fromCodepage(const char* str, size_t count, + const char* codepage) throw(OutOfMemory, UnicodeError) { - return String(); + if(count == npos) + count = strlen(str); + + ScopedPtr<Converter> cvt(new Converter(codepage)); + return cvt->toUnicode(str, count); } -std::string String::toCharset(const char* charset) const +const uchar16_t* String::data() const throw() { - return std::string(); + if(_data) + return _data->str; + + return 0; } String operator+(const String& lhs, const String& rhs) @@ -489,11 +845,12 @@ std::ostream& operator<<(std::ostream& os, const String& str) { - os << str.local(); + os << str.toCodepage(); return os; } + } // !namespace Unicode } // !namespace P Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.am 20 May 2005 14:14:39 -0000 1.10 +++ Makefile.am 24 May 2005 02:32:59 -0000 1.11 @@ -5,7 +5,8 @@ CPPFLAGS = -DPUNICODE_BUILD -libpclasses_unicode_la_SOURCES = Char.cpp String.cpp TextStream.cpp +libpclasses_unicode_la_SOURCES = Char.cpp String.cpp Converter.cpp \ + UnicodeError.cpp TextStream.cpp libpclasses_unicode_la_LDFLAGS = -no-undefined --- NEW FILE: UnicodeError.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/Unicode/UnicodeError.h" #include <unicode/utypes.h> namespace P { namespace Unicode { UnicodeError::UnicodeError(int errorNo, const char* what, const SourceInfo& si) throw() : RuntimeError(what, si), _errorNo(errorNo) { } UnicodeError::~UnicodeError() throw() { } int UnicodeError::errorNo() const throw() { return _errorNo; } } // !namespace Unicode } // !namespace P Index: Char.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Char.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Char.cpp 20 May 2005 14:14:39 -0000 1.7 +++ Char.cpp 24 May 2005 02:32:59 -0000 1.8 @@ -1,22 +1,22 @@ -/* - * 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 - * - */ +/*************************************************************************** + * Copyright (C) 2004,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. * + ***************************************************************************/ #include "pclasses/Unicode/Char.h" #include <unicode/uchar.h> @@ -25,21 +25,11 @@ namespace Unicode { -InvalidCharError::InvalidCharError(const char* what, const SourceInfo& si) throw() -: RuntimeError(what, si) -{ -} - -InvalidCharError::~InvalidCharError() throw() -{ -} - - -Char::Char(uchar32_t ch) throw(InvalidCharError) +Char::Char(uchar32_t ch) throw(UnicodeError) : _char(ch) { if(ch < UCHAR_MIN_VALUE || ch > UCHAR_MAX_VALUE) - throw InvalidCharError("Invalid UNICODE character", P_SOURCEINFO); + throw UnicodeError(U_INVALID_CHAR_FOUND, "Invalid UNICODE character", P_SOURCEINFO); } Char::Char(const Char& ch) throw() @@ -137,10 +127,10 @@ return _char; } -Char& Char::operator=(uchar32_t ch) throw(InvalidCharError) +Char& Char::operator=(uchar32_t ch) throw(UnicodeError) { if(ch < UCHAR_MIN_VALUE || ch > UCHAR_MAX_VALUE) - throw InvalidCharError("Invalid UNICODE character", P_SOURCEINFO); + throw UnicodeError(U_INVALID_CHAR_FOUND, "Invalid UNICODE character", P_SOURCEINFO); _char = ch; return *this; |