Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

domain.C

Go to the documentation of this file.
00001 // $Id: domain_C-source.html,v 1.1 2001/04/16 17:42:59 dvermeir Exp $
00002 #include "domain.h"
00003 
00004 Domain::Domain(const Domain& d, unsigned int n) {
00005 unsigned int m(min(d.size(),n));
00006 list<string>::const_iterator i=d.data().begin();
00007 
00008 for (unsigned int j=1; j<=m; ++j) 
00009   domain_.push_back(*i++);
00010 }
00011 
00012 // Parse a string "tinf2.vub.ac.be" as <"be","ac","vub","tinf2">.
00013 bool
00014 Domain::parse(const string& ds) {
00015 domain_.clear();
00016 string::size_type n0(ds.find_first_not_of('.'));
00017 if (n0!=0)
00018   return false;
00019 string::size_type n1(string::npos);
00020 
00021 while ((n1 = ds.find_first_of('.',n0)) != string::npos) {
00022   if (n1>n0)
00023     domain_.push_front(ds.substr(n0,n1-n0));
00024   n0 = n1+1;
00025   }
00026 // If domain does not end with '.', we still need to add a final component.
00027 if (n0<ds.size()) 
00028   domain_.push_front(ds.substr(n0));
00029 return true;
00030 }
00031 
00032 ostream&
00033 operator<<(ostream& os,const Domain& d) {
00034 for (list<string>::const_iterator i=d.data().begin(); i!=d.data().end(); ++i) {
00035   if (i!=d.data().begin())
00036     os << ".";
00037   os << (*i);
00038   }
00039 return os;
00040 }

httpstats-stage04 [ 7 April, 2001]