]> git.donarmstrong.com Git - lilypond.git/blob - flower/test/stringtest.cc
release: 0.0.47
[lilypond.git] / flower / test / stringtest.cc
1 /*
2   stupid test program to verify stringlib
3   stringtest.cc
4   */
5 #include <iostream.h>
6 #include "string.hh"
7 #include "varray.hh"
8 #include "string-convert.hh"
9
10 void
11 ctors()
12 {
13     cout << "constructors"<<endl;
14
15     String str( "hai" );
16     String def;
17     String fromi(10);
18     String fromc('c');
19     String fromf(1.32e-2, "%g");
20
21     cout << str << endl;
22     cout << def << endl;
23     cout << fromi<< endl;
24     cout << fromc<< endl;       
25     cout << fromf<< endl;
26 }
27
28 void
29 cmp()
30 {
31     Array<String> a;
32     a.push("abcd");
33     a.push("zxy");
34     a.push("abc");
35     a.push("");
36     a.sort(String::compare_i);
37     cout << "compares: "<<endl;
38     for (int i=0; i < a.size(); i++)
39         cout << a[i] << endl;
40 }
41
42
43 void
44 searching()
45 {
46     String hay = "foobarbazblub";
47
48     char c =   'b';
49     String cstr =c;
50     String set = "bar";
51     cout << "hay = \"" << hay << "\" len="<< hay.length_i()<<endl;
52     cout << "index_i('"<< c<<"') " << c << "= " << hay.index_i(c) <<endl;
53     cout << "last_index_i('"<< c<<"') " << c << "= " << hay.index_last_i(c) <<endl;    
54 //    cout << "last index of cstr " << c << ": " << hay.index_last_i(cstr) <<endl;    
55 //    cout << "index_last_i(\""<<set<<"\"): " << hay.index_last_i(set) <<endl;
56     cout << "index_i(\""<<set<<"\"): " << hay.index_i(set) <<endl;    
57     cout << "index_any(\"" << set << "\"): " << cstr << ": " << hay.index_any_i(cstr) <<endl;
58
59     
60     
61 }
62
63
64 void
65 kutenpeer()
66 {
67     String str( "hai" );
68     for (int i=-1; i < str.length_i()+2; i++) {
69         cout<<" left_str(" << i<<"): " << str.left_str( i ) << endl;
70         cout<<" right_str( "<<i<<"): " << str.right_str( i ) << endl;
71     }
72     str = "blonde haren";
73     cout << str<<endl;
74     cout << "mid(2,6)="<<str.mid_str(2,6)<<endl;
75     cout << "nomid(2,6)="<<str.nomid_str(2,6)<<endl;
76 }
77
78 bool
79 test_empty_b( String str )
80 {
81     cout << "`" << str << "' is ";
82
83     if ( str == String( "" ) ) {
84         cout << "empty" << endl;
85         return true;
86     }
87
88     cout << "not empty" << endl;
89     return false;
90 }
91
92 int 
93 main()
94 {
95     ctors();
96     cmp();
97     searching();
98     kutenpeer();
99     String str( "hai" );
100     cout <<  str << endl;
101     cout << "left" << endl;
102     str += " daar";
103     cout << str << endl;
104
105 //    str = String( "Hallo" ) + " daaR" + '!'; // no go on doze-s gcc2.7.2?
106     str = String( "Hallo" ) + " daaR" + "!";
107     cout << str << endl;
108
109     cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
110     
111     if ( test_empty_b( str ) )
112         return 1;
113     
114     String fn = "";
115     if ( !test_empty_b( fn ) )
116         return 1;
117     
118     fn = "";
119     fn += "";
120     delete fn.copy_byte_p();
121     delete str.copy_byte_p();
122
123     cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
124     cout << "-1:" << String_convert::i2hex_str( -1, 2, '0' );
125     cout << endl;
126     return 0;
127 }
128
129