File: string-operations.cpp

package info (click to toggle)
finalcut 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: cpp: 90,264; makefile: 546; sh: 412
file content (804 lines) | stat: -rw-r--r-- 25,622 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
/***********************************************************************
* string-operations.cpp - Demonstrates the functionality of FString    *
*                                                                      *
* This file is part of the FINAL CUT widget toolkit                    *
*                                                                      *
* Copyright 2012-2022 Markus Gans                                      *
*                                                                      *
* FINAL CUT is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU Lesser General Public License as       *
* published by the Free Software Foundation; either version 3 of       *
* the License, or (at your option) any later version.                  *
*                                                                      *
* FINAL CUT is distributed in the hope that it will be useful, but     *
* WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
* GNU Lesser General Public License for more details.                  *
*                                                                      *
* You should have received a copy of the GNU Lesser General Public     *
* License along with this program.  If not, see                        *
* <http://www.gnu.org/licenses/>.                                      *
***********************************************************************/

#include <langinfo.h>
#include <unistd.h>

#include <clocale>
#include <iomanip>
#include <string>
#include <vector>

#include <final/final.h>

// function prototype
void init();
void inputStreamExample();
void outputStreamExample();
void streamingIntoFStringExample();
void streamingFromFStringExample();
void streamToInterger();
void streamToUnsignedInterger();
void streamToDouble();
void streamToFloat();
void CStringOutputExample();
void copyIntoFString();
void utf8StringOutputExample();
void letterCaseExample();
void stringConcatenationExample();
void stringCompareExample();
void stringSplittingExample();
void fromatStringExample();
void convertToNumberExample();
void convertNumberToStringExample();
void formatedNumberExample();
void trimExample();
void substringExample();
void insertExample();
void indexExample();
void iteratorExample();
void overwriteExample();
void removeExample();
void substringIncludeExample();
void replaceExample();
void tabToSpaceExample();
void backspaceControlCharacterExample();
void deleteControlCharacterExample();

//----------------------------------------------------------------------
// functions
//----------------------------------------------------------------------
void init()
{
  std::cout << "----------------[ terminal ]-------------------"
            << std::endl;

  // init current locale
  std::cout << "    Locale: " << std::setlocale(LC_CTYPE, "")
            << std::endl;

  if ( isatty(1) && ! std::strcmp(nl_langinfo(CODESET), "ANSI_X3.4-1968") )
  {
    // locale C -> switch from 7bit ascii -> latin1
    std::setlocale(LC_ALL, "C");
  }

  std::cout << "   Codeset: " << nl_langinfo(CODESET) << std::endl;
  std::cout << "--------------[ FString test ]-----------------"
            << std::endl;
}

//----------------------------------------------------------------------
void inputStreamExample()
{
  // Test: input stream (operator >>)
  finalcut::FString in;
  std::cout << "     Input: ";
  std::cin >> in;
  std::cout << "  instream >> " << in << std::endl;
}

//----------------------------------------------------------------------
void outputStreamExample()
{
  // Test: output stream (operator <<)
  const finalcut::FString out{L"A test string for 0 \x20ac"};
  std::cout << " outstream << " << out << std::endl;
}

