]> git.donarmstrong.com Git - lilypond.git/blob - flower/test/stringtest.cc
release: 0.0.42
[lilypond.git] / flower / test / 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         cout<<" left_str(" << i<<"): " << str.left_str( i ) << endl;
71         cout<<" right_str( "<<i<<"): " << str.right_str( i ) << endl;
72     }
73     str = "blonde haren";
74     cout << str<<endl;
75     cout << "mid(2,6)="<<str.mid_str(2,6)<<endl;
76     cout << "nomid(2,6)="<<str.nomid_str(2,6)<<endl;
77 }
78
79 bool
80 test_empty_b( String str )
81 {
82     cout << "`" << str << "' is ";
83
84     if ( str == String( "" ) ) {
85         cout << "empty" << endl;
86         return true;
87     }
88
89     cout << "not empty" << endl;
90     return false;
91 }
92
93 int 
94 main()
95 {
96     ctors();
97     cmp();
98     searching();
99     kutenpeer();
100     String str( "hai" );
101     cout <<  str << endl;
102     cout << "left" << endl;
103     str += " daar";
104     cout << str << endl;
105
106 //    str = String( "Hallo" ) + " daaR" + '!'; // no go on doze-s gcc2.7.2?
107     str = String( "Hallo" ) + " daaR" + "!";
108     cout << str << endl;
109
110     cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
111     
112     if ( test_empty_b( str ) )
113         return 1;
114     
115     String fn = "";
116     if ( !test_empty_b( fn ) )
117         return 1;
118     
119     fn = "";
120     fn += "";
121     delete fn.copy_byte_p();
122     delete str.copy_byte_p();
123
124     cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
125     cout << "-1:" << String_convert::i2hex_str( -1, 2, '0' );
126     cout << endl;
127     return 0;
128 }
129
130 #endif STRING_TEST
131