]> git.donarmstrong.com Git - lilypond.git/blob - flower/stringtest.cc
bc431567b929aa66e8ee04256d8f7e2c28731eb3
[lilypond.git] / flower / stringtest.cc
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"
10
11 void
12 ctors()
13 {
14   cout << "constructors"<<endl;
15
16   String str ("hai");
17   String def;
18   String fromi (10);
19   String fromc ('c');
20   String fromf (1.32e-2, "%g");
21
22   cout << str << endl;
23   cout << def << endl;
24   cout << fromi<< endl;
25   cout << fromc<< endl;       
26   cout << fromf<< endl;
27 }
28
29 void
30 cmp()
31 {
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;
41 }
42
43
44 void
45 searching()
46 {
47   String hay = "foobarbazblub";
48
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;
59
60   
61   
62 }
63
64
65 void
66 kutenpeer()
67 {
68   String str ("hai");
69   for (int i=-1; i < str.length_i()+2; i++) 
70     {
71         cout<<" left_str (" << i<<"): " << str.left_str (i) << endl;
72         cout<<" right_str ("<<i<<"): " << str.right_str (i) << endl;
73     }
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;
78 }
79
80 int 
81 main()
82 {
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;
92
93   str = String ("Hallo") + " daaR" + '!';
94   cout << str << endl;
95
96   cout << "up: " << str.upper_str() << " down: " << str.lower_str ()<<endl;
97   
98   if ( str == String ("") )
99       cout << str << " is empty" << endl;
100   else
101         cout << str << " is not empty"<<endl;
102
103   
104   String fn = "";
105   if ( fn == "")
106       cout << fn << " is empty" << endl;
107   else
108         assert (false);
109   
110   fn = "";
111   fn += "";
112   delete fn.copy_byte_p();
113   delete str.copy_byte_p();
114
115   cout << String_convert::bin2hex_str (String ((char)0xff) ) << endl;
116 }
117
118 #endif STRING_TEST
119