lilypond-0.1.56
[lilypond.git] / flowertest / stringtest.cc
blob4597ff3b8558c6476976971f920cefe1e9778eda
1 /*
2 stupid test program to verify stringlib
3 stringtest.cc
4 */
5 #include "string.hh"
6 #include "varray.hh"
7 #include "string-convert.hh"
8 #include "flower-test.hh"
10 void
11 ctors ()
13 cout << "constructors"<<endl;
15 String str ("hai");
16 cout << str << endl;
19 String fromi (10);
20 cout << fromi<< endl;
22 {String fromf (1.32e-2, "%g");
23 cout << fromf<< endl;
26 String def;
27 cout << def << endl;
30 String fromc ('c');
31 cout << fromc<< endl;
34 void
35 cmp ()
38 String path = "";
39 String sep ('/');
40 String right(path.right_str (1));
41 cout << "cmp ('', '/'): " << String::compare_i (sep,right) << endl;
43 Array<String> a;
44 a.push ("abcd");
45 a.push ("zxy");
46 a.push ("abc");
47 a.push ("");
48 a.push ("a");
49 a.sort (String::compare_i);
50 cout << "compares: "<<endl;
51 for (int i=0; i < a.size (); i++)
52 cout << a[i] << endl;
56 void
57 searching ()
59 String hay = "foobarbazblub";
61 char c = 'b';
62 String cstr =c;
63 String set = "bar";
64 cout << "hay = \"" << hay << "\" len="<< hay.length_i ()<<endl;
65 cout << "index_i ('"<< c<<"') " << c << "= " << hay.index_i (c) <<endl;
66 cout << "last_index_i ('"<< c<<"') " << c << "= " << hay.index_last_i (c) <<endl;
67 // cout << "last index of cstr " << c << ": " << hay.index_last_i (cstr) <<endl;
68 // cout << "index_last_i (\""<<set<<"\"): " << hay.index_last_i (set) <<endl;
69 cout << "index_i (\""<<set<<"\"): " << hay.index_i (set) <<endl;
70 cout << "index_any (\"" << set << "\"): " << cstr << ": " << hay.index_any_i (cstr) <<endl;
77 void
78 kutenpeer ()
80 String str ("hai");
81 for (int i=-1; i < str.length_i ()+2; i++) {
82 cout<<" left_str (" << i<<"): " << str.left_str (i) << endl;
83 cout<<" right_str ("<<i<<"): " << str.right_str (i) << endl;
85 str = "blonde haren";
86 cout << str<<endl;
87 cout << "mid (2,6)="<<str.cut (2,6)<<endl;
88 cout << "nomid (2,6)="<<str.nomid_str (2,6)<<endl;
91 bool
92 test_empty_b (String str)
94 cout << "`" << str << "' is ";
96 if (str == String ("")) {
97 cout << "empty" << endl;
98 return true;
101 cout << "not empty" << endl;
102 return false;
105 void
106 stringtest ()
108 ctors ();
109 cmp ();
110 searching ();
111 kutenpeer ();
112 String str ("hai");
113 cout << str << endl;
114 cout << "left" << endl;
115 str += " daar";
116 cout << str << endl;
118 // str = String ("Hallo") + " daaR" + '!'; // no go on doze-s gcc2.7.2?
119 str = String ("Hallo") + " daaR" + "!";
120 cout << str << endl;
122 cout << "up: " << str.upper_str () << " down: " << str.lower_str ()<<endl;
124 if (test_empty_b (str))
125 cout << "failed";
127 String fn = "";
128 if (!test_empty_b (fn))
129 cout << "failed";
132 fn = "";
133 fn += "";
134 delete fn.copy_byte_p ();
135 delete str.copy_byte_p ();
137 cout << String_convert::bin2hex_str (String ( (char)0xff)) << endl;
138 cout << "-1:" << String_convert::i2hex_str (-1, 2, '0');
139 cout << endl;
144 ADD_TEST (stringtest);