You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Christian P. <cp...@us...> - 2005-05-24 04:19:58
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10841/src/System Modified Files: PathFinder.cpp Log Message: - Modified PathFinder to not search for the resource without any extension Index: PathFinder.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/PathFinder.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- PathFinder.cpp 7 May 2005 13:23:39 -0000 1.7 +++ PathFinder.cpp 24 May 2005 04:19:49 -0000 1.8 @@ -146,13 +146,14 @@ if(!path.empty()) { path = Path(path).absPath(); - path += Path::separator(); + path += Unicode::String::fromAscii(Path::separator()); } ++piter; - checkhere = path + resource; - CHECKPATH(checkhere); + // do not check without extension ... + //checkhere = path + resource; + //CHECKPATH(checkhere); eiter = _exts.begin(); while(eiter != _exts.end()) |
From: Christian P. <cp...@us...> - 2005-05-24 04:19:58
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10841/include/pclasses/System Modified Files: PathFinder.h Log Message: - Modified PathFinder to not search for the resource without any extension Index: PathFinder.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/PathFinder.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- PathFinder.h 7 May 2005 13:23:39 -0000 1.8 +++ PathFinder.h 24 May 2005 04:19:50 -0000 1.9 @@ -5,9 +5,6 @@ // License: Public Domain // Readability cleanup and code P-ificaton by Christian Prochnow <cp...@se...> -// TODO: get rid of string_list and joinList and tokenize_to_list and provide a common -// implementation as it may be useful for other too. -- cproch - #include <pclasses/Export.h> #include <pclasses/StringList.h> #include <pclasses/Unicode/String.h> @@ -25,19 +22,16 @@ <pre> PathFinder p; - p.path( "/lib/lib:/usr/lib/lib" ); + p.path( "/lib:/usr/lib" ); p.extensions( ".a:.so" ); - cout << p.find( "z" ); + cout << p.find( "libz" ); </pre> That would print an empty string if it finds nothing, or a string if it finds any of the following: - - z - - /lib/libz - /lib/libz.a - /lib/libz.so - - /usr/lib/libz - /usr/lib/libz.a - /usr/lib/libz.so |
From: Christian P. <cp...@us...> - 2005-05-24 03:08:49
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv406/src/Unicode Modified Files: String.cpp Log Message: - Fix for the removed SharedPtr::operator bool() Index: String.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/String.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- String.cpp 24 May 2005 02:32:59 -0000 1.8 +++ String.cpp 24 May 2005 03:08:21 -0000 1.9 @@ -71,7 +71,7 @@ String::String(const String& str, size_t offset, size_t count/*= npos*/) { - if(!str._data) + if(str._data.null()) return; if(count == npos) @@ -137,7 +137,7 @@ bool String::null() const throw() { - return !_data; + return _data.null(); } void String::setNull() throw() @@ -147,7 +147,7 @@ bool String::empty() const throw() { - if(_data) + if(!_data.null()) return !_data->length; return true; @@ -155,7 +155,7 @@ size_t String::size() const throw() { - if(_data) + if(!_data.null()) return u_countChar32(_data->str, _data->length); return 0; @@ -163,7 +163,7 @@ size_t String::capacity() const throw() { - if(_data) + if(!_data.null()) return _data->size; return 0; @@ -178,7 +178,7 @@ } Data* newData = alloc(sz); - if(_data) + if(!_data.null()) { newData->length = _data->length < sz ? _data->length : sz; u_strncpy(newData->str, _data->str, newData->length); @@ -273,13 +273,13 @@ String& String::append(const String& str) { - if(!_data || _data->length == 0) + if(_data.null() || _data->length == 0) { _data = str._data; return *this; } - if(!str._data || str._data->length == 0) + if(str._data.null() || str._data->length == 0) return *this; if(_data->size <= _data->length + str._data->length) @@ -293,7 +293,7 @@ String& String::append(const Char& ch) { - if(!_data) + if(_data.null()) _data = alloc(2); else if(_data->size <= _data->length + 2) resize(_data->length + 2); @@ -310,10 +310,10 @@ size_t String::find(const String& str, size_t pos/*=0*/) const { - if(!str._data || !str._data->length) + if(str._data.null() || !str._data->length) return 0; - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -331,7 +331,7 @@ size_t String::find(const Char& ch, size_t pos/*=0*/) const { - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -351,10 +351,10 @@ if(pos==npos) pos = size(); - if(!str._data || !str._data->length) + if(str._data.null() || !str._data->length) return pos; - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -373,7 +373,7 @@ size_t String::rfind(const Char& ch, size_t pos/*=npos*/) const { - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; if(pos==npos) @@ -394,10 +394,10 @@ size_t String::find_first_of(const String& str, size_t pos/*=0*/) const { - if(!str._data || !str._data->length) + if(str._data.null() || !str._data->length) return npos; - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -432,14 +432,14 @@ size_t String::find_first_not_of(const String& str, size_t pos) const { - if(!str._data || !str._data->length) + if(str._data.null() || !str._data->length) { // strange .. but we aim for std::string compability... - if(_data && _data->length) + if(!_data.null() && _data->length) return 0; } - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -477,7 +477,7 @@ size_t String::find_first_not_of(const Char& ch, size_t pos) const { - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -501,10 +501,10 @@ size_t String::find_last_of(const String& str, size_t pos /*=npos*/) const { - if(!str._data || !str._data->length) + if(str._data.null() || !str._data->length) return npos; - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; if(pos==npos) @@ -546,10 +546,10 @@ if(pos==npos) pos = size(); - if(!str._data || !str._data->length) + if(str._data.null() || !str._data->length) return pos - 1; - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -591,7 +591,7 @@ if(pos==npos) pos = size(); - if(!_data || !_data->length) + if(_data.null() || !_data->length) return npos; // get the initial uchar16 offset specified by codepoint pos @@ -624,14 +624,14 @@ int String::compare(const String& str) const throw() { - if(!_data || _data->length == 0) + if(_data.null() || _data->length == 0) { - if(!str._data || _data->length == 0) + if(str._data.null() || _data->length == 0) return 0; return -1; } - else if(!str._data || _data->length == 0) + else if(str._data.null() || _data->length == 0) return +1; return u_strCompare(_data->str, _data->length, str._data->str, @@ -640,14 +640,14 @@ int String::caseCompare(const String& str) const throw(UnicodeError) { - if(!_data || _data->length == 0) + if(_data.null() || _data->length == 0) { - if(!str._data || _data->length == 0) + if(str._data.null() || _data->length == 0) return 0; return -1; } - else if(!str._data || _data->length == 0) + else if(str._data.null() || _data->length == 0) return +1; UErrorCode errorCode = U_ZERO_ERROR; @@ -728,7 +728,7 @@ std::string String::ascii() const throw(OutOfMemory) { - if(!_data || _data->length == 0) + if(_data.null() || _data->length == 0) return std::string(); char* ret = new char[_data->length]; @@ -755,7 +755,7 @@ std::string String::utf8() const throw(OutOfMemory, UnicodeError) { - if(!_data || _data->length == 0) + if(_data.null() || _data->length == 0) return std::string(); ::int32_t resultLen = 0; @@ -827,7 +827,7 @@ const uchar16_t* String::data() const throw() { - if(_data) + if(!_data.null()) return _data->str; return 0; |
From: Christian P. <cp...@us...> - 2005-05-24 03:07:41
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32619/include/pclasses Modified Files: SharedPtr.h Log Message: - Removed "operator bool()" from SharedPtr, it's dangerous - Added more compare operators to SharedPtr Index: SharedPtr.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/SharedPtr.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SharedPtr.h 20 May 2005 14:21:29 -0000 1.3 +++ SharedPtr.h 24 May 2005 03:07:32 -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 * @@ -47,6 +47,9 @@ ~SharedPtr() throw() { _ptr->putRef(); } + bool null() const throw() + { return !_ptr->ptr; } + Type* get() const throw() { return _ptr->ptr; } @@ -72,9 +75,6 @@ Type* operator->() throw() { return _ptr->ptr; } - operator bool() const throw() - { return _ptr->ptr ? true : false; } - SharedPtr& operator=(Type* ptr) throw(OutOfMemory) { SharedPtr(ptr).swap(*this); @@ -96,9 +96,31 @@ bool operator==(const SharedPtr& ptr) const throw() { return _ptr == ptr._ptr; } + bool operator==(const Type* ptr) const throw() + { return _ptr == ptr; } + + template <class Type2> + bool operator==(const SharedPtr<Type2>& ptr) const throw() + { return _ptr == ptr.get(); } + + template <class Type2> + bool operator==(const Type2* ptr) const throw() + { return _ptr == ptr; } + bool operator!=(const SharedPtr& ptr) const throw() { return _ptr != ptr._ptr; } + bool operator!=(Type* ptr) const throw() + { return _ptr != ptr; } + + template <class Type2> + bool operator!=(const SharedPtr<Type2>& ptr) const throw() + { return _ptr != ptr.get(); } + + template <class Type2> + bool operator!=(const Type2* ptr) const throw() + { return _ptr != ptr; } + private: //! Private data structure |
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 |
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; |
From: Christian P. <cp...@us...> - 2005-05-20 14:23:40
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9621/test Modified Files: StringTest.cpp Log Message: - Started StringTest Index: StringTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/StringTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- StringTest.cpp 30 Dec 2004 17:39:01 -0000 1.1 +++ StringTest.cpp 20 May 2005 14:23:25 -0000 1.2 @@ -20,33 +20,35 @@ #include "Test.h" #include "pclasses/Unicode/String.h" +#include <string> namespace P { +using namespace Unicode; + class StringTest: public UnitTest { public: void run() throw() { - Unicode::String s1(2); + std::string s2 = "blablasuelz"; + String s1 = s2; + //P_TEST(s1.empty()); - s1 = L"ba"; - print(s1); - - s1.insert(1, Unicode::Char('-')); - print(s1); + P_TEST(s2.size() == s1.size()); + P_TEST(s2.find("bla") == s1.find("bla")); + P_TEST(s2.find_first_of("bla") == s1.find_first_of("bla")); + P_TEST(s2.rfind("bla") == s1.rfind("bla")); + P_TEST(s2.find_last_of("bla") == s1.find_last_of("bla")); - P_TEST(s1[0] == Unicode::Char('b')); - P_TEST(s1[1] == Unicode::Char('-')); - P_TEST(s1[2] == Unicode::Char('a')); + std::cout << s2.find_last_of("bla") << std::endl; + + print(s1); } - void print(const Unicode::String& str) + void print(const String& str) { - for(size_t i = 0; i < str.length(); i++) - std::cout << str.at(i).latin1(); - - std::cout << std::endl; + std::cout << str << std::endl; } }; |
From: Christian P. <cp...@us...> - 2005-05-20 14:22:12
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9287/src/System Modified Files: FdListener.posix.cpp SignalListener.posix.cpp Log Message: - Added some Trace-messages Index: FdListener.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/FdListener.posix.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- FdListener.posix.cpp 23 Apr 2005 17:47:07 -0000 1.5 +++ FdListener.posix.cpp 20 May 2005 14:21:58 -0000 1.6 @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/Trace.h" #include "FdListener.h" #include "timeout.h" @@ -77,6 +78,7 @@ protected: void onRead() { + P_TRACE(WakeupListener) << "onRead(): got woken up ..."; // read data from pipe .. we dont want to get signaled forever ... char tmp[256]; ::read(fd(), tmp, sizeof(tmp)); @@ -129,6 +131,7 @@ void FdListenerList::wakeup() { + P_TRACE(FdListenerList) << "wakeup(): waking up FdListenerList..."; ::write(_wakeupPipe[1], "W", 1); } @@ -205,20 +208,26 @@ { CriticalSection::ScopedLock lck(_listenersCs); - highest_fd = + highest_fd = populate_fd_sets(&read_fds, &write_fds, &error_fds, _listeners); } _select_loop: Private::get_timeout(&timeout, timeout_ms, Private::TIMEOUT_RELATIVE); + P_TRACE(FdListenerList) << "wait() wait for fd-events .. highest_fd=" + << highest_fd << ", timeout_ms=" << timeout_ms; + int ret = ::select(highest_fd + 1, &read_fds, &write_fds, &error_fds, &timeout); if(ret == -1) { if(errno == EINTR) + { + P_TRACE(FdListenerList) << "wait() interrupted ... restarting"; goto _select_loop; + } //@@fixme ... we don't want to throw from Thread::main() !!! throw SystemError(errno, "Could not select() for events", P_SOURCEINFO); Index: SignalListener.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SignalListener.posix.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SignalListener.posix.cpp 28 Apr 2005 10:23:57 -0000 1.6 +++ SignalListener.posix.cpp 20 May 2005 14:21:58 -0000 1.7 @@ -127,6 +127,8 @@ */ void onRead() { + P_TRACE(SignalFdListener) << "Dispatching signals ..."; + // block all signals ... sigset_t blockedSet, oldSet; sigfillset(&blockedSet); @@ -139,7 +141,7 @@ qs = _signals.front(); _signals.pop(); - P_TRACE(SignalFdListener) << "Dispatching signal sig=" << qs.sig; + P_TRACE(SignalFdListener) << "Dispatching signal #" << qs.sig; if(_listeners[qs.sig]) _listeners[qs.sig]->onSignal(qs.val); @@ -184,7 +186,7 @@ SignalListener::SignalListener(int sig) : _sig(sig) { - P_TRACE(SignalListener) << "Installing signal handler for sig=" << sig; + P_TRACE(SignalListener) << "Installing signal handler for signal #" << sig; struct sigaction sa; sa.sa_sigaction = &signal_handler; @@ -199,7 +201,7 @@ SignalListener::~SignalListener() { - P_TRACE(SignalListener) << "Destroying signal handler for sig=" << _sig; + P_TRACE(SignalListener) << "Destroying signal handler for signal #" << _sig; SignalFdListener& l = SignalFdListener::instance(); l.removeListener(*this); |
From: Christian P. <cp...@us...> - 2005-05-20 14:21:44
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9164/include/pclasses Modified Files: SharedPtr.h Log Message: - Added operator bool() to SharedPtr<> Index: SharedPtr.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/SharedPtr.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SharedPtr.h 25 Apr 2005 11:03:19 -0000 1.2 +++ SharedPtr.h 20 May 2005 14:21:29 -0000 1.3 @@ -72,6 +72,9 @@ Type* operator->() throw() { return _ptr->ptr; } + operator bool() const throw() + { return _ptr->ptr ? true : false; } + SharedPtr& operator=(Type* ptr) throw(OutOfMemory) { SharedPtr(ptr).swap(*this); |
From: Christian P. <cp...@us...> - 2005-05-20 14:20:55
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9014/src/System Modified Files: Makefile.am Log Message: - Added System::Path to Makefile.am Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Makefile.am,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- Makefile.am 6 May 2005 16:13:07 -0000 1.20 +++ Makefile.am 20 May 2005 14:20:45 -0000 1.21 @@ -57,13 +57,13 @@ IO_Sources = IOHandle.posix.cpp Pipe.posix.cpp File.posix.cpp \ FileInfo.posix.cpp Directory.posix.cpp Process.posix.cpp \ FdListener.posix.cpp SignalListener.posix.cpp \ - SerialDevice.posix.cpp + SerialDevice.posix.cpp Path.posix.cpp endif if WITH_WIN32_IO IO_Sources = IOHandle.win32.cpp Pipe.win32.cpp File.win32.cpp \ FileInfo.win32.cpp Directory.win32.cpp Process.win32.cpp \ - FdListener.win32.cpp SerialDevice.win32.cpp + FdListener.win32.cpp SerialDevice.win32.cpp Path.win32.cpp endif if WITH_POSIX_TIME |
From: Christian P. <cp...@us...> - 2005-05-20 14:20:01
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8806/include/pclasses Modified Files: Trace.h Log Message: - Use template parameter in NullTraceStream Index: Trace.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Trace.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Trace.h 7 May 2005 11:56:21 -0000 1.4 +++ Trace.h 20 May 2005 14:19:52 -0000 1.5 @@ -78,36 +78,8 @@ inline NullTraceStream& operator()(const SourceInfo& si) { return *this; } - inline NullTraceStream& operator<<(char ch) - { return *this; } - - inline NullTraceStream& operator<<(const char* str) - { return *this; } - - inline NullTraceStream& operator<<(int16_t val) - { return *this; } - - inline NullTraceStream& operator<<(uint16_t val) - { return *this; } - - inline NullTraceStream& operator<<(int32_t val) - { return *this; } - - inline NullTraceStream& operator<<(uint32_t val) - { return *this; } - - #ifdef PCLASSES_HAVE_64BIT_INT - inline NullTraceStream& operator<<(int64_t val) - { return *this; } - - inline NullTraceStream& operator<<(uint64_t val) - { return *this; } - #endif - - inline NullTraceStream& operator<<(const void* ptr) - { return *this; } - - inline NullTraceStream& operator<<(const std::string& str) + template <class DummyType> + inline NullTraceStream& operator<<(const DummyType&) { return *this; } }; |
From: Christian P. <cp...@us...> - 2005-05-20 14:19:29
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8748/include/pclasses/IO Removed Files: StringDevice.h Log Message: - Removed IO::StringDevice --- StringDevice.h DELETED --- |
From: Christian P. <cp...@us...> - 2005-05-20 14:19:24
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8748/src/IO Modified Files: Makefile.am Removed Files: StringDevice.cpp Log Message: - Removed IO::StringDevice --- StringDevice.cpp DELETED --- Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.am 17 Jan 2005 22:50:34 -0000 1.9 +++ Makefile.am 20 May 2005 14:19:15 -0000 1.10 @@ -5,8 +5,7 @@ CPPFLAGS = -DPIO_BUILD libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp \ - IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp BZip2IOFilter.cpp \ - StringDevice.cpp + IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp BZip2IOFilter.cpp libpclasses_io_la_LDFLAGS = -no-nundefined |
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7861 Modified Files: String.cpp Char.cpp Makefile.am Removed Files: uctype.cpp unicodedata.awk unicodedata.cpp ustring.cpp genunicodedata.cpp unicodedata.h Log Message: - Dropping own Unicode implementation. We now use UCI --- genunicodedata.cpp DELETED --- --- unicodedata.cpp DELETED --- Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.am 6 May 2005 15:32:11 -0000 1.9 +++ Makefile.am 20 May 2005 14:14:39 -0000 1.10 @@ -1,11 +1,3 @@ -noinst_HEADERS = unicodedata.h - -UnicodeData.txt: - wget --passive-ftp http://www.unicode.org/Public/UNIDATA/UnicodeData.txt - -unicodedata_db.cpp unicodedata_casemap_db.cpp unicodedata_number_db.cpp: genunicodedata$(EXEEXT) UnicodeData.txt - $(top_builddir)/src/Unicode/genunicodedata$(EXEEXT) UnicodeData.txt - INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_builddir)/src/Unicode $(all_includes) METASOURCES = AUTO @@ -13,15 +5,8 @@ CPPFLAGS = -DPUNICODE_BUILD -libpclasses_unicode_la_SOURCES = unicodedata.cpp unicodedata_db.cpp unicodedata_casemap_db.cpp \ - unicodedata_number_db.cpp unicodedata_decomp_db.cpp uctype.cpp ustring.cpp Char.cpp String.cpp TextStream.cpp +libpclasses_unicode_la_SOURCES = Char.cpp String.cpp TextStream.cpp libpclasses_unicode_la_LDFLAGS = -no-undefined -libpclasses_unicode_la_LIBADD = $(top_builddir)/src/libpclasses.la $(LIBICONV) - -noinst_PROGRAMS = genunicodedata -genunicodedata_SOURCES = genunicodedata.cpp - -CLEAN_FILES = UnicodeData.txt unicodedata_db.cpp unicodedata_casemap_db.cpp unicodedata_number_db.cpp \ - unicodedata_decomp_db.cpp +libpclasses_unicode_la_LIBADD = $(top_builddir)/src/libpclasses.la $(LIBICONV) -licuuc Index: Char.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Char.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Char.cpp 6 May 2005 15:32:11 -0000 1.6 +++ Char.cpp 20 May 2005 14:14:39 -0000 1.7 @@ -19,214 +19,182 @@ */ #include "pclasses/Unicode/Char.h" -#include "unicodedata.h" +#include <unicode/uchar.h> namespace P { namespace Unicode { -Char::Char(uchar_t ch) -: _char(ch) -{ } - -Char::Char(const Char& ch) -: _char(ch._char) +InvalidCharError::InvalidCharError(const char* what, const SourceInfo& si) throw() +: RuntimeError(what, si) { } -bool Char::isNumber() const +InvalidCharError::~InvalidCharError() throw() { - return isudigit(_char) == 1 ? true : false; } -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; +Char::Char(uchar32_t ch) throw(InvalidCharError) +: _char(ch) +{ + if(ch < UCHAR_MIN_VALUE || ch > UCHAR_MAX_VALUE) + throw InvalidCharError("Invalid UNICODE character", P_SOURCEINFO); } -bool Char::isMark() const +Char::Char(const Char& ch) throw() +: _char(ch._char) { - bool ret = false; - - switch(category()) - { - case Mark_NonSpacing: - case Mark_SpacingCombining: - case Mark_Enclosing: - ret = true; - default: - break; - } +} - return ret; +bool Char::isDefined() const throw() +{ + return u_isdefined(_char); } -bool Char::isPunct() const +bool Char::isAlphabetic() const throw() { - bool ret = false; + return u_isUAlphabetic(_char); +} - 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; - } +bool Char::isAlphaNumeric() const throw() +{ + return u_isalnum(_char); +} - return ret; +bool Char::isDigit() const throw() +{ + return u_isdigit(_char); } -bool Char::isLetter() const +int Char::digitValue() const throw() { - return isualpha(_char) == 1 ? true : false; + return u_charDigitValue(_char); } -float Char::toNumber() const +bool Char::isNumeric() const throw() { - float ret = 0.0f; - const codePointData* data = lookupCodePoint(_char); + return u_getNumericValue(_char) != U_NO_NUMERIC_VALUE; +} - if(data) - { - const numberMappingData* numberData = lookupNumberMappingData(data); - if(numberData) - ret = numberData->num; - } +double Char::numericValue() const throw() +{ + return u_getNumericValue(_char); +} - return ret; +bool Char::isLower() const throw() +{ + return u_isULowercase(_char); } -bool Char::isLower() const +Char Char::toLower() const throw() { - return isulower(_char) == 1 ? true : false; + return u_tolower(_char); } -Char Char::toLower() const +bool Char::isUpper() const throw() { - return toulower(_char); + return u_isUUppercase(_char); } -bool Char::isUpper() const +Char Char::toUpper() const throw() { - return isuupper(_char) == 1 ? true : false; + return u_toupper(_char); } -Char Char::toUpper() const +bool Char::isTitle() const throw() { - return touupper(_char); + return u_istitle(_char); } -bool Char::isMirrored() const +Char Char::toTitle() const throw() { - const codePointData* data = lookupCodePoint(_char); - return data->mirrored; + return u_totitle(_char); } -Char::Category Char::category() const +bool Char::isMirrored() const throw() { - const codePointData* data = lookupCodePoint(_char); - return (Char::Category)data->category; + return u_isMirrored(_char); } -Char::BidiClass Char::bidiClass() const +Char Char::mirrorChar() const throw() { - const codePointData* data = lookupCodePoint(_char); - return (Char::BidiClass)data->bidi; + return u_charMirror(_char); } -Char::Decomposition Char::decompTag() const +bool Char::isWhiteSpace() const throw() { - const codePointData* data = lookupCodePoint(_char); - return (Char::Decomposition)data->decomp; + return u_isWhitespace(_char); } -Char::CombiningClass Char::combiningClass() const +bool Char::isIgnorable() const throw() { - const codePointData* data = lookupCodePoint(_char); - return (Char::CombiningClass)data->combining; + return u_hasBinaryProperty(_char, UCHAR_DEFAULT_IGNORABLE_CODE_POINT); } -Char::operator const uchar_t& () const throw() +Char::operator const uchar32_t& () const throw() { return _char; } -Char& Char::operator=(uchar_t ch) +Char& Char::operator=(uchar32_t ch) throw(InvalidCharError) { + if(ch < UCHAR_MIN_VALUE || ch > UCHAR_MAX_VALUE) + throw InvalidCharError("Invalid UNICODE character", P_SOURCEINFO); + _char = ch; return *this; } -Char& Char::operator=(const Char& ch) +Char& Char::operator=(const Char& ch) throw() { _char = ch._char; return *this; } -bool Char::operator==(const Char& ch) const +bool Char::operator==(const Char& ch) const throw() { return _char == ch._char; } -bool Char::operator!=(const Char& ch) const +bool Char::operator!=(const Char& ch) const throw() { return _char != ch._char; } -bool Char::operator<(const Char& ch) const +bool Char::operator<(const Char& ch) const throw() { - //@todo Char::operator< - return false; + return _char < ch._char; } -bool Char::operator>(const Char& ch) const +bool Char::operator>(const Char& ch) const throw() { - //@todo Char::operator> - return false; + return _char > ch._char; } -bool Char::operator<=(const Char& ch) const +bool Char::operator<=(const Char& ch) const throw() { return (operator<(ch) || operator==(ch)); } -bool Char::operator>=(const Char& ch) const +bool Char::operator>=(const Char& ch) const throw() { return (operator>(ch) || operator==(ch)); } -const Char& Char::eof() +const Char& Char::eof() throw() { - static Char _eof(UEOF); + static Char _eof(0); return _eof; } -const Char& Char::nl() +const Char& Char::nl() throw() { static Char _nl('\n'); return _nl; } -const Char& Char::cr() +const Char& Char::cr() throw() { static Char _cr('\r'); return _cr; --- uctype.cpp DELETED --- Index: String.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/String.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- String.cpp 6 May 2005 15:32:11 -0000 1.6 +++ String.cpp 20 May 2005 14:14:39 -0000 1.7 @@ -23,60 +23,140 @@ #include <cstring> #include <sstream> -#include <iconv.h> -#include <errno.h> +#include <unicode/ustring.h> #include <langinfo.h> +#include <errno.h> namespace P { namespace Unicode { +struct String::Data { + size_t size; // size of str counted in uchar16_t + size_t length; // length of str counted in uchar16_t + uchar16_t str[1]; +}; + String::String() { } +String::String(size_t sz) +: _data(alloc(sz * 2)) +{ +} + String::String(const String& str) -: _str(str._str) +: _data(str._data) { } -String::String(const ustring& str) -: _str(str) +String::String(const String& str, size_t offset, size_t count/*= npos*/) { + if(!str._data) + return; + + if(count == npos) + count = str.size() - offset; + + _data = alloc(count * 2); + + size_t charOffset = 0; + U16_FWD_N(str._data->str, charOffset, str._data->length, offset); + + size_t charCount = charOffset; + U16_FWD_N(str._data->str, charCount, str._data->length, count); + charCount -= charOffset; + + u_strncpy(_data->str, str._data->str + charOffset, charCount); + _data->length = charCount; } String::String(const std::string& str) { - *this = fromLatin1(str.c_str(), str.size()); + *this = fromLocal(str.c_str(), str.size()); } String::String(const char* str, size_t count) { - *this = fromLatin1(str, count); + *this = fromLocal(str, count); } String::~String() throw() { } +String::Data* String::alloc(size_t size) +{ + Data* d = (Data*)new char[sizeof(Data) + sizeof(uchar16_t) * size]; + d->size = size; + d->length = 0; + d->str[0] = 0; + return d; +} + +void String::deepCopy() +{ + if(_data.useCount() > 1) + { + Data* newData = (Data*)new char[sizeof(Data) + sizeof(uchar16_t) * _data->size]; + newData->size = _data->size; + newData->length = _data->length; + u_strncpy(newData->str, _data->str, _data->length); + _data = newData; + } +} + void String::swap(String& b) { - std::swap(b._str, _str); + _data.swap(b._data); } bool String::empty() const throw() { - return _str.empty(); + if(_data) + return !_data->length; + + return true; } size_t String::size() const throw() { - return _str.size(); + if(_data) + return u_countChar32(_data->str, _data->length); + + return 0; } -String String::substr(size_t offset, size_t length) const +size_t String::capacity() const throw() { - return _str.substr(offset, length); + if(_data) + return _data->size; + + return 0; +} + +void String::resize(size_t sz) +{ + if(!sz) + { + _data = 0; + return; + } + + Data* newData = alloc(sz); + if(_data) + { + newData->length = _data->length < sz ? _data->length : sz; + u_strncpy(newData->str, _data->str, newData->length); + } + + _data = newData; +} + +String String::substr(size_t offset, size_t length/*=npos*/) const +{ + return String(*this, offset, length); } String String::left(size_t length) const @@ -86,137 +166,234 @@ String String::right(size_t length) const { - return substr(_str.size() - length, length); + return substr(size() - length, length); } String& String::append(const String& str) { - _str.append(str._str); + if(!_data || _data->length == 0) + { + _data = str._data; + return *this; + } + + if(!str._data || str._data->length == 0) + return *this; + + if(_data->size <= _data->length + str._data->length) + resize(_data->length + str._data->length); + else + deepCopy(); + + u_strncat(_data->str, str._data->str, str._data->length); return *this; } String& String::append(const Char& ch) { - _str.append(1, ch); + if(!_data) + _data = alloc(2); + else if(_data->size <= _data->length + 2) + resize(_data->length + 2); + else + deepCopy(); + + bool error = false; + U16_APPEND(_data->str, _data->length, _data->size, (const uchar32_t)ch, error); + return *this; } -size_t String::find(const String& str, size_t pos) const +#define getUCharOffset(data, pos, offset) U16_FWD_N(data->str, offset, data->length, pos) + +size_t String::find(const String& str, size_t pos/*=0*/) const { - return _str.find(str._str, pos); + if(!_data || !_data->length || !str._data || !str._data->length) + return npos; + + size_t offset = 0; + getUCharOffset(_data, pos, offset); + + UChar* res = u_strFindFirst(_data->str + offset, _data->length, + str._data->str, str._data->length); + + if(!res) + return npos; + + return u_countChar32(_data->str + offset, res - (_data->str + offset)); } -size_t String::find(const Char& ch, size_t pos) const +size_t String::find(const Char& ch, size_t pos/*=0*/) const { - return _str.find(ch, pos); + if(!_data || !_data->length) + return npos; + + size_t offset = 0; + getUCharOffset(_data, pos, offset); + + UChar* res = u_memchr32(_data->str + offset, (const uchar32_t&)ch, _data->length); + + if(!res) + return npos; + + return u_countChar32(_data->str + offset, res - (_data->str + offset)); } -size_t String::rfind(const String& str, size_t pos) const +size_t String::rfind(const String& str, size_t pos/*=npos*/) const { - return _str.rfind(str._str, pos); + if(!_data || !_data->length || !str._data || !str._data->length) + return npos; + + if(pos==npos) + pos = size(); + + size_t searchLen = 0; + getUCharOffset(_data, pos, searchLen); + + UChar* res = u_strFindLast(_data->str, searchLen, + str._data->str, str._data->length); + + if(!res) + return npos; + + return u_countChar32(_data->str, res - _data->str); } -size_t String::rfind(const Char& ch, size_t pos) const +size_t String::rfind(const Char& ch, size_t pos/*=npos*/) const { - return _str.rfind(ch, pos); + if(!_data || !_data->length) + return npos; + + if(pos==npos) + pos = size(); + + size_t searchLen = 0; + getUCharOffset(_data, pos, searchLen); + + UChar* res = u_memrchr32(_data->str, (const uchar32_t&)ch, searchLen); + + if(!res) + return npos; + + return u_countChar32(_data->str, res - _data->str); } -size_t String::find_first_of(const String& str, size_t pos) const +size_t String::find_first_of(const String& str, size_t pos/*=0*/) const { - return _str.find_first_of(str._str, pos); + return find(str, pos); } -size_t String::find_first_of(const Char& ch, size_t pos) const +size_t String::find_first_of(const Char& ch, size_t pos/*=0*/) const { - return _str.find_first_of(ch, pos); + return find(ch, pos); } size_t String::find_first_not_of(const String& str, size_t pos) const { - return _str.find_first_not_of(str._str, pos); + return 0; } size_t String::find_first_not_of(const Char& ch, size_t pos) const { - return _str.find_first_not_of(ch, pos); + return 0; } -size_t String::find_last_of(const String& str, size_t pos) const +size_t String::find_last_of(const String& str, size_t pos /*=npos*/) const { - return _str.find_last_of(str._str, pos); + return rfind(str, pos); } -size_t String::find_last_of(const Char& ch, size_t pos) const +size_t String::find_last_of(const Char& ch, size_t pos /*=npos*/) const { - return _str.find_last_of(ch, pos); + return rfind(ch, pos); } size_t String::find_last_not_of(const String& str, size_t pos) const { - return _str.find_last_not_of(str._str, pos); + return 0; } size_t String::find_last_not_of(const Char& ch, size_t pos) const { - return _str.find_last_not_of(ch, pos); + return 0; } -const Char& String::at(size_t pos) const +Char String::at(size_t pos) const { - return at(pos); + uchar32_t cp; + U16_GET(_data->str, 0, pos, _data->length, cp); + return Char(cp); } -Char& String::at(size_t pos) +int String::compare(const String& str) const throw() { - return at(pos); + if(!_data || _data->length == 0) + { + if(!str._data || _data->length == 0) + return 0; + + return +1; + } + else if(!str._data || _data->length == 0) + return -1; + + return u_strncmp(_data->str, str._data->str, + _data->length < str._data->length ? _data->length : str._data->length); } std::string String::local() const { - return toCharset(nl_langinfo(CODESET)); -} + if(!_data || _data->length == 0) + return std::string(); -std::string String::latin1() const -{ - return toCharset("LATIN1"); + char* ret = new char[_data->length]; + u_austrncpy(ret, _data->str, _data->length); + std::string retstr(ret); + delete[] ret; + return retstr; } std::string String::utf8() const { - return toCharset("UTF8"); -} + if(!_data || _data->length == 0) + return std::string(); -const Char& String::operator[](size_t pos) const -{ - return (Char&)_str.operator[](pos); -} + ::int32_t resultLen = 0; + UErrorCode errorCode = U_ZERO_ERROR; -Char& String::operator[](size_t pos) -{ - return (Char&)_str.operator[](pos); + // pre-flight .. get the required storage ... + u_strToUTF8(0, 0, &resultLen, _data->str, _data->length, &errorCode); + + char* ret = new char[resultLen + 1]; + ::int32_t retLen = 0; + + errorCode = U_ZERO_ERROR; + u_strToUTF8(ret, resultLen + 1, &retLen, _data->str, _data->length, &errorCode); + std::string retstr(ret); + delete[] ret; + return retstr; } -String& String::operator=(const String& str) +Char String::operator[](size_t pos) const { - _str = str._str; - return *this; + return at(pos); } -String& String::operator=(const ustring& str) +String& String::operator=(const String& str) { - _str = str; + _data = str._data; return *this; } String& String::operator=(const char* str) { - *this = fromLatin1(str); + *this = fromLocal(str); return *this; } String& String::operator=(const std::string& str) { - *this = fromLatin1(str.c_str(), str.size()); + *this = fromLocal(str.c_str(), str.size()); return *this; } @@ -234,23 +411,22 @@ bool String::operator==(const String& str) const throw() { - return _str == str._str; + return compare(str) == 0; } bool String::operator!=(const String& str) const throw() { - return !operator==(str); - return false; + return compare(str) != 0; } bool String::operator<(const String& str) const throw() { - return _str < str._str; + return compare(str) < 0; } bool String::operator>(const String& str) const throw() { - return _str > str._str; + return compare(str) > 0; } bool String::operator<=(const String& str) const throw() @@ -268,15 +444,14 @@ if(count == npos) count = strlen(str); - return fromCharset(nl_langinfo(CODESET), str, count); -} + SharedPtr<Data> data(alloc(count + 1)); -String String::fromLatin1(const char* str, size_t count) -{ - if(count == npos) - count = strlen(str); + u_uastrncpy(data->str, str, count); + data->length = u_strlen(data->str); - return fromCharset("LATIN1", str, count); + String ret; + ret._data = data; + return ret; } String String::fromUtf8(const char* str, size_t count) @@ -294,85 +469,12 @@ String String::fromCharset(const char* charset, const char* str, size_t count) { - ustring outstr; - char outstrbuf[1024]; - - iconv_t icd = iconv_open("UCS4", charset); - - char* inbuf = (char*)str; - size_t inbytesleft = count; - - char* outbuf = (char*)outstrbuf; - size_t outbytesleft = sizeof(outstrbuf); - -_do_iconv: - size_t ret = iconv(icd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - - // get number of chars converted ... - unsigned int numchars = sizeof(outstrbuf) - outbytesleft; - unsigned int numuchars = numchars / sizeof(uchar_t); - - // append already converted chars to our string ... - outstr.append((uchar_t*)outstrbuf, numuchars); - - if(ret == (size_t)-1) - { - if(errno == E2BIG) - { - outbytesleft = sizeof(outstrbuf); - outbuf = outstrbuf; - goto _do_iconv; - } - else - { - //TODO: throw InvalidString - throw; - } - } - - iconv_close(icd); - return outstr; + return String(); } std::string String::toCharset(const char* charset) const { - std::string outstr; - char outstrbuf[1024]; - - iconv_t icd = iconv_open(charset, "UCS4"); - - char* inbuf = (char*)_str.c_str(); - size_t inbytesleft = _str.size() * sizeof(uchar_t); - - char* outbuf = (char*)outstrbuf; - size_t outbytesleft = sizeof(outstrbuf); - -_do_iconv: - size_t ret = iconv(icd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - - // get number of chars converted ... - unsigned int numchars = sizeof(outstrbuf) - outbytesleft; - - // append already converted chars to our string ... - outstr.append(outstrbuf, numchars); - - if(ret == (size_t)-1) - { - if(errno == E2BIG) - { - outbytesleft = sizeof(outstrbuf); - outbuf = outstrbuf; - goto _do_iconv; - } - else - { - //TODO: throw InvalidString - throw; - } - } - - iconv_close(icd); - return outstr; + return std::string(); } String operator+(const String& lhs, const String& rhs) @@ -387,7 +489,7 @@ std::ostream& operator<<(std::ostream& os, const String& str) { - os << str.utf8(); + os << str.local(); return os; } --- unicodedata.h DELETED --- --- ustring.cpp DELETED --- --- unicodedata.awk DELETED --- |
From: Christian P. <cp...@us...> - 2005-05-20 14:11:41
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7319 Modified Files: Char.h String.h Log Message: - Dropping own Unicode implementation. We now use UCI Index: Char.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Char.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Char.h 6 May 2005 15:32:11 -0000 1.5 +++ Char.h 20 May 2005 14:11:32 -0000 1.6 @@ -23,177 +23,74 @@ #include <pclasses/Export.h> #include <pclasses/BasicTypes.h> -#include <pclasses/Unicode/uctype.h> -#include <cwchar> +#include <pclasses/Exception.h> namespace P { namespace Unicode { +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: - //! 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 - }; + Char(uchar32_t ch = 0) throw(InvalidCharError); + Char(const Char& ch) throw(); - //! Character Decomposition Tag - enum Decomposition { - Decomp_None, - Decomp_Standard, - Decomp_Font, // <font> - Decomp_NoBreak, // <noBreak> - Decomp_Initial, // <initial> - Decomp_Medial, // <medial> - Decomp_Final, // <final> - Decomp_Isolated, // <isolated> - Decomp_Encircled, // <circle> - Decomp_Superscript, // <super> - Decomp_Subscript, // <sub> - Decomp_Vertical, // <vertical> - Decomp_Wide, // <wide> - Decomp_Narrow, // <narrow> - Decomp_Small, // <small> - Decomp_Square, // <square> - Decomp_Fraction, // <fraction> - Decomp_Compat // <compat> - }; + bool isDefined() const throw(); - //! 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 - }; + bool isAlphabetic() const throw(); + bool isAlphaNumeric() const throw(); - Char(uchar_t ch = 0); - Char(const Char& ch); + bool isDigit() const throw(); + int digitValue() const throw(); - bool isLetter() const; + bool isNumeric() const throw(); + double numericValue() const throw(); - bool isSymbol() const; - bool isPunct() const; - bool isMark() const; + bool isLower() const throw(); + Char toLower() const throw(); - bool isNumber() const; - float toNumber() const; + bool isUpper() const throw(); + Char toUpper() const throw(); - bool isLower() const; - Char toLower() const; + bool isTitle() const throw(); + Char toTitle() const throw(); - bool isUpper() const; - Char toUpper() const; + bool isMirrored() const throw(); + Char mirrorChar() const throw(); - bool isMirrored() const; + bool isWhiteSpace() const throw(); - Category category() const; - BidiClass bidiClass() const; - Decomposition decompTag() const; - CombiningClass combiningClass() const; + bool isIgnorable() const throw(); - operator const uchar_t& () const throw(); + operator const uchar32_t& () const throw(); - Char& operator=(uchar_t ch); - Char& operator=(const Char& ch); + Char& operator=(uchar32_t ch) throw(InvalidCharError); + Char& operator=(const Char& ch) throw(); - bool operator==(const Char& ch) const; - bool operator!=(const Char& ch) const; + bool operator==(const Char& ch) const throw(); + bool operator!=(const Char& ch) const throw(); - bool operator<(const Char& ch) const; - bool operator>(const Char& ch) const; + bool operator<(const Char& ch) const throw(); + bool operator>(const Char& ch) const throw(); - bool operator<=(const Char& ch) const; - bool operator>=(const Char& ch) const; + bool operator<=(const Char& ch) const throw(); + bool operator>=(const Char& ch) const throw(); - static const Char& eof(); - static const Char& nl(); - static const Char& cr(); + static const Char& eof() throw(); + static const Char& nl() throw(); + static const Char& cr() throw(); private: - uchar_t _char; - + uchar32_t _char; }; } // !namespace Unicode Index: String.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/String.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- String.h 28 Apr 2005 10:15:01 -0000 1.5 +++ String.h 20 May 2005 14:11:32 -0000 1.6 @@ -24,8 +24,8 @@ #include <pclasses/Export.h> #include <pclasses/BasicTypes.h> #include <pclasses/Alloc.h> +#include <pclasses/SharedPtr.h> #include <pclasses/Unicode/Char.h> -#include <pclasses/Unicode/ustring.h> #include <string> @@ -40,13 +40,21 @@ npos = (size_t)-1 }; - typedef ustring::size_type size_type; - typedef ustring::const_iterator const_iterator; - typedef ustring::iterator iterator; + typedef size_t size_type; + + class Iterator; + class ConstIterator; + + typedef Iterator iterator; + typedef ConstIterator const_iterator; String(); + String(size_t sz); + String(const String& str); - String(const ustring& str); + String(const String& str, size_t offset, size_t count = npos); + + String(const Char* str, size_t count = npos); String(const std::string& str); String(const char* str, size_t count = npos); @@ -58,14 +66,18 @@ bool empty() const throw(); size_t size() const throw(); - const Char& at(size_t index) const; - Char& at(size_t index); + size_t capacity() const throw(); + void resize(size_t sz); + + Char at(size_t index) const; String substr(size_t offset = 0, size_t length = npos) const; String left(size_t length) const; String right(size_t length) const; + int compare(const String& str) const throw(); + String& append(const String& str); String& append(const Char& ch); @@ -87,11 +99,9 @@ size_t find_last_not_of(const String& str, size_t pos = npos) const; size_t find_last_not_of(const Char& ch, size_t pos = npos) const; - Char& operator[](size_t pos); - const Char& operator[](size_t pos) const; + Char operator[](size_t pos) const; String& operator=(const String& str); - String& operator=(const ustring& str); String& operator=(const char* str); String& operator=(const std::string& str); @@ -111,9 +121,6 @@ //! Returns the string in local encoding std::string local() const; - //! Returns the string in latin1 encoding - std::string latin1() const; - //! Returns the string in utf8 encoding std::string utf8() const; @@ -121,8 +128,6 @@ static String fromLocal(const char* str, size_t count = npos); - static String fromLatin1(const char* str, size_t count = npos); - static String fromUtf8(const char* str, size_t count = npos); static String fromUcs2(const char* str, size_t count); @@ -131,7 +136,12 @@ size_t count); private: - ustring _str; + struct Data; + + static Data* alloc(size_t size); + void deepCopy(); + + SharedPtr<Data> _data; }; PUNICODE_EXPORT String operator+(const String& lhs, const String& rhs); |
From: Christian P. <cp...@us...> - 2005-05-20 14:10:54
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7164 Modified Files: Makefile.am Removed Files: uctype.h ustring.h Log Message: - Droping own Unicode implementation, we now use UCI Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 16 Jan 2005 00:08:09 -0000 1.3 +++ Makefile.am 20 May 2005 14:10:45 -0000 1.4 @@ -2,4 +2,4 @@ INCLUDES = METASOURCES = AUTO -pclasses_unicode_include_HEADERS = uctype.h ustring.h Char.h String.h TextStream.h +pclasses_unicode_include_HEADERS = Char.h String.h TextStream.h --- ustring.h DELETED --- --- uctype.h DELETED --- |
From: Christian P. <cp...@us...> - 2005-05-07 13:27:20
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17478/src/Unicode Modified Files: ustring.cpp Log Message: - Fixed wrong declaration of Unicode::umemchr(). Index: ustring.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/ustring.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ustring.cpp 6 May 2005 15:32:11 -0000 1.3 +++ ustring.cpp 7 May 2005 13:27:09 -0000 1.4 @@ -50,7 +50,7 @@ return n; } -const uchar_t* umemchr(const uchar_t* s, size_t n, uchar_t a) +const uchar_t* umemchr(const uchar_t* s, uchar_t a, size_t n) { while(n-- > 0) { |
From: Christian P. <cp...@us...> - 2005-05-07 13:27:20
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17478/include/pclasses/Unicode Modified Files: ustring.h Log Message: - Fixed wrong declaration of Unicode::umemchr(). Index: ustring.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/ustring.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ustring.h 26 Apr 2005 12:16:02 -0000 1.3 +++ ustring.h 7 May 2005 13:27:09 -0000 1.4 @@ -34,7 +34,7 @@ PUNICODE_EXPORT int umemcmp(const uchar_t* s1, const uchar_t* s2, size_t n); PUNICODE_EXPORT size_t ucslen(const uchar_t* s); -PUNICODE_EXPORT const uchar_t* umemchr(const uchar_t* s, size_t n, uchar_t a); +PUNICODE_EXPORT const uchar_t* umemchr(const uchar_t* s, uchar_t a, size_t n); PUNICODE_EXPORT uchar_t* umemmove(uchar_t* s1, const uchar_t* s2, size_t n); PUNICODE_EXPORT uchar_t* umemcpy(uchar_t* s1, const uchar_t* s2, size_t n); PUNICODE_EXPORT uchar_t* umemset(uchar_t* s, size_t n, uchar_t a); |
From: Christian P. <cp...@us...> - 2005-05-07 13:26:10
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17167/include/pclasses Modified Files: CoreMutex.h Log Message: - Added missing export macro Index: CoreMutex.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/CoreMutex.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CoreMutex.h 6 May 2005 15:21:01 -0000 1.1 +++ CoreMutex.h 7 May 2005 13:26:02 -0000 1.2 @@ -28,28 +28,28 @@ //! CoreMutex /*! - The CoreMutex class is a minimalistic Mutex class used by the + The CoreMutex class is a minimalistic Mutex class used by the P::Classes Core module where locking is necessary. */ class PCORE_EXPORT CoreMutex: public NonCopyable { - public: - CoreMutex(); - ~CoreMutex(); - - void lock() throw(); - void unlock() throw(); + public: + CoreMutex(); + ~CoreMutex(); - class ScopedLock: public NonCopyable { - public: - ScopedLock(CoreMutex& mtx); - ~ScopedLock(); + void lock() throw(); + void unlock() throw(); - private: - CoreMutex& _mtx; - }; + class PCORE_EXPORT ScopedLock: public NonCopyable { + public: + ScopedLock(CoreMutex& mtx); + ~ScopedLock(); - private: - unsigned long _handle; + private: + CoreMutex& _mtx; + }; + + private: + unsigned long _handle; }; } // !namespace P |
From: Christian P. <cp...@us...> - 2005-05-07 13:25:29
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16744/src/System Modified Files: SharedLibCache.h SharedLib.dl.cpp SharedLib.ltdl.cpp SharedLib.shl.cpp SharedLib.win32.cpp Log Message: - SharedLibCache now caches the Unicode file names instead of their utf8 representation. - SharedLib: use absolute paths when loading / and caching filenames. Index: SharedLibCache.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLibCache.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SharedLibCache.h 28 Apr 2005 10:37:50 -0000 1.5 +++ SharedLibCache.h 7 May 2005 13:25:20 -0000 1.6 @@ -23,6 +23,7 @@ #include "pclasses/Trace.h" #include "pclasses/Phoenix.h" +#include "pclasses/Unicode/String.h" #include "pclasses/System/CriticalSection.h" #include <map> @@ -36,7 +37,7 @@ template <typename handle_t, typename destroyF> struct SharedLibCache { - typedef std::map<std::string, handle_t> map_t; + typedef std::map<Unicode::String, handle_t> map_t; typedef typename map_t::const_iterator iterator; SharedLibCache() @@ -56,7 +57,7 @@ _handles.clear(); } - void add(const std::string& name, handle_t handle) + void add(const Unicode::String& name, handle_t handle) { iterator i = _handles.find(name); if(i == _handles.end()) @@ -66,7 +67,7 @@ } } - iterator lookup(const std::string& name) const + iterator lookup(const Unicode::String& name) const { return _handles.find(name); } Index: SharedLib.ltdl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.ltdl.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- SharedLib.ltdl.cpp 28 Apr 2005 10:37:50 -0000 1.9 +++ SharedLib.ltdl.cpp 7 May 2005 13:25:20 -0000 1.10 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/Trace.h" +#include "pclasses/System/Path.h" #include "pclasses/System/SharedLib.h" #include "SharedLibCache.h" @@ -56,13 +57,13 @@ Cache& cache = shared_lib_cache<lt_dlhandle, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); - std::string utf8name = name.utf8(); + Unicode::String absName = Path(name).absPath(); // see if we can get it from the handle cache ... - Cache::iterator i = cache.lookup(utf8name); + Cache::iterator i = cache.lookup(absName); if(i == cache.end()) { - lt_dlhandle h = lt_dlopen(utf8name.c_str() /** BindMode2Flags(mode) */ ); + lt_dlhandle h = lt_dlopen(absName.utf8().c_str() /** BindMode2Flags(mode) */ ); if(!h) throw SystemError(errno, lt_dlerror(), P_SOURCEINFO); @@ -70,7 +71,7 @@ P_TRACE(SharedLib) << "library opened, handle=" << _handle; // add it to the handle cache - cache.add(utf8name, h); + cache.add(absName, h); } else { Index: SharedLib.dl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dl.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- SharedLib.dl.cpp 28 Apr 2005 10:37:50 -0000 1.11 +++ SharedLib.dl.cpp 7 May 2005 13:25:20 -0000 1.12 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/Trace.h" +#include "pclasses/System/Path.h" #include "pclasses/System/SharedLib.h" #include "SharedLibCache.h" @@ -71,20 +72,20 @@ Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); - std::string utf8name = name.utf8(); + Unicode::String absName = Path(name).absPath(); // see if we can get it from the handle cache ... - Cache::iterator i = cache.lookup(utf8name); + Cache::iterator i = cache.lookup(absName); if(i == cache.end()) { - _handle = (unsigned long)dlopen(utf8name.c_str(), BindMode2Flags(mode)); + _handle = (unsigned long)dlopen(absName.utf8().c_str(), BindMode2Flags(mode)); if(!_handle) throw SystemError(errno, dlerror(), P_SOURCEINFO); P_TRACE(SharedLib) << "library opened, handle=" << _handle; // add it to the handle cache - cache.add(utf8name, _handle); + cache.add(absName, _handle); } else { Index: SharedLib.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.win32.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- SharedLib.win32.cpp 28 Apr 2005 10:37:50 -0000 1.9 +++ SharedLib.win32.cpp 7 May 2005 13:25:20 -0000 1.10 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/Trace.h" +#include "pclasses/System/Path.h" #include "pclasses/System/SharedLib.h" #include "SharedLibCache.h" @@ -46,19 +47,21 @@ Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); + Unicode::String absName = Path(name).absPath(); + // se if we can get it from the handle cache ... - Cache::iterator i = cache.lookup(name.utf8()); + Cache::iterator i = cache.lookup(absName); if(i == cache.end()) { //@fixme .. use win32 Unicode API !!! - _handle = (unsigned long)LoadLibrary(name.utf8().c_str()); + _handle = (unsigned long)LoadLibrary(absName.utf8().c_str()); if(!_handle) throw SystemError(GetLastError(), "Could not load shared library", P_SOURCEINFO); P_TRACE(SharedLib) << "library opened, handle=" << _handle; // add the handle to the cache - cache.add(name.utf8(), _handle); + cache.add(absName, _handle); } else { Index: SharedLib.shl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.shl.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- SharedLib.shl.cpp 28 Apr 2005 10:37:50 -0000 1.8 +++ SharedLib.shl.cpp 7 May 2005 13:25:20 -0000 1.9 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/Trace.h" +#include "pclasses/System/Path.h" #include "pclasses/System/SharedLib.h" #include "SharedLibCache.h" @@ -64,20 +65,20 @@ Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); - std::string utf8name = name.utf8(); + Unicode::String absName = Path(name).absPath(); // se if we have the handle cached ... - Cache::Iterator i = cache.lookup(utf8name); + Cache::Iterator i = cache.lookup(absName); if(i == cache.end()) { - _handle = (unsigned long)shl_load(utf8name.c_str(), BindMode2Flags(mode)); + _handle = (unsigned long)shl_load(absName.utf8().c_str(), BindMode2Flags(mode)); if(!_handle) throw SystemError(errno, "Error loading shared library", P_SOURCEINFO); P_TRACE(SharedLib) << "library opened, handle=" << _handle; // add the handle to the cache - cache.add(utf8name, _handle); + cache.add(absName, _handle); } else { |
From: Christian P. <cp...@us...> - 2005-05-07 13:23:50
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16085/src/System Modified Files: PathFinder.cpp Log Message: - Removed basename(), dirSeparator() and isAccessible() from PathFinder, it now uses the Path class. - Use absolute pathes when finding Files ... without we may cache relative paths that point to the same absolute path. Index: PathFinder.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/PathFinder.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- PathFinder.cpp 28 Apr 2005 10:21:44 -0000 1.6 +++ PathFinder.cpp 7 May 2005 13:23:39 -0000 1.7 @@ -15,6 +15,7 @@ #endif #include "pclasses/Trace.h" +#include "pclasses/System/Path.h" #include "pclasses/System/PathFinder.h" namespace P { @@ -91,42 +92,6 @@ _exts.insert(_exts.end(), ne.begin(), ne.end()); } -// static -bool PathFinder::isAccessible(const Unicode::String & path) -{ -#if WIN32 -# define CHECKACCESS _access -# define CHECKRIGHTS 0 -#else -# define CHECKACCESS access -# define CHECKRIGHTS F_OK -#endif - - return 0 == CHECKACCESS(path.utf8().c_str(), CHECKRIGHTS); -#undef CHECKACCESS -#undef CHECKRIGHTS -} - -Unicode::String PathFinder::basename(const Unicode::String& name) -{ - Unicode::String::size_type slashat = - name.find_last_of(PathFinder::dirSeparator()); - - if(slashat == Unicode::String::npos) - return name; - - return name.substr(slashat + 1); -} - -Unicode::String PathFinder::dirSeparator() -{ -#ifdef WIN32 - return Unicode::String( "\\" ); -#else - return Unicode::String( "/" ); -#endif -} - Unicode::String PathFinder::pathSeparator() { #ifdef WIN32 @@ -148,7 +113,7 @@ #define CHECKPATH(CHECKAT) \ P_TRACE(PathFinder) << "testing '" << CHECKAT << "'"; \ - if( ! CHECKAT.empty() && PathFinder::isAccessible( CHECKAT ) ) \ + if( ! CHECKAT.empty() && Path(CHECKAT).isAccessible() ) \ { \ P_TRACE(PathFinder) << "found '" << CHECKAT << "'"; \ return _hitcache.insert(std::make_pair(resource, CHECKAT)).first->second; \ @@ -166,17 +131,12 @@ } } - CHECKPATH(resource); + //security risk! do not search in current directory by default!! + //CHECKPATH(resource); string_list::const_iterator piter = _paths.begin(); string_list::const_iterator eiter = _exts.begin(); - if(PathFinder::isAccessible(resource)) - { - P_TRACE(PathFinder) << "found '" << resource << "'"; - return resource; - } - Unicode::String path, ext; Unicode::String checkhere; @@ -185,7 +145,8 @@ path = (*piter); if(!path.empty()) { - path += PathFinder::dirSeparator(); + path = Path(path).absPath(); + path += Path::separator(); } ++piter; |
From: Christian P. <cp...@us...> - 2005-05-07 13:23:50
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16085/include/pclasses/System Modified Files: PathFinder.h Log Message: - Removed basename(), dirSeparator() and isAccessible() from PathFinder, it now uses the Path class. - Use absolute pathes when finding Files ... without we may cache relative paths that point to the same absolute path. Index: PathFinder.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/PathFinder.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- PathFinder.h 28 Apr 2005 10:21:43 -0000 1.7 +++ PathFinder.h 7 May 2005 13:23:39 -0000 1.8 @@ -119,23 +119,6 @@ const string_list & extensions() const; /** - Returns true if path is readable. - */ - static bool isAccessible(const Unicode::String& path); - - /** - Returns the "base name" of the given string: any part - following the final directory separator character. - */ - static Unicode::String basename(const Unicode::String &); - - /** - Returns a platform-dependent directory separator. This - is set when the class is compiled. - */ - static Unicode::String dirSeparator(); - - /** Returns a platform-dependent path-list separator string. This is set when the class is compiled. */ |
From: Christian P. <cp...@us...> - 2005-05-07 13:20:50
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15622/src/System Added Files: Path.posix.cpp Log Message: - Added System::Path for obtaining dirName/baseName of a path. Also used to retrieve absolute pathes. --- NEW FILE: Path.posix.cpp --- /*************************************************************************** * Copyright (C) 2005 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/System/Path.h" #include <errno.h> #include <limits.h> #include <stdlib.h> #include <unistd.h> namespace P { namespace System { Path::Path(const Unicode::String& path) { // cut trailing "/" if not leading ... if(path.size() > 1 && path.substr(path.size()-1) == separator()) _path = path.substr(0,path.size()-1); else _path = path; } Path::~Path() { } Unicode::String Path::dirName() const throw() { Unicode::String::size_type slashat = _path.find_last_of(separator()); if(slashat == Unicode::String::npos || slashat == 0) return _path; return _path.substr(0, slashat); } Unicode::String Path::absDirName() const throw(SystemError) { char* absDirName = realpath(dirName().utf8().c_str(), 0); if(!absDirName) throw SystemError(errno, "Could not resolve real path", P_SOURCEINFO); Unicode::String res = Unicode::String::fromUtf8(absDirName); free(absDirName); return res; } Unicode::String Path::baseName() const throw() { Unicode::String::size_type slashat = _path.find_last_of(separator()); if(slashat == Unicode::String::npos) return _path; return _path.substr(slashat + 1); } Unicode::String Path::path() const throw() { return _path; } Unicode::String Path::absPath() const throw(SystemError) { char* absPath = realpath(_path.utf8().c_str(), 0); if(!absPath) throw SystemError(errno, "Could not resolve real path", P_SOURCEINFO); Unicode::String res = Unicode::String::fromUtf8(absPath); free(absPath); return res; } bool Path::isAccessible() const throw() { return 0 == access(_path.utf8().c_str(), F_OK); } Path& Path::operator=(const Unicode::String& path) { _path = path; return *this; } const char* Path::separator() throw() { return "/"; } } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-05-07 13:20:49
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15622/include/pclasses/System Added Files: Path.h Log Message: - Added System::Path for obtaining dirName/baseName of a path. Also used to retrieve absolute pathes. --- NEW FILE: Path.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_System_Path_h #define P_System_Path_h #include <pclasses/Export.h> #include <pclasses/Unicode/String.h> #include <pclasses/System/SystemError.h> namespace P { namespace System { class PSYSTEM_EXPORT Path { public: Path(const Unicode::String& path); ~Path(); //! Returns the name of the directory (may be relative) Unicode::String dirName() const throw(); //! Returns the absolute directory name Unicode::String absDirName() const throw(SystemError); //! Returns the name of the filesystem object Unicode::String baseName() const throw(); //! Returns the full path to the filesystem object Unicode::String path() const throw(); //! Returns the full absolute path to the filesystem object Unicode::String absPath() const throw(SystemError); bool isAccessible() const throw(); Path& operator=(const Unicode::String& path); static const char* separator() throw(); private: Unicode::String _path; }; } // !namespace System } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-05-07 11:56:34
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29836/include/pclasses Modified Files: Trace.h Log Message: - Fixed P_TRACE macros Index: Trace.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Trace.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Trace.h 6 May 2005 15:26:24 -0000 1.3 +++ Trace.h 7 May 2005 11:56:21 -0000 1.4 @@ -113,11 +113,11 @@ }; #if defined(_DEBUG) && !defined(NO_DEBUG) -# define P_TRACE(c) NullTraceStream() -# define P_TRACE_GLOBAL(c) NullTraceStream() -#else # define P_TRACE(c) P::TraceLog::instance().stream(P_SOURCEINFO,#c,this)() # define P_TRACE_GLOBAL(c) P::TraceLog::instance().stream(P_SOURCEINFO)() +#else +# define P_TRACE(c) NullTraceStream() +# define P_TRACE_GLOBAL(c) NullTraceStream() #endif } // !namespace P |