//----------------------------------------------------------------------
void streamingIntoFStringExample()
{
  // Test: Streaming into a FString (operator <<)...

  // ...from FStrings
  finalcut::FString streamer1;
  streamer1 << finalcut::FString("FStr") << finalcut::FString("ing");
  std::cout << " stream in: " << streamer1 << std::endl;

  // ...from c++ wide string
  finalcut::FString streamer2;
  streamer2 << std::wstring(L"std::wstring");
  std::cout << " stream in: " << streamer2 << std::endl;

  // ...from wide string
  finalcut::FString streamer3;
  const wchar_t wchar_str[] = L"wchar_t*";
  const wchar_t* wchar_str_ptr = wchar_str;
  streamer3 << wchar_str_ptr;
  std::cout << " stream in: " << streamer3 << std::endl;

  // ...from c++ string
  finalcut::FString streamer4;
  streamer4 << std::string("std::string");
  std::cout << " stream in: " << streamer4 << std::endl;

  // ...from c-string
  finalcut::FString streamer5;
  const char char_str[] = "char*";
  const char* char_str_ptr = char_str;
  streamer5 << char_str_ptr;
  std::cout << " stream in: " << streamer5 << std::endl;

  // ...from wide character
  finalcut::FString streamer6;
  streamer6 << wchar_t(L'w');
  std::cout << " stream in: " << streamer6 << std::endl;

  // ...from character
  finalcut::FString streamer7;
  streamer7 << char('c');
  std::cout << " stream in: " << streamer7 << std::endl;

  // ...from interger
  finalcut::FString streamer8;
  streamer8 << int(-12'345);
  std::cout << " stream in: " << streamer8 << std::endl;

  // ...from unsigned interger
  finalcut::FString streamer9;
  streamer9 << uInt(54'321);
  std::cout << " stream in: " << streamer9 << std::endl;

  // ...from long double
  finalcut::FString streamer10;
  streamer10 << lDouble(0.333'333'333'333'333'333L);
  std::cout << " stream in: " << streamer10 << std::endl;

  // ...from double
  finalcut::FString streamer11;
  streamer11 << double(0.111'111'111'11);
  std::cout << " stream in: " << streamer11 << std::endl;

  // ...from float
  finalcut::FString streamer12;
  streamer12 << float(0.222'222'22);
  std::cout << " stream in: " << streamer12 << std::endl;
}

//----------------------------------------------------------------------
void streamingFromFStringExample()
{
  // Test: Streaming from a FString (operator >>)...

  // ...to FStrings
  finalcut::FString stream_fstring;
  finalcut::FString("FString") >> stream_fstring;
  std::cout << "stream out: " << stream_fstring << std::endl;

  // ...to c++ wide string
  std::wstring stream_wstring;
  finalcut::FString("std::wstring") >> stream_wstring;
  std::wcout << "stream out: " << stream_wstring << std::endl;

  // ...to wide character
  wchar_t stream_wchar_t{L'\0'};
  finalcut::FString("w") >> stream_wchar_t;
  std::wcout << "stream out: " << stream_wchar_t << std::endl;

  // ...to character
  char stream_char;
  finalcut::FString('c') >> stream_char;
  std::cout << "stream out: " << stream_char << std::endl;

  // ...to interger
  streamToInterger();

  // ...to unsigned interger
  streamToUnsignedInterger();

  // ...to double
  streamToDouble();

  // ...to float
  streamToFloat();
}

//----------------------------------------------------------------------
void streamToInterger()
{
  // Streaming from a FString to interger

  try
  {
    int stream_int;
    finalcut::FString("-321") >> stream_int;
    std::cout << "stream out: " << stream_int << std::endl;
  }
  catch (const std::underflow_error&)
  {
    finalcut::FApplication::getLog()->error("Underflow");
  }
  catch (const std::overflow_error&)
  {
    finalcut::FApplication::getLog()->error("Overflow");
  }
  catch (const std::invalid_argument&)
  {
    finalcut::FApplication::getLog()->error("Arithmetic error");
  }
}

//----------------------------------------------------------------------
void streamToUnsignedInterger()
{
  // Streaming from a FString to unsigned interger
  try
  {
    uInt stream_uint;
    finalcut::FString("123") >> stream_uint;
    std::cout << "stream out: " << stream_uint << std::endl;
  }
  catch (const std::underflow_error&)
  {
    finalcut::FApplication::getLog()->error("Underflow");
  }
  catch (const std::overflow_error&)
  {
    finalcut::FApplication::getLog()->error("Overflow");
  }
  catch (const std::invalid_argument&)
  {
    finalcut::FApplication::getLog()->error("Arithmetic error");
  }
}

//----------------------------------------------------------------------
void streamToDouble()
{
  // Streaming from a FString to double
  try
  {
    double stream_double;
    finalcut::FString("0.123456e+2") >> stream_double;
    std::cout << "stream out: " << stream_double << std::endl;
  }
  catch (const std::underflow_error&)
  {
    finalcut::FApplication::getLog()->error("Underflow");
  }
  catch (const std::overflow_error&)
  {
    finalcut::FApplication::getLog()->error("Overflow");
  }
  catch (const std::invalid_argument&)
  {
    finalcut::FApplication::getLog()->error("Arithmetic error");
  }
}

//----------------------------------------------------------------------
void streamToFloat()
{
  // Streaming from a FString to float
  try
  {
    float stream_float;
    finalcut::FString("0.123e-3") >> stream_float;
    std::cout << "stream out: " << stream_float << std::endl;
  }
  catch (const std::underflow_error&)
  {
    finalcut::FApplication::getLog()->error("Underflow");
  }
  catch (const std::overflow_error&)
  {
    finalcut::FApplication::getLog()->error("Overflow");
  }
  catch (const std::invalid_argument&)
  {
    finalcut::FApplication::getLog()->error("Arithmetic error");
  }
}

//----------------------------------------------------------------------
void CStringOutputExample()
{
  // Test: c-string output
  const finalcut::FString out{L"A test string for 0 \x20ac"};
  printf ("     c_str:  \"%s\"\n", out.c_str());
}

//----------------------------------------------------------------------
void copyIntoFString()
{
  // Test: copy a c++ string
  const finalcut::FString& cpp_str( std::string("c++ String") );
  std::cout << "   cpp_str: \"" << cpp_str << "\"" << std::endl;

  // Test: copy a character
  const finalcut::FString ch('c');
  std::cout << "      char: '" << ch << "'" << std::endl;

  // Test: copy a wide character
  const finalcut::FString wch(L'w');
  std::cout << "   wchar_t: '" << wch << "'" << std::endl;
}

//----------------------------------------------------------------------
void utf8StringOutputExample()
{
  // Test: utf-8 string
  const finalcut::FString len{"длина́"};
  std::cout << "    length: \"" << len << "\" has "
            << len.getLength() << " characters" << std::endl;
}

//----------------------------------------------------------------------
void letterCaseExample()
{
  // Test: convert uppercase letter to lowercase
  const finalcut::FString lower{finalcut::FString(L"InPut").toLower()};
  std::wcout << L"   toLower: " << lower << std::endl;

  // Test: convert lowercase letter to uppercase
  const finalcut::FString upper{finalcut::FString("inPut").toUpper()};
  std::cout << "   toUpper: " << upper << std::endl;
}

//----------------------------------------------------------------------
void stringConcatenationExample()
{
  // Test: concatenate two FStrings (operator +)
  const finalcut::FString& add1 = finalcut::FString("FString + ")
                                + finalcut::FString("FString");
  std::cout << "       add: " << add1 << std::endl;

  // Test: concatenate a FString and a c++ wide string (operator +)
  const finalcut::FString& add2 = finalcut::FString("FString + ")
                                + std::wstring(L"std::wstring");
  std::cout << "       add: " << add2 << std::endl;

  // Test: concatenate a FString and a wide string (operator +)
  const finalcut::FString& add3 = finalcut::FString("FString + ")
                                + L"wchar_t*";
  std::cout << "       add: " << add3 << std::endl;

  // Test: concatenate a FString and a c++ string (operator +)
  const finalcut::FString& add4 = finalcut::FString("FString + ")
                                + std::string("std::string");
  std::cout << "       add: " << add4 << std::endl;

  // Test: concatenate a FString and a c-string (operator +)
  const finalcut::FString& add5 = finalcut::FString("FString + ")
                                + const_cast<char*>("char*");
  std::cout << "       add: " << add5 << std::endl;

  // Test: concatenate a FString and a wide character (operator +)
  const finalcut::FString& add6 = finalcut::FString("FString + ")
                                + wchar_t(L'w');
  std::cout << "       add: " << add6 << std::endl;

  // Test: concatenate a FString and a character (operator +)
  const finalcut::FString& add7 = finalcut::FString("FString + ")
                                + char('c');
  std::cout << "       add: " << add7 << std::endl;

  // Test: concatenate a character and a FString (operator +)
  const finalcut::FString& add8 = 'c' + finalcut::FString(" + FString");
  std::cout << "       add: " << add8 << std::endl;

  // Test: concatenate a wide character and a FString (operator +)
  const finalcut::FString& add9 = L'w' + finalcut::FString(" + FString");
  std::cout << "       add: " << add9 << std::endl;

  // Test: concatenate a c-string and a FString (operator +)
  const finalcut::FString& add10 = "char*"
                                 + finalcut::FString(" + FString");
  std::cout << "       add: " << add10 << std::endl;

  // Test: concatenate a c++ string and a FString (operator +)
  const finalcut::FString& add11 = std::string("std::string")
                                 + finalcut::FString(" + FString");
  std::cout << "       add: " << add11 << std::endl;

  // Test: concatenate a wide string and a FString (operator +)
  const finalcut::FString& add12 = L"wchar_t*"
                                 + finalcut::FString(" + FString");
  std::cout << "       add: " << add12 << std::endl;

  // Test: concatenate a c++ wide string and a FString (operator +)
  const finalcut::FString& add13 = std::wstring(L"std::wstring")
                                 + finalcut::FString(" + FString");
  std::cout << "       add: " << add13 << std::endl;
}

//----------------------------------------------------------------------
void stringCompareExample()
{
  // Test: compare operators ==, <=, <, >=, >, !=
  const finalcut::FString cmp{"compare"};

  if ( cmp == finalcut::FString("compare") )
    std::cout << "       cmp: == Ok" << std::endl;
  else
    std::cout << "       cmp: == Not Ok" << std::endl;

  if ( cmp <= finalcut::FString("d_compare") )
    std::cout << "       cmp: <= Ok" << std::endl;
  else
    std::cout << "       cmp: <= Not Ok" << std::endl;

  if ( cmp < finalcut::FString("e_compare") )
    std::cout << "       cmp: <  Ok" << std::endl;
  else
    std::cout << "       cmp: <  Not Ok" << std::endl;

  if ( cmp >= finalcut::FString("b_compare") )
    std::cout << "       cmp: >= Ok" << std::endl;
  else
    std::cout << "       cmp: >= Not Ok" << std::endl;

  if ( cmp > finalcut::FString("a_compare") )
    std::cout << "       cmp: >  Ok" << std::endl;
  else
    std::cout << "       cmp: >  Not Ok" << std::endl;

  if ( cmp != finalcut::FString("equal") )
    std::cout << "       cmp: != Ok" << std::endl;
  else
    std::cout << "       cmp: != Not Ok" << std::endl;
}

//----------------------------------------------------------------------
void stringSplittingExample()
{
  // Test: split a string with a delimiter and returns a vector (array)
  finalcut::FString split_str{"a,b,c,d"};
  std::cout << "     split: \""
            << split_str << "\" into substrings ->";
  finalcut::FStringList parts{ split_str.split(",") };
  auto end = parts.end();

  for (auto it = parts.begin(); it != end; ++it)
    std::cout << " \"" << (*it) << "\"";

  std::cout << std::endl;
}

//----------------------------------------------------------------------
void fromatStringExample()
{
  // Test: format a string with sprintf
  finalcut::FString format_str{""};
  std::cout << " formatted: "
            << format_str.sprintf("sqrt(%d) = %d", 16, 4)
            << std::endl;
}

//----------------------------------------------------------------------
void convertToNumberExample()
{
  // Test: convert a string to a unsigned long interger
  try
  {
    const uLong ulong_num = finalcut::FString("123456789").toULong();
    std::cout << "   toULong:  " << ulong_num << std::endl;
  }
  catch (const std::underflow_error&)
  {
    finalcut::FApplication::getLog()->error("Underflow");
  }
  catch (const std::overflow_error&)
  {
    finalcut::FApplication::getLog()->error("Overflow");
  }
  catch (const std::invalid_argument&)
  {
    finalcut::FApplication::getLog()->error("Arithmetic error");
  }

  // Test: convert a string to a signed long interger
  try
  {
    const long long_num = finalcut::FString("-9876543210").toLong();
    std::cout << "    toLong:  " << long_num << std::endl;
  }
  catch (const std::underflow_error&)
  {
    finalcut::FApplication::getLog()->error("Underflow");
  }
  catch (const std::overflow_error&)
  {
    finalcut::FApplication::getLog()->error("Overflow");
  }
  catch (const std::invalid_argument&)
  {
    finalcut::FApplication::getLog()->error("Arithmetic error");
  }

  // Test: convert a string to a double value
  std::setlocale(LC_NUMERIC, "C");

  try
  {
    const double double_num = \
        finalcut::FString("2.718'281'828'459'045'235'3").toDouble();
    std::ios_base::fmtflags save_flags = std::cout.flags();
    std::cout << "  toDouble:  " << std::setprecision(11)
                                 << double_num << std::endl;
    std::cout.flags(save_flags);
  }
  catch (const std::underflow_error&)
  {
    finalcut::FApplication::getLog()->error("Underflow");
  }
  catch (const std::overflow_error&)
  {
    finalcut::FApplication::getLog()->error("Overflow");
  }
  catch (const std::invalid_argument&)
  {
    finalcut::FApplication::getLog()->error("Arithmetic error");
  }
}

//----------------------------------------------------------------------
void convertNumberToStringExample()
{
  // Test: convert integer and double value to a string
  finalcut::FString num1{};
  finalcut::FString num2{};
  finalcut::FString num3{};
  num1.setNumber(137U);
  num2.setNumber(-512);
  num3.setNumber(3.141'592'653'589'793'238L, 12);
  std::cout << " setNumber:  "
            << num1 << " (unsigned)"    << std::endl;
  std::cout << " setNumber: "
            << num2 << " (signed)"      << std::endl;
  std::cout << " setNumber:  "
            << num3 << " (long double)" << std::endl;
}

//----------------------------------------------------------------------
void formatedNumberExample()
{
  // Test: convert and format a integer number with thousand separator
  std::setlocale (LC_NUMERIC, "");
  finalcut::FString fnum1{};
  finalcut::FString fnum2{};
#if defined(__LP64__) || defined(_LP64)
  // 64-bit architecture
  fnum1.setFormatedNumber(0xffffffffffffffffU, '\'');
  fnum2.setFormatedNumber(-9223372036854775807);
#else
  // 32-bit architecture
  fnum1.setFormatedNumber(0xffffffffU, '\'');
  fnum2.setFormatedNumber(-2147483647);
#endif
  std::cout << "setFormatedNumber: "
            << fnum1 << " (unsigned)" << std::endl;
  std::cout << "setFormatedNumber: "
            << fnum2 << " (signed)"   << std::endl;
}

//----------------------------------------------------------------------
void trimExample()
{
  // Test: remove whitespace from the end of a string
  const finalcut::FString& trim_str{"  A string \t"};
  std::wcout << "    rtrim: \""
             << trim_str.rtrim() << "\"" << std::endl;

  // Test: remove whitespace from the beginning of a string
  std::cout << "    ltrim: \""
            << trim_str.ltrim() << "\"" << std::endl;

  // Test: remove whitespace from the beginning and end of a string
  std::cout << "     trim: \""
            << trim_str.trim()  << "\"" << std::endl;
}

//----------------------------------------------------------------------
void substringExample()
{
  // Test: 11 characters from the left of the string
  const finalcut::FString alphabet{ "a b c d e f g h i j k l m "
                                    "n o p q r s t u v w x y z" };
  std::cout << "     left: \""
            << alphabet.left(11)   << "\"" << std::endl;

  // Test: extract a substring of 27 characters from position 12
  std::cout << "      mid: \""
            << alphabet.mid(13, 27) << "\"" << std::endl;

  // Test: 11 characters from the right of the string
  std::cout << "    right: \""
            << alphabet.right(11)  << "\"" << std::endl;
}

//----------------------------------------------------------------------
void insertExample()
{
  // Test: insert a string at index position 7
  finalcut::FString insert_str{"I am a string"};

  try
  {
    std::cout << "   insert: "
              << insert_str.insert("changed ", 7) << std::endl;
  }
  catch (const std::out_of_range&)
  {
    finalcut::FApplication::getLog()->error("Out of Range");
  }
}

//----------------------------------------------------------------------
void indexExample()
{
  // Test: get character access at a specified index position
  finalcut::FString index{5};  // string with five characters
  index.setString("index");

  try
  {
    index[0] = L'I';  // Write a wide character at position 0
    printf ( "    index: [0] = %c ; [4] = %c\n"
           , char(index[0])
           , char(index[4]) );
  }
  catch (const std::out_of_range&)
  {
    finalcut::FApplication::getLog()->error("Out of Range");
  }
}

//----------------------------------------------------------------------
void iteratorExample()
{
  // Test: character access with std::iterator
  const finalcut::FString stringIterator{"iterator"};
  finalcut::FString::const_iterator iter;
  iter = stringIterator.begin();
  std::cout << " " << stringIterator << ": ";

  while ( iter != stringIterator.end() )
  {
    std::cout << char(*iter) << "|";
    ++iter;
  }

  std::cout << "  (front='" << char(stringIterator.front())
            << "', back='" << char(stringIterator.back())
            << "')" << std::endl;
}

//----------------------------------------------------------------------
void overwriteExample()
{
  // Test: overwrite string at position 10 with "for t"
  finalcut::FString overwrite_std{"Overwrite the rest"};
  std::cout << "overwrite: "
            << overwrite_std.overwrite("for t", 10) << std::endl;
}

//----------------------------------------------------------------------
void removeExample()
{
  // Test: remove 2 characters at position 7
  finalcut::FString remove_std{"A fast remove"};
  std::cout << "   remove: "
            << remove_std.remove(7, 2) << std::endl;
}

//----------------------------------------------------------------------
void substringIncludeExample()
{
  // Test: includes a substring (positive test)
  finalcut::FString include_std{"string"};

  if ( include_std.includes("ring") )
    std::cout << R"( includes: ")"
              << include_std << R"(" includes "ring" )"
              << std::endl;
  else
    std::cout << R"( includes: ")"
              << include_std << R"(" includes no "ring" )"
              << std::endl;

  // Test: includes a substring (negativ test)
  if ( include_std.includes("data") )
    std::cout << R"( includes: ")"
              << include_std << R"(" includes "data" )"
              << std::endl;
  else
    std::cout << R"( includes: ")"
              << include_std << R"(" includes no "data" )"
              << std::endl;
}

