Bugfix: empty FString() + wchar_t

This commit is contained in:
Markus Gans 2020-09-23 23:18:48 +02:00
parent d10e2888ac
commit a69d38fb1e
10 changed files with 92 additions and 43 deletions

View File

@ -1,3 +1,6 @@
2020-09-23 Markus Gans <guru.mail@muenster.de>
* Bugfix: empty FString() + wchar_t
2020-09-22 Markus Gans <guru.mail@muenster.de>
* Bugfix in FDialog::setSize(): Automatic size adjustment and
simultaneous widget movement are now possible.

View File

@ -85,6 +85,7 @@ You need three things:
* autoconf
* autoconf-archive
* libtool
* pkg-config
3. Development packages for following libraries:

View File

@ -93,7 +93,7 @@ int main (int argc, char* argv[])
After entering the source code in *dialog.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal dialog.cpp -o dialog
g++ dialog.cpp -o dialog -O2 -lfinal
```
@ -240,7 +240,7 @@ int main (int argc, char* argv[])
After entering the source code in *memory.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal memory.cpp -o memory
g++ memory.cpp -o memory -O2 -lfinal
```
@ -380,7 +380,7 @@ int main (int argc, char* argv[])
After entering the source code in *timer.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 timer.cpp -o timer
g++ timer.cpp -o timer -O2 -lfinal -std=c++11
```
@ -493,7 +493,7 @@ int main (int argc, char* argv[])
After entering the source code in *user-event.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 user-event.cpp -o user-event
g++ user-event.cpp -o user-event -O2 -lfinal -std=c++11
```
@ -764,7 +764,7 @@ int main (int argc, char* argv[])
After entering the source code in *callback-function.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal callback-function.cpp -o callback-function
g++ callback-function.cpp -o callback-function -O2 -lfinal
```
&nbsp;
@ -827,7 +827,7 @@ int main (int argc, char* argv[])
After entering the source code in *callback-lambda.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 callback-lambda.cpp -o callback-lambda
g++ callback-lambda.cpp -o callback-lambda -O2 -lfinal -std=c++11
```
&nbsp;
@ -886,7 +886,7 @@ int main (int argc, char* argv[])
After entering the source code in *callback-method.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 callback-method.cpp -o callback-method
g++ callback-method.cpp -o callback-method -O2 -lfinal -std=c++11
```
&nbsp;
@ -1007,7 +1007,7 @@ int main (int argc, char* argv[])
After entering the source code in *emit-signal.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 emit-signal.cpp -o emit-signal
g++ emit-signal.cpp -o emit-signal -O2 -lfinal -std=c++11
```
@ -1278,7 +1278,7 @@ int main (int argc, char* argv[])
After entering the source code in *size-adjustment.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 size-adjustment.cpp -o size-adjustment
g++ size-adjustment.cpp -o size-adjustment -O2 -lfinal -std=c++11
```
@ -1406,5 +1406,5 @@ int main (int argc, char* argv[])
After entering the source code in *scrollview.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 scrollview.cpp -o scrollview
g++ scrollview.cpp -o scrollview -O2 -lfinal -std=c++11
```

View File

@ -438,6 +438,6 @@ int main (int argc, char* argv[])
After entering the source code in *theme.cpp* you can compile
the above program with gcc:
```cpp
g++ -O2 -lfinal -std=c++11 theme.cpp -o theme
g++ theme.cpp -o theme -O2 -lfinal -std=c++11
```

View File

