testp.cxx File Reference

#include "testp.h"
#include <vector>
#include <string>
#include <iostream>

Go to the source code of this file.

Functions

vector< string > parse_path (const char *path)
int test_parse_path ()

Function Documentation

vector<string> parse_path ( const char *  path  ) 

Definition at line 8 of file testp.cxx.

References done(), and find().

00009 {
00010     vector<string> vs;
00011     string p(path);
00012     string::iterator it1=p.begin(), it2, done=p.end();
00013     for (it2=find(p.begin(),done,'/'); it2 != done; it2=find(it1,done,'/')) {
00014         if (it1==it2) {
00015             ++it1;
00016             continue;
00017         }
00018         string dir(it1,it2);
00019         if (dir != ".")
00020             vs.push_back(dir);
00021         it1 = it2+1;
00022     }
00023     if (it1 != it2) {
00024         string dir(it1,it2);
00025         if (dir != ".")
00026             vs.push_back(string(it1,it2));
00027     }
00028     return vs;
00029 }

int test_parse_path (  ) 

Definition at line 31 of file testp.cxx.

References parse_path().

00032 {
00033     const char* paths[] = {
00034         "/an/absolute/path",
00035         "a/relative/path",
00036         "a/path/ending/in/slash/",
00037         "/a/path/with//double/slash",
00038         ".",
00039         "a/path/with/a/./dot",
00040         "",
00041         0
00042     };
00043 
00044     for (int ind=0; paths[ind]; ++ind) {
00045         vector<string> vs = parse_path(paths[ind]);
00046         cerr << "\"" << paths[ind] << "\" " << vs.size() << " subdirs: ";
00047         for (unsigned int i=0;i<vs.size();++i) 
00048             cerr << "\"" << vs[i] << "\" ";
00049         cerr << endl;
00050     }
00051 
00052 
00053     return 0;
00054 } // end of main()


Generated on 8 Jul 2019 for loon by  doxygen 1.6.1