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: stephan b. <sg...@us...> - 2004-12-26 14:42:03
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9326/src/s11n Modified Files: Makefile.toc Log Message: Brought test_bin_LDADD up to date. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/Makefile.toc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.toc 26 Dec 2004 12:30:05 -0000 1.7 +++ Makefile.toc 26 Dec 2004 14:41:53 -0000 1.8 @@ -53,6 +53,7 @@ BIN_PROGRAMS = test test_bin_OBJECTS = test.o libpclasses_s11n.so +test_bin_LDADD = $(LIBP_TESTS_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) $(LIBPUTIL_CLIENT_LDADD) include $(TOC_MAKESDIR)/BIN_PROGRAMS.make all: symlink-headers subdirs SHARED_LIBS |
From: stephan b. <sg...@us...> - 2004-12-26 14:41:16
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9210/src/s11n Modified Files: SIO.h Log Message: Added s11n_cast(). Index: SIO.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/SIO.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SIO.h 26 Dec 2004 09:44:27 -0000 1.4 +++ SIO.h 26 Dec 2004 14:41:07 -0000 1.5 @@ -221,6 +221,23 @@ */ std::string serializerClass(); + /** + Serializes fromobj and deserializes the data by passing + it to toobj. Returns false if either operation fails. + + SerializableT1 and SerializableT must of course be + Serializables for this to work. + + See ::P::s11n::s11n_cast() for full details, including + tips on how to use this to easily convert containers + to different types. + */ + template <typename SerializableT1, typename SerializableT2> + bool s11n_cast( const SerializableT1 & fromobj, SerializableT2 & toobj ) + { + return ::P::s11n::s11n_cast<S11nNode,SerializableT1,SerializableT2>( fromobj, toobj ); + } + } // namespace SIO } // namespace P |
From: stephan b. <sg...@us...> - 2004-12-26 14:39:58
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8884 Modified Files: configure.pclasses2 Log Message: Added optional libz/bz2 tests. Index: configure.pclasses2 =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.pclasses2,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- configure.pclasses2 26 Dec 2004 09:20:57 -0000 1.14 +++ configure.pclasses2 26 Dec 2004 14:39:48 -0000 1.15 @@ -24,9 +24,9 @@ ############################################################ -# reminder: need to add SharedLib.ltdl.cpp toc_test libltdl || toc_test_require libdl # prefer ltdl, else allow dl. -# toc_test_require libdl +toc_test bzlib +toc_test zlib ############################################################ |
From: stephan b. <sg...@us...> - 2004-12-26 14:39:10
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8737/src/s11n Modified Files: traits.h Log Message: Removed a bunch of commented-out code. Index: traits.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/traits.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- traits.h 26 Dec 2004 04:09:28 -0000 1.4 +++ traits.h 26 Dec 2004 14:39:01 -0000 1.5 @@ -371,61 +371,6 @@ typedef ::P::s11n::default_serialize_functor deserialize_functor; }; // end s11n_traits<> -// namespace Private -// { -// /** -// An internal helper to enable -// s11n_traits<T*>. Wraps up calls to ProxyT's -// operator()(NodeT,T&) by providing -// operator(NodeT,T*) implementations which -// dereference the T pointer and pass it on to -// ProxyT's implementation. - -// Achtung: doesn't compile properly: ambiguity problem. -// */ -// template <typename ProxyT> -// struct ser_pointer_type_wrapper -// { -// typedef ProxyT proxy_type; -// proxy_type proxy; - -// /** -// Returns proxy( dest, src ). -// */ -// template <typename NodeT, typename SerializableT> -// bool operator()( NodeT & dest, const SerializableT * src ) const -// { -// if( ! src ) return false; -// return proxy( dest, *src ); -// } - -// /** -// Returns proxy( src, dest ). -// */ -// template <typename NodeT, typename DeserializableT> -// bool operator()( const NodeT & src, DeserializableT * dest ) const -// { -// if( ! dest ) return false; -// return proxy( src, *dest ); -// } -// }; -// } // namespace Private - -// /** -// A specialization to catch pointer types. With this specialization -// in place, de/serialize( node, foo ) and de/serialize(node, &foo) will -// work identically. -// */ -// template <typename SerializableType> -// struct s11n_traits < SerializableType * > -// { -// typedef s11n_traits < SerializableType > parent_type; -// typedef typename parent_type::serializable_type serializable_type; -// typedef typename Private::ser_pointer_type_wrapper<typename parent_type::serialize_functor> serialize_functor; -// typedef typename Private::ser_pointer_type_wrapper<typename parent_type::deserialize_functor> deserialize_functor; -// typedef typename parent_type::factory_type factory_type; -// }; - } } // namespace P::s11n |
From: stephan b. <sg...@us...> - 2004-12-26 14:38:31
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8647/src/s11n Modified Files: reg_serializable_traits.h Log Message: Tweaked the registration a bit. Index: reg_serializable_traits.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/reg_serializable_traits.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- reg_serializable_traits.h 26 Dec 2004 04:09:28 -0000 1.4 +++ reg_serializable_traits.h 26 Dec 2004 14:38:22 -0000 1.5 @@ -81,12 +81,7 @@ #endif #ifndef PS11N_TYPE_NAME -# ifdef PS11N_NAME // older convention -# define PS11N_TYPE_NAME PS11N_NAME -# undef PS11N_NAME -# else -# error "PS11N_TYPE_NAME must be set before including this file. Set it to the stringified form of PS11N_TYPE." -# endif +# error "PS11N_TYPE_NAME must be set before including this file. Set it to the stringified form of PS11N_TYPE." #endif @@ -114,17 +109,25 @@ # define PS11N_REG_CLLITE 0 #endif // PS11N_FACTORY_TYPE +#include <pclasses/s11n/traits.h> //////////////////////////////////////////////////////////////////////// // Set up s11n_traits<> specialization... -namespace P {namespace s11n { +namespace P { namespace s11n { template <> struct s11n_traits < PS11N_TYPE > #if PS11N_INHERIT - : public ::P::s11n::s11n_traits < PS11N_TYPE_INTERFACE > + : public s11n_traits < PS11N_TYPE_INTERFACE > #endif { +// #if PS11N_INHERIT +// typedef s11n_traits < PS11N_TYPE_INTERFACE > ParentType; +// typedef PS11N_TYPE serializable_type; +// typedef ParentType::serialize_functor serialize_functor; +// typedef ParentType::deserialize_functor deserialize_functor; +// typedef ParentType::factory_type factory_type; +// #endif #if ! PS11N_INHERIT typedef PS11N_TYPE serializable_type; typedef PS11N_SERIALIZE_FUNCTOR serialize_functor; |
From: Christian P. <cp...@us...> - 2004-12-26 14:38:22
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8454/src/System Modified Files: SharedLib.dl.cpp SharedLib.ltdl.cpp SharedLib.shl.cpp SharedLib.win32.cpp SharedLibCache.h Log Message: Added SharedLibCache to libltdl implementation. Added templatetized handle type to SharedLibCache. stephan: please see if this is a solution with lt_dlclose() Index: SharedLibCache.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLibCache.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SharedLibCache.h 25 Dec 2004 07:05:59 -0000 1.2 +++ SharedLibCache.h 26 Dec 2004 14:38:09 -0000 1.3 @@ -32,13 +32,12 @@ namespace System { // Shared library handle cache -template <typename destroyF> +template <typename handle_t, typename destroyF> struct SharedLibCache { - typedef std::map<std::string, unsigned long> map_t; + typedef std::map<std::string, handle_t> map_t; + typedef typename map_t::const_iterator iterator; - enum { InvalidHandle = (unsigned long)-1 }; - SharedLibCache() { } @@ -57,18 +56,24 @@ void add(const std::string& name, unsigned long handle) { - map_t::iterator i = _handles.find(name); + iterator i = _handles.find(name); if(i == _handles.end()) _handles[name] = handle; } - unsigned long lookup(const std::string& name) const + iterator lookup(const std::string& name) const { - map_t::const_iterator i = _handles.find(name); - if(i == _handles.end()) - return InvalidHandle; + return _handles.find(name); + } - return i->second; + iterator begin() + { + return _handles.begin(); + } + + iterator end() + { + return _handles.end(); } CriticalSection mutex; @@ -80,11 +85,11 @@ /** Internal marker type. */ struct cached_libs_context {}; -template <typename destroyF> -SharedLibCache<destroyF> & shared_lib_cache() +template <typename handle_t, typename destroyF> +SharedLibCache<handle_t, destroyF> & shared_lib_cache() { return ::P::Phoenix< - SharedLibCache<destroyF>, + SharedLibCache<handle_t, destroyF>, cached_libs_context> ::instance(); } Index: SharedLib.ltdl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.ltdl.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SharedLib.ltdl.cpp 25 Dec 2004 20:08:07 -0000 1.6 +++ SharedLib.ltdl.cpp 26 Dec 2004 14:38:09 -0000 1.7 @@ -20,6 +20,7 @@ #include "pclasses/System/SharedLib.h" #include "pclasses/Phoenix.h" +#include "SharedLibCache.h" #include <ltdl.h> #include <errno.h> @@ -33,29 +34,38 @@ namespace System { - void ltdl_init() - { - lt_dlinit(); - lt_dlopen( 0 ); - } - int ltdl_init_placeholder = (ltdl_init(),0); +void ltdl_init() +{ + lt_dlinit(); + lt_dlopen( 0 ); +} +int ltdl_init_placeholder = (ltdl_init(),0); - typedef unsigned long handle_type; - typedef std::map<handle_type,lt_dlhandle> lt_handle_map_t; +typedef unsigned long handle_type; +typedef std::map<handle_type,lt_dlhandle> lt_handle_map_t; - struct ltdl_sharing_context {}; // marker class - lt_handle_map_t & - lt_handle_map() - { - typedef ::P::Phoenix< lt_handle_map_t, ltdl_sharing_context > PHX; - return PHX::instance(); - } +struct ltdl_sharing_context {}; // marker class +lt_handle_map_t & +lt_handle_map() +{ + typedef ::P::Phoenix< lt_handle_map_t, ltdl_sharing_context > PHX; + return PHX::instance(); +} - int BindMode2Flags(SharedLib::BindMode mode) - { // ltdl doesn't use dlopen() flags - return 0; +int BindMode2Flags(SharedLib::BindMode mode) +{ // ltdl doesn't use dlopen() flags + return 0; +} + +struct SharedLibCloser +{ + void operator()(lt_dlhandle handle) + { + lt_dlclose((handle); } +}; +typedef SharedLibCache<lt_dlhandle, SharedLibCloser> Cache; SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) @@ -79,16 +89,31 @@ SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) : _handle(0) { + Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); + CriticalSection::ScopedLock lck(cache.mutex); - lt_dlhandle h = lt_dlopen(name.c_str() /** BindMode2Flags(mode) */ ); - if( h ) + // see if we can get it from the handle cache ... + Cache::iterator i = cache.lookup(name); + if(i == cache.end()) { - _handle = reinterpret_cast<handle_type>( static_cast<void *>( h ) ); - lt_handle_map().insert( std::make_pair( _handle, h ) ); - } else + lt_dlhandle h = lt_dlopen(name.c_str() /** BindMode2Flags(mode) */ ); + if( h ) + { + _handle = reinterpret_cast<handle_type>( static_cast<void *>( h ) ); + lt_handle_map().insert( std::make_pair( _handle, h ) ); + + // add it to the handle cache + cache.add(name, _handle); + } + else + { + // CERR << "SharedLib("<<name<<") failed.\n"; + throw SystemError(errno, lt_dlerror(), P_SOURCEINFO); + } + } + else { - // CERR << "SharedLib("<<name<<") failed.\n"; - throw SystemError(errno, lt_dlerror(), P_SOURCEINFO); + _handle = i->second; } } Index: SharedLib.dl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dl.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- SharedLib.dl.cpp 25 Dec 2004 16:02:51 -0000 1.8 +++ SharedLib.dl.cpp 26 Dec 2004 14:38:05 -0000 1.9 @@ -45,7 +45,7 @@ } }; -typedef SharedLibCache<SharedLibCloser> Cache; +typedef SharedLibCache<unsigned long, SharedLibCloser> Cache; int BindMode2Flags(SharedLib::BindMode mode) { @@ -77,12 +77,12 @@ SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) { - Cache& cache = shared_lib_cache<SharedLibCloser>(); + Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); - // se if we can get it from the handle cache ... - unsigned long handle = cache.lookup(name); - if(handle == Cache::InvalidHandle) + // see if we can get it from the handle cache ... + Cache::iterator i = cache.lookup(name); + if(i == cache.end()) { _handle = (unsigned long)dlopen(name.c_str(), BindMode2Flags(mode)); if(!_handle) @@ -93,7 +93,7 @@ } else { - _handle = handle; + _handle = i->second; } } Index: SharedLib.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.win32.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SharedLib.win32.cpp 25 Dec 2004 16:02:51 -0000 1.6 +++ SharedLib.win32.cpp 26 Dec 2004 14:38:09 -0000 1.7 @@ -38,7 +38,7 @@ } }; -typedef SharedLibCache<SharedLibCloser> Cache; +typedef SharedLibCache<unsigned long, SharedLibCloser> Cache; SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) { @@ -56,7 +56,7 @@ // realName << name; // realName << ".dll"; - Cache& cache = shared_lib_cache<SharedLibCloser>(); + Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); // se if we can get it from the handle cache ... Index: SharedLib.shl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.shl.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SharedLib.shl.cpp 25 Dec 2004 16:02:51 -0000 1.6 +++ SharedLib.shl.cpp 26 Dec 2004 14:38:09 -0000 1.7 @@ -39,7 +39,7 @@ } }; -typedef SharedLibCache<SharedLibCloser> Cache; +typedef SharedLibCache<unsigned long, SharedLibCloser> Cache; int BindMode2Flags(SharedLib::BindMode mode) { @@ -75,7 +75,7 @@ // std::ostringstream realName; // realName << name; // realName << ".sl"; - Cache& cache = shared_lib_cache<SharedLibCloser>(); + Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); // se if we have the handle cached ... |
From: stephan b. <sg...@us...> - 2004-12-26 14:38:09
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8534/src/s11n Modified Files: list.h Log Message: Corrected a namespace-qualified call into the s11n namespace. Index: list.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/list.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- list.h 26 Dec 2004 07:53:19 -0000 1.4 +++ list.h 26 Dec 2004 14:38:00 -0000 1.5 @@ -149,7 +149,7 @@ const NodeType * nch = 0; CHIT it = TR::children(src).begin(); CHIT et = TR::children(src).end(); - s11n::object_reference_wrapper<SerType> dwrap(dest); + ::P::s11n::object_reference_wrapper<SerType> dwrap(dest); VT ser; // reminder: might be a pointer type std::string implclass; static const char * errprefix = "deserialize_list(node,list) "; |
From: stephan b. <sg...@us...> - 2004-12-26 14:36:39
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io/expat In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8309/src/s11n/io/expat Modified Files: expat_serializer.h Log Message: Corrected a bug in the entity translation. gcc LET ME IMPLICITELY CAST A size_t to string!!! Without a warning! No error! Just broken code! Index: expat_serializer.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/io/expat/expat_serializer.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- expat_serializer.h 26 Dec 2004 12:30:06 -0000 1.2 +++ expat_serializer.h 26 Dec 2004 14:36:29 -0000 1.3 @@ -10,7 +10,7 @@ -#define MAGIC_COOKIE_EXPAT_XML "<!DOCTYPE P::s11n::io::expat_serializer>" +#define MAGIC_COOKIE_EXPAT_XML "<!DOCTYPE s11n::io::expat_serializer>" #include <stdexcept> #include <sstream> @@ -102,7 +102,7 @@ else { buff << ">"; - propval = ::P::StringTool::translateEntities( propval, expat_serializer_translations(), false ); + ::P::StringTool::translateEntities( propval, expat_serializer_translations(), false ); buff << propval; buff << "</" << key << ">"; } |
From: stephan b. <sg...@us...> - 2004-12-26 14:35:22
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8125/src/s11n/io Modified Files: data_node_io.h Log Message: Fixed a broken if(os.good() ) return false. Removed a bunch of commented-out code. Index: data_node_io.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/io/data_node_io.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- data_node_io.h 26 Dec 2004 12:30:06 -0000 1.3 +++ data_node_io.h 26 Dec 2004 14:35:13 -0000 1.4 @@ -163,7 +163,7 @@ { std::ofstream os( destfile.c_str() ); // @fixme: zfstream support was removed for P! - if( os.good() ) return false; + if( ! os.good() ) return false; bool b = this->serialize( src, os ); return b; } @@ -267,12 +267,14 @@ Special feature: - If the first line of the stream is "#s11n::io::load_serializer" - then the next token on that line is expected to be a Serializer - class name. This function will try to classload that object. - If successful it will use that type to deserialize the input - string. If unsuccessful it will read the next line for a cookie - and try to use that Serializer. If that fails, it will return 0. + If the first line of the stream is + "#s11n::io::serializer CLASSNAME" then the CLASSNAME + token is expected to be a Serializer class name. This + function will try to classload that object. If + successful it will use that type to deserialize the + input stream. NOT YET IMPLEMENTED: if unsuccessful it + will read the next line for a cookie and try to use + that Serializer. If that fails, it will return 0. */ template <typename NodeType> NodeType * @@ -370,14 +372,15 @@ if( AsFile ) { is = AP( new std::ifstream( src.c_str() ) ); + if( ! is->good() ) return 0; } else { is = AP( new std::istringstream(src) ); } // AP is = AP( zfstream::get_istream( src, AsFile ) ); - // ^^^^ @fixme: zfstream removed because P doesn't have this support (yet) - if( ! is.get() ) return 0; +// if( ! is.get() ) return 0; +// ^^^^ @fixme: zfstream removed because P doesn't have this support (yet) return load_node<NodeType>( *is ); } @@ -432,61 +435,6 @@ } - /** - Saves src to the given ostream using the given - Serializer type. - - ONLY use this for saving root nodes! - */ - template <typename SerializerT> - bool save_node( const typename SerializerT::node_type & src, std::ostream & dest ) - { - return SerializerT().serialize( src, dest ); - } - - - /** - Saves src, a Serializable type, to the given - ostream using a SerializerT serializer. - - SerializerT must be compatible with - s11n::io::data_node_serializer<> - conventions and must provide a <code>typedef XXX - node_type</code>, where XXX is a data type - conforming to s11n::data_node - conventions. - - Returns true on success, false on error. - - ONLY use this for saving root nodes! - */ - template <typename SerializerT,typename SerializableT> - bool save_serializable( const SerializableT & src, - std::ostream & dest ) - { - typedef typename SerializerT::node_type node_type; - node_type node( "serializable" ); - if( ! ::P::s11n::serialize<node_type,SerializableT>( node, src ) ) return false; - return SerializerT().serialize( node, dest ); - } - - /** - An overloaded form which takes a filename. - - ONLY use this for saving root nodes! - */ - template <typename SerializerT,typename SerializableT> - bool save_serializable( const SerializableT & src, - const std::string & filename ) - { -// typedef std::auto_ptr<std::ostream> AP; -// AP os = AP( zfstream::get_ostream( filename ) ); -// if( ! os.get() ) return false; -// @fixme: ^^^ zfstream removed for P - std::ofstream os( filename.c_str() ); - if( ! os.good() ) return false; - return save_serializable<SerializerT,SerializableT>( src, os ); - } } // namespace io |
From: stephan b. <sg...@us...> - 2004-12-26 13:14:09
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28103/test Modified Files: StringToolTest.cpp Log Message: Accomodated args order change in StringTool::expandDollar*(). Index: StringToolTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/StringToolTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- StringToolTest.cpp 26 Dec 2004 12:16:53 -0000 1.2 +++ StringToolTest.cpp 26 Dec 2004 13:13:59 -0000 1.3 @@ -27,11 +27,11 @@ std::string v2 = v1; CERR << "string: ["<<v1<<"]\n" - << "expanded: [" << expandDollarRefs( map, v1 ) << "]\n"; + << "expanded: [" << expandDollarRefs( v1, map ) << "]\n"; escapeString( v2, "$", "\\" ); CERR << "escaped string: ["<<v2<<"]\n" - << "pre-escaped, expanded: [" << expandDollarRefs( map, v2 ) << "]\n"; + << "pre-escaped, expanded: [" << expandDollarRefs( v2, map ) << "]\n"; EntityMap mymap; |
From: stephan b. <sg...@us...> - 2004-12-26 13:11:11
|
Update of /cvsroot/pclasses/pclasses2/src/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27708/src/Util Modified Files: StringTool.cpp Log Message: Reversed the order of the args for expandDollarRefs*(), for consistency with translateEntities(). Index: StringTool.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Util/StringTool.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- StringTool.cpp 26 Dec 2004 12:18:09 -0000 1.4 +++ StringTool.cpp 26 Dec 2004 13:11:02 -0000 1.5 @@ -233,15 +233,15 @@ } std::string - expandDollarRefs( const EntityMap & src, const std::string & text ) + expandDollarRefs( const std::string & text, const EntityMap & src ) { std::string foo = text; - expandDollarRefsInline( src, foo ); + expandDollarRefsInline( foo, src ); return foo; } size_t - expandDollarRefsInline( const EntityMap & src, std::string & buffer ) + expandDollarRefsInline( std::string & buffer, const EntityMap & src ) { using std::string; //CERR << "environment::expand_vars(["<<buffer<<"])"<<std::endl; |
From: stephan b. <sg...@us...> - 2004-12-26 13:11:11
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27708/include/pclasses/Util Modified Files: StringTool.h Log Message: Reversed the order of the args for expandDollarRefs*(), for consistency with translateEntities(). Index: StringTool.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/StringTool.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- StringTool.h 26 Dec 2004 12:19:15 -0000 1.4 +++ StringTool.h 26 Dec 2004 13:11:01 -0000 1.5 @@ -306,7 +306,7 @@ be the same as the original. */ - std::string expandDollarRefs( const EntityMap & src, const std::string & text ); + std::string expandDollarRefs( const std::string & text, const EntityMap & src ); /** Parsed env vars out of buffer, replacing them with their @@ -348,7 +348,7 @@ a slash, the slash is stripped even if the $ does not expand to anything. This is arguably behaviour. */ - size_t expandDollarRefsInline( const EntityMap & src, std::string & buffer ); + size_t expandDollarRefsInline( std::string & buffer, const EntityMap & src ); |
From: stephan b. <sg...@us...> - 2004-12-26 12:31:32
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22185/test Modified Files: Makefile.toc Log Message: Added some ld flags, to get around some "bad" circular deps in the P libs. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.toc,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.toc 26 Dec 2004 11:13:27 -0000 1.10 +++ Makefile.toc 26 Dec 2004 12:31:22 -0000 1.11 @@ -34,12 +34,12 @@ BIN_PROGRAMS = FactoryTest PtrTest s11nTest StringToolTest BIN_PROGRAMS_LDADD = $(LIBP_TESTS_LDADD) FactoryTest_bin_OBJECTS = FactoryTest.o registrations.o - FactoryTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) $(LIBPS11N_CLIENT_LDADD) + FactoryTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) $(LIBPS11N_CLIENT_LDADD) $(LIBPUTIL_CLIENT_LDADD) StringToolTest_bin_OBJECTS = StringToolTest.o StringToolTest_bin_LDADD = $(LIBPUTIL_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) PtrTest_bin_OBJECTS = PtrTest.o PtrTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) - s11nTest_bin_OBJECTS = s11nTest.o registrations.o $(LIBPS11N_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) + s11nTest_bin_OBJECTS = s11nTest.o registrations.o $(LIBPS11N_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) $(LIBPUTIL_CLIENT_LDADD) include $(TOC_MAKESDIR)/BIN_PROGRAMS.make endif |
From: stephan b. <sg...@us...> - 2004-12-26 12:30:20
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io/expat In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21948/src/s11n/io/expat Modified Files: expat_serializer.h Log Message: Mass commit: ported 2 s11n mini-libs (stringutil, str) into P::StringTool. Index: expat_serializer.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/io/expat/expat_serializer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- expat_serializer.h 26 Dec 2004 04:04:31 -0000 1.1 +++ expat_serializer.h 26 Dec 2004 12:30:06 -0000 1.2 @@ -1,7 +1,7 @@ #ifndef s11n_EXPAT_SERIALIZER_HPP_INCLUDED #define s11n_EXPAT_SERIALIZER_HPP_INCLUDED 1 -#include <pclasses/s11n/str.h> // translate() +#include <pclasses/Util/StringTool.h> // translateEntities() #include <pclasses/s11n/s11n_debuggering_macros.h> // COUT/CERR #include <pclasses/s11n/io/data_node_format.h> #include <pclasses/s11n/traits.h> // node_traits @@ -76,7 +76,7 @@ std::string nname = NT::name(src); std::string impl = NT::class_name(src); - str::translate( impl, expat_serializer_translations(), false ); + ::P::StringTool::translateEntities( impl, expat_serializer_translations(), false ); std::string indent; buff << "<" << nname << " "<<EXPAT_CLASS_ATTRIBUTE<<"=\""<< impl <<"\""; bool closed = false; @@ -102,7 +102,7 @@ else { buff << ">"; - propval = str::translate( propval, expat_serializer_translations(), false ); + propval = ::P::StringTool::translateEntities( propval, expat_serializer_translations(), false ); buff << propval; buff << "</" << key << ">"; } |
From: stephan b. <sg...@us...> - 2004-12-26 12:30:20
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21948/src/s11n/io Modified Files: data_node_format.h data_node_io.h Log Message: Mass commit: ported 2 s11n mini-libs (stringutil, str) into P::StringTool. Index: data_node_format.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/io/data_node_format.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- data_node_format.h 26 Dec 2004 04:04:32 -0000 1.1 +++ data_node_format.h 26 Dec 2004 12:30:06 -0000 1.2 @@ -13,15 +13,9 @@ #include <list> #include <map> #include <stdexcept> -// #include <typeinfo> - - -// #include <s11n.net/zfstream/zfstream.h> // get_i/ostream() -// #include <s11n.net/tostring/to_string.h> // to/from_string() -// #include <s11n.net/stringutil/string_util.h> // translate_entities() #include <pclasses/s11n/s11n_debuggering_macros.h> // COUT/CERR -#include <pclasses/s11n/classload.h> // classload() +// #include <pclasses/s11n/classload.h> // classloader stuff #include <pclasses/s11n/data_node_functor.h> // some utility functors #include <pclasses/s11n/data_node_serialize.h> // data_node_serializer<> and friends Index: data_node_io.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/io/data_node_io.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- data_node_io.h 26 Dec 2004 07:53:19 -0000 1.2 +++ data_node_io.h 26 Dec 2004 12:30:06 -0000 1.3 @@ -108,7 +108,7 @@ /** Returns a map intended for use with - stringutil::translate_entities(). + P::StringTool::translateEntities(). The default implementation returns an empty map. |
From: stephan b. <sg...@us...> - 2004-12-26 12:30:19
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21948/src/s11n Modified Files: Makefile.toc s11n_node.h Log Message: Mass commit: ported 2 s11n mini-libs (stringutil, str) into P::StringTool. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/Makefile.toc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.toc 26 Dec 2004 07:53:19 -0000 1.6 +++ Makefile.toc 26 Dec 2004 12:30:05 -0000 1.7 @@ -9,8 +9,9 @@ data_node.cpp \ s11n.cpp \ s11n_node.cpp \ - SIO.cpp \ - string_util.cpp + SIO.cpp + +# string_util.cpp HEADERS = $(wildcard *.h) @@ -20,7 +21,6 @@ s11n \ s11n_node \ SIO \ - string_util \ ) objects: $(OBJECTS) Index: s11n_node.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/s11n_node.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- s11n_node.h 26 Dec 2004 09:15:02 -0000 1.4 +++ s11n_node.h 26 Dec 2004 12:30:05 -0000 1.5 @@ -11,8 +11,10 @@ #include <map> #include <vector> -#include "str.h" // to/from() string +// #include "str.h" // to/from() string #include "traits.h" // node_traits +#include <pclasses/Util/StringTool.h> + namespace P { namespace s11n { /** @@ -241,7 +243,7 @@ template < typename T > void set( const std::string & key, const T & val ) { - this->m_map[key] = str::to(val); + this->m_map[key] = ::P::StringTool::to(val); } /** @@ -260,7 +262,7 @@ T get( const std::string & key, const T & defaultval ) const { const_iterator cit = this->m_map.find( key ); - return ( this->m_map.end() == cit ) ? defaultval : str::from( (*cit).second, defaultval); + return ( this->m_map.end() == cit ) ? defaultval : ::P::StringTool::from( (*cit).second, defaultval); } /** |
From: stephan b. <sg...@us...> - 2004-12-26 12:29:19
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21844/src/s11n Removed Files: str.h string_util.cpp string_util.h Log Message: No longer needed - ported client code to P::StringTool. --- string_util.cpp DELETED --- --- string_util.h DELETED --- --- str.h DELETED --- |
From: stephan b. <sg...@us...> - 2004-12-26 12:19:25
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12673/include/pclasses/Util Modified Files: StringTool.h Log Message: Renamed expandVars*() to expandDollarRefs*(). Fixed a minor escaped-$var bug. Index: StringTool.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/StringTool.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- StringTool.h 26 Dec 2004 11:58:33 -0000 1.3 +++ StringTool.h 26 Dec 2004 12:19:15 -0000 1.4 @@ -229,11 +229,11 @@ /** Adds the following escape sequences to map: - - single backslash (\) == double backslash. + - 1x backslash (\) == 2x backslash. - - single quote == backslash, quote + - 1x apostrophe == 1x backslash 1x apostrophe - - double quote == backslash, double quote + - 1x double-quote == 1x backslash 1x double-quote */ void operator()( EntityMap & map ); }; @@ -301,12 +301,12 @@ } /** - Exactly like expandVarsInline() but returns a new string + Exactly like expandDollarRefsInline() but returns a new string which results from the expansions. The returned string may be the same as the original. */ - std::string expandVars( const EntityMap & src, const std::string & text ); + std::string expandDollarRefs( const EntityMap & src, const std::string & text ); /** Parsed env vars out of buffer, replacing them with their @@ -340,8 +340,15 @@ accepting any lexically-castable key/val types, but the function is quite long, and therefore not really suitable to inclusion in the header. + + + Known misgivings: + + - When buffer contains dollar signs which are preceeded by + a slash, the slash is stripped even if the $ does not + expand to anything. This is arguably behaviour. */ - size_t expandVarsInline( const EntityMap & src, std::string & buffer ); + size_t expandDollarRefsInline( const EntityMap & src, std::string & buffer ); |
From: stephan b. <sg...@us...> - 2004-12-26 12:18:21
|
Update of /cvsroot/pclasses/pclasses2/src/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12523/src/Util Modified Files: StringTool.cpp Log Message: Renamed expandVars*() to expandDollarRefs*(). Fixed a minor escaped-$var bug. Index: StringTool.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Util/StringTool.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- StringTool.cpp 26 Dec 2004 11:58:33 -0000 1.3 +++ StringTool.cpp 26 Dec 2004 12:18:09 -0000 1.4 @@ -233,15 +233,15 @@ } std::string - expandVars( const EntityMap & src, const std::string & text ) + expandDollarRefs( const EntityMap & src, const std::string & text ) { std::string foo = text; - expandVarsInline( src, foo ); + expandDollarRefsInline( src, foo ); return foo; } size_t - expandVarsInline( const EntityMap & src, std::string & buffer ) + expandDollarRefsInline( const EntityMap & src, std::string & buffer ) { using std::string; //CERR << "environment::expand_vars(["<<buffer<<"])"<<std::endl; @@ -275,6 +275,11 @@ if( posA>0 && !slashmode && buffer[posA-1] == '\\' ) slashmode = true; if( slashmode ) { + // arguable: + --posA; // strip 1 slash + buffer.erase( posA, 1 ); + // todo: only remove slashe preeding $. + // end arguable slashmode = false; continue; } |
From: stephan b. <sg...@us...> - 2004-12-26 12:17:04
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12300/test Modified Files: StringToolTest.cpp Log Message: added an (un)escaping test. Index: StringToolTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/StringToolTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- StringToolTest.cpp 26 Dec 2004 11:13:01 -0000 1.1 +++ StringToolTest.cpp 26 Dec 2004 12:16:53 -0000 1.2 @@ -23,11 +23,31 @@ map["foo"] = "FOOFOO"; map["bar"] = "BARBAR"; - std::string ins = "this is a ${foo} input ${bar}."; + std::string v1 = "this $bar is a ${foo} input ${bar}. $UNMAPPED_VAR, \\ \\ \\\\ ${} $ \\$ escaped \\${foo}."; + std::string v2 = v1; - CERR << "string: ["<<ins<<"]\n" - << "Expanded: [" << expandVars( map, ins ) << "]\n"; + CERR << "string: ["<<v1<<"]\n" + << "expanded: [" << expandDollarRefs( map, v1 ) << "]\n"; + + escapeString( v2, "$", "\\" ); + CERR << "escaped string: ["<<v2<<"]\n" + << "pre-escaped, expanded: [" << expandDollarRefs( map, v2 ) << "]\n"; + + EntityMap mymap; + mymap["<"] = "<"; + mymap[">"] = ">"; + mymap["\""] = """; + mymap["'"] = "'"; + mymap["$GOODGRIEF"] = "excellent"; + + size_t num = 0; + std::string q1 = "this is a '<\"test string\">'. $GOODGRIEF!"; + CERR << "reference string=["<<q1<<"]\n"; + num = translateEntities( q1, mymap ); + CERR << num << " translated: [" << q1 << "]\n"; + translateEntities( q1, mymap, true ); + CERR << num << " reverse translated: [" << q1 << "]\n"; return 0; |
From: stephan b. <sg...@us...> - 2004-12-26 11:58:45
|
Update of /cvsroot/pclasses/pclasses2/src/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9127/src/Util Modified Files: StringTool.cpp Log Message: More tweaking... Index: StringTool.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Util/StringTool.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- StringTool.cpp 26 Dec 2004 11:10:00 -0000 1.2 +++ StringTool.cpp 26 Dec 2004 11:58:33 -0000 1.3 @@ -1,4 +1,5 @@ #include <pclasses/Util/StringTool.h> +// #include <pclasses/s11n/s11n_debuggering_macros.h> // CERR namespace P { namespace StringTool { @@ -10,12 +11,12 @@ std::string::size_type pos = str.npos; EntityMap::const_iterator mit; EntityMap::const_iterator met = map.end(); - std::string key; std::string val; if( reverse ) { - + // CERR << "Reverse-translating entities.\n"; + // treat KEY=VAL as VAL=KEY mit = map.begin(); for( ; mit != met; ++mit ) { @@ -30,14 +31,28 @@ } else { - pos = str.size() - 1; - for( ; pos != std::string::npos; --pos ) + // CERR << "Translating entities in ["<<str<<"]...\n"; + // treat KEY=VAL as KEY=VAL + mit = map.begin(); + for( ; mit != met; ++mit ) { - mit = map.find( str.substr(pos,1) ); - if( met == mit ) continue; - ++count; - str.replace( pos, 1, (*mit).second ); + key = (*mit).first; + val = (*mit).second; + while( str.npos != (pos = str.rfind( key )) ) + { + ++count; + str.replace( pos, key.size(), val ); + } } +// this code works, and is much more efficient, but only accepts keys with length of 1: +// pos = str.size() - 1; +// for( ; pos != std::string::npos; --pos ) +// { +// mit = map.find( str.substr(pos,1) ); +// if( met == mit ) continue; +// ++count; +// str.replace( pos, 1, (*mit).second ); +// } } return count; } @@ -109,7 +124,7 @@ void normalizeString( std::string &str ) { - //COUT << "normalize_string("<<str<<")" << endl; + //COUT << "normalizeString("<<str<<")" << endl; trimString( str ); stripSlashes( str ); const char ch = str[0]; @@ -173,7 +188,7 @@ } - int int4hexchar( char c ) + int int4hexchar( int c ) { int i = -1; if( c >= 48 && c <=57 ) // 0-9 @@ -195,14 +210,16 @@ int hex2int( const std::string & wd ) { unsigned int mult = 1; - int ret = 0; + int ret = -1; char c; + int tmp; for( std::string::size_type i = wd.size(); i > 0; --i ) { //COUT << "i="<<i<<endl; c = wd[i-1]; if( '#' == c ) continue; - ret += mult * int4hexchar( c ); + if( -1 == (tmp = int4hexchar( c )) ) return -1; + ret += mult * tmp; mult = mult * 16; } return ret; @@ -226,29 +243,29 @@ size_t expandVarsInline( const EntityMap & src, std::string & buffer ) { - //CERR << "expandVars(["<<buffer<<"])"<<std::endl; + using std::string; + //CERR << "environment::expand_vars(["<<buffer<<"])"<<std::endl; if( buffer.size() < 2 ) return 0; - EntityMap::const_iterator entit, entet = src.end(); - - std::string::size_type posA = 0, posB = 0; - static const char vardelim = '$'; - posA = buffer.find( vardelim ); - if( std::string::npos == posA ) - { + string::size_type posA = 0, posB = 0; + static const char vardelim = '$'; + posA = buffer.find( vardelim ); + if( string::npos == posA ) + { return 0; } static const char opener = '{'; static const char closer = '}'; + string tmpvar; size_t count = 0; - static const std::string allowable_chars = + static const string allowable_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_?"; // ^^^^^^ why is '?' in the list? So that eshell can support the shell-ish $? var :/. char atc; posA = buffer.size() - 1; bool slashmode = false; - std::string varname; - for( ; posA >= 0 && posA != std::string::npos; posA-- ) + EntityMap::const_iterator srcit, srcet = src.end(); + for( ; posA >= 0 && posA != string::npos; posA-- ) { atc = buffer[posA]; if( atc != vardelim ) @@ -263,11 +280,12 @@ } posB = buffer.find_first_not_of( allowable_chars, posA+1 ); // find first non-variablename char if( posB != posA +1 ) posB -= 1; - if( posB == std::string::npos ) + if( posB == string::npos ) { posB = buffer.size() -1; } - + + tmpvar.clear(); if( posB == posA + 1 ) // ${VAR} or $F, hopefully { atc = buffer[posB]; @@ -275,12 +293,12 @@ { // $NONBRACED_VAR posB = buffer.find_first_not_of( allowable_chars, posB ); - varname = buffer.substr( posA + 1, posB ); - //CERR << "nonbraced var? ["<<varname<<"]\n"; - // varname += atc; - // if( varname.find_first_of( allowable_chars ) != 0 ) + tmpvar = buffer.substr( posA + 1, posB ); + //CERR << "nonbraced var? ["<<tmpvar<<"]\n"; + // tmpvar += atc; + // if( tmpvar.find_first_of( allowable_chars ) != 0 ) // { - // varname = string(); + // tmpvar = string(); // } } @@ -291,29 +309,28 @@ while( atc != closer && posB <= maxpos ) { // extract variable-name part: atc = buffer[++posB]; - if ( atc != closer ) varname += atc; + if ( atc != closer ) tmpvar += atc; } } } else { // extract variable-name part: - varname = buffer.substr( posA+1 /*skip '$'*/, posB-posA ); + tmpvar = buffer.substr( posA+1 /*skip '$'*/, posB-posA ); } - //CERR << "expandVars(): varname=["<<varname<<"]"<<endl; - if( varname.empty() ) continue; - - entit = src.find( varname ); - if( entet == entit ) continue;// don't expand unknown vars to empty strings. - varname = (*entit).second; - //CERR << "expandVars(): expanded varname=["<<varname<<"]"<<endl; + //CERR << "expand_vars(): tmpvar=["<<tmpvar<<"]"<<endl; + if( tmpvar.empty() ) continue; + srcit = src.find( tmpvar ); // don't expand unknown vars to empty strings. + if( srcet == srcit ) continue; + tmpvar = (*srcit).second; + //CERR << "expand_vars(): expanded tmpvar=["<<tmpvar<<"]"<<endl; ++count; buffer.erase( posA, posB - posA +1 ); - buffer.insert( posA, varname.c_str() ); - varname.clear(); + buffer.insert( posA, tmpvar.c_str() ); } return count; } -} } // P::StringTool +}} // P::StringTool + |
From: stephan b. <sg...@us...> - 2004-12-26 11:58:45
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9127/include/pclasses/Util Modified Files: StringTool.h Log Message: More tweaking... Index: StringTool.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/StringTool.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- StringTool.h 26 Dec 2004 11:10:00 -0000 1.2 +++ StringTool.h 26 Dec 2004 11:58:33 -0000 1.3 @@ -9,8 +9,11 @@ namespace P { /** -The StringTool namespace encapsulates a set of utility functions for working -with string objects. +The StringTool namespace encapsulates a set of utility functions for +working with string objects. + +Most of these functions were developed to support libs11n, and have a +proven track-record. */ namespace StringTool { @@ -29,15 +32,23 @@ It returns the number of translations made. If reverse_translation == true then a reverse mapping is - done: map values are treated as keys. + done: map values are treated as keys. This is useful, for example, for doing XML-entity-to-char conversions. - It is amazingly INefficient, but seems to work okay. + Complexity is essentially linear, based on a combination of + buffer.size() and translation_map.size(). Best used with + small maps on short strings! The speed can be increased + signifcantly, but probably only if we restrict keys and + values to 1 character each. + Design note: this really should be a function template, + accepting any lexically-castable key/val types, but the + function is quite long, and therefore not really suitable + to inclusion in the header. */ - size_t translateEntities( std::string &, const EntityMap & translation_map, bool reverse_translation = false ); + size_t translateEntities( std::string & buffer, const EntityMap & translation_map, bool reverse_translation = false ); /** @@ -101,7 +112,7 @@ /** normalizeString() is like trimString() and - strip_slashes(), combined, plus it removes leading/trailing + stripSlashes(), combined, plus it removes leading/trailing quotes: <pre> @@ -137,15 +148,16 @@ Returns int values for chars '0'-'9', 'a'-'f' and 'A'-'F', else -1. */ - int int4hexchar( char c ); + int int4hexchar( int character ); /** Returns decimal value of wd, which is assumed to be a hex-encoded number. wd may optionally be prefixed with '#', as in \#ff00ff. Case is insignificant. - On error 0 is returned, but 0 is also a valid number, so - there is really no way of knowing if it fails or not. :/ + On error -1 is returned, but -1 is also potentially a valid + number, so there is really no way of knowing if it fails or + not. :/ */ int hex2int( const std::string & wd ); @@ -189,7 +201,7 @@ calls to operator(). */ EntityTranslator( const EntityMap & map, bool reverse ) - : m_map(map),m_rev(reverse) + : m_map(&map),m_rev(reverse) { } @@ -200,10 +212,10 @@ */ inline void operator()( std::string & str ) const { - translateEntities( str, this->m_map, this->m_rev ); + translateEntities( str, *(this->m_map), this->m_rev ); } private: - EntityMap m_map; + const EntityMap * m_map; bool m_rev; }; @@ -289,8 +301,17 @@ } /** - Parsed env vars out of text, replacing them with their - values. Accepts variable tokens in the format ${VAR}. + Exactly like expandVarsInline() but returns a new string + which results from the expansions. The returned string may + be the same as the original. + + */ + std::string expandVars( const EntityMap & src, const std::string & text ); + + /** + Parsed env vars out of buffer, replacing them with their + values, as defined in the src map. Accepts variables + in the format ${VAR} and $VAR. e.g., ${foo} corresponds to the value set in src["foo"]. @@ -302,15 +323,25 @@ To get a dollar sign into the resulting string, escape it with a single backslash: this keeps it from being parsed as a ${variable}. - */ - std::string expandVars( const EntityMap & src, const std::string & text ); - /** - Exactly like expandVars() but directly modifies - the input string. Returns the number of variables - expanded. + Returns the number of variables expanded. + + Note that this function is much *more* efficient than using + translateEntities() to perform a similar operation. + Because of it's stricter format we can do a single pass + through the string and may not even have to reference the + source map. + + Complexity depends on the number of ${vars} parts are expanded + in buffer: overall runtime depends on buffer length, + plus a non-determinate amount of time per ${var} expanded. + + Design note: this really should be a function template, + accepting any lexically-castable key/val types, but the + function is quite long, and therefore not really suitable + to inclusion in the header. */ - size_t expandVarsInline( const EntityMap & src, std::string & text ); + size_t expandVarsInline( const EntityMap & src, std::string & buffer ); |
From: stephan b. <sg...@us...> - 2004-12-26 11:13:36
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3767/test Modified Files: Makefile.toc Log Message: added StringToolTest. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.toc,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.toc 26 Dec 2004 07:54:10 -0000 1.9 +++ Makefile.toc 26 Dec 2004 11:13:27 -0000 1.10 @@ -31,10 +31,12 @@ build_bins = 1 ifeq (1,$(build_bins)) - BIN_PROGRAMS = FactoryTest PtrTest s11nTest + BIN_PROGRAMS = FactoryTest PtrTest s11nTest StringToolTest BIN_PROGRAMS_LDADD = $(LIBP_TESTS_LDADD) FactoryTest_bin_OBJECTS = FactoryTest.o registrations.o FactoryTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) $(LIBPS11N_CLIENT_LDADD) + StringToolTest_bin_OBJECTS = StringToolTest.o + StringToolTest_bin_LDADD = $(LIBPUTIL_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) PtrTest_bin_OBJECTS = PtrTest.o PtrTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) s11nTest_bin_OBJECTS = s11nTest.o registrations.o $(LIBPS11N_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) |
From: stephan b. <sg...@us...> - 2004-12-26 11:13:12
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3706/test Added Files: StringToolTest.cpp Log Message: egg --- NEW FILE: StringToolTest.cpp --- #ifdef NDEBUG # // force assert() to work... # undef NDEBUG #endif #include <string> #include <map> #include <cassert> #include <pclasses/s11n/s11n_debuggering_macros.h> #include <pclasses/Util/StringTool.h> int main( int argc, char ** argv ) { CERR << "StringTool tests...\n"; using namespace P::StringTool; EntityMap map; map["foo"] = "FOOFOO"; map["bar"] = "BARBAR"; std::string ins = "this is a ${foo} input ${bar}."; CERR << "string: ["<<ins<<"]\n" << "Expanded: [" << expandVars( map, ins ) << "]\n"; return 0; } |
From: stephan b. <sg...@us...> - 2004-12-26 11:10:12
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3367/include/pclasses/Util Modified Files: StringTool.h Log Message: Added expandVars() and expandVarsInline(), to expand a map<string,string> as a set of ${vars} in an input string. Index: StringTool.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/StringTool.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- StringTool.h 26 Dec 2004 10:42:05 -0000 1.1 +++ StringTool.h 26 Dec 2004 11:10:00 -0000 1.2 @@ -288,6 +288,32 @@ return quote + to( v ) + quote; } + /** + Parsed env vars out of text, replacing them with their + values. Accepts variable tokens in the format ${VAR}. + + e.g., ${foo} corresponds to the value set in src["foo"]. + + Referencing a variable which is not set does not + expand the variable to an empty value: it is left + as-is. Thus expanding ${FOO} when "FOO" is not set + will result in "${FOO}". + + To get a dollar sign into the resulting string, escape + it with a single backslash: this keeps it from being + parsed as a ${variable}. + */ + std::string expandVars( const EntityMap & src, const std::string & text ); + + /** + Exactly like expandVars() but directly modifies + the input string. Returns the number of variables + expanded. + */ + size_t expandVarsInline( const EntityMap & src, std::string & text ); + + + }} // namespace P::StringTool |