//----------------------------------------------------------------------
void replaceExample()
{
  // Test: find and replace a substring
  finalcut::FString source_str{"computer and software"};
  const finalcut::FString& replace_str = \
      source_str.replace("computer", "hard-");
  std::cout << "  replace: "
            << replace_str << std::endl;
}

//----------------------------------------------------------------------
void tabToSpaceExample()
{
  // Test: convert tabs to spaces
  const finalcut::FString tab_str{"1234\t5678"};
  std::cout << "      tab: "
            << tab_str.expandTabs() << std::endl;
}

//----------------------------------------------------------------------
void backspaceControlCharacterExample()
{
  // Test: backspaces remove characters in the string
  const finalcut::FString bs_str{"t\b\bTesT\bt"};
  std::cout << "backspace: "
            << bs_str.removeBackspaces() << std::endl;
}

//----------------------------------------------------------------------
void deleteControlCharacterExample()
{
  // Test: delete characters remove characters in the string
  const finalcut::FString del_str{"apple \177\177\177pietree"};
  std::cout << "   delete: "
            << del_str.removeDel() << std::endl;
}

//----------------------------------------------------------------------
//                               main part
//----------------------------------------------------------------------
auto main (int, char**) -> int
{
  init();

  // Some FString examples
  inputStreamExample();
  outputStreamExample();
  streamingIntoFStringExample();
  streamingFromFStringExample();
  CStringOutputExample();
  copyIntoFString();
  utf8StringOutputExample();
  letterCaseExample();
  stringConcatenationExample();
  stringCompareExample();
  stringSplittingExample();
  fromatStringExample();
  convertToNumberExample();
  convertNumberToStringExample();
  formatedNumberExample();
  trimExample();
  substringExample();
  insertExample();
  indexExample();
  iteratorExample();
  overwriteExample();
  removeExample();
  substringIncludeExample();
  replaceExample();
  tabToSpaceExample();
  backspaceControlCharacterExample();
  deleteControlCharacterExample();
}