1 ////////////////////////////////////////////////////////////////////////
3 ////////////////////////////////////////////////////////////////////////
5 #include <simgear/compiler.h>
8 #include "strutils.hxx"
14 using namespace simgear::strutils;
16 #define COMPARE(a, b) \
18 cerr << "failed:" << #a << " != " << #b << endl; \
24 cerr << "failed:" << #a << endl; \
28 int main (int ac, char ** av)
30 std::string a("abcd");
32 COMPARE(strip(" a "), "a");
33 COMPARE(lstrip(" a "), "a ");
34 COMPARE(rstrip("\ta "), "\ta");
35 // check internal spacing is preserved
36 COMPARE(strip("\t \na \t b\r \n "), "a \t b");
39 VERIFY(starts_with("banana", "ban"));
40 VERIFY(!starts_with("abanana", "ban"));
41 VERIFY(starts_with("banana", "banana")); // pass - string starts with itself
42 VERIFY(!starts_with("ban", "banana")); // fail - original string is prefix of
44 VERIFY(ends_with("banana", "ana"));
45 VERIFY(ends_with("foo.text", ".text"));
46 VERIFY(!ends_with("foo.text", ".html"));
48 COMPARE(simplify("\ta\t b \nc\n\r \r\n"), "a b c");
49 COMPARE(simplify("The quick - brown dog!"), "The quick - brown dog!");
50 COMPARE(simplify("\r\n \r\n \t \r"), "");
52 COMPARE(to_int("999"), 999);
53 COMPARE(to_int("0000000"), 0);
54 COMPARE(to_int("-10000"), -10000);
56 cout << "all tests passed successfully!" << endl;