2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* string-operations.cpp - Demonstrates the functionality of FString *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-08-25 22:16:00 +02:00
|
|
|
* Copyright 2012-2019 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The 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. *
|
|
|
|
* *
|
|
|
|
* The 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/>. *
|
|
|
|
***********************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#include <langinfo.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <clocale>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
// function prototype
|
|
|
|
void init();
|
|
|
|
void inputStreamExample();
|
|
|
|
void outputStreamExample();
|
|
|
|
void streamingIntoFStringExample();
|
|
|
|
void streamingFromFStringExample();
|
2018-01-31 00:17:00 +01:00
|
|
|
void streamToInterger();
|
|
|
|
void streamToUnsignedInterger();
|
|
|
|
void streamToDouble();
|
|
|
|
void streamToFloat();
|
2017-12-21 00:25:58 +01:00
|
|
|
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();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-12-21 00:25:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// functions
|
|
|
|
//----------------------------------------------------------------------
|
2017-11-19 19:47:24 +01:00
|
|
|
void init()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-11-19 19:47:24 +01:00
|
|
|
std::cout << "----------------[ terminal ]-------------------"
|
|
|
|
<< std::endl;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
// init current locale
|
2017-11-19 19:47:24 +01:00
|
|
|
std::cout << " Locale: " << std::setlocale(LC_CTYPE, "")
|
|
|
|
<< std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-06 23:15:09 +02:00
|
|
|
if ( isatty(1) && ! std::strcmp(nl_langinfo(CODESET), "ANSI_X3.4-1968") )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
// locale C -> switch from 7bit ascii -> latin1
|
2016-11-12 22:59:48 +01:00
|
|
|
std::setlocale(LC_ALL, "C");
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
std::cout << " Codeset: " << nl_langinfo(CODESET) << std::endl;
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << "--------------[ FString test ]-----------------"
|
|
|
|
<< std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void inputStreamExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: input stream (operator >>)
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString in;
|
2017-09-20 02:51:17 +02:00
|
|
|
std::cout << " Input: ";
|
|
|
|
std::cin >> in;
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " instream >> " << in << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void outputStreamExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: output stream (operator <<)
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString out{L"A test string for 0 \x20ac"};
|
2017-04-17 22:49:42 +02:00
|
|
|
std::cout << " outstream << " << out << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2017-04-17 22:49:42 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void streamingIntoFStringExample()
|
|
|
|
{
|
2017-09-20 02:51:17 +02:00
|
|
|
// Test: Streaming into a FString (operator <<)...
|
|
|
|
|
|
|
|
// ...from FStrings
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer1;
|
|
|
|
streamer1 << finalcut::FString("FStr") << finalcut::FString("ing");
|
2017-09-20 02:51:17 +02:00
|
|
|
std::cout << " stream in: " << streamer1 << std::endl;
|
|
|
|
|
|
|
|
// ...from c++ wide string
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer2;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer2 << std::wstring(L"std::wstring");
|
|
|
|
std::cout << " stream in: " << streamer2 << std::endl;
|
|
|
|
|
|
|
|
// ...from wide string
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer3;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer3 << const_cast<wchar_t*>(L"wchar_t*");
|
|
|
|
std::cout << " stream in: " << streamer3 << std::endl;
|
|
|
|
|
|
|
|
// ...from c++ string
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer4;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer4 << std::string("std::string");
|
|
|
|
std::cout << " stream in: " << streamer4 << std::endl;
|
|
|
|
|
|
|
|
// ...from c-string
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer5;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer5 << const_cast<char*>("char*");
|
|
|
|
std::cout << " stream in: " << streamer5 << std::endl;
|
|
|
|
|
|
|
|
// ...from wide character
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer6;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer6 << wchar_t(L'w');
|
|
|
|
std::cout << " stream in: " << streamer6 << std::endl;
|
|
|
|
|
|
|
|
// ...from character
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer7;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer7 << char('c');
|
|
|
|
std::cout << " stream in: " << streamer7 << std::endl;
|
|
|
|
|
|
|
|
// ...from interger
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer8;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer8 << int(-12345);
|
|
|
|
std::cout << " stream in: " << streamer8 << std::endl;
|
|
|
|
|
|
|
|
// ...from unsigned interger
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer9;
|
2017-09-20 02:51:17 +02:00
|
|
|
streamer9 << uInt(54321);
|
|
|
|
std::cout << " stream in: " << streamer9 << std::endl;
|
|
|
|
|
|
|
|
// ...from long double
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer10;
|
2017-09-20 06:50:29 +02:00
|
|
|
streamer10 << lDouble(0.333333333333333333L);
|
|
|
|
std::cout << " stream in: " << streamer10 << std::endl;
|
2017-09-20 02:51:17 +02:00
|
|
|
|
|
|
|
// ...from double
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer11;
|
2017-09-20 06:50:29 +02:00
|
|
|
streamer11 << double(0.11111111111);
|
|
|
|
std::cout << " stream in: " << streamer11 << std::endl;
|
2017-09-20 02:51:17 +02:00
|
|
|
|
|
|
|
// ...from float
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString streamer12;
|
2017-09-20 06:50:29 +02:00
|
|
|
streamer12 << float(0.22222222);
|
|
|
|
std::cout << " stream in: " << streamer12 << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2017-09-20 02:51:17 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void streamingFromFStringExample()
|
|
|
|
{
|
2017-09-20 02:51:17 +02:00
|
|
|
// Test: Streaming from a FString (operator >>)...
|
|
|
|
|
|
|
|
// ...to FStrings
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString stream_fstring;
|
|
|
|
finalcut::FString("FString") >> stream_fstring;
|
2017-09-20 02:51:17 +02:00
|
|
|
std::cout << "stream out: " << stream_fstring << std::endl;
|
|
|
|
|
|
|
|
// ...to c++ wide string
|
|
|
|
std::wstring stream_wstring;
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString("std::wstring") >> stream_wstring;
|
2017-09-20 02:51:17 +02:00
|
|
|
std::wcout << "stream out: " << stream_wstring << std::endl;
|
|
|
|
|
|
|
|
// ...to wide character
|
2019-08-25 22:16:00 +02:00
|
|
|
wchar_t stream_wchar_t{L'\0'};
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString("w") >> stream_wchar_t;
|
2017-09-20 02:51:17 +02:00
|
|
|
std::wcout << "stream out: " << stream_wchar_t << std::endl;
|
|
|
|
|
|
|
|
// ...to character
|
|
|
|
char stream_char;
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString('c') >> stream_char;
|
2017-09-20 02:51:17 +02:00
|
|
|
std::cout << "stream out: " << stream_char << std::endl;
|
|
|
|
|
|
|
|
// ...to interger
|
2018-01-31 00:17:00 +01:00
|
|
|
streamToInterger();
|
|
|
|
|
|
|
|
// ...to unsigned interger
|
|
|
|
streamToUnsignedInterger();
|
|
|
|
|
|
|
|
// ...to double
|
|
|
|
streamToDouble();
|
|
|
|
|
|
|
|
// ...to float
|
|
|
|
streamToFloat();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void streamToInterger()
|
|
|
|
{
|
|
|
|
// Streaming from a FString to interger
|
|
|
|
|
2017-09-20 06:50:29 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
int stream_int;
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString("-321") >> stream_int;
|
2017-09-20 06:50:29 +02:00
|
|
|
std::cout << "stream out: " << stream_int << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument: " << ex.what() << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::overflow_error& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "overflow: " << ex.what() << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Arithmetic error: " << ex.what() << std::endl;
|
|
|
|
}
|
2018-01-31 00:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void streamToUnsignedInterger()
|
|
|
|
{
|
|
|
|
// Streaming from a FString to unsigned interger
|
2017-09-20 06:50:29 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
uInt stream_uint;
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString("123") >> stream_uint;
|
2017-09-20 06:50:29 +02:00
|
|
|
std::cout << "stream out: " << stream_uint << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument: " << ex.what() << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::overflow_error& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "overflow: " << ex.what() << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Arithmetic error: " << ex.what() << std::endl;
|
|
|
|
}
|
2018-01-31 00:17:00 +01:00
|
|
|
}
|
2017-09-20 02:51:17 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void streamToDouble()
|
|
|
|
{
|
|
|
|
// Streaming from a FString to double
|
2017-09-20 06:25:53 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
double stream_double;
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString("0.123456e+2") >> stream_double;
|
2017-09-20 06:25:53 +02:00
|
|
|
std::cout << "stream out: " << stream_double << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument: " << ex.what() << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Arithmetic error: " << ex.what() << std::endl;
|
|
|
|
}
|
2018-01-31 00:17:00 +01:00
|
|
|
}
|
2017-09-20 02:51:17 +02:00
|
|
|
|
2018-01-31 00:17:00 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void streamToFloat()
|
|
|
|
{
|
|
|
|
// Streaming from a FString to float
|
2017-09-20 06:25:53 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
float stream_float;
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FString("0.123e-3") >> stream_float;
|
2017-09-20 06:25:53 +02:00
|
|
|
std::cout << "stream out: " << stream_float << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument: " << ex.what() << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Arithmetic error: " << ex.what() << std::endl;
|
|
|
|
}
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2017-09-20 02:51:17 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CStringOutputExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: c-string output
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString out{L"A test string for 0 \x20ac"};
|
2015-05-23 13:35:12 +02:00
|
|
|
printf (" c_str: \"%s\"\n", out.c_str());
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void copyIntoFString()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: copy a c++ string
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& cpp_str( std::string("c++ String") );
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " cpp_str: \"" << cpp_str << "\"" << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: copy a character
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString ch('c');
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " char: '" << ch << "'" << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: copy a wide character
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString wch(L'w');
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " wchar_t: '" << wch << "'" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void utf8StringOutputExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: utf-8 string
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString len{"длина́"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " length: \"" << len << "\" has "
|
|
|
|
<< len.getLength() << " characters" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void letterCaseExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert uppercase letter to lowercase
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString lower{finalcut::FString(L"InPut").toLower()};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::wcout << L" toLower: " << lower << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: convert lowercase letter to uppercase
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString upper{finalcut::FString("inPut").toUpper()};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " toUpper: " << upper << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void stringConcatenationExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: concatenate two FStrings (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add1 = finalcut::FString("FString + ")
|
|
|
|
+ finalcut::FString("FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add1 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a FString and a c++ wide string (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add2 = finalcut::FString("FString + ")
|
|
|
|
+ std::wstring(L"std::wstring");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add2 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a FString and a wide string (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add3 = finalcut::FString("FString + ")
|
|
|
|
+ const_cast<wchar_t*>(L"wchar_t*");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add3 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a FString and a c++ string (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add4 = finalcut::FString("FString + ")
|
|
|
|
+ std::string("std::string");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add4 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a FString and a c-string (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add5 = finalcut::FString("FString + ")
|
|
|
|
+ const_cast<char*>("char*");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add5 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a FString and a wide character (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add6 = finalcut::FString("FString + ")
|
|
|
|
+ wchar_t(L'w');
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add6 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a FString and a character (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add7 = finalcut::FString("FString + ")
|
|
|
|
+ char('c');
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add7 << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: concatenate a character and a FString (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add8 = 'c' + finalcut::FString(" + FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add8 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a wide character and a FString (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add9 = L'w' + finalcut::FString(" + FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add9 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a c-string and a FString (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add10 = const_cast<char*>("char*")
|
|
|
|
+ finalcut::FString(" + FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add10 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a c++ string and a FString (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add11 = std::string("std::string")
|
|
|
|
+ finalcut::FString(" + FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add11 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a wide string and a FString (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add12 = const_cast<wchar_t*>(L"wchar_t*")
|
|
|
|
+ finalcut::FString(" + FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add12 << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: concatenate a c++ wide string and a FString (operator +)
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& add13 = std::wstring(L"std::wstring")
|
|
|
|
+ finalcut::FString(" + FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add13 << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void stringCompareExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: compare operators ==, <=, <, >=, >, !=
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString cmp{"compare"};
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( cmp == finalcut::FString("compare") )
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " cmp: == Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: == Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( cmp <= finalcut::FString("d_compare") )
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " cmp: <= Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: <= Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( cmp < finalcut::FString("e_compare") )
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " cmp: < Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: < Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( cmp >= finalcut::FString("b_compare") )
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " cmp: >= Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: >= Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( cmp > finalcut::FString("a_compare") )
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " cmp: > Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: > Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( cmp != finalcut::FString("equal") )
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " cmp: != Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: != Not Ok" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void stringSplittingExample()
|
|
|
|
{
|
2017-04-23 18:54:46 +02:00
|
|
|
// Test: split a string with a delimiter and returns a vector (array)
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString split_str{"a,b,c,d"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " split: \""
|
|
|
|
<< split_str << "\" into substrings ->";
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FStringList parts{ split_str.split(",") };
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FStringList::iterator it, end;
|
2015-05-23 13:35:12 +02:00
|
|
|
end = parts.end();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
for (it = parts.begin(); it != end; ++it)
|
|
|
|
std::cout << " \"" << (*it) << "\"";
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void fromatStringExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: format a string with sprintf
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString formatStr{""};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " formatted: "
|
|
|
|
<< formatStr.sprintf("sqrt(%d) = %d", 16, 4)
|
|
|
|
<< std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2017-04-17 22:49:42 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void convertToNumberExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert a string to a unsigned long interger
|
2015-06-28 20:23:39 +02:00
|
|
|
try
|
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
const uLong ulong_num = finalcut::FString("123456789").toULong();
|
2015-06-28 20:23:39 +02:00
|
|
|
std::cout << " toULong: " << ulong_num << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument: " << ex.what() << std::endl;
|
|
|
|
}
|
2015-06-30 00:25:36 +02:00
|
|
|
catch (const std::exception& ex)
|
2015-06-28 20:23:39 +02:00
|
|
|
{
|
2015-06-30 00:25:36 +02:00
|
|
|
std::cerr << "Arithmetic error: " << ex.what() << std::endl;
|
2015-06-28 20:23:39 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert a string to a signed long interger
|
2015-06-28 20:23:39 +02:00
|
|
|
try
|
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
const long long_num = finalcut::FString("-9876543210").toLong();
|
2015-06-30 09:29:49 +02:00
|
|
|
std::cout << " toLong: " << long_num << std::endl;
|
2015-06-28 20:23:39 +02:00
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument: " << ex.what() << std::endl;
|
|
|
|
}
|
2015-06-30 00:21:50 +02:00
|
|
|
catch (const std::exception& ex)
|
2015-06-28 20:23:39 +02:00
|
|
|
{
|
2015-06-30 00:21:50 +02:00
|
|
|
std::cerr << "Arithmetic error: " << ex.what() << std::endl;
|
2015-06-28 20:23:39 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert a string to a double value
|
2016-10-06 23:15:09 +02:00
|
|
|
std::setlocale(LC_NUMERIC, "C");
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-06-27 23:00:12 +02:00
|
|
|
try
|
|
|
|
{
|
2018-11-20 21:11:04 +01:00
|
|
|
const double double_num = \
|
|
|
|
finalcut::FString("2.7182818284590452353").toDouble();
|
2015-09-30 22:39:02 +02:00
|
|
|
std::ios_base::fmtflags save_flags = std::cout.flags();
|
2015-06-27 23:00:12 +02:00
|
|
|
std::cout << " toDouble: " << std::setprecision(11)
|
|
|
|
<< double_num << std::endl;
|
2015-09-30 22:39:02 +02:00
|
|
|
std::cout.flags(save_flags);
|
2015-06-27 23:00:12 +02:00
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument: " << ex.what() << std::endl;
|
|
|
|
}
|
2015-06-30 00:21:50 +02:00
|
|
|
catch (const std::exception& ex)
|
2015-06-27 23:00:12 +02:00
|
|
|
{
|
2015-06-30 00:21:50 +02:00
|
|
|
std::cerr << "Arithmetic error: " << ex.what() << std::endl;
|
2015-06-27 23:00:12 +02:00
|
|
|
}
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-06-30 00:21:50 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void convertNumberToStringExample()
|
|
|
|
{
|
2017-04-23 18:54:46 +02:00
|
|
|
// Test: convert integer and double value to a string
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString num1{}, num2{}, num3{};
|
2019-04-26 21:06:04 +02:00
|
|
|
num1.setNumber(137u);
|
2015-05-23 13:35:12 +02:00
|
|
|
num2.setNumber(-512);
|
2015-06-27 23:00:12 +02:00
|
|
|
num3.setNumber(3.141592653589793238L, 12);
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " setNumber: "
|
2015-06-27 23:00:12 +02:00
|
|
|
<< num1 << " (unsigned)" << std::endl;
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " setNumber: "
|
2015-06-27 23:00:12 +02:00
|
|
|
<< num2 << " (signed)" << std::endl;
|
|
|
|
std::cout << " setNumber: "
|
|
|
|
<< num3 << " (long double)" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void formatedNumberExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert and format a integer number with thousand separator
|
2016-10-06 23:15:09 +02:00
|
|
|
std::setlocale (LC_NUMERIC, "");
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString fnum1{}, fnum2{};
|
2015-09-18 21:38:26 +02:00
|
|
|
#if defined(__LP64__) || defined(_LP64)
|
|
|
|
// 64-bit architecture
|
2019-04-26 21:06:04 +02:00
|
|
|
fnum1.setFormatedNumber(0xffffffffffffffffu, '\'');
|
2015-05-23 13:35:12 +02:00
|
|
|
fnum2.setFormatedNumber(-9223372036854775807);
|
2015-09-18 21:38:26 +02:00
|
|
|
#else
|
|
|
|
// 32-bit architecture
|
2019-04-26 21:06:04 +02:00
|
|
|
fnum1.setFormatedNumber(0xffffffffu, '\'');
|
2015-09-18 21:38:26 +02:00
|
|
|
fnum2.setFormatedNumber(-2147483647);
|
|
|
|
#endif
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << "setFormatedNumber: "
|
|
|
|
<< fnum1 << " (unsigned)" << std::endl;
|
|
|
|
std::cout << "setFormatedNumber: "
|
|
|
|
<< fnum2 << " (signed)" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void trimExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: remove whitespace from the end of a string
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString& trim_str{" A string \t"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::wcout << " rtrim: \""
|
|
|
|
<< trim_str.rtrim() << "\"" << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: remove whitespace from the beginning of a string
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " ltrim: \""
|
|
|
|
<< trim_str.ltrim() << "\"" << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: remove whitespace from the beginning and end of a string
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " trim: \""
|
|
|
|
<< trim_str.trim() << "\"" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void substringExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: 11 characters from the left of the string
|
2019-08-25 22:16:00 +02:00
|
|
|
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" };
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " left: \""
|
|
|
|
<< alphabet.left(11) << "\"" << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: extract a substring of 27 characters from position 12
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " mid: \""
|
2017-09-11 03:06:02 +02:00
|
|
|
<< alphabet.mid(13, 27) << "\"" << std::endl;
|
2017-04-17 22:49:42 +02:00
|
|
|
|
|
|
|
// Test: 11 characters from the right of the string
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " right: \""
|
|
|
|
<< alphabet.right(11) << "\"" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void insertExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: insert a string at index position 7
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString insert_str{"I am a string"};
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-01 04:44:26 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
std::cout << " insert: "
|
|
|
|
<< insert_str.insert("changed ", 7) << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::out_of_range& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Out of Range error: " << ex.what() << std::endl;
|
|
|
|
}
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void indexExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: get character access at a specified index position
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString index{5}; // string with five characters
|
2020-04-04 20:58:47 +02:00
|
|
|
index.setString("index");
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
try
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
index[0] = L'I'; // write a wide character at position 0
|
2015-09-30 22:39:02 +02:00
|
|
|
printf ( " index: [0] = %c ; [4] = %c\n"
|
|
|
|
, char(index[0])
|
|
|
|
, char(index[4]) );
|
|
|
|
}
|
|
|
|
catch (const std::out_of_range& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Out of Range error: " << ex.what() << std::endl;
|
|
|
|
}
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void iteratorExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: character access with std::iterator
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString stringIterator{"iterator"};
|
2019-09-28 03:13:06 +02:00
|
|
|
finalcut::FString::const_iterator iter;
|
2015-05-23 13:35:12 +02:00
|
|
|
iter = stringIterator.begin();
|
|
|
|
std::cout << " " << stringIterator << ": ";
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
while ( iter != stringIterator.end() )
|
|
|
|
{
|
|
|
|
std::cout << char(*iter) << "|";
|
|
|
|
++iter;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " (front='" << char(stringIterator.front())
|
|
|
|
<< "', back='" << char(stringIterator.back())
|
|
|
|
<< "')" << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void overwriteExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: overwrite string at position 10 with "for t"
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString overwrite_std{"Overwrite the rest"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << "overwrite: "
|
|
|
|
<< overwrite_std.overwrite("for t", 10) << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void removeExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: remove 2 characters at position 7
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString remove_std{"A fast remove"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " remove: "
|
2017-09-11 03:06:02 +02:00
|
|
|
<< remove_std.remove(7, 2) << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void substringIncludeExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: includes a substring (positive test)
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString include_std{"string"};
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( include_std.includes("ring") )
|
|
|
|
std::cout << " includes: \""
|
|
|
|
<< include_std << "\" includes \"ring\" "
|
|
|
|
<< std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " includes: \""
|
|
|
|
<< include_std << "\" includes no \"ring\" "
|
|
|
|
<< std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: includes a substring (negativ test)
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( include_std.includes("data") )
|
|
|
|
std::cout << " includes: \""
|
|
|
|
<< include_std << "\" includes \"data\" "
|
|
|
|
<< std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " includes: \""
|
|
|
|
<< include_std << "\" includes no \"data\" "
|
|
|
|
<< std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void replaceExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: find and replace a substring
|
2019-08-25 22:16:00 +02:00
|
|
|
finalcut::FString source_str{"computer and software"};
|
2018-09-20 23:59:01 +02:00
|
|
|
const finalcut::FString& replace_str = \
|
|
|
|
source_str.replace("computer", "hard-");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " replace: "
|
|
|
|
<< replace_str << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void tabToSpaceExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert tabs to spaces
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString tab_str{"1234\t5678"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " tab: "
|
|
|
|
<< tab_str.expandTabs() << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void backspaceControlCharacterExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: backspaces remove characters in the string
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString bs_str{"t\b\bTesT\bt"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << "backspace: "
|
|
|
|
<< bs_str.removeBackspaces() << std::endl;
|
2017-11-19 19:47:24 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-11-19 19:47:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void deleteControlCharacterExample()
|
|
|
|
{
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: delete characters remove characters in the string
|
2019-08-25 22:16:00 +02:00
|
|
|
const finalcut::FString del_str{"apple \177\177\177pietree"};
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " delete: "
|
|
|
|
<< del_str.removeDel() << std::endl;
|
|
|
|
}
|
2017-11-19 19:47:24 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int, char**)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|