]> git.donarmstrong.com Git - lilypond.git/blob - flowertest/stringtest.cc
release: 0.1.54
[lilypond.git] / flowertest / stringtest.cc
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"
9
10 void
11 ctors ()
12 {
13   cout << "constructors"<<endl;
14   {
15     String str ("hai");
16     cout << str << endl;
17   }
18   {
19     String fromi (10);
20     cout << fromi<< endl;
21   }
22   {String fromf (1.32e-2, "%g");
23   cout << fromf<< endl;
24   }
25   {
26     String def;
27     cout << def << endl;
28   }
29   {
30     String fromc ('c');
31     cout << fromc<< endl;       
32   }
33 }
34 void
35 cmp ()
36 {
37   
38   String path  = "";
39   String sep ('/');
40   String right(path.right_str (1));
41   cout << "cmp ('', '/'): " << String::compare_i (sep,right) << endl;
42   
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;
53 }
54
55
56 void
57 searching ()
58 {
59   String hay = "foobarbazblub";
60
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;
71
72     
73     
74 }
75
76
77 void
78 kutenpeer ()
79 {
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;
84   }
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;
89 }
90
91 bool
92 test_empty_b (String str)
93 {
94   cout << "`" << str << "' is ";
95
96   if  (str == String ("")) {
97     cout << "empty" << endl;
98     return true;
99   }
100
101   cout << "not empty" << endl;
102   return false;
103 }
104
105 void
106 stringtest ()
107 {
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;
117
118   //    str = String ("Hallo") + " daaR" + '!'; // no go on doze-s gcc2.7.2?
119   str = String ("Hallo") + " daaR" + "!";
120   cout << str << endl;
121
122   cout << "up: " << str.upper_str () << " down: " << str.lower_str ()<<endl;
123     
124   if  (test_empty_b (str))
125     cout << "failed";
126
127   String fn = "";
128   if  (!test_empty_b (fn))
129     cout << "failed";
130
131     
132   fn = "";
133   fn += "";
134   delete fn.copy_byte_p ();
135   delete str.copy_byte_p ();
136
137   cout << String_convert::bin2hex_str (String ( (char)0xff)) << endl;
138   cout << "-1:" << String_convert::i2hex_str (-1, 2, '0');
139   cout << endl;
140
141 }
142
143
144 ADD_TEST (stringtest);