summaryrefslogtreecommitdiff
path: root/src/cookie_helper.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-02-16 22:51:58 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-02-16 22:51:58 +0900
commitb3acf4d393f21af822bb59cdb191760b92b540ad (patch)
tree5500a1559a08a6e4ad951d5fab9777d32fe50a73 /src/cookie_helper.cc
parent61665d2c26be32c396e295345e92449ef3b9c001 (diff)
Rewrite cookie_helper::reverseDomainLevel()
Diffstat (limited to 'src/cookie_helper.cc')
-rw-r--r--src/cookie_helper.cc30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/cookie_helper.cc b/src/cookie_helper.cc
index a61055aa..87697b0a 100644
--- a/src/cookie_helper.cc
+++ b/src/cookie_helper.cc
@@ -402,18 +402,28 @@ bool pathMatch(const std::string& requestPath, const std::string& path)
std::string reverseDomainLevel(const std::string& domain)
{
std::string r;
- for(std::string::const_iterator i = domain.begin(), eoi = domain.end();
- i != eoi;) {
- std::string::const_iterator j = std::find(i, eoi, '.');
- r.insert(r.begin(), '.');
- r.insert(r.begin(), i, j);
- i = j;
- if(j != eoi) {
- ++i;
+ if(domain.empty()) {
+ return r;
+ }
+ r.reserve(domain.size());
+ // Cut trailing dots
+ std::string::const_iterator s = domain.end() - 1;
+ for(; *s == '.'; --s) {
+ if(s == domain.begin()) {
+ return r;
}
}
- if(!r.empty()) {
- r.erase(r.size()-1, 1);
+ std::string::const_iterator t = s + 1;
+ for(; ; --s) {
+ if(*s == '.') {
+ r.append(s + 1, t);
+ r += '.';
+ t = s;
+ }
+ if(s == domain.begin()) {
+ r.append(s, t);
+ break;
+ }
}
return r;
}