From 19bfde8ba866e2c900dcd1377fd23e9b25801221 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Sat, 17 Jul 2010 00:33:12 -0400 Subject: [PATCH] lib: starting to pull in the os4x specific parts of the vbase code --- ChangeLog | 2 ++ src/vbase.cc | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/vbase.h | 5 ++++ src/vcard.cc | 3 --- 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 879be87c..00109b86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Release: version 0.17 - 2010/01/?? - lib: added tm_to_iso() to tzwrapper functions - lib: vbase now has default implementation of vTimeConverter (was vTimeZone) with a simpler API, based on TzWrapper underneath + - lib: pulled in os4x vbase code, so both plugins are using one + set of vformat code 2010/07/16 - lib: added BARRY_GCC_FORMAT_CHECK() for printf() style arg checking - lib: added C-style BarryLogf() function for internal use diff --git a/src/vbase.cc b/src/vbase.cc index 1d302558..5cc850c7 100644 --- a/src/vbase.cc +++ b/src/vbase.cc @@ -248,6 +248,7 @@ vBase::~vBase() { if( m_format ) { b_vformat_free(m_format); + m_format = 0; } } @@ -397,6 +398,38 @@ std::string vBase::GetAttr(const char *attrname, const char *block) return ret; } +std::vector vBase::GetValueVector(const char *attrname, const char *block) +{ +// Trace trace("vBase::GetValueVector"); +// trace.logf("getting value vector for: %s", attrname); + + std::vector ret; + const char *value = 0; + bool needs_freeing = false; + + b_VFormatAttribute *attr = b_vformat_find_attribute(m_format, attrname, 0, block); + if( attr ) { + if( b_vformat_attribute_is_single_valued(attr) ) { + value = b_vformat_attribute_get_value(attr); + needs_freeing = true; + } else { + // nasty, but avoids tweaking vformat. + int idx = 0; + do { + value = b_vformat_attribute_get_nth_value(attr, idx++); + if( value ) { + ret.push_back(value); + } + } while( value ); + } + } + + if( needs_freeing ) + g_free((char *)value); + + return ret; +} + vAttr vBase::GetAttrObj(const char *attrname, int nth, const char *block) { // Trace trace("vBase::GetAttrObj"); @@ -405,5 +438,53 @@ vAttr vBase::GetAttrObj(const char *attrname, int nth, const char *block) return vAttr(b_vformat_find_attribute(m_format, attrname, nth, block)); } +std::vector vBase::Tokenize(const std::string& str, const char delim) +{ + std::vector tokens; + std::string::size_type delimPos = 0, tokenPos = 0, pos = 0; + + if( str.length() < 1 ) { + return tokens; + } + + while( 1 ) { + delimPos = str.find_first_of(delim, pos); + tokenPos = str.find_first_not_of(delim, pos); + + if( std::string::npos != delimPos ) { + if( std::string::npos != tokenPos ) { + if( tokenPos < delimPos ) { + tokens.push_back(str.substr(pos, delimPos-pos)); + } else { + tokens.push_back(""); + } + } else { + tokens.push_back(""); + } + pos = delimPos + 1; + } else { + if( std::string::npos != tokenPos ){ + tokens.push_back(str.substr(pos)); + } else { + tokens.push_back(""); + } + break; + } + } + return tokens; +} + +std::string vBase::ToStringList(const std::vector &list, const char delim) +{ + std::string str; + for( unsigned int idx = 0; idx < list.size(); idx++ ) { + if( idx ) { + str += delim; + } + str += list[idx]; + } + return str; +} + }} // namespace Barry::Sync diff --git a/src/vbase.h b/src/vbase.h index 188c7159..06b06e5e 100644 --- a/src/vbase.h +++ b/src/vbase.h @@ -26,6 +26,7 @@ #include "vsmartptr.h" #include "vformat.h" #include "error.h" +#include namespace Barry { namespace Sync { @@ -137,7 +138,11 @@ protected: void AddParam(vAttrPtr &attr, const char *name, const char *value); std::string GetAttr(const char *attrname, const char *block = 0); + std::vector GetValueVector(const char *attrname, const char *block = 0); vAttr GetAttrObj(const char *attrname, int nth = 0, const char *block = 0); + + std::vector Tokenize(const std::string &str, const char delim = ','); + std::string ToStringList(const std::vector &list, const char delim = ','); }; }} // namespace Barry::Sync diff --git a/src/vcard.cc b/src/vcard.cc index 2470b877..385bced8 100644 --- a/src/vcard.cc +++ b/src/vcard.cc @@ -227,9 +227,6 @@ const std::string& vCard::ToVCard(const Barry::Contact &con) AddAttr(NewAttr("ROLE", con.JobTitle.c_str())); } - // Image not supported, since vformat routines probably don't - // support binary VCARD fields.... - if( con.Company.size() ) { // RFC 2426, 3.5.5 vAttrPtr org = NewAttr("ORG", con.Company.c_str()); // Organization name -- 2.11.4.GIT