diff options
author | Michael Larson <slioch@eng-140.vyatta.com> | 2007-12-14 13:40:31 -0800 |
---|---|---|
committer | Michael Larson <slioch@eng-140.vyatta.com> | 2007-12-14 13:40:31 -0800 |
commit | 59b21be36b2f4cd74aa0cea53492e3023b59770b (patch) | |
tree | c1f1893bcba148eff202148f548328155bf729d4 /src/rl_str_proc.cc | |
download | vyatta-wanloadbalance-debian/0.1.tar.gz vyatta-wanloadbalance-debian/0.1.zip |
initial check wan lbdebian/0.1
Signed-off-by: Michael Larson <slioch@eng-140.vyatta.com>
Diffstat (limited to 'src/rl_str_proc.cc')
-rw-r--r-- | src/rl_str_proc.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/rl_str_proc.cc b/src/rl_str_proc.cc new file mode 100644 index 0000000..3a5d151 --- /dev/null +++ b/src/rl_str_proc.cc @@ -0,0 +1,82 @@ +#include "rl_str_proc.hh" + +using namespace std; + +/** + * + **/ +StrProc::StrProc(const string &in_str, const string &token) +{ + string tmp = in_str; + + //convert tabs to spaces + uint32_t pos = 0; + string tabtospace = " "; + string::iterator iter = tmp.begin(); + while ((pos = tmp.find("\t", pos)) != string::npos) { + tmp.replace(pos, 1, tabtospace); + pos += tabtospace.length(); + } + + //remove the cr + pos = tmp.find("\n"); + if (pos != string::npos) { + tmp.replace(pos, 1, ""); + } + + //now handle the case of the multiple length token + //note that we are using the '~' as a token internally + uint32_t start = 0, end; + while ((start = tmp.find(token, start)) != string::npos) { + tmp.replace(start, token.length(), "~"); + } + + + while ((start = tmp.find_first_not_of("~")) != string::npos) { + tmp = tmp.substr(start, tmp.length() - start); + end = tmp.find_first_of("~"); + _str_coll.push_back(tmp.substr(0, end)); + tmp = tmp.substr(end+1, tmp.length() - end-1); + if (end == string::npos) { + break; + } + } +} + +/** + * + **/ +string +StrProc::get(int i) +{ + if (uint32_t(i) >= _str_coll.size()) { + return string(""); + } + return _str_coll[i]; +} + +/** + * + **/ +string +StrProc::get(int start, int end) +{ + if (uint32_t(start) >= _str_coll.size()) { + return string(""); + } + + string tmp; + for (int i = start; (i < end) && (uint32_t(i) < _str_coll.size()); ++i) { + tmp += _str_coll[i] + " "; + } + return tmp.substr(0,tmp.length()-1); +} + +/** + * + **/ +vector<string> +StrProc::get() +{ + return _str_coll; +} |