lilypond-1.3.18
[lilypond.git] / flower / stringtest.cc
bloba5bc0c603600454da163d8a010e9242bd0629ad1
1 #ifdef STRING_TEST
2 /*
3 stupid test program to verify stringlib
4 stringtest.cc
5 */
6 #include <iostream.h>
7 #include "string.hh"
8 #include "varray.hh"
9 #include "string-convert.hh"
11 void
12 ctors()
14 cout << "constructors"<<endl;
16 String str ("hai");
17 String def;
18 String fromi (10);
19 String fromc ('c');
20 String fromf (1.32e-2, "%g");
22 cout << str << endl;
23 cout << def << endl;
24 cout << fromi<< endl;
25 cout << fromc<< endl;
26 cout << fromf<< endl;
29 void
30 cmp()
32 Array<String> a;
33 a.push ("abcd");
34 a.push ("zxy");
35 a.push ("abc");
36 a.push ("");
37 a.sort (String::compare_i);
38 cout << "compares: "<<endl;
39 for (int i=0; i < a.size(); i++)
40 cout << a[i] << endl;
44 void
45 searching()
47 String hay = "foobarbazblub";
49 char c = 'b';
50 String cstr =c;
51 String set = "bar";
52 cout << "hay = \"" << hay << "\" len="<< hay.length_i()<<endl;
53 cout << "index_i ('"<< c<<"') " << c << "= " << hay.index_i (c) <<endl;
54 cout << "last_index_i ('"<< c<<"') " << c << "= " << hay.index_last_i (c) <<endl;
55 // cout << "last index of cstr " << c << ": " << hay.index_last_i (cstr) <<endl;
56 // cout << "index_last_i (\""<<set<<"\"): " << hay.index_last_i (set) <<endl;
57 cout << "index_i (\""<<set<<"\"): " << hay.index_i (set) <<endl;
58 cout << "index_any (\"" << set << "\"): " << cstr << ": " << hay.index_any_i (cstr) <<endl;
65 void
66 kutenpeer()
68 String str ("hai");
69 for (int i=-1; i < str.length_i()+2; i++)
71 cout<<" left_str (" << i<<"): " << str.left_str (i) << endl;
72 cout<<" right_str ("<<i<<"): " << str.right_str (i) << endl;
74 str = "blonde haren";
75 cout << str<<endl;
76 cout << "mid (2,6)="<<str.mid_str (2,3)<<endl;
77 cout << "nomid (2,6)="<<str.nomid_str (2,3)<<endl;
80 int
81 main()
83 ctors();
84 cmp();
85 searching();
86 kutenpeer();
87 String str ("hai");
88 cout << str << endl;
89 cout << "left" << endl;
90 str += " daar";
91 cout << str << endl;
93 str = String ("Hallo") + " daaR" + '!';
94 cout << str << endl;
96 cout << "up: " << str.upper_str() << " down: " << str.lower_str ()<<endl;
98 if (str == String ("") )
99 cout << str << " is empty" << endl;
100 else
101 cout << str << " is not empty"<<endl;
104 String fn = "";
105 if (fn == "")
106 cout << fn << " is empty" << endl;
107 else
108 assert (false);
110 fn = "";
111 fn += "";
112 delete fn.copy_byte_p();
113 delete str.copy_byte_p();
115 cout << String_convert::bin2hex_str (String ((char)0xff) ) << endl;
118 #endif STRING_TEST