From: Leandro Lucarella Date: Sun, 17 Aug 2003 23:10:35 +0000 (+0000) Subject: Added a string substr test. X-Git-Tag: svn_import~4 X-Git-Url: https://git.llucax.com/software/bife/bife%20%20.git/commitdiff_plain/62eb4c434ac30aa83ef05be78130cb42105f618c/software/bife/bife++.git/commitdiff_plain/62eb4c434ac30aa83ef05be78130cb42105f618c Added a string substr test. --- diff --git a/tests/test_substr.cpp b/tests/test_substr.cpp new file mode 100644 index 0000000..0bab8c9 --- /dev/null +++ b/tests/test_substr.cpp @@ -0,0 +1,27 @@ +// vim: set et ts=4 sw=4: + +#include +#include + +using namespace std; + +int main(void) { + string s1 = "base_translate"; + string::size_type pos = s1.find("."); + if (pos == string::npos) { + cerr << "Dot not found in: " << s1 << endl; + } + s1 = "base.translate"; + pos = s1.find("."); + if (pos == string::npos) { + cerr << "Dot not found in: " << s1 << endl; + return 1; + } else { + cerr << "Dot at position " << pos << " in: " << s1 << endl; + } + string s2(s1, 0, pos); + cout << "Module name: " << s2 << endl; + string s3 = s1.substr(pos + 1, s1.length() - 1); + cout << "Module name: " << s3 << endl; + return 0; +}