summaryrefslogtreecommitdiffabout
path: root/lib/fields.cc
Side-by-side diff
Diffstat (limited to 'lib/fields.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/fields.cc59
1 files changed, 54 insertions, 5 deletions
diff --git a/lib/fields.cc b/lib/fields.cc
index d494098..916b603 100644
--- a/lib/fields.cc
+++ b/lib/fields.cc
@@ -43,12 +43,16 @@ namespace opkele {
}
__om_query_builder(const char *p,string& r,const basic_fields& m,const string& u)
: om(m), first(true), rv(r), pfx(p) {
+ basic_fields::fields_iterator i=om.fields_begin(),
+ ie=om.fields_end();
rv = u;
- if(rv.find('?')==string::npos)
- rv += '?';
- else
- first = false;
- for_each(om.fields_begin(),om.fields_end(),*this);
+ if(i!=ie) {
+ if(rv.find('?')==string::npos)
+ rv += '?';
+ else
+ first = false;
+ for_each(i,ie,*this);
+ }
}
result_type operator()(argument_type f) {
@@ -82,5 +86,50 @@ namespace opkele {
throw not_implemented(OPKELE_CP_ "reset_field() not implemented");
}
+ void basic_fields::from_query(const string& qs) {
+ for(string::size_type p=0,np;;p=np+1) {
+ np = qs.find('&',p);
+ string::size_type eq = qs.find('=',p);
+ if(eq==string::npos) break;
+ if(np==string::npos) {
+ set_field(
+ util::url_decode(qs.substr(p,eq-p)),
+ util::url_decode(qs.substr(eq+1)) );
+ break;
+ }else if(eq<np) {
+ set_field(
+ util::url_decode(qs.substr(p,eq-p)),
+ util::url_decode(qs.substr(eq+1,np-eq-1)) );
+ }
+ }
+ }
+
+
+ bool fields_t::has_field(const string& n) const {
+ return find(n)!=end();
+ }
+ const string& fields_t::get_field(const string& n) const {
+ const_iterator i=find(n);
+ if(i==end())
+ throw failed_lookup(OPKELE_CP_ n+": no such field");
+ return i->second;
+ }
+
+ fields_t::fields_iterator fields_t::fields_begin() const {
+ return util::map_keys_iterator<const_iterator,string,const string&,const string*>(begin(),end());
+ }
+ fields_t::fields_iterator fields_t::fields_end() const {
+ return util::map_keys_iterator<const_iterator,string,const string&,const string*>(end(),end());
+ }
+
+ void fields_t::reset_fields() {
+ clear();
+ }
+ void fields_t::set_field(const string& n,const string& v) {
+ (*this)[n]=v;
+ }
+ void fields_t::reset_field(const string& n) {
+ erase(n);
+ }
}