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

nameutils Namespace Reference


Functions

string parse_format (const string &prefix_, vector< string > &vs_)
string parse_seq_number (const string &name_, const string &prefix_)
string format_seqnum (int seqnum_, const string &fmt_)
string make_name_with_offset (const string &name_, const string &fmt_, const string &prefix_, const string &dirpath_, int offset_)
string make_prev_name (const string &name_, const string &fmt_, const string &prefix_, const string &dirpath_)
string make_next_name (const string &name_, const string &fmt_, const string &prefix_, const string &dirpath_)
int fast_copy (const string &src_, const string &dest_)


Function Documentation

int nameutils::fast_copy const string &    src_,
const string &    dest_
 

Definition at line 252 of file NameUtils.cpp.

00253 {
00254     ifstream source (src_.c_str (), std::ios::in);
00255     ofstream destination (dest_.c_str (), std::ios::out);
00256 
00257     if (!(source.good () || destination.good ())) {
00258         return -1;
00259     }
00260 
00261     destination << source.rdbuf();
00262     source.close ();
00263     destination.close ();
00264     return 0;
00265 }

string nameutils::format_seqnum int    seqnum_,
const string &    fmt_
 

Definition at line 124 of file test.cpp.

00125 {
00126     char buf [PATH_MAX];
00127 
00128     snprintf (buf, PATH_MAX, fmt_.c_str (), seqnum_);
00129     return string (buf);
00130 }

string nameutils::make_name_with_offset const string &    name_,
const string &    fmt_,
const string &    prefix_,
const string &    dirpath_,
int    offset_
 

Definition at line 141 of file test.cpp.

00144 {
00145     string s (name_);
00146     string::size_type idx;
00147 
00148     cout << '\n';
00149     s = parse_seq_number (s, prefix_);
00150     cout << "\tparsed sequence number: " << s << '\n';
00151     if (s.length () == 0) {
00152         return s;
00153     }
00154     return (dirpath_ + prefix_ 
00155             + format_seqnum (atoi (s.c_str ()) + offset_, fmt_) 
00156             + string (".wav"));
00157 }

string nameutils::make_next_name const string &    name_,
const string &    fmt_,
const string &    prefix_,
const string &    dirpath_
 

Definition at line 181 of file test.cpp.

00183 {
00184     return make_name_with_offset (name_, fmt_, prefix_, dirpath_, +1);
00185 }

string nameutils::make_prev_name const string &    name_,
const string &    fmt_,
const string &    prefix_,
const string &    dirpath_
 

Definition at line 167 of file test.cpp.

00169 {
00170     return make_name_with_offset (name_, fmt_, prefix_, dirpath_, -1);
00171 }

string nameutils::parse_format const string &    prefix_,
vector< string > &    vs_
 

Definition at line 38 of file test.cpp.

00039 {
00040     string ret;
00041     int i = 0;
00042     bool is_varlen = false;
00043     int len = 0;
00044     bool is_numeric = true;
00045     string name;
00046 
00047     vector<string>::const_iterator cit = vs_.begin ();
00048     name = parse_seq_number (*cit, prefix_);
00049 
00050     if ((len = name.length ()) == 0) {
00051         return ret;
00052     }
00053 
00054     while (cit != vs_.end ()) {
00055         if (*cit != "gap") {
00056             name = parse_seq_number (*cit, prefix_);
00057             if (name.length () == 0) {
00058                 return ret;
00059             }
00060             i = strtol (name.c_str (), (char **) NULL, 10);
00061             if (i == LONG_MIN || i == LONG_MAX) {
00062                 is_numeric = false;
00063                 break;
00064             }
00065             if (name.length () != len) {
00066                 is_varlen = true;
00067             }
00068         }
00069         cit++;
00070     }
00071     if (is_numeric) {
00072         if (!is_varlen) {
00073             ostringstream os;
00074             os << "%0" << len << "d";
00075             ret = os.str ();
00076         }
00077         else {
00078             ret = "%d";
00079         }
00080     }
00081     return ret;
00082 }

string nameutils::parse_seq_number const string &    name_,
const string &    prefix_
 

Definition at line 98 of file test.cpp.

00099 {
00100     string s (name_);
00101     string::size_type idx = string::npos;
00102 
00103     if ((idx = s.find (prefix_)) == 0) {
00104         s.erase (0, prefix_.length ());
00105         idx = s.find ('.');
00106         if (idx != string::npos) {
00107             if (s.substr (idx) == ".wav") {
00108                 s.replace (idx, name_.size (), "");
00109                 return s;
00110             }
00111         }
00112     }
00113     return ("");
00114 }


Generated on Tue Feb 11 23:05:34 2003 for gwavmerger by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002