00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "CommonFramework.h"
00019
00020
00021
00022
00023 _LIT(KTxtPressToContinue," (press any key to continue)\n");
00024 _LIT(KTxtnotfound,"NOT FOUND");
00025 _LIT(KTxtfound,"found");
00026 _LIT(KTxtlessthan," is less than ");
00027 _LIT(KTxtgreaterthan," is greater than ");
00028 _LIT(KTxtequalto," is equal to ");
00029
00030
00031
00032
00033 _LIT(KCommonFormat2,"Length()=%d; Size()=%d\n");
00034 _LIT(KCommonFormat8,"\"%S\" Char %c is at pos %d (%S)\n");
00035 _LIT(KCommonFormat9,"%- 8S pos %2d (%S)\n");
00036
00037
00038
00039 _LIT(KTxtCompstr1,"Hello World!@@");
00040 _LIT(KTxtCompstr2,"Hello");
00041 _LIT(KTxtCompstr3,"Hello Worl");
00042 _LIT(KTxtCompstr4,"Hello World!");
00043 _LIT(KTxtCompstr5,"hello world!");
00044 _LIT(KTxtCompstr6,"Hello World ");
00045 _LIT(KTxtCompstr7,"Hello World@");
00046
00047
00048
00049
00050 _LIT(KTxtMatchstr1,"*World*");
00051 _LIT(KTxtMatchstr2,"*W?rld*");
00052 _LIT(KTxtMatchstr3,"Wor*");
00053 _LIT(KTxtMatchstr4,"Hello");
00054 _LIT(KTxtMatchstr5,"*W*");
00055 _LIT(KTxtMatchstr6,"hello*");
00056 _LIT(KTxtMatchstr7,"*");
00057
00058
00059
00060 LOCAL_C void doExampleL()
00061 {
00062 TInt index;
00063 TInt pos;
00064 TPtrC genptr;
00065
00066
00067
00068 _LIT(KTxtHelloWorld,"Hello World!");
00069 const TBufC<16> bufc(KTxtHelloWorld);
00070
00071
00072
00073
00074 _LIT(KTxtRightMid,"\n--->Right() & Mid()\n");
00075 console->Printf(KTxtRightMid);
00076
00077
00078 _LIT(KFormat1," TBufC: \"%S\"; Ptr()=%x; ");
00079 console->Printf(KFormat1,&bufc,bufc.Ptr());
00080
00081 console->Printf(KCommonFormat2,bufc.Length(),bufc.Size());
00082
00083
00084
00085
00086 TPtrC ptrc1 = bufc.Right(5);
00087
00088
00089
00090
00091
00092 _LIT(KFormat3,"Right TPtrC: \"%S\"; Ptr()=%x; ");
00093 console->Printf(KFormat3,&ptrc1,ptrc1.Ptr());
00094 console->Printf(KCommonFormat2,ptrc1.Length(),ptrc1.Size());
00095
00096
00097
00098
00099 TPtrC ptrc2 = bufc.Mid(3,6);
00100
00101
00102
00103
00104
00105 _LIT(KFormat4," Mid TPtrC: \"%S\"; Ptr()=%x; ");
00106 console->Printf(KFormat4,&ptrc2,ptrc2.Ptr());
00107 console->Printf(KCommonFormat2,ptrc2.Length(),ptrc2.Size());
00108
00109
00110
00111
00112
00113
00114
00115 pos = (bufc.Mid(3,6)).Locate('W');
00116 _LIT(KFormat5,"(bufc.Mid(3,6)).Locate('W') returns %d\n");
00117 console->Printf(KFormat5,pos);
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 _LIT(KTxtCompare,"\n--->Compare() & CompareF()");
00131 console->Printf(KTxtCompare);
00132 console->Printf(KTxtPressToContinue);
00133 console->Getch();
00134
00135
00136
00137
00138
00139
00140
00141
00142 const TBufC<16> compstr[7] = {*&KTxtCompstr1,
00143 *&KTxtCompstr2,
00144 *&KTxtCompstr3,
00145 *&KTxtCompstr4,
00146 *&KTxtCompstr5,
00147 *&KTxtCompstr6,
00148 *&KTxtCompstr7
00149 };
00150
00151 for (index = 0; index < 7; index++)
00152 {
00153
00154 if ( (bufc.Compare(compstr[index])) < 0 )
00155 genptr.Set(KTxtlessthan);
00156 else if ( (bufc.Compare(compstr[index])) > 0)
00157 genptr.Set(KTxtgreaterthan);
00158 else genptr.Set(KTxtequalto);
00159 _LIT(KFormat6,"\"%S\"%S\"%S\"\n");
00160 console->Printf(KFormat6,&bufc,&genptr,&compstr[index]);
00161 }
00162
00163
00164
00165
00166
00167 for (index = 3; index < 5; index++)
00168 {
00169 if ( (bufc.CompareF(compstr[index])) < 0 )
00170 genptr.Set(KTxtlessthan);
00171 else if ( (bufc.CompareF(compstr[index])) > 0)
00172 genptr.Set(KTxtgreaterthan);
00173 else genptr.Set(KTxtequalto);
00174 _LIT(KTxtusingCF," (using CompareF())");
00175 _LIT(KFormat7,"\"%S\"%S\"%S\"%S\n");
00176 console->Printf(KFormat7,&bufc,&genptr,&compstr[index],&KTxtusingCF);
00177 }
00178
00179
00180
00181
00182
00183 _LIT(KTxtLocate,"\n--->Locate(), LocateF() & LocateReverse()");
00184 console->Printf(KTxtLocate);
00185 console->Printf(KTxtPressToContinue);
00186 console->Getch();
00187
00188
00189
00190 TChar ch[4] = {'H', '!', 'o', 'w'};
00191
00192
00193
00194
00195 _LIT(KTxtUsingLocate,"using Locate() \n");
00196 console->Printf(KTxtUsingLocate);
00197 for (index = 0 ; index < 4; index++)
00198 {
00199 pos = bufc.Locate(ch[index]);
00200
00201 if (pos < 0)
00202 genptr.Set(KTxtnotfound);
00203 else
00204 genptr.Set(KTxtfound);
00205
00206 console->Printf(KCommonFormat8,&bufc,TUint(ch[index]),pos,&genptr);
00207 }
00208
00209
00210
00211
00212
00213
00214 _LIT(KTxtUsingLocateF,"using LocateF() \n");
00215 console->Printf(KTxtUsingLocateF);
00216 for (index = 0 ; index < 4; index++)
00217 {
00218 pos = bufc.LocateF(ch[index]);
00219
00220 if (pos < 0)
00221 genptr.Set(KTxtnotfound);
00222 else
00223 genptr.Set(KTxtfound);
00224
00225 console->Printf(KCommonFormat8,&bufc,TUint(ch[index]),pos,&genptr);
00226 }
00227
00228
00229
00230 _LIT(KTxtUsingLocateReverse,"using LocateReverse() \n");
00231 console->Printf(KTxtUsingLocateReverse);
00232 for (index = 0 ; index < 4; index++)
00233 {
00234 pos = bufc.LocateReverse(ch[index]);
00235
00236 if (pos < 0)
00237 genptr.Set(KTxtnotfound);
00238 else
00239 genptr.Set(KTxtfound);
00240
00241 console->Printf(KCommonFormat8,&bufc,TUint(ch[index]),pos,&genptr);
00242 }
00243
00244
00245
00246
00247
00248
00249 _LIT(KTxtMatch,"\n--->Match()");
00250 console->Printf(KTxtMatch);
00251 console->Printf(KTxtPressToContinue);
00252 console->Getch();
00253
00254
00255 TBufC<8> matchstr[7] = {*&KTxtMatchstr1,
00256 *&KTxtMatchstr2,
00257 *&KTxtMatchstr3,
00258 *&KTxtMatchstr4,
00259 *&KTxtMatchstr5,
00260 *&KTxtMatchstr6,
00261 *&KTxtMatchstr7
00262 };
00263
00264
00265 _LIT(KFormat10,"\"%S\"\n");
00266 console->Printf(KFormat10,&bufc);
00267
00268
00269 for (index = 0 ; index < 7; index++)
00270 {
00271 pos = bufc.Match(matchstr[index]);
00272
00273 if (pos < 0)
00274 genptr.Set(KTxtnotfound);
00275 else
00276 genptr.Set(KTxtfound);
00277
00278 console->Printf(KCommonFormat9,&matchstr[index],pos,&genptr);
00279 }
00280
00281
00282
00283
00284
00285
00286
00287 _LIT(KTxtMatchF,"\n--->MatchF()");
00288 console->Printf(KTxtMatchF);
00289 console->Printf(KTxtPressToContinue);
00290 console->Getch();
00291
00292 for (index = 0 ; index < 7; index++)
00293 {
00294 pos = bufc.MatchF(matchstr[index]);
00295
00296 if (pos < 0)
00297 genptr.Set(KTxtnotfound);
00298 else
00299 genptr.Set(KTxtfound);
00300
00301 console->Printf(KCommonFormat9,&matchstr[index],pos,&genptr);
00302 }
00303 }
00304
00305
00306
00307
00308
00309
00310