summaryrefslogtreecommitdiffabout
path: root/lib/discovery.cc
authorMichael Krelin <hacker@klever.net>2008-02-19 23:48:32 (UTC)
committer Michael Krelin <hacker@klever.net>2008-02-19 23:48:32 (UTC)
commitdaf2d4bcb4a31df6b46d3da7a33ee3f98d85e464 (patch) (side-by-side diff)
tree7d929285bc296777c63d4f482c7bb07f8541bce2 /lib/discovery.cc
parent42e4fb613d190508b3e8b8993d233044eeea4d20 (diff)
downloadlibopkele-daf2d4bcb4a31df6b46d3da7a33ee3f98d85e464.zip
libopkele-daf2d4bcb4a31df6b46d3da7a33ee3f98d85e464.tar.gz
libopkele-daf2d4bcb4a31df6b46d3da7a33ee3f98d85e464.tar.bz2
added an identifier normalization utility function
* moved iname leader characters and whitespace characters strings to opkele::data namespace * added opkele::util::normalize_identifier() function Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'lib/discovery.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/discovery.cc17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc
index b7f2db6..5913ad4 100644
--- a/lib/discovery.cc
+++ b/lib/discovery.cc
@@ -6,6 +6,7 @@
#include <opkele/exception.h>
#include <opkele/util.h>
#include <opkele/tidy.h>
+#include <opkele/data.h>
#include <opkele/debug.h>
#include "config.h"
@@ -21,8 +22,6 @@ namespace opkele {
/* TODO: the whole discovery thing needs cleanup and optimization due to
* many changes of concept. */
- static const char *whitespace = " \t\r\n";
- static const char *i_leaders = "=@+$!(";
static const size_t max_html = 16384;
static const struct service_type_t {
@@ -128,10 +127,10 @@ namespace opkele {
string discover(endpoint_discovery_iterator& oi,const string& identity) {
string rv;
idiscovery_t idis;
- string::size_type fsc = identity.find_first_not_of(whitespace);
+ string::size_type fsc = identity.find_first_not_of(data::_whitespace_chars);
if(fsc==string::npos)
throw bad_input(OPKELE_CP_ "whitespace-only identity");
- string::size_type lsc = identity.find_last_not_of(whitespace);
+ string::size_type lsc = identity.find_last_not_of(data::_whitespace_chars);
assert(lsc!=string::npos);
if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1))
fsc += sizeof("xri://")-1;
@@ -139,7 +138,7 @@ namespace opkele {
throw bad_input(OPKELE_CP_ "not a character of importance in identity");
string id(identity,fsc,lsc-fsc+1);
idis.clear();
- if(strchr(i_leaders,id[0])) {
+ if(strchr(data::_iname_leaders,id[0])) {
/* TODO: further normalize xri identity? Like folding case
* or whatever... */
rv = id;
@@ -495,13 +494,13 @@ namespace opkele {
const char *ns = a[1];
for(;*ns && isspace(*ns);++ns);
href.assign(ns);
- string::size_type lns=href.find_last_not_of(whitespace);
+ string::size_type lns=href.find_last_not_of(data::_whitespace_chars);
href.erase(lns+1);
}
}
- for(string::size_type ns=rels.find_first_not_of(whitespace);
- ns!=string::npos; ns=rels.find_first_not_of(whitespace,ns)) {
- string::size_type s = rels.find_first_of(whitespace,ns);
+ for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars);
+ ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) {
+ string::size_type s = rels.find_first_of(data::_whitespace_chars,ns);
string rel;
if(s==string::npos) {
rel.assign(rels,ns,string::npos);