@ -138,9 +138,7 @@ void FMenu::onKeyPress (FKeyEvent* ev)
if ( menu_bar )
{
auto mbar = static_cast<FMenuBar*>(menu_bar);
if ( mbar->hotkeyMenu(ev) )
if ( menu_bar->hotkeyMenu(ev) )
return;
}
@ -989,9 +987,8 @@ void FMenu::passEventToMenuBar (FMouseEvent* const& ev) const
const auto& _ev = \
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, t, b);
setClickedWidget(menu_bar);
auto& mbar = *(static_cast<FMenuBar*>(menu_bar));
mbar.mouse_down = true;
mbar.onMouseMove(_ev.get());
menu_bar->mouse_down = true;
menu_bar->onMouseMove(_ev.get());
}
catch (const std::bad_alloc&)
{
@ -1060,7 +1057,7 @@ bool FMenu::selectNextItem()
++next_element;
if ( next_element == list.end() )
next_element = list.begin();
next = static_cast<FMenuItem*>(*next_element);
next = *next_element;
}
while ( ! next->isEnabled()
|| ! next->acceptFocus()
@ -1110,7 +1107,7 @@ bool FMenu::selectPrevItem()
if ( prev_element == list.begin() )
prev_element = list.end();
--prev_element;
prev = static_cast<FMenuItem*>(*prev_element);
prev = *prev_element;
}
while ( ! prev->isEnabled()
|| ! prev->acceptFocus()

View File

@ -302,7 +302,7 @@ bool FMenuBar::selectNextItem()
if ( next_element == list.end() )
next_element = list.begin();
next = static_cast<FMenuItem*>(*next_element);
next = *next_element;
} while ( ! next->isEnabled()
|| ! next->acceptFocus()
|| ! next->isShown()
@ -365,7 +365,7 @@ bool FMenuBar::selectPrevItem()
prev_element = list.end();
--prev_element;
prev = static_cast<FMenuItem*>(*prev_element);
prev = *prev_element;
}
while ( ! prev->isEnabled()
|| ! prev->acceptFocus()

View File

@ -40,7 +40,7 @@ FScrollbar::FScrollbar(FWidget* parent)
: FWidget{parent}
{
// The default scrollbar orientation is vertical
setGeometry(FPoint{1, 1}, FSize{1, length}, false);
FScrollbar::setGeometry(FPoint{1, 1}, FSize{1, length}, false);
init();
}

View File

@ -1537,9 +1537,12 @@ const FString operator + (const FString& s1, const FString& s2)
//----------------------------------------------------------------------
const FString operator + (const FString& s, const wchar_t c)
{
FString tmp{s};
tmp._insert (tmp.length, 1, &c);
return tmp;
FString tmp1{s};
wchar_t tmp2[2];
tmp2[0] = c;
tmp2[1] = L'\0';
tmp1._insert (tmp1.length, 1, tmp2);
return tmp1;
}
//----------------------------------------------------------------------
@ -1597,7 +1600,7 @@ const FString operator + (const FString& s, const char c)
wchar_t tmp2[2];
tmp2[0] = wchar_t(c & 0xff);
tmp2[1] = L'\0';
tmp1._insert (s.length, 1, tmp2);
tmp1._insert (tmp1.length, 1, tmp2);
return tmp1;
}

View File

@ -1706,9 +1706,10 @@ void FVTerm::updateVTerm() const
vdesktop->has_changes = false;
}
const FWidget* widget = static_cast<FWidget*>(vterm->widget);
const FWidget* widget = vterm->widget;
if ( ! widget->getWindowList() || widget->getWindowList()->empty() )
if ( ! widget || ! widget->getWindowList()
|| widget->getWindowList()->empty() )
return;
for (auto&& window : *(widget->getWindowList()))

View File

