2015-09-25 21:37:19 +02:00
|
|
|
// File: string-operations.cpp
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#include <langinfo.h>
|
|
|
|
#include <term.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <clocale>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include <final/fstring.h>
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
int main (int, char**)
|
|
|
|
{
|
|
|
|
printf ("----------------[ terminal ]-------------------\n");
|
|
|
|
|
|
|
|
// init current locale
|
2016-10-06 23:15:09 +02:00
|
|
|
printf (" Locale: %s\n", std::setlocale(LC_CTYPE, "") );
|
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
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
printf (" Codeset: %s\n", nl_langinfo(CODESET));
|
|
|
|
|
|
|
|
std::cout << "--------------[ FString test ]-----------------"
|
|
|
|
<< std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: input stream (operator >>)
|
2015-05-23 13:35:12 +02:00
|
|
|
FString in;
|
|
|
|
std::cout << " Input: "; std::cin >> in;
|
|
|
|
std::cout << " instream >> " << in << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: output stream (operator <<)
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& out = L"A test string for 0 \x20ac";
|
2017-04-17 22:49:42 +02:00
|
|
|
std::cout << " outstream << " << out << std::endl;
|
|
|
|
|
|
|
|
// Test: c-string output
|
2015-05-23 13:35:12 +02:00
|
|
|
printf (" c_str: \"%s\"\n", out.c_str());
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: copy a c++ string
|
2017-09-09 22:03:17 +02:00
|
|
|
const 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
|
2017-09-09 22:03:17 +02:00
|
|
|
const 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
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& wch(L'w');
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " wchar_t: '" << wch << "'" << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: utf-8 string
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& len = "длина́";
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " length: \"" << len << "\" has "
|
|
|
|
<< len.getLength() << " characters" << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert uppercase letter to lowercase
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& lower = 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
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& upper = FString("inPut").toUpper();
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " toUpper: " << upper << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: concatenate two FStrings (operator +)
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& add1 = FString("FString + ") + 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add2 = 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add3 = 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add4 = 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add5 = 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 +)
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& add6 = 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 +)
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& add7 = 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 +)
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& add8 = 'c' + 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 +)
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& add9 = L'w' + 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add10 = const_cast<char*>("char*")
|
|
|
|
+ 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add11 = std::string("std::string")
|
|
|
|
+ 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add12 = const_cast<wchar_t*>(L"wchar_t*")
|
|
|
|
+ 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 +)
|
2017-09-11 03:06:02 +02:00
|
|
|
const FString& add13 = std::wstring(L"std::wstring")
|
|
|
|
+ FString(" + FString");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " add: " << add13 << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: compare operators ==, <=, <, >=, >, !=
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& cmp = "compare";
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cmp == FString("compare") )
|
|
|
|
std::cout << " cmp: == Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: == Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cmp <= FString("d_compare") )
|
|
|
|
std::cout << " cmp: <= Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: <= Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cmp < FString("e_compare") )
|
|
|
|
std::cout << " cmp: < Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: < Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cmp >= FString("b_compare") )
|
|
|
|
std::cout << " cmp: >= Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: >= Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cmp > FString("a_compare") )
|
|
|
|
std::cout << " cmp: > Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: > Not Ok" << std::endl;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( cmp != FString("equal") )
|
|
|
|
std::cout << " cmp: != Ok" << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << " cmp: != Not Ok" << std::endl;
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
// Test: split a string with a delimiter and returns a vector (array)
|
2015-05-23 13:35:12 +02:00
|
|
|
FString split_str = "a,b,c,d";
|
|
|
|
std::cout << " split: \""
|
|
|
|
<< split_str << "\" into substrings ->";
|
|
|
|
std::vector <FString> parts = split_str.split(",");
|
|
|
|
std::vector<FString>::iterator it, end;
|
|
|
|
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-04-17 22:49:42 +02:00
|
|
|
// Test: format a string with sprintf
|
2015-05-23 13:35:12 +02:00
|
|
|
FString formatStr = "";
|
|
|
|
std::cout << " formatted: "
|
|
|
|
<< formatStr.sprintf("sqrt(%d) = %d", 16, 4)
|
|
|
|
<< std::endl;
|
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
|
|
|
|
{
|
2017-09-09 22:03:17 +02:00
|
|
|
const uLong ulong_num = 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
|
|
|
|
{
|
2017-09-09 22:03:17 +02:00
|
|
|
const long long_num = 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
|
|
|
|
{
|
2017-09-09 22:03:17 +02:00
|
|
|
const double double_num = 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
|
|
|
}
|
2015-06-30 00:21:50 +02:00
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
// Test: convert integer and double value to a string
|
2015-06-27 23:00:12 +02:00
|
|
|
FString num1, num2, num3;
|
2015-05-23 13:35:12 +02:00
|
|
|
num1.setNumber(137);
|
|
|
|
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;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
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, "");
|
2015-05-23 13:35:12 +02:00
|
|
|
FString fnum1, fnum2;
|
2015-09-18 21:38:26 +02:00
|
|
|
#if defined(__LP64__) || defined(_LP64)
|
|
|
|
// 64-bit architecture
|
2015-05-23 13:35:12 +02:00
|
|
|
fnum1.setFormatedNumber(0xffffffffffffffff, '\'');
|
|
|
|
fnum2.setFormatedNumber(-9223372036854775807);
|
2015-09-18 21:38:26 +02:00
|
|
|
#else
|
|
|
|
// 32-bit architecture
|
|
|
|
fnum1.setFormatedNumber(0xffffffff, '\'');
|
|
|
|
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-04-17 22:49:42 +02:00
|
|
|
// Test: remove whitespace from the end of a string
|
2017-09-09 22:03:17 +02:00
|
|
|
const 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-04-17 22:49:42 +02:00
|
|
|
// Test: 11 characters from the left of the string
|
2017-09-09 22:03:17 +02:00
|
|
|
const 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-04-17 22:49:42 +02:00
|
|
|
// Test: insert a string at index position 7
|
2015-05-23 13:35:12 +02:00
|
|
|
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;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: get character access at a specified index position
|
2017-09-11 03:06:02 +02:00
|
|
|
FString index(5); // string with five characters
|
2015-05-23 13:35:12 +02:00
|
|
|
index = "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;
|
|
|
|
}
|
2015-10-01 04:44:26 +02:00
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: character access with std::iterator
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& stringIterator = "iterator";
|
2015-05-23 13:35:12 +02:00
|
|
|
FString::iterator iter;
|
|
|
|
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-04-17 22:49:42 +02:00
|
|
|
// Test: overwrite string at position 10 with "for t"
|
2015-05-23 13:35:12 +02:00
|
|
|
FString overwrite_std = "Overwrite the rest";
|
|
|
|
std::cout << "overwrite: "
|
|
|
|
<< overwrite_std.overwrite("for t", 10) << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: remove 2 characters at position 7
|
2015-05-23 13:35:12 +02:00
|
|
|
FString remove_std = "A fast remove";
|
|
|
|
std::cout << " remove: "
|
2017-09-11 03:06:02 +02:00
|
|
|
<< remove_std.remove(7, 2) << std::endl;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: includes a substring (positive test)
|
2015-05-23 13:35:12 +02:00
|
|
|
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-04-17 22:49:42 +02:00
|
|
|
// Test: find and replace a substring
|
2015-05-23 13:35:12 +02:00
|
|
|
FString source_str = "computer and software";
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& replace_str = source_str.replace("computer", "hard-");
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " replace: "
|
|
|
|
<< replace_str << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: convert tabs to spaces
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& tab_str = "1234\t5678";
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " tab: "
|
|
|
|
<< tab_str.expandTabs() << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: backspaces remove characters in the string
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& bs_str = "t\b\bTesT\bt";
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << "backspace: "
|
|
|
|
<< bs_str.removeBackspaces() << std::endl;
|
|
|
|
|
2017-04-17 22:49:42 +02:00
|
|
|
// Test: delete characters remove characters in the string
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& del_str = "apple \177\177\177pietree";
|
2015-05-23 13:35:12 +02:00
|
|
|
std::cout << " delete: "
|
|
|
|
<< del_str.removeDel() << std::endl;
|
|
|
|
}
|