00001
00002
00003
00004 #include <stdlib.h>
00005
00006 #include "Riostream.h"
00007 #include "TString.h"
00008 #include "TRegexp.h"
00009 #include "TPRegexp.h"
00010
00011
00012 void Ok(int i, int b)
00013 {
00014 cout << "Test " << i;
00015 if (b)
00016 cout << " ok" << endl;
00017 else
00018 cout << " NOT ok" << endl;
00019 }
00020
00021
00022
00023 int main()
00024 {
00025
00026 TString s = "aap noot mies";
00027 cout << s << endl;
00028
00029
00030 TString s1 = TString("aa") + "p ";
00031 s1 += TString("noot ") + "mi" + "es";
00032 cout << s1 << endl;
00033 Ok(1, s1==s);
00034
00035
00036 TString s2 = 'a';
00037 s2 += "ap ";
00038 s2 += "noot ";
00039 s2 += "mies";
00040 cout << s2 << endl;
00041 Ok(2, s2==s);
00042
00043
00044 TString s3 = s(4,9);
00045 s3(0,4) = "mama papa";
00046 cout << s3 << endl;
00047 Ok(3, s3=="mama papa mies");
00048
00049
00050
00051 TRegexp re(" n.*t ");
00052 TString s4 = s;
00053 s4(re) = " pipo ";
00054 cout << s4 << endl;
00055 Ok(4, s4=="aap pipo mies");
00056
00057
00058
00059 const char *a = (const char*)s;
00060 cout << a << endl;
00061 Ok(5, !strcmp(a, s.Data()));
00062
00063
00064
00065 TString s6 = s;
00066 s6[12] = 't';
00067 cout << s6 << endl;
00068 cout << "*** Error message ok, accessing intentionaly out-of-bounds" << endl;
00069 char b = s6[13];
00070 cout << b << endl;
00071 Ok(6, s6=="aap noot miet");
00072
00073
00074
00075
00076 TString s7 = s;
00077 s7(12) = 'p';
00078 cout << s7 << endl;
00079 char c = s7(13);
00080 cout << c << endl;
00081 Ok(7, s7=="aap noot miep");
00082
00083
00084 TString s8 = s;
00085 s8.Append(" tante ");
00086 s8.Append(s7(9,4));
00087 cout << s8 << endl;
00088
00089 s8.Remove(0,14);
00090 cout << s8 << endl;
00091 s8.Prepend("oom jan");
00092 cout << s8 << endl;
00093 s8.Insert(7," en ");
00094 cout << s8 << endl;
00095 s8.Replace(4,3,"jaap");
00096 cout << s8 << endl;
00097 Ok(8, s8=="oom jaap en tante miep");
00098
00099
00100 TString s9 = s;
00101 Ok(9, !s9.CompareTo(s));
00102 Ok(10, !s9.CompareTo("AAP NOOT MIES", TString::kIgnoreCase));
00103
00104
00105 Ok(11, s9.Contains("NooT", TString::kIgnoreCase));
00106 Ok(12, !s9.Contains("pipo"));
00107
00108
00109 Ok(13, s.First('o')==5);
00110 Ok(14, s.First('z')==kNPOS);
00111 Ok(15, s.Last('a')==1);
00112 Ok(16, s.Last('z')==kNPOS);
00113
00114
00115 Ok(17, s.Index("mies")==9);
00116 Ok(18, s.Index("aa",1)==kNPOS);
00117
00118
00119 Ok(19, s.Length()==13);
00120
00121
00122 TString s10;
00123
00124 Ok(20, s10.IsNull());
00125 Ok(21, !s.IsNull());
00126
00127
00128 s10 = "\xb9";
00129
00130 Ok(22, !s10.IsAscii());
00131 Ok(23, s.IsAscii());
00132
00133
00134 TString s11("Food is on the foo table.");
00135 TPRegexp("\\b(foo)\\s+(\\w+)").Substitute(s11, "round $2");
00136 Ok(24, s11=="Food is on the round table.");
00137
00138 TString s12("pepernotenkoek");
00139 TPRegexp("peper(.*)koek").Substitute(s12, "wal$1boom");
00140 Ok(25, s12=="walnotenboom");
00141
00142 TString s13("hihi haha");
00143 TPRegexp("^([^ ]*) *([^ ]*)").Substitute(s13, "$2 $1");
00144 Ok(26, s13=="haha hihi");
00145
00146 Ok(27, TPRegexp("^(\\w+) *(\\w+)").Match(s13) == 3);
00147
00148
00149 s9.Prepend(" ");
00150 cout << s9 << endl;
00151
00152 s9.Resize(50);
00153 cout << s9 << "<<ends here" << endl;
00154
00155 cout << s9.Strip(TString::kBoth) << "<<ends here" << endl;
00156
00157 Printf("Using Print: %s (%d)\n", (const char*) s9, s9.Length());
00158
00159 return 0;
00160 }