]> git.donarmstrong.com Git - lilypond.git/blob - flower/test/stringtest.cc
release: 0.1.41
[lilypond.git] / flower / test / 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   Array<String> a;
38   a.push("abcd");
39   a.push("zxy");
40   a.push("abc");
41   a.push("");
42   a.sort(String::compare_i);
43   cout << "compares: "<<endl;
44   for (int i=0; i < a.size(); i++)
45     cout << a[i] << endl;
46 }
47
48
49 void
50 searching()
51 {
52   String hay = "foobarbazblub";
53
54   char c =   'b';
55   String cstr =c;
56   String set = "bar";
57   cout << "hay = \"" << hay << "\" len="<< hay.length_i()<<endl;
58   cout << "index_i('"<< c<<"') " << c << "= " << hay.index_i(c) <<endl;
59   cout << "last_index_i('"<< c<<"') " << c << "= " << hay.index_last_i(c) <<endl;    
60   //    cout << "last index of cstr " << c << ": " << hay.index_last_i(cstr) <<endl;    
61   //    cout << "index_last_i(\""<<set<<"\"): " << hay.index_last_i(set) <<endl;
62   cout << "index_i(\""<<set<<"\"): " << hay.index_i(set) <<endl;    
63   cout << "index_any(\"" << set << "\"): " << cstr << ": " << hay.index_any_i(cstr) <<endl;
64
65     
66     
67 }
68
69
70 void
71 kutenpeer()
72 {
73   String str( "hai" );
74   for (int i=-1; i < str.length_i()+2; i++) {
75     cout<<" left_str(" << i<<"): " << str.left_str( i ) << endl;
76     cout<<" right_str( "<<i<<"): " << str.right_str( i ) << endl;
77   }
78   str = "blonde haren";
79   cout << str<<endl;
80   cout << "mid(2,6)="<<str.cut(2,6)<<endl;
81   cout << "nomid(2,6)="<<str.nomid_str(2,6)<<endl;
82 }
83
84 bool
85 test_empty_b( String str )
86 {
87   cout << "`" << str << "' is ";
88
89   if ( str == String( "" ) ) {
90     cout << "empty" << endl;
91     return true;
92   }
93
94   cout << "not empty" << endl;
95   return false;
96 }
97
98 void
99 stringtest()
100 {
101   ctors();
102   cmp();
103   searching();
104   kutenpeer();
105   String str( "hai" );
106   cout <<  str << endl;
107   cout << "left" << endl;
108   str += " daar";
109   cout << str << endl;
110
111   //    str = String( "Hallo" ) + " daaR" + '!'; // no go on doze-s gcc2.7.2?
112   str = String( "Hallo" ) + " daaR" + "!";
113   cout << str << endl;
114
115   cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
116     
117   if ( test_empty_b( str ) )
118     cout << "failed";
119
120   String fn = "";
121   if ( !test_empty_b( fn ) )
122     cout << "failed";
123
124     
125   fn = "";
126   fn += "";
127   delete fn.copy_byte_p();
128   delete str.copy_byte_p();
129
130   cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
131   cout << "-1:" << String_convert::i2hex_str( -1, 2, '0' );
132   cout << endl;
133
134 }
135
136
137 ADD_TEST(stringtest);