00001
00002 #include "path.h"
00003
00004
00005 Path::Path(const Path& p,unsigned int n) {
00006 unsigned int m(min(p.size(),n));
00007 path_.resize(m);
00008 for (unsigned int i=0; i<m; ++i)
00009 path_[i] = p[i];
00010 }
00011
00012 bool
00013 Path::parse(const string& ps) {
00014 str_.erase();
00015 path_.clear();
00016
00017
00018
00019
00020
00021
00022
00023
00024 string::size_type n0(ps.find_first_not_of('/',0));
00025
00026 if (n0==string::npos) {
00027 path_.push_back("");
00028 return true;
00029 }
00030
00031 string::size_type n1(string::npos);
00032
00033
00034
00035
00036
00037 while ((n1=ps.find_first_of('/',n0))!=string::npos) {
00038 if (n1>n0)
00039 path_.push_back(ps.substr(n0,n1-n0));
00040 n0 = n1+1;
00041 }
00042
00043 if (n0<ps.size())
00044 path_.push_back(ps.substr(n0));
00045
00046 return true;
00047 }
00048
00049 const string&
00050 Path::str() const {
00051 if (str_.size()==0) {
00052 for (unsigned int j=0; j<size() ; ++j) {
00053 str_ += '/';
00054 str_ += path_[j];
00055 }
00056 }
00057 return str_;
00058 }
00059
00060 ostream&
00061 operator<<(ostream& os,const Path& path) {
00062 return os << path.str();
00063 }
00064