FString internally changed from wchar_t* to std::wstring

This commit is contained in:
Markus Gans 2021-05-30 23:52:03 +02:00
parent 95c0717589
commit 7f9ba7464b
22 changed files with 274 additions and 711 deletions

View File

@ -1,3 +1,6 @@
2021-05-30 Markus Gans <guru.mail@muenster.de>
* FString internally changed from wchar_t* to std::wstring
2021-05-24 Markus Gans <guru.mail@muenster.de> 2021-05-24 Markus Gans <guru.mail@muenster.de>
* Using std::string for the attribute buffer * Using std::string for the attribute buffer

View File

@ -385,7 +385,7 @@ void Calc::drawDispay()
{ {
finalcut::FString display{input}; finalcut::FString display{input};
if ( display.isNull() || display.isEmpty() ) if ( display.isEmpty() )
display = L'0'; display = L'0';
if ( display.right(3) == L"-0." ) if ( display.right(3) == L"-0." )
@ -651,7 +651,6 @@ void Calc::radix_point (const lDouble&)
return; return;
if ( isDataEntryKey(last_key) if ( isDataEntryKey(last_key)
&& ! input.isNull()
&& ! input.isEmpty() && ! input.isEmpty()
&& ! input.includes('.') ) && ! input.includes('.') )
input += '.'; input += '.';

View File

@ -1013,7 +1013,7 @@ void MyDialog::cb_view (const finalcut::FMenuItem* item)
else else
file = finalcut::FFileDialog::fileOpenChooser (this); file = finalcut::FFileDialog::fileOpenChooser (this);
if ( file.isNull() ) if ( file.isEmpty() )
return; return;
const auto& view = new TextWindow(this); const auto& view = new TextWindow(this);

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2012-2020 Markus Gans * * Copyright 2012-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -209,11 +209,7 @@ bool FButton::setDown (bool enable)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setText (const FString& txt) void FButton::setText (const FString& txt)
{ {
if ( txt.isNull() ) text.setString(txt);
text.setString("");
else
text.setString(txt);
detectHotkey(); detectHotkey();
} }

View File

@ -361,7 +361,7 @@ void FButtonGroup::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::drawLabel() void FButtonGroup::drawLabel()
{ {
if ( text.isNull() || text.isEmpty() ) if ( text.isEmpty() )
return; return;
FString label_text{}; FString label_text{};

View File

@ -65,15 +65,15 @@ FString fileChooser ( FWidget* parent
FString path{dirname}; FString path{dirname};
FString file_filter{filter}; FString file_filter{filter};
if ( path.isNull() || path.isEmpty() ) if ( path.isEmpty() )
{ {
path.setString(FFileDialog::getHomeDir()); path.setString(FFileDialog::getHomeDir());
if ( path.isNull() || path.isEmpty() ) if ( path.isEmpty() )
path.setString("/"); path.setString("/");
} }
if ( file_filter.isNull() || file_filter.isEmpty() ) if ( file_filter.isEmpty() )
file_filter.setString("*"); file_filter.setString("*");
FFileDialog fileopen ( path FFileDialog fileopen ( path
@ -111,7 +111,7 @@ FFileDialog::FFileDialog ( const FString& dirname
, filter_pattern{filter} , filter_pattern{filter}
, dlg_type{type} , dlg_type{type}
{ {
if ( ! dirname.isNull() ) if ( ! dirname.isEmpty() )
setPath(dirname); setPath(dirname);
init(); init();
@ -728,7 +728,7 @@ void FFileDialog::cb_processActivate()
{ {
return ! entry.name.empty() return ! entry.name.empty()
&& input && input
&& ! input.isNull() && ! input.isEmpty()
&& std::strcmp(entry.name.c_str(), input.c_str()) == 0 && std::strcmp(entry.name.c_str(), input.c_str()) == 0
&& entry.directory; && entry.directory;
} }

View File

@ -398,7 +398,7 @@ inline bool FKeyboard::isKeypressTimeout()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FKey FKeyboard::UTF8decode (const std::string& utf8) const FKey FKeyboard::UTF8decode (const std::string& utf8) const
{ {
using distance_type = std::iterator_traits<std::string::iterator>::difference_type; using distance_type = std::string::difference_type;
FKey ucs{FKey::None}; // Universal coded character FKey ucs{FKey::None}; // Universal coded character
constexpr std::size_t max = 4; constexpr std::size_t max = 4;
const auto len = utf8.length(); const auto len = utf8.length();

View File

@ -749,7 +749,7 @@ void FListBox::drawScrollbars() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::drawHeadline() void FListBox::drawHeadline()
{ {
if ( text.isNull() || text.isEmpty() ) if ( text.isEmpty() )
return; return;
const FString txt{" " + text + " "}; const FString txt{" " + text + " "};
@ -1678,7 +1678,7 @@ void FListBox::changeOnResize() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::lazyConvert(FListBoxItems::iterator iter, std::size_t y) void FListBox::lazyConvert(FListBoxItems::iterator iter, std::size_t y)
{ {
if ( conv_type != ConvertType::Lazy || ! iter->getText().isNull() ) if ( conv_type != ConvertType::Lazy || ! iter->getText().isEmpty() )
return; return;
lazy_inserter (*iter, source_container, y + std::size_t(yoffset)); lazy_inserter (*iter, source_container, y + std::size_t(yoffset));

View File

@ -281,7 +281,7 @@ void FMessageBox::calculateDimensions()
if ( text_num_lines == 0 ) if ( text_num_lines == 0 )
return; return;
if ( ! headline_text.isNull() ) if ( ! headline_text.isEmpty() )
headline_height = 2; headline_height = 2;
for (auto&& line : text_components) for (auto&& line : text_components)

View File

@ -604,9 +604,9 @@ int FOptiMove::capDurationToLength (int duration) const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FOptiMove::repeatedAppend ( const Capability& o int FOptiMove::repeatedAppend ( std::string& dst
, int count , const Capability& o
, std::string& dst ) const , int count ) const
{ {
const std::size_t src_len = std::strlen(o.cap); const std::size_t src_len = std::strlen(o.cap);
const std::size_t dst_len = dst.length(); const std::size_t dst_len = dst.length();
@ -702,7 +702,7 @@ inline void FOptiMove::downMove ( std::string& move, int& vtime
if ( ! move.empty() ) if ( ! move.empty() )
move.clear(); move.clear();
vtime = repeatedAppend (F_cursor_down, num, move); vtime = repeatedAppend (move, F_cursor_down, num);
} }
} }
@ -723,7 +723,7 @@ inline void FOptiMove::upMove ( std::string& move, int& vtime
if ( ! move.empty() ) if ( ! move.empty() )
move.clear(); move.clear();
vtime = repeatedAppend (F_cursor_up, num, move); vtime = repeatedAppend (move, F_cursor_up, num);
} }
} }
@ -737,7 +737,6 @@ inline int FOptiMove::horizontalMove (std::string& hmove, int from_x, int to_x)
// Move to fixed column position // Move to fixed column position
hmove = FTermcap::encodeParameter(F_column_address.cap, to_x); hmove = FTermcap::encodeParameter(F_column_address.cap, to_x);
htime = F_column_address.duration; htime = F_column_address.duration;
} }
if ( to_x > from_x ) if ( to_x > from_x )
@ -777,7 +776,7 @@ inline void FOptiMove::rightMove ( std::string& hmove, int& htime
if ( tab_pos > to_x ) if ( tab_pos > to_x )
break; break;
htime_r += repeatedAppend (F_tab, 1, str); htime_r += repeatedAppend (str, F_tab, 1);
if ( htime_r >= LONG_DURATION ) if ( htime_r >= LONG_DURATION )
break; break;
@ -788,7 +787,7 @@ inline void FOptiMove::rightMove ( std::string& hmove, int& htime
num = to_x - pos; num = to_x - pos;
} }
htime_r += repeatedAppend (F_cursor_right, num, str); htime_r += repeatedAppend (str, F_cursor_right, num);
if ( htime_r < htime ) if ( htime_r < htime )
{ {
@ -827,7 +826,7 @@ inline void FOptiMove::leftMove ( std::string& hmove, int& htime
if ( tab_pos < to_x ) if ( tab_pos < to_x )
break; break;
htime_l += repeatedAppend (F_back_tab, 1, str); htime_l += repeatedAppend (str, F_back_tab, 1);
if ( htime_l >= LONG_DURATION ) if ( htime_l >= LONG_DURATION )
break; break;
@ -838,11 +837,10 @@ inline void FOptiMove::leftMove ( std::string& hmove, int& htime
num = pos - to_x; num = pos - to_x;
} }
htime_l += repeatedAppend (F_cursor_left, num, str); htime_l += repeatedAppend (str, F_cursor_left, num);
if ( htime_l < htime ) if ( htime_l < htime )
{ {
hmove = str; hmove = str;
htime = htime_l; htime = htime_l;
} }

File diff suppressed because it is too large Load Diff

View File

@ -199,9 +199,9 @@ constexpr std::array<UniChar, 20> reverse_newfont_list =
// FTerm non-member functions // FTerm non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt env2uint (const char* env) uInt env2uint (const std::string& env)
{ {
const FString str{getenv(env)}; const FString str{getenv(env.data())};
if ( str.isEmpty() ) if ( str.isEmpty() )
return 0; return 0;

View File

@ -66,7 +66,6 @@ FString FTermBuffer::toString() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FTermBuffer::write (const FString& string) int FTermBuffer::write (const FString& string)
{ {
assert ( ! string.isNull() );
data.reserve(data.size() + string.getLength()); data.reserve(data.size() + string.getLength());
const auto last = string.end(); const auto last = string.end();
auto begin = string.begin(); auto begin = string.begin();

View File

@ -345,10 +345,6 @@ void FTermXTerminal::setXTermTitle()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
if ( xterm_title.isNull() )
xterm_title = "";
FTerm::putstringf (OSC "0;%s" BEL, xterm_title.c_str()); FTerm::putstringf (OSC "0;%s" BEL, xterm_title.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);

View File

@ -280,9 +280,7 @@ void FTextView::replaceRange (const FString& str, int from, int to)
auto iter = data.begin(); auto iter = data.begin();
data.erase (iter + from, iter + to + 1); data.erase (iter + from, iter + to + 1);
insert(str, from);
if ( ! str.isNull() )
insert(str, from);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2014-2020 Markus Gans * * Copyright 2014-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -383,7 +383,7 @@ void FToggleButton::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::drawLabel() void FToggleButton::drawLabel()
{ {
if ( text.isNull() || text.isEmpty() ) if ( text.isEmpty() )
return; return;
const FString txt(text); const FString txt(text);

View File

@ -342,8 +342,8 @@ void FVTerm::delPreprocessingHandler (const FVTerm* instance)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FVTerm::print (const FString& string) int FVTerm::print (const FString& string)
{ {
if ( string.isNull() ) if ( string.isEmpty() )
return -1; return 0;
FTermBuffer term_buffer{}; FTermBuffer term_buffer{};
term_buffer.write(string); term_buffer.write(string);
@ -353,7 +353,7 @@ int FVTerm::print (const FString& string)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FVTerm::print (FTermArea* area, const FString& string) int FVTerm::print (FTermArea* area, const FString& string)
{ {
if ( ! area || string.isNull() ) if ( ! area || string.isEmpty() )
return -1; return -1;
FTermBuffer term_buffer{}; FTermBuffer term_buffer{};

View File

@ -167,7 +167,7 @@ class FOptiMove final
void calculateCharDuration(); void calculateCharDuration();
int capDuration (const char[], int) const; int capDuration (const char[], int) const;
int capDurationToLength (int) const; int capDurationToLength (int) const;
int repeatedAppend (const Capability&, int, std::string&) const; int repeatedAppend (std::string&, const Capability&, int) const;
int relativeMove (std::string&, int, int, int, int) const; int relativeMove (std::string&, int, int, int, int) const;
int verticalMove (std::string&, int, int) const; int verticalMove (std::string&, int, int) const;
void downMove (std::string&, int&, int, int) const; void downMove (std::string&, int&, int, int) const;

View File

@ -80,10 +80,11 @@ class FString
{ {
public: public:
// Using-declarations // Using-declarations
using iterator = wchar_t*; using iterator = std::wstring::iterator;
using const_iterator = const wchar_t*; using const_iterator = std::wstring::const_iterator;
using reference = wchar_t&; using reference = std::wstring::reference;
using const_reference = const wchar_t&; using const_reference = std::wstring::const_reference;
using difference_type = std::wstring::difference_type;
// Constructors // Constructors
FString () = default; FString () = default;
@ -167,7 +168,7 @@ class FString
virtual FString getClassName() const; virtual FString getClassName() const;
// inquiries // inquiries
bool isNull() const noexcept; bool isNull() const noexcept; // deprecated
bool isEmpty() const noexcept; bool isEmpty() const noexcept;
// Methods // Methods
@ -245,24 +246,17 @@ class FString
private: private:
// Constants // Constants
static constexpr uInt FWDBUFFER = 15;
static constexpr uInt INPBUFFER = 200; static constexpr uInt INPBUFFER = 200;
// Methods // Methods
void _initLength (std::size_t); void _assign (const std::wstring&);
void _assign (const wchar_t[]); std::string _toCharString (const std::wstring&) const;
void _insert (std::size_t, const wchar_t[]); std::wstring _toWideString (const std::string&) const;
void _insert (std::size_t, std::size_t, const wchar_t[]); const wchar_t* _extractToken (wchar_t*[], const wchar_t[], const wchar_t[]) const;
void _remove (std::size_t, std::size_t);
const char* _to_cstring (const wchar_t[]) const;
const wchar_t* _to_wcstring (const char[]) const;
const wchar_t* _extractToken (wchar_t*[], const wchar_t[], const wchar_t[]) const;
// Data members // Data members
wchar_t* string{nullptr}; std::wstring string{};
std::size_t length{0}; mutable std::string char_string{};
std::size_t bufsize{0};
mutable char* c_string{nullptr};
static wchar_t null_char; static wchar_t null_char;
static const wchar_t const_null_char; static const wchar_t const_null_char;
@ -288,7 +282,7 @@ template <typename NumT
inline FString& FString::operator << (const NumT val) inline FString& FString::operator << (const NumT val)
{ {
const FString numstr(FString().setNumber(val)); const FString numstr(FString().setNumber(val));
_insert (length, numstr.length, numstr.string); string.append(numstr.string);
return *this; return *this;
} }
@ -296,10 +290,10 @@ inline FString& FString::operator << (const NumT val)
template <typename IndexT> template <typename IndexT>
inline FString::reference FString::operator [] (const IndexT pos) inline FString::reference FString::operator [] (const IndexT pos)
{ {
if ( isNegative(pos) || pos > IndexT(length) ) if ( isNegative(pos) || pos > IndexT(string.length()) )
throw std::out_of_range(""); // Invalid index position throw std::out_of_range(""); // Invalid index position
if ( std::size_t(pos) == length ) if ( std::size_t(pos) == string.length() )
return null_char; return null_char;
return string[std::size_t(pos)]; return string[std::size_t(pos)];
@ -309,10 +303,10 @@ inline FString::reference FString::operator [] (const IndexT pos)
template <typename IndexT> template <typename IndexT>
inline FString::const_reference FString::operator [] (const IndexT pos) const inline FString::const_reference FString::operator [] (const IndexT pos) const
{ {
if ( isNegative(pos) || pos > IndexT(length) ) if ( isNegative(pos) || pos > IndexT(string.length()) )
throw std::out_of_range(""); // Invalid index position throw std::out_of_range(""); // Invalid index position
if ( std::size_t(pos) == length ) if ( std::size_t(pos) == string.length() )
return const_null_char; return const_null_char;
return string[std::size_t(pos)]; return string[std::size_t(pos)];
@ -371,63 +365,63 @@ inline FString FString::getClassName() const
{ return "FString"; } { return "FString"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FString::isNull() const noexcept inline bool FString::isNull() const noexcept // deprecated
{ return ( bufsize == 0 || (bufsize > 0 && ! string) ); } { return false; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FString::isEmpty() const noexcept inline bool FString::isEmpty() const noexcept
{ return ( length == 0 || (length > 0 && string[0] == L'\0') ); } { return string.empty(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline std::size_t FString::getLength() const noexcept inline std::size_t FString::getLength() const noexcept
{ return length; } { return string.length(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline std::size_t FString::capacity() const noexcept inline std::size_t FString::capacity() const noexcept
{ return ( length > 0 ) ? bufsize - 1 : 0; } { return string.capacity(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::iterator FString::begin() noexcept inline FString::iterator FString::begin() noexcept
{ return string; } { return string.begin(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::iterator FString::end() noexcept inline FString::iterator FString::end() noexcept
{ return string + length; } { return string.end(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::const_iterator FString::begin() const noexcept inline FString::const_iterator FString::begin() const noexcept
{ return string; } { return string.cbegin(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::const_iterator FString::end() const noexcept inline FString::const_iterator FString::end() const noexcept
{ return string + length; } { return string.cend(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::reference FString::front() inline FString::reference FString::front()
{ {
assert ( ! isEmpty() ); assert ( ! isEmpty() );
return (*this)[0]; return string.front();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::reference FString::back() inline FString::reference FString::back()
{ {
assert( ! isEmpty() ); assert( ! isEmpty() );
return (*this)[length - 1]; return string.back();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::const_reference FString::front() const inline FString::const_reference FString::front() const
{ {
assert ( ! isEmpty() ); assert ( ! isEmpty() );
return (*this)[0]; return string.front();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::const_reference FString::back() const inline FString::const_reference FString::back() const
{ {
assert( ! isEmpty() ); assert( ! isEmpty() );
return (*this)[length - 1]; return string.back();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -367,7 +367,7 @@ class FTerm final
// non-member function forward declarations // non-member function forward declarations
// implemented in fterm_functions.cpp // implemented in fterm_functions.cpp
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt env2uint (const char*); uInt env2uint (const std::string&);
bool isReverseNewFontchar (wchar_t); bool isReverseNewFontchar (wchar_t);
bool hasFullWidthSupports(); bool hasFullWidthSupports();
wchar_t cp437_to_unicode (uChar); wchar_t cp437_to_unicode (uChar);

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2018-2020 Markus Gans * * Copyright 2018-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -158,12 +158,11 @@ void FStringTest::classNameTest()
void FStringTest::noArgumentTest() void FStringTest::noArgumentTest()
{ {
finalcut::FString empty; finalcut::FString empty;
CPPUNIT_ASSERT ( empty.isNull() );
CPPUNIT_ASSERT ( empty.isEmpty() ); CPPUNIT_ASSERT ( empty.isEmpty() );
CPPUNIT_ASSERT ( empty.getLength() == 0 ); CPPUNIT_ASSERT ( empty.getLength() == 0 );
CPPUNIT_ASSERT ( empty.capacity() == 0 ); CPPUNIT_ASSERT ( empty.capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( empty.wc_str() == nullptr ); CPPUNIT_ASSERT ( empty.wc_str()[0] == L'\0' );
CPPUNIT_ASSERT ( empty.c_str() == nullptr ); CPPUNIT_ASSERT ( empty.c_str()[0] == '\0' );
CPPUNIT_ASSERT_EQUAL ( empty.toString(), std::string() ); CPPUNIT_ASSERT_EQUAL ( empty.toString(), std::string() );
CPPUNIT_ASSERT ( strlen(finalcut::FString(99).c_str()) == 0 ); CPPUNIT_ASSERT ( strlen(finalcut::FString(99).c_str()) == 0 );
CPPUNIT_ASSERT ( wcslen(finalcut::FString(99).wc_str()) == 0 ); CPPUNIT_ASSERT ( wcslen(finalcut::FString(99).wc_str()) == 0 );
@ -171,17 +170,16 @@ void FStringTest::noArgumentTest()
CPPUNIT_ASSERT ( wcslen(finalcut::FString("").wc_str()) == 0 ); CPPUNIT_ASSERT ( wcslen(finalcut::FString("").wc_str()) == 0 );
char* cstr = empty.c_str(); char* cstr = empty.c_str();
CPPUNIT_ASSERT ( cstr == nullptr ); CPPUNIT_ASSERT ( cstr[0] == '\0' );
wchar_t* wcstr = empty.wc_str(); wchar_t* wcstr = empty.wc_str();
CPPUNIT_ASSERT ( wcstr == nullptr ); CPPUNIT_ASSERT ( wcstr[0] == L'\0' );
std::string str = empty.toString(); std::string str = empty.toString();
CPPUNIT_ASSERT ( str.length() == 0 ); CPPUNIT_ASSERT ( str.length() == 0 );
CPPUNIT_ASSERT ( str.size() == 0 ); CPPUNIT_ASSERT ( str.size() == 0 );
CPPUNIT_ASSERT ( str.empty() ); CPPUNIT_ASSERT ( str.empty() );
const finalcut::FString fstr = str; const finalcut::FString fstr = str;
CPPUNIT_ASSERT ( fstr.isNull() );
CPPUNIT_ASSERT ( fstr.isEmpty() ); CPPUNIT_ASSERT ( fstr.isEmpty() );
CPPUNIT_ASSERT ( fstr.capacity() == 0 ); CPPUNIT_ASSERT ( fstr.capacity() < std::wstring().max_size() );
cstr = 0; cstr = 0;
CPPUNIT_ASSERT ( empty == cstr ); CPPUNIT_ASSERT ( empty == cstr );
@ -209,7 +207,7 @@ void FStringTest::noArgumentTest()
CPPUNIT_ASSERT_EQUAL ( empty, finalcut::FString(L"123") ); CPPUNIT_ASSERT_EQUAL ( empty, finalcut::FString(L"123") );
empty.clear(); empty.clear();
CPPUNIT_ASSERT ( empty.isNull() ); CPPUNIT_ASSERT ( empty.isEmpty() );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -217,70 +215,60 @@ void FStringTest::initLengthTest()
{ {
const finalcut::FString s1(0); const finalcut::FString s1(0);
CPPUNIT_ASSERT ( s1.getLength() == 0 ); CPPUNIT_ASSERT ( s1.getLength() == 0 );
CPPUNIT_ASSERT ( s1.capacity() == 0 ); CPPUNIT_ASSERT ( s1.capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
constexpr int x1 = 10; constexpr int x1 = 10;
constexpr std::size_t x2 = 10; constexpr std::size_t x2 = 10;
const finalcut::FString s2(x1); const finalcut::FString s2(x1);
CPPUNIT_ASSERT ( s2.getLength() == 10 ); CPPUNIT_ASSERT ( s2.getLength() == 10 );
CPPUNIT_ASSERT ( s2.capacity() == 25 ); CPPUNIT_ASSERT ( s2.capacity() >= 10 );
CPPUNIT_ASSERT ( ! s2.isNull() ); CPPUNIT_ASSERT ( ! s2.isEmpty() );
CPPUNIT_ASSERT ( s2.isEmpty() );
const finalcut::FString s3(x2); const finalcut::FString s3(x2);
CPPUNIT_ASSERT ( s3.getLength() == 10 ); CPPUNIT_ASSERT ( s3.getLength() == 10 );
CPPUNIT_ASSERT ( s3.capacity() == 25 ); CPPUNIT_ASSERT ( s3.capacity() >= 10 );
CPPUNIT_ASSERT ( ! s3.isNull() ); CPPUNIT_ASSERT ( ! s3.isEmpty() );
CPPUNIT_ASSERT ( s3.isEmpty() );
const finalcut::FString s4(0, L'-'); const finalcut::FString s4(0, L'-');
CPPUNIT_ASSERT ( s4.getLength() == 0 ); CPPUNIT_ASSERT ( s4.getLength() == 0 );
CPPUNIT_ASSERT ( s4.capacity() == 0 ); CPPUNIT_ASSERT ( s4.capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( s4.isNull() );
CPPUNIT_ASSERT ( s4.isEmpty() ); CPPUNIT_ASSERT ( s4.isEmpty() );
const finalcut::FString s5(0, '-'); const finalcut::FString s5(0, '-');
CPPUNIT_ASSERT ( s5.getLength() == 0 ); CPPUNIT_ASSERT ( s5.getLength() == 0 );
CPPUNIT_ASSERT ( s5.capacity() == 0 ); CPPUNIT_ASSERT ( s5.capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( s5.isNull() );
CPPUNIT_ASSERT ( s5.isEmpty() ); CPPUNIT_ASSERT ( s5.isEmpty() );
const finalcut::FString s6(0, char(0)); const finalcut::FString s6(0, char(0));
CPPUNIT_ASSERT ( s6.getLength() == 0 ); CPPUNIT_ASSERT ( s6.getLength() == 0 );
CPPUNIT_ASSERT ( s6.capacity() == 0 ); CPPUNIT_ASSERT ( s6.capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( s6.isNull() );
CPPUNIT_ASSERT ( s6.isEmpty() ); CPPUNIT_ASSERT ( s6.isEmpty() );
const finalcut::FString s7(x1, '-'); const finalcut::FString s7(x1, '-');
CPPUNIT_ASSERT ( s7.getLength() == 10 ); CPPUNIT_ASSERT ( s7.getLength() == 10 );
CPPUNIT_ASSERT ( ! s7.isNull() ); CPPUNIT_ASSERT ( s7.capacity() >= 10 );
CPPUNIT_ASSERT ( ! s7.isEmpty() ); CPPUNIT_ASSERT ( ! s7.isEmpty() );
const finalcut::FString s8(x2, '-'); const finalcut::FString s8(x2, '-');
CPPUNIT_ASSERT ( s8.getLength() == 10 ); CPPUNIT_ASSERT ( s8.getLength() == 10 );
CPPUNIT_ASSERT ( s8.capacity() == 25 ); CPPUNIT_ASSERT ( s8.capacity() >= 10 );
CPPUNIT_ASSERT ( ! s8.isNull() );
CPPUNIT_ASSERT ( ! s8.isEmpty() ); CPPUNIT_ASSERT ( ! s8.isEmpty() );
const finalcut::FString s9(x1, L'-'); const finalcut::FString s9(x1, L'-');
CPPUNIT_ASSERT ( s9.getLength() == 10 ); CPPUNIT_ASSERT ( s9.getLength() == 10 );
CPPUNIT_ASSERT ( s9.capacity() == 25 ); CPPUNIT_ASSERT ( s9.capacity() >= 10 );
CPPUNIT_ASSERT ( ! s9.isNull() );
CPPUNIT_ASSERT ( ! s9.isEmpty() ); CPPUNIT_ASSERT ( ! s9.isEmpty() );
const finalcut::FString s10(x2, L'-'); const finalcut::FString s10(x2, L'-');
CPPUNIT_ASSERT ( s10.getLength() == 10 ); CPPUNIT_ASSERT ( s10.getLength() == 10 );
CPPUNIT_ASSERT ( s10.capacity() == 25 ); CPPUNIT_ASSERT ( s10.capacity() >= 10 );
CPPUNIT_ASSERT ( ! s10.isNull() );
CPPUNIT_ASSERT ( ! s10.isEmpty() ); CPPUNIT_ASSERT ( ! s10.isEmpty() );
const finalcut::FString s11(x2, wchar_t(0)); const finalcut::FString s11(x2, wchar_t(0));
CPPUNIT_ASSERT ( s11.getLength() == 10 ); CPPUNIT_ASSERT ( s11.getLength() == 10 );
CPPUNIT_ASSERT ( s11.capacity() == 25 ); CPPUNIT_ASSERT ( s11.capacity() >= 10 );
CPPUNIT_ASSERT ( ! s11.isNull() ); CPPUNIT_ASSERT ( ! s11.isEmpty() );
CPPUNIT_ASSERT ( s11.isEmpty() );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -290,7 +278,7 @@ void FStringTest::copyConstructorTest()
const finalcut::FString s2(s1); const finalcut::FString s2(s1);
CPPUNIT_ASSERT ( s2 == L"abc" ); CPPUNIT_ASSERT ( s2 == L"abc" );
CPPUNIT_ASSERT ( s2.getLength() == 3 ); CPPUNIT_ASSERT ( s2.getLength() == 3 );
CPPUNIT_ASSERT ( s2.capacity() == 18 ); CPPUNIT_ASSERT ( s2.capacity() >= 3 );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -300,11 +288,10 @@ void FStringTest::moveConstructorTest()
const finalcut::FString s2{std::move(s1)}; const finalcut::FString s2{std::move(s1)};
CPPUNIT_ASSERT ( s2 == L"abc" ); CPPUNIT_ASSERT ( s2 == L"abc" );
CPPUNIT_ASSERT ( s2.getLength() == 3 ); CPPUNIT_ASSERT ( s2.getLength() == 3 );
CPPUNIT_ASSERT ( s2.capacity() == 18 ); CPPUNIT_ASSERT ( s2.capacity() >= 3 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
CPPUNIT_ASSERT ( s1.getLength() == 0 ); CPPUNIT_ASSERT ( s1.getLength() == 0 );
CPPUNIT_ASSERT ( s1.capacity() == 0 ); CPPUNIT_ASSERT ( s1.capacity() < std::wstring().max_size() );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -313,37 +300,30 @@ void FStringTest::assignmentTest()
finalcut::FString s1; finalcut::FString s1;
s1 = static_cast<finalcut::FString>(0); s1 = static_cast<finalcut::FString>(0);
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = std::wstring(); s1 = std::wstring();
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = std::string(); s1 = std::string();
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = static_cast<wchar_t*>(0); s1 = static_cast<wchar_t*>(0);
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = static_cast<char*>(0); s1 = static_cast<char*>(0);
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = wchar_t(0); s1 = wchar_t(0);
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = char(0); s1 = char(0);
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
const finalcut::FString s2("abc"); const finalcut::FString s2("abc");
@ -351,49 +331,49 @@ void FStringTest::assignmentTest()
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
CPPUNIT_ASSERT ( s1 == L"abc" ); CPPUNIT_ASSERT ( s1 == L"abc" );
CPPUNIT_ASSERT ( s1.getLength() == 3 ); CPPUNIT_ASSERT ( s1.getLength() == 3 );
CPPUNIT_ASSERT ( s1.capacity() == 18 ); CPPUNIT_ASSERT ( s1.capacity() >= 3 );
const std::wstring s3(L"def"); const std::wstring s3(L"def");
s1 = s3; s1 = s3;
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
CPPUNIT_ASSERT ( s1 == L"def" ); CPPUNIT_ASSERT ( s1 == L"def" );
CPPUNIT_ASSERT ( s1.getLength() == 3 ); CPPUNIT_ASSERT ( s1.getLength() == 3 );
CPPUNIT_ASSERT ( s1.capacity() == 18 ); CPPUNIT_ASSERT ( s1.capacity() >= 3 );
const std::string s4("ghi"); const std::string s4("ghi");
s1 = s4; s1 = s4;
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
CPPUNIT_ASSERT ( s1 == L"ghi" ); CPPUNIT_ASSERT ( s1 == L"ghi" );
CPPUNIT_ASSERT ( s1.getLength() == 3 ); CPPUNIT_ASSERT ( s1.getLength() == 3 );
CPPUNIT_ASSERT ( s1.capacity() == 18 ); CPPUNIT_ASSERT ( s1.capacity() >= 3 );
constexpr wchar_t s5[] = L"abc"; constexpr wchar_t s5[] = L"abc";
s1 = s5; s1 = s5;
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
CPPUNIT_ASSERT ( s1 == L"abc" ); CPPUNIT_ASSERT ( s1 == L"abc" );
CPPUNIT_ASSERT ( s1.getLength() == 3 ); CPPUNIT_ASSERT ( s1.getLength() == 3 );
CPPUNIT_ASSERT ( s1.capacity() == 18 ); CPPUNIT_ASSERT ( s1.capacity() >= 3 );
constexpr char s6[] = "def"; constexpr char s6[] = "def";
s1 = s6; s1 = s6;
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
CPPUNIT_ASSERT ( s1 == L"def" ); CPPUNIT_ASSERT ( s1 == L"def" );
CPPUNIT_ASSERT ( s1.getLength() == 3 ); CPPUNIT_ASSERT ( s1.getLength() == 3 );
CPPUNIT_ASSERT ( s1.capacity() == 18 ); CPPUNIT_ASSERT ( s1.capacity() >= 3 );
constexpr wchar_t s7 = L'#'; constexpr wchar_t s7 = L'#';
s1 = s7; s1 = s7;
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
CPPUNIT_ASSERT ( s1 == L"#" ); CPPUNIT_ASSERT ( s1 == L"#" );
CPPUNIT_ASSERT ( s1.getLength() == 1 ); CPPUNIT_ASSERT ( s1.getLength() == 1 );
CPPUNIT_ASSERT ( s1.capacity() == 16 ); CPPUNIT_ASSERT ( s1.capacity() >= 1 );
constexpr char s8 = '%'; constexpr char s8 = '%';
s1 = s8; s1 = s8;
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
CPPUNIT_ASSERT ( s1 == L"%" ); CPPUNIT_ASSERT ( s1 == L"%" );
CPPUNIT_ASSERT ( s1.getLength() == 1 ); CPPUNIT_ASSERT ( s1.getLength() == 1 );
CPPUNIT_ASSERT ( s1.capacity() == 16 ); CPPUNIT_ASSERT ( s1.capacity() >= 1 );
s1.setString("A character string"); s1.setString("A character string");
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 );
@ -407,10 +387,10 @@ void FStringTest::assignmentTest()
CPPUNIT_ASSERT ( s1 == L"A wide character string" ); CPPUNIT_ASSERT ( s1 == L"A wide character string" );
s1.setString(""); s1.setString("");
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( ! s1 );
s1.setString(L""); s1.setString(L"");
CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( ! s1 );
s1.setString(""); s1.setString("");
CPPUNIT_ASSERT ( s1 == "" ); CPPUNIT_ASSERT ( s1 == "" );
@ -425,28 +405,25 @@ void FStringTest::assignmentTest()
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1.setString(""); s1.setString("");
CPPUNIT_ASSERT ( ! s1.isNull() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1.setString(L""); s1.setString(L"");
CPPUNIT_ASSERT ( ! s1.isNull() ); CPPUNIT_ASSERT ( s1.isEmpty() );
constexpr wchar_t* wc = 0; constexpr wchar_t* wc = 0;
s1.setString(wc); s1.setString(wc);
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
constexpr char* c = 0; constexpr char* c = 0;
s1.setString(c); s1.setString(c);
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( ! s1 ); CPPUNIT_ASSERT ( ! s1 );
// Move assignment operator // Move assignment operator
auto empty = finalcut::FString(0); auto empty = finalcut::FString(0);
const finalcut::FString s9 = std::move(empty); const finalcut::FString s9 = std::move(empty);
CPPUNIT_ASSERT ( ! s9 ); CPPUNIT_ASSERT ( ! s9 );
CPPUNIT_ASSERT ( s9.isNull() );
CPPUNIT_ASSERT ( s9.isEmpty() ); CPPUNIT_ASSERT ( s9.isEmpty() );
finalcut::FString s10("abc"); finalcut::FString s10("abc");
@ -454,11 +431,10 @@ void FStringTest::assignmentTest()
CPPUNIT_ASSERT ( s11 ); CPPUNIT_ASSERT ( s11 );
CPPUNIT_ASSERT ( s11 == L"abc" ); CPPUNIT_ASSERT ( s11 == L"abc" );
CPPUNIT_ASSERT ( s11.getLength() == 3 ); CPPUNIT_ASSERT ( s11.getLength() == 3 );
CPPUNIT_ASSERT ( s11.capacity() == 18 ); CPPUNIT_ASSERT ( s11.capacity() >= 3 );
CPPUNIT_ASSERT ( s10.isNull() );
CPPUNIT_ASSERT ( s10.isEmpty() ); CPPUNIT_ASSERT ( s10.isEmpty() );
CPPUNIT_ASSERT ( s10.getLength() == 0 ); CPPUNIT_ASSERT ( s10.getLength() == 0 );
CPPUNIT_ASSERT ( s10.capacity() == 0 ); CPPUNIT_ASSERT ( s10.capacity() < std::wstring().max_size() );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -475,7 +451,6 @@ void FStringTest::additionAssignmentTest()
CPPUNIT_ASSERT ( s1 == L"abcdef" ); CPPUNIT_ASSERT ( s1 == L"abcdef" );
s1.clear(); s1.clear();
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isEmpty() );
s1 += std::wstring(L"abc"); s1 += std::wstring(L"abc");
CPPUNIT_ASSERT ( s1 == L"abc" ); CPPUNIT_ASSERT ( s1 == L"abc" );
@ -545,8 +520,8 @@ void FStringTest::additionTest()
// Empty const finalcut::FString + ... // Empty const finalcut::FString + ...
const finalcut::FString s3; const finalcut::FString s3;
CPPUNIT_ASSERT ( s3.getLength() == 0 ); CPPUNIT_ASSERT ( s3.getLength() == 0 );
CPPUNIT_ASSERT ( s3.c_str() == nullptr ); CPPUNIT_ASSERT ( s3.c_str()[0] == '\0' );
CPPUNIT_ASSERT ( s3.wc_str() == nullptr ); CPPUNIT_ASSERT ( s3.wc_str()[0] == L'\0' );
CPPUNIT_ASSERT ( s3 + finalcut::FString("def") == L"def" ); CPPUNIT_ASSERT ( s3 + finalcut::FString("def") == L"def" );
CPPUNIT_ASSERT ( s3 + std::wstring(L"def") == L"def" ); CPPUNIT_ASSERT ( s3 + std::wstring(L"def") == L"def" );
CPPUNIT_ASSERT ( s3 + const_cast<wchar_t*>(L"def") == L"def" ); CPPUNIT_ASSERT ( s3 + const_cast<wchar_t*>(L"def") == L"def" );
@ -558,8 +533,8 @@ void FStringTest::additionTest()
// Empty finalcut::FString + ... // Empty finalcut::FString + ...
finalcut::FString s4; finalcut::FString s4;
CPPUNIT_ASSERT ( s4.getLength() == 0 ); CPPUNIT_ASSERT ( s4.getLength() == 0 );
CPPUNIT_ASSERT ( s4.c_str() == nullptr ); CPPUNIT_ASSERT ( s4.c_str()[0] == '\0' );
CPPUNIT_ASSERT ( s4.wc_str() == nullptr ); CPPUNIT_ASSERT ( s4.wc_str()[0] == L'\0' );
CPPUNIT_ASSERT ( s4 + finalcut::FString("def") == L"def" ); CPPUNIT_ASSERT ( s4 + finalcut::FString("def") == L"def" );
CPPUNIT_ASSERT ( s4 + std::wstring(L"def") == L"def" ); CPPUNIT_ASSERT ( s4 + std::wstring(L"def") == L"def" );
CPPUNIT_ASSERT ( s4 + const_cast<wchar_t*>(L"def") == L"def" ); CPPUNIT_ASSERT ( s4 + const_cast<wchar_t*>(L"def") == L"def" );
@ -642,7 +617,7 @@ void FStringTest::equalTest()
CPPUNIT_ASSERT ( one_char == ch ); CPPUNIT_ASSERT ( one_char == ch );
CPPUNIT_ASSERT ( ch == one_char.c_str()[0] ); CPPUNIT_ASSERT ( ch == one_char.c_str()[0] );
CPPUNIT_ASSERT ( one_char.getLength() == 1 ); CPPUNIT_ASSERT ( one_char.getLength() == 1 );
CPPUNIT_ASSERT ( one_char.capacity() == 16 ); CPPUNIT_ASSERT ( one_char.capacity() >= 1 );
constexpr wchar_t wch = L'a'; constexpr wchar_t wch = L'a';
CPPUNIT_ASSERT ( one_char == wch ); CPPUNIT_ASSERT ( one_char == wch );
@ -656,7 +631,7 @@ void FStringTest::equalTest()
constexpr char cstr[] = "abc"; constexpr char cstr[] = "abc";
CPPUNIT_ASSERT ( str == cstr ); CPPUNIT_ASSERT ( str == cstr );
CPPUNIT_ASSERT ( str.getLength() == 3 ); CPPUNIT_ASSERT ( str.getLength() == 3 );
CPPUNIT_ASSERT ( str.capacity() == 18 ); CPPUNIT_ASSERT ( str.capacity() >= 3 );
CPPUNIT_ASSERT ( strncmp(cstr, str.c_str(), 3) == 0 ); CPPUNIT_ASSERT ( strncmp(cstr, str.c_str(), 3) == 0 );
constexpr wchar_t wcstr[] = L"abc"; constexpr wchar_t wcstr[] = L"abc";
@ -677,7 +652,7 @@ void FStringTest::equalTest()
CPPUNIT_ASSERT ( s->c_str()[0] == 'c'); CPPUNIT_ASSERT ( s->c_str()[0] == 'c');
CPPUNIT_ASSERT ( s->getLength() == 1 ); CPPUNIT_ASSERT ( s->getLength() == 1 );
CPPUNIT_ASSERT ( s->capacity() == 16 ); CPPUNIT_ASSERT ( s->capacity() >= 1 );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -688,7 +663,7 @@ void FStringTest::notEqualTest()
CPPUNIT_ASSERT ( one_char != ch ); CPPUNIT_ASSERT ( one_char != ch );
CPPUNIT_ASSERT ( ch != one_char.c_str()[0] ); CPPUNIT_ASSERT ( ch != one_char.c_str()[0] );
CPPUNIT_ASSERT ( one_char.getLength() == 1 ); CPPUNIT_ASSERT ( one_char.getLength() == 1 );
CPPUNIT_ASSERT ( one_char.capacity() == 16 ); CPPUNIT_ASSERT ( one_char.capacity() >= 1 );
constexpr wchar_t wch = L'_'; constexpr wchar_t wch = L'_';
CPPUNIT_ASSERT ( one_char != wch ); CPPUNIT_ASSERT ( one_char != wch );
@ -704,8 +679,8 @@ void FStringTest::notEqualTest()
CPPUNIT_ASSERT ( strlen(s1.c_str()) == 3 ); CPPUNIT_ASSERT ( strlen(s1.c_str()) == 3 );
CPPUNIT_ASSERT ( s2.getLength() == 3 ); CPPUNIT_ASSERT ( s2.getLength() == 3 );
CPPUNIT_ASSERT ( strlen(s2.c_str()) == 6 ); CPPUNIT_ASSERT ( strlen(s2.c_str()) == 6 );
CPPUNIT_ASSERT ( s1.capacity() == 18 ); CPPUNIT_ASSERT ( s1.capacity() >= 3 );
CPPUNIT_ASSERT ( s2.capacity() == 18 ); CPPUNIT_ASSERT ( s2.capacity() >= 3 );
CPPUNIT_ASSERT ( strncmp(cstr, s1.c_str(), 3) != 0 ); CPPUNIT_ASSERT ( strncmp(cstr, s1.c_str(), 3) != 0 );
constexpr wchar_t wcstr[] = L"abc"; constexpr wchar_t wcstr[] = L"abc";
@ -1196,15 +1171,15 @@ void FStringTest::formatTest()
const finalcut::FString null_fstring{}; const finalcut::FString null_fstring{};
str2.sprintf (null_fstring, 0); str2.sprintf (null_fstring, 0);
CPPUNIT_ASSERT ( str2.isNull() ); CPPUNIT_ASSERT ( str2.isEmpty() );
constexpr wchar_t* null_wstring = 0; constexpr wchar_t* null_wstring = 0;
str2.sprintf (null_wstring, 0); str2.sprintf (null_wstring, 0);
CPPUNIT_ASSERT ( str2.isNull() ); CPPUNIT_ASSERT ( str2.isEmpty() );
constexpr char* null_string = 0; constexpr char* null_string = 0;
str2.sprintf (null_string, 0); str2.sprintf (null_string, 0);
CPPUNIT_ASSERT ( str2.isNull() ); CPPUNIT_ASSERT ( str2.isEmpty() );
std::setlocale (LC_NUMERIC, "C"); std::setlocale (LC_NUMERIC, "C");
finalcut::FString fnum1, fnum2; finalcut::FString fnum1, fnum2;
@ -1483,31 +1458,27 @@ void FStringTest::trimTest()
const finalcut::FString& trim_str2 = L"\n \n\n"; const finalcut::FString& trim_str2 = L"\n \n\n";
CPPUNIT_ASSERT ( trim_str2.rtrim().isEmpty() ); CPPUNIT_ASSERT ( trim_str2.rtrim().isEmpty() );
CPPUNIT_ASSERT ( ! trim_str2.rtrim().isNull() );
CPPUNIT_ASSERT ( trim_str2.rtrim().getLength() == 0 ); CPPUNIT_ASSERT ( trim_str2.rtrim().getLength() == 0 );
CPPUNIT_ASSERT ( trim_str2.rtrim().capacity() == 0 ); CPPUNIT_ASSERT ( trim_str2.rtrim().capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( *(trim_str2.rtrim().c_str() + trim_str2.rtrim().getLength()) == '\0' ); CPPUNIT_ASSERT ( *(trim_str2.rtrim().c_str() + trim_str2.rtrim().getLength()) == '\0' );
CPPUNIT_ASSERT ( *(trim_str2.rtrim().wc_str() + trim_str2.rtrim().getLength()) == L'\0' ); CPPUNIT_ASSERT ( *(trim_str2.rtrim().wc_str() + trim_str2.rtrim().getLength()) == L'\0' );
CPPUNIT_ASSERT ( trim_str2.ltrim().isEmpty() ); CPPUNIT_ASSERT ( trim_str2.ltrim().isEmpty() );
CPPUNIT_ASSERT ( ! trim_str2.ltrim().isNull() );
CPPUNIT_ASSERT ( trim_str2.ltrim().getLength() == 0 ); CPPUNIT_ASSERT ( trim_str2.ltrim().getLength() == 0 );
CPPUNIT_ASSERT ( trim_str2.ltrim().capacity() == 0 ); CPPUNIT_ASSERT ( trim_str2.ltrim().capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( *(trim_str2.ltrim().c_str() + trim_str2.ltrim().getLength()) == '\0' ); CPPUNIT_ASSERT ( *(trim_str2.ltrim().c_str() + trim_str2.ltrim().getLength()) == '\0' );
CPPUNIT_ASSERT ( *(trim_str2.ltrim().wc_str() + trim_str2.ltrim().getLength()) == L'\0' ); CPPUNIT_ASSERT ( *(trim_str2.ltrim().wc_str() + trim_str2.ltrim().getLength()) == L'\0' );
const finalcut::FString trim_str3{}; const finalcut::FString trim_str3{};
CPPUNIT_ASSERT ( trim_str3.ltrim().isEmpty() ); CPPUNIT_ASSERT ( trim_str3.ltrim().isEmpty() );
CPPUNIT_ASSERT ( trim_str3.ltrim().isNull() );
CPPUNIT_ASSERT ( trim_str3.ltrim().getLength() == 0 ); CPPUNIT_ASSERT ( trim_str3.ltrim().getLength() == 0 );
CPPUNIT_ASSERT ( trim_str3.ltrim().capacity() == 0 ); CPPUNIT_ASSERT ( trim_str3.ltrim().capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( trim_str3.rtrim().isEmpty() ); CPPUNIT_ASSERT ( trim_str3.rtrim().isEmpty() );
CPPUNIT_ASSERT ( trim_str3.rtrim().isEmpty() ); CPPUNIT_ASSERT ( trim_str3.rtrim().isEmpty() );
CPPUNIT_ASSERT ( trim_str3.rtrim().getLength() == 0 ); CPPUNIT_ASSERT ( trim_str3.rtrim().getLength() == 0 );
CPPUNIT_ASSERT ( trim_str3.rtrim().capacity() == 0 ); CPPUNIT_ASSERT ( trim_str3.rtrim().capacity() < std::wstring().max_size() );
CPPUNIT_ASSERT ( trim_str3.trim().isEmpty() ); CPPUNIT_ASSERT ( trim_str3.trim().isEmpty() );
CPPUNIT_ASSERT ( trim_str3.trim().isNull() );
CPPUNIT_ASSERT ( trim_str3.trim().getLength() == 0 ); CPPUNIT_ASSERT ( trim_str3.trim().getLength() == 0 );
CPPUNIT_ASSERT ( trim_str3.trim().capacity() == 0 ); CPPUNIT_ASSERT ( trim_str3.trim().capacity() < std::wstring().max_size() );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1527,9 +1498,7 @@ void FStringTest::subStringTest()
CPPUNIT_ASSERT ( str1.left(-5).getLength() == 39 ); CPPUNIT_ASSERT ( str1.left(-5).getLength() == 39 );
CPPUNIT_ASSERT ( str1.left(0) == L"" ); CPPUNIT_ASSERT ( str1.left(0) == L"" );
CPPUNIT_ASSERT ( str1.left(0).isEmpty() ); CPPUNIT_ASSERT ( str1.left(0).isEmpty() );
CPPUNIT_ASSERT ( ! str1.left(0).isNull() ); CPPUNIT_ASSERT ( finalcut::FString().left(5).isEmpty() );
CPPUNIT_ASSERT ( finalcut::FString().left(5).isNull() );
CPPUNIT_ASSERT ( ! finalcut::FString("").left(5).isNull() );
CPPUNIT_ASSERT ( finalcut::FString("").left(5).isEmpty() ); CPPUNIT_ASSERT ( finalcut::FString("").left(5).isEmpty() );
CPPUNIT_ASSERT ( finalcut::FString("").left(5).getLength() == 0 ); CPPUNIT_ASSERT ( finalcut::FString("").left(5).getLength() == 0 );
@ -1546,9 +1515,7 @@ void FStringTest::subStringTest()
CPPUNIT_ASSERT ( str1.right(-5).getLength() == 39 ); CPPUNIT_ASSERT ( str1.right(-5).getLength() == 39 );
CPPUNIT_ASSERT ( str1.right(0) == L"" ); CPPUNIT_ASSERT ( str1.right(0) == L"" );
CPPUNIT_ASSERT ( str1.right(0).isEmpty() ); CPPUNIT_ASSERT ( str1.right(0).isEmpty() );
CPPUNIT_ASSERT ( ! str1.right(0).isNull() ); CPPUNIT_ASSERT ( finalcut::FString().right(5).isEmpty() );
CPPUNIT_ASSERT ( finalcut::FString().right(5).isNull() );
CPPUNIT_ASSERT ( ! finalcut::FString("").right(5).isNull() );
CPPUNIT_ASSERT ( finalcut::FString("").right(5).isEmpty() ); CPPUNIT_ASSERT ( finalcut::FString("").right(5).isEmpty() );
CPPUNIT_ASSERT ( finalcut::FString("").right(5).getLength() == 0 ); CPPUNIT_ASSERT ( finalcut::FString("").right(5).getLength() == 0 );
@ -1567,9 +1534,7 @@ void FStringTest::subStringTest()
CPPUNIT_ASSERT ( str1.mid(0, 0) == L"" ); CPPUNIT_ASSERT ( str1.mid(0, 0) == L"" );
CPPUNIT_ASSERT ( str1.mid(0, 5) == L"Look " ); CPPUNIT_ASSERT ( str1.mid(0, 5) == L"Look " );
CPPUNIT_ASSERT ( str1.mid(0, 0).isEmpty() ); CPPUNIT_ASSERT ( str1.mid(0, 0).isEmpty() );
CPPUNIT_ASSERT ( ! str1.mid(0, 0).isNull() ); CPPUNIT_ASSERT ( finalcut::FString().mid(5, 0).isEmpty() );
CPPUNIT_ASSERT ( finalcut::FString().mid(5, 0).isNull() );
CPPUNIT_ASSERT ( ! finalcut::FString("").mid(5, 0).isNull() );
CPPUNIT_ASSERT ( finalcut::FString("").mid(5, 0).isEmpty() ); CPPUNIT_ASSERT ( finalcut::FString("").mid(5, 0).isEmpty() );
CPPUNIT_ASSERT ( str1.mid(5, 0).getLength() == 0 ); CPPUNIT_ASSERT ( str1.mid(5, 0).getLength() == 0 );
@ -1935,14 +1900,10 @@ void FStringTest::replaceTest()
CPPUNIT_ASSERT ( s1.replace(from6, empty) == "ABC" ); CPPUNIT_ASSERT ( s1.replace(from6, empty) == "ABC" );
s1.clear(); s1.clear();
CPPUNIT_ASSERT ( s1.replace(from1, to1).isNull() );
CPPUNIT_ASSERT ( s1.replace(from1, to1).isEmpty() ); CPPUNIT_ASSERT ( s1.replace(from1, to1).isEmpty() );
CPPUNIT_ASSERT ( s1.replace(from6, to1).isNull() );
CPPUNIT_ASSERT ( s1.replace(from6, to1).isEmpty() ); CPPUNIT_ASSERT ( s1.replace(from6, to1).isEmpty() );
CPPUNIT_ASSERT ( s1.replace(from5, to5).isNull() );
CPPUNIT_ASSERT ( s1.replace(from5, to5).isEmpty() ); CPPUNIT_ASSERT ( s1.replace(from5, to5).isEmpty() );
CPPUNIT_ASSERT ( s1.replace(from7, to7).isNull() );
CPPUNIT_ASSERT ( s1.replace(from7, to7).isEmpty() ); CPPUNIT_ASSERT ( s1.replace(from7, to7).isEmpty() );
} }

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2020 Markus Gans * * Copyright 2020-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -83,12 +83,10 @@ void FStringStreamTest::classNameTest()
void FStringStreamTest::defaultObjectTest() void FStringStreamTest::defaultObjectTest()
{ {
finalcut::FStringStream ss{std::ios_base::out}; finalcut::FStringStream ss{std::ios_base::out};
CPPUNIT_ASSERT ( ss.str().isNull() );
CPPUNIT_ASSERT ( ss.str().isEmpty() ); CPPUNIT_ASSERT ( ss.str().isEmpty() );
CPPUNIT_ASSERT ( ss.str() != "" ); CPPUNIT_ASSERT ( ss.str() == "" );
ss << "Hello"; ss << "Hello";
CPPUNIT_ASSERT ( ! ss.str().isNull() );
CPPUNIT_ASSERT ( ! ss.str().isEmpty() ); CPPUNIT_ASSERT ( ! ss.str().isEmpty() );
CPPUNIT_ASSERT ( ss.str() = "Hello" ); CPPUNIT_ASSERT ( ss.str() = "Hello" );
@ -97,9 +95,8 @@ void FStringStreamTest::defaultObjectTest()
CPPUNIT_ASSERT ( ss.str() == L"Hello, World!" ); CPPUNIT_ASSERT ( ss.str() == L"Hello, World!" );
ss.clear(); ss.clear();
CPPUNIT_ASSERT ( ss.str().isNull() );
CPPUNIT_ASSERT ( ss.str().isEmpty() ); CPPUNIT_ASSERT ( ss.str().isEmpty() );
CPPUNIT_ASSERT ( ss.str() != "" ); CPPUNIT_ASSERT ( ss.str() == "" );
ss.clear(); ss.clear();
ss << "Three" << " " << "parts"; ss << "Three" << " " << "parts";
@ -140,7 +137,6 @@ void FStringStreamTest::moveConstructorTest()
const finalcut::FStringStream ss2{std::move(ss1)}; const finalcut::FStringStream ss2{std::move(ss1)};
CPPUNIT_ASSERT ( ss2.str() == L"abc" ); CPPUNIT_ASSERT ( ss2.str() == L"abc" );
CPPUNIT_ASSERT ( ss2.str().getLength() == 3 ); CPPUNIT_ASSERT ( ss2.str().getLength() == 3 );
CPPUNIT_ASSERT ( ss1.str().isNull() );
CPPUNIT_ASSERT ( ss1.str().isEmpty() ); CPPUNIT_ASSERT ( ss1.str().isEmpty() );
CPPUNIT_ASSERT ( ss1.str().getLength() == 0 ); CPPUNIT_ASSERT ( ss1.str().getLength() == 0 );
} }
@ -153,7 +149,6 @@ void FStringStreamTest::assignmentTest()
ss2 = std::move(ss1); ss2 = std::move(ss1);
CPPUNIT_ASSERT ( ss2.str() == L"xyz" ); CPPUNIT_ASSERT ( ss2.str() == L"xyz" );
CPPUNIT_ASSERT ( ss2.str().getLength() == 3 ); CPPUNIT_ASSERT ( ss2.str().getLength() == 3 );
CPPUNIT_ASSERT ( ss1.str().isNull() );
CPPUNIT_ASSERT ( ss1.str().isEmpty() ); CPPUNIT_ASSERT ( ss1.str().isEmpty() );
CPPUNIT_ASSERT ( ss1.str().getLength() == 0 ); CPPUNIT_ASSERT ( ss1.str().getLength() == 0 );
} }
@ -189,7 +184,6 @@ void FStringStreamTest::rdbufTest()
CPPUNIT_ASSERT ( ss.str().getLength() == 4 ); CPPUNIT_ASSERT ( ss.str().getLength() == 4 );
ss.rdbuf()->str(L""); ss.rdbuf()->str(L"");
CPPUNIT_ASSERT ( ss.str().isNull() );
CPPUNIT_ASSERT ( ss.str().isEmpty() ); CPPUNIT_ASSERT ( ss.str().isEmpty() );
CPPUNIT_ASSERT ( ss.str().getLength() == 0 ); CPPUNIT_ASSERT ( ss.str().getLength() == 0 );
} }