]> git.donarmstrong.com Git - lilypond.git/blob - flower/lib/stringtest.cc
0bbde77c99a5397bc1d942c6945ad6696c564083
[lilypond.git] / flower / lib / 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,3)<<endl;
76     cout << "nomid(2,6)="<<str.nomid_str(2,3)<<endl;
77 }
78
79 int 
80 main()
81 {
82     ctors();
83     cmp();
84     searching();
85     kutenpeer();
86     String str( "hai" );
87     cout <<  str << endl;
88     cout << "left" << endl;
89     str += " daar";
90     cout << str << endl;
91
92     str = String( "Hallo" ) + " daaR" + '!';
93     cout << str << endl;
94
95     cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
96     
97     if ( str == String( "" ) )
98         cout << str << " is empty" << endl;
99     else
100         cout << str << " is not empty"<<endl;
101
102     
103     String fn = "";
104     if ( fn == "" )
105         cout << fn << " is empty" << endl;
106     else
107         assert(false);
108     
109     fn = "";
110     fn += "";
111     delete fn.copy_byte_p();
112     delete str.copy_byte_p();
113
114     cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
115 }
116
117 #endif STRING_TEST
118