diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-02-22 16:01:54 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-02-22 16:01:54 +0000 |
| commit | 44beebd257b0fb265bea5387850b9beb33c0adc2 (patch) | |
| tree | 0ec08e4aad18ccff2d578aca1c0b3799d2716c6c /src/Util.cc | |
| parent | d027ca8e7c383e9755d6fb997e8a880df99e88b9 (diff) | |
| parent | 87a229cab18679042beb06076e5dec1dcfadaeae (diff) | |
Tagging release 0.2.0 of aria2release-0.2.0
Diffstat (limited to 'src/Util.cc')
| -rw-r--r-- | src/Util.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Util.cc b/src/Util.cc index 13258e41..72e487e4 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -108,3 +108,32 @@ void Util::slice(vector<string>& result, string src, char delim) { result.push_back(trim(term)); } } + +bool Util::endsWith(string target, string part) { + if(target.size() < part.size()) { + return false; + } + if(target.compare(target.size()-part.size(), part.size(), part, 0, part.size()) == 0) { + return true; + } else { + return false; + } +} + +string Util::replace(string target, string oldstr, string newstr) { + if(target == "" || oldstr == "" ) { + return target; + } + string result; + string::size_type p = 0; + string::size_type np = target.find(oldstr); + while(np != string::npos) { + result += target.substr(p, np-p)+newstr; + p = np+oldstr.size(); + np = target.find(oldstr, p); + } + result += target.substr(p); + + return result; +} + |