@ -163,8 +163,8 @@ void FStringTest::noArgumentTest()
CPPUNIT_ASSERT ( empty.getLength() == 0 );
CPPUNIT_ASSERT ( empty.capacity() == 0 );
CPPUNIT_ASSERT ( empty.getUTF8length() == 0 );
CPPUNIT_ASSERT ( empty.wc_str() == 0 );
CPPUNIT_ASSERT ( empty.c_str() == 0 );
CPPUNIT_ASSERT ( empty.wc_str() == nullptr );
CPPUNIT_ASSERT ( empty.c_str() == nullptr );
CPPUNIT_ASSERT_EQUAL ( empty.toString(), std::string() );
CPPUNIT_ASSERT ( strlen(finalcut::FString(99).c_str()) == 0 );
CPPUNIT_ASSERT ( wcslen(finalcut::FString(99).wc_str()) == 0 );
@ -172,9 +172,9 @@ void FStringTest::noArgumentTest()
CPPUNIT_ASSERT ( wcslen(finalcut::FString("").wc_str()) == 0 );
char* cstr = empty.c_str();
CPPUNIT_ASSERT ( cstr == 0 );
CPPUNIT_ASSERT ( cstr == nullptr );
wchar_t* wcstr = empty.wc_str();
CPPUNIT_ASSERT ( wcstr == 0 );
CPPUNIT_ASSERT ( wcstr == nullptr );
std::string str = empty.toString();
CPPUNIT_ASSERT ( str.length() == 0 );
CPPUNIT_ASSERT ( str.size() == 0 );
@ -516,7 +516,7 @@ void FStringTest::additionAssignmentTest()
//----------------------------------------------------------------------
void FStringTest::additionTest()
{
// finalcut::FString member operator
// const finalcut::FString + ...
const finalcut::FString s1("abc");
CPPUNIT_ASSERT ( s1.getLength() == 3 );
CPPUNIT_ASSERT ( *(s1.c_str() + s1.getLength()) == '\0' );
@ -529,8 +529,7 @@ void FStringTest::additionTest()
CPPUNIT_ASSERT ( s1 + wchar_t(L'd') == L"abcd" );
CPPUNIT_ASSERT ( s1 + char('d') == L"abcd" );
// finalcut::FString non-member operator
// finalcut::FString + ...
finalcut::FString s2("abc");
CPPUNIT_ASSERT ( s2.getLength() == 3 );
CPPUNIT_ASSERT ( *(s2.c_str() + s2.getLength()) == '\0' );
@ -543,25 +542,70 @@ void FStringTest::additionTest()
CPPUNIT_ASSERT ( s2 + wchar_t(L'd') == L"abcd" );
CPPUNIT_ASSERT ( s2 + char('d') == L"abcd" );
const std::wstring& s3 = L"abc";
CPPUNIT_ASSERT ( s3 + finalcut::FString("def") == L"abcdef" );
// Empty const finalcut::FString + ...
const finalcut::FString s3;
CPPUNIT_ASSERT ( s3.getLength() == 0 );
CPPUNIT_ASSERT ( s3.c_str() == nullptr );
CPPUNIT_ASSERT ( s3.wc_str() == nullptr );
CPPUNIT_ASSERT ( s3 + finalcut::FString("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 + std::string("def") == L"def" );
CPPUNIT_ASSERT ( s3 + const_cast<char*>("def") == L"def" );
CPPUNIT_ASSERT ( s3 + wchar_t(L'd') == L"d" );
CPPUNIT_ASSERT ( s3 + char('d') == L"d" );
constexpr wchar_t s4[] = L"abc";
CPPUNIT_ASSERT ( s4 + finalcut::FString("def") == L"abcdef" );
// Empty finalcut::FString + ...
finalcut::FString s4;
CPPUNIT_ASSERT ( s4.getLength() == 0 );
CPPUNIT_ASSERT ( s4.c_str() == nullptr );
CPPUNIT_ASSERT ( s4.wc_str() == nullptr );
CPPUNIT_ASSERT ( s4 + finalcut::FString("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 + std::string("def") == L"def" );
CPPUNIT_ASSERT ( s4 + const_cast<char*>("def") == L"def" );
CPPUNIT_ASSERT ( s4 + wchar_t(L'd') == L"d" );
CPPUNIT_ASSERT ( s4 + char('d') == L"d" );
const std::string& s5 = "abc";
// Other string types + finalcut::FString
const std::wstring& s5 = L"abc";
CPPUNIT_ASSERT ( s5 + finalcut::FString("def") == L"abcdef" );
constexpr char s6[] = "abc";
constexpr wchar_t s6[] = L"abc";
CPPUNIT_ASSERT ( s6 + finalcut::FString("def") == L"abcdef" );
const std::string& s7 = "abc";
CPPUNIT_ASSERT ( s7 + finalcut::FString("def") == L"abcdef" );
constexpr char s8[] = "abc";
CPPUNIT_ASSERT ( s8 + finalcut::FString("def") == L"abcdef" );
constexpr wchar_t c1 = L'a';
CPPUNIT_ASSERT ( c1 + s3 == L"aabc" );
CPPUNIT_ASSERT ( c1 + s5 == L"aabc" );
CPPUNIT_ASSERT ( c1 + finalcut::FString("def") == L"adef" );
constexpr char c2 = 'a';
CPPUNIT_ASSERT ( c2 + s5 == "aabc" );
CPPUNIT_ASSERT ( c2 + s7 == "aabc" );
CPPUNIT_ASSERT ( c2 + finalcut::FString("def") == L"adef" );
// Other string types + empty const finalcut::FString
CPPUNIT_ASSERT ( s5 + s3 == L"abc" );
CPPUNIT_ASSERT ( s6 + s3 == L"abc" );
CPPUNIT_ASSERT ( s7 + s3 == L"abc" );
CPPUNIT_ASSERT ( s8 + s3 == L"abc" );
CPPUNIT_ASSERT ( c1 + s3 == L"a" );
CPPUNIT_ASSERT ( c1 + s3 == L"a" );
CPPUNIT_ASSERT ( c2 + s3 == "a" );
// Other string types + empty finalcut::FString
CPPUNIT_ASSERT ( s5 + s4 == L"abc" );
CPPUNIT_ASSERT ( s6 + s4 == L"abc" );
CPPUNIT_ASSERT ( s7 + s4 == L"abc" );
CPPUNIT_ASSERT ( s8 + s4 == L"abc" );
CPPUNIT_ASSERT ( c1 + s4 == L"a" );
CPPUNIT_ASSERT ( c1 + s4 == L"a" );
CPPUNIT_ASSERT ( c2 + s4 == "a" );
}
//----------------------------------------------------------------------