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(KPressAnyKeyToContinue," (press any key to continue)\n");
00024 _LIT(KTextHelloWorld,"Hello World!");
00025 _LIT(KTextHello,"Hello");
00026 _LIT(KTextXYZ,"XYZ");
00027 _LIT(KTextDinner,"D\214ner \205 la Fran\207ais");
00028
00029
00030
00031
00032
00033 _LIT(KFormatfourex,"%4x");
00034 _LIT(KFormatBufLenSizeMax,"\"%S\"; %d; %d; %d\n");
00035 _LIT(KFormatLenSizeMax,"; %d; %d; %d\n");
00036 _LIT(KFormatBufLen,"\"%S\"; Length()=%d; ");
00037 _LIT(KFormatSizeMax,"Size()=%d; MaxLength()=%d\n");
00038 _LIT(KFormatCommon,"0x%02x ");
00039
00040
00041
00042
00043
00044 class TestOverflow : public TDesOverflow
00045 {
00046 void Overflow(TDes& aDes);
00047 };
00048
00049
00050 void TestOverflow::Overflow(TDes& aDes)
00051 {
00052 _LIT(KTextDescOverflow,"Descriptor overflow - maxlength %d\n");
00053 console->Printf(KTextDescOverflow,aDes.MaxLength());
00054 }
00055
00056
00057
00058 LOCAL_C void doExampleL()
00059 {
00060
00061 TInt index;
00062 TInt counter;
00063
00064
00065 TBuf<32> buf(KTextHelloWorld);
00066
00067
00068
00069
00070
00071
00072 _LIT(KTitleCopy,"\n--->Copy(),CopyF(),CopyUC() & CopyCP()\n");
00073 _LIT(KNoteAboutLocale1,"\nNote that the behaviour of CopyF(), CopyUC() & CopyCP() is\n");
00074 _LIT(KNoteAboutLocale2,"dependent on the locale.\n");
00075 console->Printf(KTitleCopy);
00076 console->Printf(KNoteAboutLocale1);
00077 console->Printf(KNoteAboutLocale2);
00078
00079
00080
00081 console->Printf(KFormatBufLen,&buf,buf.Length());
00082 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00083
00084
00085 buf.Copy(KTextDinner);
00086
00087
00088
00089 console->Printf(KFormatBufLen,&buf,buf.Length());
00090 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00091
00092
00093
00094
00095
00096
00097
00098 buf.CopyF(KTextDinner);
00099
00100
00101
00102 console->Printf(KFormatBufLen,&buf,buf.Length());
00103 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00104
00105
00106 buf.CopyUC(KTextDinner);
00107
00108
00109
00110 console->Printf(KFormatBufLen,&buf,buf.Length());
00111 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00112
00113
00114
00115 _LIT(KTextCatOnMat,"tHe CaT sAt On ThE mAt - voil\205");
00116 buf.CopyCP(KTextCatOnMat);
00117
00118
00119
00120 console->Printf(KFormatBufLen,&buf,buf.Length());
00121 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 _LIT(KTitleAppend,"\n--->Append & Operator+=");
00134 console->Printf(KTitleAppend);
00135 console->Printf(KPressAnyKeyToContinue);
00136 console->Getch();
00137
00138
00139
00140 buf = KTextHelloWorld;
00141 console->Printf(KFormatBufLen,&buf,buf.Length());
00142 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00143
00144
00145
00146
00147
00148
00149
00150
00151 buf.Append('@');
00152 buf.Append(KTextXYZ);
00153 _LIT(KTextHashHash,"##");
00154 buf += KTextHashHash;
00155 console->Printf(KFormatBufLen,&buf,buf.Length());
00156 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00157
00158
00159
00160
00161 _LIT(KTitleSwap,"\n--->Swap()");
00162 console->Printf(KTitleSwap);
00163 console->Printf(KPressAnyKeyToContinue);
00164 console->Getch();
00165
00166 _LIT(KWhatANiceDay,"What a nice day");
00167 TBuf<16> altbuf1(KWhatANiceDay);
00168 buf = KTextHelloWorld;
00169
00170
00171 _LIT(KTextBefore," BEFORE...\n");
00172 console->Printf(KTextBefore);
00173 console->Printf(KFormatBufLen,&buf,buf.Length());
00174 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00175
00176 console->Printf(KFormatBufLen,&altbuf1,altbuf1.Length());
00177 console->Printf(KFormatSizeMax,altbuf1.Size(),altbuf1.MaxLength());
00178
00179
00180
00181
00182
00183
00184 buf.Swap(altbuf1);
00185
00186 _LIT(KTextAfter," AFTER...\n");
00187 console->Printf(KTextAfter);
00188 console->Printf(KFormatBufLen,&buf,buf.Length());
00189 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00190
00191 console->Printf(KFormatBufLen,&altbuf1,altbuf1.Length());
00192 console->Printf(KFormatSizeMax,altbuf1.Size(),altbuf1.MaxLength()
00193 );
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 _LIT(KTitleRepeat,"\n--->Repeat()");
00214 console->Printf(KTitleRepeat);
00215 console->Printf(KPressAnyKeyToContinue);
00216 console->Getch();
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 buf.SetLength(16);
00227 buf.Repeat(KTextHello);
00228
00229
00230 console->Printf(KFormatBufLen,&buf,buf.Length());
00231 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00232
00233
00234
00235
00236
00237
00238 buf.SetLength(8);
00239 buf.Repeat(KTextHello);
00240
00241
00242 console->Printf(KFormatBufLen,&buf,buf.Length());
00243 console->Printf(KFormatSizeMax,buf.Size(),buf.MaxLength());
00244
00245
00246
00247
00248 _LIT(KTitleInsert,"\n--->Insert() & Delete()");
00249 console->Printf(KTitleInsert);
00250 console->Printf(KPressAnyKeyToContinue);
00251 console->Getch();
00252
00253
00254
00255 _LIT(KTextAbc,"abc");
00256 buf = KTextAbc;
00257 console->Printf(KFormatBufLenSizeMax,
00258 &buf,
00259 buf.Length(),
00260 buf.Size(),
00261 buf.MaxLength()
00262 );
00263
00264
00265
00266
00267
00268 buf.Insert(0,KTextXYZ);
00269
00270
00271 console->Printf(KFormatBufLenSizeMax,
00272 &buf,
00273 buf.Length(),
00274 buf.Size(),
00275 buf.MaxLength()
00276 );
00277
00278
00279
00280
00281 _LIT(KTextijklmn,"ijklmn");
00282 buf.Insert(1,KTextijklmn);
00283
00284
00285 console->Printf(KFormatBufLenSizeMax,
00286 &buf,
00287 buf.Length(),
00288 buf.Size(),
00289 buf.MaxLength()
00290 );
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 buf.Delete(0,3);
00315
00316
00317 console->Printf(KFormatBufLenSizeMax,
00318 &buf,
00319 buf.Length(),
00320 buf.Size(),
00321 buf.MaxLength()
00322 );
00323
00324
00325
00326
00327 buf.Delete(4,4);
00328
00329
00330 console->Printf(KFormatBufLenSizeMax,
00331 &buf,
00332 buf.Length(),
00333 buf.Size(),
00334 buf.MaxLength()
00335 );
00336
00337
00338
00339
00340
00341
00342
00343
00344 buf.Delete(1,25000);
00345
00346
00347 console->Printf(KFormatBufLenSizeMax,
00348 &buf,
00349 buf.Length(),
00350 buf.Size(),
00351 buf.MaxLength()
00352 );
00353
00354
00355
00356
00357 _LIT(KTitleTrimLeft,"\n--->TrimLeft() & TrimRight()");
00358 console->Printf(KTitleTrimLeft);
00359 console->Printf(KPressAnyKeyToContinue);
00360 console->Getch();
00361
00362
00363 buf.Fill(' ',18);
00364 buf.Replace(3,(&KTextHelloWorld)->Length(),KTextHelloWorld);
00365 console->Printf(KFormatBufLenSizeMax,
00366 &buf,
00367 buf.Length(),
00368 buf.Size(),
00369 buf.MaxLength()
00370 );
00371
00372
00373 buf.TrimLeft();
00374 console->Printf(KFormatBufLenSizeMax,
00375 &buf,
00376 buf.Length(),
00377 buf.Size(),
00378 buf.MaxLength()
00379 );
00380
00381
00382 buf.TrimRight();
00383 console->Printf(KFormatBufLenSizeMax,
00384 &buf,
00385 buf.Length(),
00386 buf.Size(),
00387 buf.MaxLength()
00388 );
00389
00390
00391
00392
00393
00394
00395
00396
00397 _LIT(KTitleFill,"\n--->FillZ() & Fill()");
00398 console->Printf(KTitleFill);
00399 console->Printf(KPressAnyKeyToContinue);
00400 console->Getch();
00401
00402
00403
00404
00405 buf.SetLength(8);
00406 buf.FillZ();
00407
00408
00409 counter = buf.Length();
00410 for (index = 0; index < counter; index++)
00411 console->Printf(KFormatCommon,buf[index]);
00412
00413 console->Printf(KFormatLenSizeMax,
00414 buf.Length(),
00415 buf.Size(),
00416 buf.MaxLength()
00417 );
00418
00419
00420
00421 buf.Fill('A');
00422
00423
00424 console->Printf(KFormatBufLenSizeMax,
00425 &buf,
00426 buf.Length(),
00427 buf.Size(),
00428 buf.MaxLength()
00429 );
00430
00431
00432
00433
00434 _LIT(KTitleNum,"\n--->Num(), NumUC(), AppendNum()");
00435 console->Printf(KTitleNum);
00436 console->Printf(KPressAnyKeyToContinue);
00437 console->Getch();
00438
00439
00440
00441 buf.Num(-176);
00442
00443
00444 console->Printf(KFormatBufLenSizeMax,
00445 &buf,
00446 buf.Length(),
00447 buf.Size(),
00448 buf.MaxLength()
00449 );
00450
00451
00452 buf.Num(12345);
00453
00454
00455 console->Printf(KFormatBufLenSizeMax,
00456 &buf,
00457 buf.Length(),
00458 buf.Size(),
00459 buf.MaxLength()
00460 );
00461
00462
00463 TUint nosign = 176;
00464
00465
00466
00467 buf.Num(nosign);
00468 console->Printf(KFormatBufLenSizeMax,
00469 &buf,
00470 buf.Length(),
00471 buf.Size(),
00472 buf.MaxLength()
00473 );
00474
00475
00476 buf.Num(nosign,EBinary);
00477 console->Printf(KFormatBufLenSizeMax,
00478 &buf,
00479 buf.Length(),
00480 buf.Size(),
00481 buf.MaxLength()
00482 );
00483
00484
00485 buf.Num(nosign,EOctal);
00486 console->Printf(KFormatBufLenSizeMax,
00487 &buf,
00488 buf.Length(),
00489 buf.Size(),
00490 buf.MaxLength()
00491 );
00492
00493
00494 buf.Num(nosign,EHex);
00495 console->Printf(KFormatBufLenSizeMax,
00496 &buf,
00497 buf.Length(),
00498 buf.Size(),
00499 buf.MaxLength()
00500 );
00501
00502
00503 buf.NumUC(nosign,EHex);
00504 console->Printf(KFormatBufLenSizeMax,
00505 &buf,
00506 buf.Length(),
00507 buf.Size(),
00508 buf.MaxLength()
00509 );
00510
00511
00512
00513
00514
00515
00516 _LIT(KTextxyz,"xyz");
00517 buf = KTextxyz;
00518
00519 buf.AppendNum(nosign);
00520 buf.AppendNum(nosign,EBinary);
00521 buf.AppendNum(nosign,EOctal);
00522 buf.AppendNum(nosign,EHex);
00523 buf.AppendNumUC(nosign,EHex);
00524 console->Printf(KFormatBufLenSizeMax,
00525 &buf,
00526 buf.Length(),
00527 buf.Size(),
00528 buf.MaxLength()
00529 );
00530
00531
00532
00533
00534 _LIT(KTitleJustify,"\n--->Justify() & AppendJustify()");
00535 console->Printf(KTitleJustify);
00536 console->Printf(KPressAnyKeyToContinue);
00537
00538 console->Getch();
00539
00540
00541
00542 TBufC<40> src(KTextHelloWorld);
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 buf.Justify(src,16,ELeft,'@');
00553 console->Printf(KFormatBufLenSizeMax,
00554 &buf,
00555 buf.Length(),
00556 buf.Size(),
00557 buf.MaxLength()
00558 );
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 buf.Justify(src,16,ECenter,'@');
00569 console->Printf(KFormatBufLenSizeMax,
00570 &buf,
00571 buf.Length(),
00572 buf.Size(),
00573 buf.MaxLength()
00574 );
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 buf.Justify(src,10,ECenter,'@');
00586 console->Printf(KFormatBufLenSizeMax,
00587 &buf,
00588 buf.Length(),
00589 buf.Size(),
00590 buf.MaxLength()
00591 );
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602 buf.Justify(src,KDefaultJustifyWidth,ECenter,'@');
00603 console->Printf(KFormatBufLenSizeMax,
00604 &buf,
00605 buf.Length(),
00606 buf.Size(),
00607 buf.MaxLength()
00608 );
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643 _LIT(KTextABCD,"ABCD");
00644 buf = KTextABCD;
00645 buf.AppendJustify(src,16,ELeft,'@');
00646 console->Printf(KFormatBufLenSizeMax,
00647 &buf,
00648 buf.Length(),
00649 buf.Size(),
00650 buf.MaxLength()
00651 );
00652
00653
00654
00655
00656 _LIT(KTitleFormatAndAppendFormat,"\n--->Format() & AppendFormat()");
00657 console->Printf(KTitleFormatAndAppendFormat);
00658 console->Printf(KPressAnyKeyToContinue);
00659 console->Getch();
00660
00661
00662
00663 TBuf<128> tgt;
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676 _LIT(KFormat1,"%b %c %d %o %u %x");
00677 tgt.Format(KFormat1,65,65,65,65,65,65);
00678 console->Printf(KFormatBufLenSizeMax,
00679 &tgt,
00680 tgt.Length(),
00681 tgt.Size(),
00682 tgt.MaxLength()
00683 );
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 _LIT(KFormat2,"%04x");
00695 tgt.Format(KFormat2,65);
00696 console->Printf(KFormatBufLenSizeMax,
00697 &tgt,
00698 tgt.Length(),
00699 tgt.Size(),
00700 tgt.MaxLength()
00701 );
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712 tgt.Format(KFormatfourex,65);
00713 console->Printf(KFormatBufLenSizeMax,
00714 &tgt,
00715 tgt.Length(),
00716 tgt.Size(),
00717 tgt.MaxLength()
00718 );
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734 tgt.Format(KFormatfourex,131071);
00735 console->Printf(KFormatBufLenSizeMax,
00736 &tgt,
00737 tgt.Length(),
00738 tgt.Size(),
00739 tgt.MaxLength()
00740 );
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754 _LIT(KFormat4,"%*x");
00755 tgt.Format(KFormat4,4,65);
00756 console->Printf(KFormatBufLenSizeMax,
00757 &tgt,
00758 tgt.Length(),
00759 tgt.Size(),
00760 tgt.MaxLength()
00761 );
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783 _LIT(KTextover,"over");
00784 _LIT(KFormat5,"%+$4d.00 %S");
00785 tgt.Format(KFormat5,65,&KTextover);
00786 console->Printf(KFormatBufLenSizeMax,
00787 &tgt,
00788 tgt.Length(),
00789 tgt.Size(),
00790 tgt.MaxLength()
00791 );
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809 _LIT(KTextfred,"fred");
00810 _LIT(KFormat6,"%+0*S");
00811 tgt.Format(KFormat6,10,&KTextfred);
00812 console->Printf(KFormatBufLenSizeMax,
00813 &tgt,
00814 tgt.Length(),
00815 tgt.Size(),
00816 tgt.MaxLength()
00817 );
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835 _LIT(KFormat7,"%=*6x");
00836 tgt.Format(KFormat7,'*',65);
00837 console->Printf(KFormatBufLenSizeMax,
00838 &tgt,
00839 tgt.Length(),
00840 tgt.Size(),
00841 tgt.MaxLength()
00842 );
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862 _LIT(KFormat8,"%+**d");
00863 tgt.Format(KFormat8,'.',10,(-65));
00864 console->Printf(KFormatBufLenSizeMax,
00865 &tgt,
00866 tgt.Length(),
00867 tgt.Size(),
00868 tgt.MaxLength()
00869 );
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881 _LIT(KFormat9,"%-**d");
00882 tgt.Format(KFormat9,'.',10,(-65));
00883 console->Printf(KFormatBufLenSizeMax,
00884 &tgt,
00885 tgt.Length(),
00886 tgt.Size(),
00887 tgt.MaxLength()
00888 );
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899 _LIT(KFormat10,"%-A6p");
00900 tgt.Format(KFormat10,65);
00901 console->Printf(KFormatBufLenSizeMax,
00902 &tgt,
00903 tgt.Length(),
00904 tgt.Size(),
00905 tgt.MaxLength()
00906 );
00907
00908
00909 _LIT(KFormat10a,"%Li");
00910
00911 TInt64 var(65);
00912 tgt.Format(KFormat10a,var);
00913
00914 console->Printf(KFormatBufLenSizeMax,
00915 &tgt,
00916 tgt.Length(),
00917 tgt.Size(),
00918 tgt.MaxLength()
00919 );
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937 _LIT(KFormat11,"%m");
00938 tgt.Format(KFormat11,4660);
00939
00940 counter = tgt.Length();
00941 for (index = 0; index < counter; index++)
00942 console->Printf(KFormatCommon,tgt[index]);
00943
00944 console->Printf(KFormatLenSizeMax,
00945 tgt.Length(),
00946 tgt.Size(),
00947 tgt.MaxLength()
00948 );
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968 _LIT(KFormat12,"%M");
00969 tgt.Format(KFormat12,4660);
00970
00971 counter = tgt.Length();
00972 for (index = 0; index < counter; index++)
00973 console->Printf(KFormatCommon,tgt[index]);
00974
00975 console->Printf(KFormatLenSizeMax,
00976 tgt.Length(),
00977 tgt.Size(),
00978 tgt.MaxLength()
00979 );
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994 _LIT(KFormat13,"%w");
00995 tgt.Format(KFormat13,4660);
00996
00997 counter = tgt.Length();
00998 for (index = 0; index < counter; index++)
00999 console->Printf(KFormatCommon,tgt[index]);
01000
01001 console->Printf(KFormatLenSizeMax,
01002 tgt.Length(),
01003 tgt.Size(),
01004 tgt.MaxLength()
01005 );
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021 _LIT(KFormat14,"%W");
01022 tgt.Format(KFormat14,4660);
01023
01024 counter = tgt.Length();
01025 for (index = 0; index < counter; index++)
01026 console->Printf(KFormatCommon,tgt[index]);
01027
01028 console->Printf(KFormatLenSizeMax,
01029 tgt.Length(),
01030 tgt.Size(),
01031 tgt.MaxLength()
01032 );
01033
01034 console->Printf(KPressAnyKeyToContinue);
01035 console->Getch();
01036
01037
01038
01039
01040
01041
01042 _LIT(KTitleOverflowHandler,"\n--->AppendFormat() & the overflow handler");
01043 console->Printf(KTitleOverflowHandler);
01044 console->Printf(KPressAnyKeyToContinue);
01045 console->Getch();
01046
01047
01048
01049 TBuf<16> overtgt;
01050 TestOverflow theoverflow;
01051
01052
01053 _LIT(KTextabcdefghijklmn,"abcdefghijklmn");
01054 overtgt = KTextabcdefghijklmn;
01055
01056
01057
01058
01059
01060
01061
01062 _LIT(KTextopq,"opq");
01063 overtgt.AppendFormat(KTextopq,&theoverflow);
01064
01065
01066
01067
01068 }
01069
01070
01071
01072
01073
01074
01075
01076
01077