diff --git a/ChangeLog b/ChangeLog index cdaa503d..933985eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-10-05 Markus Gans + * Remove redundant program code from FString + 2018-10-03 Markus Gans * At the end of the lifetime of an FMenuItem object, delete its entry from the object list of the parent object diff --git a/README.md b/README.md index 352aba85..f2e74145 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ The C++ class design was inspired by the Qt framework. It provides common contro ### First steps -[How to use the library](doc/first-steps.md) +[How to use the library](doc/first-steps.md#first-steps-with-the-final-cut-widget-toolkit) ### Screenshots diff --git a/examples/choice.cpp b/examples/choice.cpp index f5121a12..cd13e04b 100644 --- a/examples/choice.cpp +++ b/examples/choice.cpp @@ -90,7 +90,6 @@ void preset (std::vector& os) //---------------------------------------------------------------------- int main (int argc, char* argv[]) { - int x, y, w, h; finalcut::FString label_text = "no OS"; // Create the application object @@ -100,10 +99,10 @@ int main (int argc, char* argv[]) finalcut::FDialog dgl(&app); dgl.setModal(); dgl.setText ("UNIX select"); - w = 20; - h = 13; - x = (app.getDesktopWidth() - w) / 2; - y = (app.getDesktopHeight() - h) / 2; + int w = 20; + int h = 13; + int x = (app.getDesktopWidth() - w) / 2; + int y = (app.getDesktopHeight() - h) / 2; dgl.setGeometry (x, y, w, h); // Create a button group diff --git a/src/flineedit.cpp b/src/flineedit.cpp index af17fea6..6648c2e9 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -842,7 +842,7 @@ inline void FLineEdit::keyDel() if ( len > 0 && cursor_pos < len ) { - text.remove(uInt(cursor_pos), 1); + text.remove(cursor_pos, 1); processChanged(); } @@ -861,7 +861,7 @@ inline void FLineEdit::keyBackspace() { if ( text.getLength() > 0 && cursor_pos > 0 ) { - text.remove(uInt(cursor_pos - 1), 1); + text.remove(cursor_pos - 1, 1); processChanged(); cursor_pos--; diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 805333bf..298204c1 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -1642,10 +1642,4 @@ void FMouseControl::xtermMouse (bool on) FTermXTerminal::setMouseSupport (on); } -//---------------------------------------------------------------------- -void FMouseControl::putstring (const char s[], int affcnt) -{ - FTerm::putstring (s, affcnt); -} - } // namespace finalcut diff --git a/src/fstring.cpp b/src/fstring.cpp index 64fa3c05..f7283af7 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -142,9 +142,7 @@ FString::FString (const FString& s) // copy constructor , bufsize(0) , c_string(0) { - if ( s.isNull() ) - return; - else + if ( ! s.isNull() ) _assign (s.string); } @@ -155,9 +153,7 @@ FString::FString (const std::wstring& s) , bufsize(0) , c_string(0) { - if ( s.empty() ) - _assign (L""); - else + if ( ! s.empty() ) _assign (s.c_str()); } @@ -168,15 +164,7 @@ FString::FString (const wchar_t s[]) , bufsize(0) , c_string(0) { - if ( ! s ) - return; - - if ( ! s[0] ) - { - _assign(L""); - return; - } - else + if ( s ) _assign (s); } @@ -187,16 +175,12 @@ FString::FString (const std::string& s) , bufsize(0) , c_string(0) { - if ( s.empty() ) + if ( ! s.empty() ) { - _assign(L""); - return; + const wchar_t* wc_string = c_to_wc_str(s.c_str()); + _assign(wc_string); + delete[] wc_string; } - - const wchar_t* wc_string; - wc_string = c_to_wc_str(s.c_str()); - _assign( wc_string ); - delete[] wc_string; } //---------------------------------------------------------------------- @@ -206,19 +190,12 @@ FString::FString (const char s[]) , bufsize(0) , c_string(0) { - if ( ! s ) - return; - - if ( ! s[0] ) + if ( s ) { - _assign(L""); - return; + const wchar_t* wc_string = c_to_wc_str(s); + _assign( wc_string ); + delete[] wc_string; } - - const wchar_t* wc_string; - wc_string = c_to_wc_str(s); - _assign (wc_string); - delete[] wc_string; } //---------------------------------------------------------------------- @@ -228,16 +205,13 @@ FString::FString (const wchar_t c) , bufsize(0) , c_string(0) { - if ( c == 0 ) + if ( c ) { - _assign(L""); - return; + wchar_t s[2]; + s[0] = c; + s[1] = L'\0'; + _assign (s); } - - wchar_t s[2]; - s[0] = c; - s[1] = L'\0'; - _assign (s); } //---------------------------------------------------------------------- @@ -247,16 +221,13 @@ FString::FString (const char c) , bufsize(0) , c_string(0) { - if ( c == 0 ) + if ( c ) { - _assign(L""); - return; + wchar_t s[2]; + s[0] = wchar_t(c & 0xff); + s[1] = L'\0'; + _assign (s); } - - wchar_t s[2]; - s[0] = wchar_t(c & 0xff); - s[1] = L'\0'; - _assign (s); } //---------------------------------------------------------------------- @@ -278,90 +249,6 @@ FString& FString::operator = (const FString& s) return *this; } -//---------------------------------------------------------------------- -FString& FString::operator = (const std::wstring& s) -{ - if ( ! s.empty() ) - _assign (s.c_str()); - else - clear(); - - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator = (const wchar_t s[]) -{ - if ( s ) - _assign (s); - else - clear(); - - return *this; -} - -//---------------------------------------------------------------------- -FString& FString::operator = (const std::string& s) -{ - if ( ! s.empty() ) - { - const wchar_t* wc_string = c_to_wc_str(s.c_str()); - _assign( wc_string ); - delete[] wc_string; - } - else - clear(); - - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator = (const char s[]) -{ - if ( s ) - { - const wchar_t* wc_string = c_to_wc_str(s); - _assign( wc_string ); - delete[] wc_string; - } - else - clear(); - - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator = (const wchar_t c) -{ - if ( c ) - { - wchar_t s[2]; - s[0] = c; - s[1] = L'\0'; - _assign (s); - } - else - clear(); - - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator = (const char c) -{ - if ( c ) - { - wchar_t s[2]; - s[0] = wchar_t(c & 0xff); - s[1] = L'\0'; - _assign (s); - } - else - clear(); - - return *this; -} - //---------------------------------------------------------------------- const FString& FString::operator += (const FString& s) { @@ -369,65 +256,6 @@ const FString& FString::operator += (const FString& s) return *this; } -//---------------------------------------------------------------------- -const FString& FString::operator += (const std::wstring& s) -{ - _insert (length, uInt(s.length()), s.c_str()); - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator += (const wchar_t s[]) -{ - _insert (length, uInt(std::wcslen(s)), s); - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator += (const std::string& s) -{ - if ( ! s.empty() ) - { - const wchar_t* wc_string = c_to_wc_str(s.c_str()); - _insert (length, uInt(s.length()), wc_string); - delete[] wc_string; - } - - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator += (const char s[]) -{ - if ( s ) - { - const wchar_t* wc_string = c_to_wc_str(s); - _insert (length, uInt(std::wcslen(wc_string)), wc_string); - delete[] wc_string; - } - - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator += (const wchar_t c) -{ - wchar_t s[2]; - s[0] = c; - s[1] = L'\0'; - _insert (length, 1, s); - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::operator += (const char c) -{ - wchar_t s[2]; - s[0] = wchar_t(c & 0xff); - s[1] = L'\0'; - _insert (length, 1, s); - return *this; -} //---------------------------------------------------------------------- const FString FString::operator + (const FString& s) @@ -738,7 +566,7 @@ uInt FString::getUTF8length() const } //---------------------------------------------------------------------- -FString& FString::sprintf (const FString format, ...) +FString& FString::sprintf (const FString& format, ...) { static const int BUFSIZE = 4096; wchar_t buffer[BUFSIZE]; @@ -758,80 +586,6 @@ FString& FString::sprintf (const FString format, ...) return *this; } -//---------------------------------------------------------------------- -FString& FString::sprintf (const wchar_t format[], ...) -{ - static const int BUFSIZE = 4096; - wchar_t buffer[BUFSIZE]; - va_list args; - - if ( ! format ) - { - clear(); - return *this; - } - - va_start (args, format); - std::vswprintf (buffer, BUFSIZE, format, args); - va_end (args); - - _assign (buffer); - return *this; -} - -//---------------------------------------------------------------------- -FString& FString::sprintf (const char format[], ...) -{ - const wchar_t* wc_string; - char buf[1024]; - char* buffer; - int len; - va_list args; - - if ( ! format ) - { - clear(); - return *this; - } - - buffer = buf; - va_start (args, format); - len = vsnprintf (buffer, sizeof(buf), format, args); - va_end (args); - - if ( len >= int(sizeof(buf)) ) - { - uLong buf_size = uInt(len) + 1; - - try - { - buffer = new char[buf_size](); - } - catch (const std::bad_alloc& ex) - { - std::cerr << bad_alloc_str << ex.what() << std::endl; - return *this; - } - - va_start (args, format); - vsnprintf (buffer, buf_size, format, args); - va_end (args); - } - - wc_string = c_to_wc_str(buffer); - - if ( wc_string ) - { - _assign(wc_string); - delete[] wc_string; - } - - if ( buffer != buf ) - delete[] buffer; - - return *this; -} - //---------------------------------------------------------------------- FString FString::clear() { @@ -1313,18 +1067,9 @@ FStringList FString::split (const FString& delimiter) } //---------------------------------------------------------------------- -FString& FString::setString (const wchar_t s[]) +FString& FString::setString (const FString& s) { - _assign (s); - return *this; -} - -//---------------------------------------------------------------------- -FString& FString::setString (const char s[]) -{ - const wchar_t* wc_string = c_to_wc_str(s); - _assign (wc_string); - delete[] wc_string; + _assign (s.string); return *this; } @@ -1503,48 +1248,6 @@ bool FString::operator < (const FString& s) const return ( std::wcscmp(string, s.string) < 0 ); } -//---------------------------------------------------------------------- -bool FString::operator < (const std::wstring& s) const -{ - const FString tmp(s); - return *this < tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator < (const wchar_t s[]) const -{ - const FString tmp(s); - return *this < tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator < (const std::string& s) const -{ - const FString tmp(s); - return *this < tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator < (const char s[]) const -{ - const FString tmp(s); - return *this < tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator < (const wchar_t c) const -{ - const FString tmp(c); - return *this < tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator < (const char c) const -{ - const FString tmp(c); - return *this < tmp; -} - //---------------------------------------------------------------------- bool FString::operator <= (const FString& s) const { @@ -1560,48 +1263,6 @@ bool FString::operator <= (const FString& s) const return ( std::wcscmp(string, s.string) <= 0 ); } -//---------------------------------------------------------------------- -bool FString::operator <= (const std::wstring& s) const -{ - const FString tmp(s); - return *this <= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator <= (const wchar_t s[]) const -{ - const FString tmp(s); - return *this <= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator <= (const std::string& s) const -{ - const FString tmp(s); - return *this <= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator <= (const char s[]) const -{ - const FString tmp(s); - return *this <= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator <= (const wchar_t c) const -{ - const FString tmp(c); - return *this <= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator <= (const char c) const -{ - const FString tmp(c); - return *this <= tmp; -} - //---------------------------------------------------------------------- bool FString::operator == (const FString& s) const { @@ -1614,48 +1275,6 @@ bool FString::operator == (const FString& s) const return ( std::wcscmp(string, s.string) == 0 ); } -//---------------------------------------------------------------------- -bool FString::operator == (const std::wstring& s) const -{ - const FString tmp(s); - return *this == tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator == (const wchar_t s[]) const -{ - const FString tmp(s); - return *this == tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator == (const std::string& s) const -{ - const FString tmp(s); - return *this == tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator == (const char s[]) const -{ - const FString tmp(s); - return *this == tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator == (const wchar_t c) const -{ - const FString tmp(c); - return *this == tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator == (const char c) const -{ - const FString tmp(c); - return *this == tmp; -} - //---------------------------------------------------------------------- bool FString::operator != (const FString& s) const { @@ -1668,48 +1287,6 @@ bool FString::operator != (const FString& s) const return ( std::wcscmp(string, s.string) != 0 ); } -//---------------------------------------------------------------------- -bool FString::operator != (const std::wstring& s) const -{ - const FString tmp(s); - return *this != tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator != (const wchar_t s[]) const -{ - const FString tmp(s); - return *this != tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator != (const std::string& s) const -{ - const FString tmp(s); - return *this != tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator != (const char s[]) const -{ - const FString tmp(s); - return *this != tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator != (const wchar_t c) const -{ - const FString tmp(c); - return *this != tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator != (const char c) const -{ - const FString tmp(c); - return *this != tmp; -} - //---------------------------------------------------------------------- bool FString::operator >= (const FString& s) const { @@ -1725,48 +1302,6 @@ bool FString::operator >= (const FString& s) const return ( std::wcscmp(string, s.string) >= 0 ); } -//---------------------------------------------------------------------- -bool FString::operator >= (const std::wstring& s) const -{ - const FString tmp(s); - return *this >= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator >= (const wchar_t s[]) const -{ - const FString tmp(s); - return *this >= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator >= (const std::string& s) const -{ - const FString tmp(s); - return *this >= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator >= (const char s[]) const -{ - const FString tmp(s); - return *this >= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator >= (const wchar_t c) const -{ - const FString tmp(c); - return *this >= tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator >= (const char c) const -{ - const FString tmp(c); - return *this >= tmp; -} - //---------------------------------------------------------------------- bool FString::operator > (const FString& s) const { @@ -1783,45 +1318,13 @@ bool FString::operator > (const FString& s) const } //---------------------------------------------------------------------- -bool FString::operator > (const std::wstring& s) const +const FString& FString::insert (const FString& s, int pos) { - const FString tmp(s); - return *this > tmp; -} + if ( pos < 0 || uInt(pos) > length ) + throw std::out_of_range(""); -//---------------------------------------------------------------------- -bool FString::operator > (const wchar_t s[]) const -{ - const FString tmp(s); - return *this > tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator > (const std::string& s) const -{ - const FString tmp(s); - return *this > tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator > (const char s[]) const -{ - const FString tmp(s); - return *this > tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator > (const wchar_t c) const -{ - const FString tmp(c); - return *this > tmp; -} - -//---------------------------------------------------------------------- -bool FString::operator > (const char c) const -{ - const FString tmp(c); - return *this > tmp; + _insert (uInt(pos), s.length, s.string); + return *this; } //---------------------------------------------------------------------- @@ -1834,34 +1337,6 @@ const FString& FString::insert (const FString& s, uInt pos) return *this; } -//---------------------------------------------------------------------- -const FString& FString::insert (const wchar_t s[], uInt pos) -{ - if ( pos > length ) - throw std::out_of_range(""); - - _insert (pos, uInt(std::wcslen(s)), s); - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::insert (const char s[], uInt pos) -{ - return insert(FString(s), pos); -} - -//---------------------------------------------------------------------- -const FString& FString::insert (const wchar_t c, uInt pos) -{ - return insert(FString(c), pos); -} - -//---------------------------------------------------------------------- -const FString& FString::insert (const char c, uInt pos) -{ - return insert(FString(c), pos); -} - //---------------------------------------------------------------------- FString FString::replace (const FString& from, const FString& to) { @@ -1903,418 +1378,6 @@ FString FString::replace (const FString& from, const FString& to) return s; } -//---------------------------------------------------------------------- -FString FString::replace (const FString& from, const std::wstring& to) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const FString& from, const wchar_t to[]) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const FString& from, const std::string& to) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const FString& from, const char to[]) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const FString& from, const wchar_t to) -{ - FString to_wchar(to); - return replace (from, to_wchar); -} - -//---------------------------------------------------------------------- -FString FString::replace (const FString& from, const char to) -{ - FString to_char(to); - return replace (from, to_char); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const FString& to) -{ - FString from_str(from); - return replace (from_str, to); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const std::wstring& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const wchar_t to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const std::string& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const char to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const wchar_t to) -{ - FString from_str(from); - FString to_wchar(to); - return replace (from_str, to_wchar); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const char to) -{ - FString from_str(from); - FString to_char(to); - return replace (from_str, to_char); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const FString& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const std::wstring& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const wchar_t to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const std::string& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const char to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const wchar_t to) -{ - FString from_str(from); - FString to_wchar(to); - return replace (from_str, to_wchar); -} - -//---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const char to) -{ - FString from_str(from); - FString to_char(to); - return replace (from_str, to_char); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from[], const FString& to) -{ - FString from_str(from); - return replace (from_str, to); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from[], const std::wstring& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from[], const wchar_t to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from[], const std::string& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from[], const char to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from[], const wchar_t to) -{ - FString from_str(from); - FString to_wchar(to); - return replace (from_str, to_wchar); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from[], const char to) -{ - FString from_str(from); - FString to_char(to); - return replace (from_str, to_char); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from[], const FString& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from[], const std::wstring& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from[], const wchar_t to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from[], const std::string& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from[], const char to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from[], const wchar_t to) -{ - FString from_str(from); - FString to_wchar(to); - return replace (from_str, to_wchar); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from[], const char to) -{ - FString from_str(from); - FString to_char(to); - return replace (from_str, to_char); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const FString& to) -{ - wchar_t* p; - FString s(string); - - // handle NULL and empty string - if ( ! (string && *string) ) - return s; - - if ( to.isNull() ) - return s; - - p = s.string; - uInt to_length = to.getLength(); - uInt pos = 0; - - while ( *p ) - { - if ( wchar_t(*p) == from ) - { - s._remove(pos, 1); - s._insert(pos, to_length, to.wc_str()); - pos += to_length; - p = s.string + pos; - } - else - { - pos++; - p++; - } - } - - return s; -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const std::wstring& to) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const wchar_t to[]) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const std::string& to) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const char to[]) -{ - FString to_str(to); - return replace (from, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const wchar_t to) -{ - FString to_wchar(to); - return replace (from, to_wchar); -} - -//---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const char to) -{ - FString to_char(to); - return replace (from, to_char); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from, const FString& to) -{ - FString from_str(from); - return replace (from_str, to); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from, const std::wstring& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from, const wchar_t to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from, const std::string& to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from, const char to[]) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from, const wchar_t to) -{ - FString from_str(from); - FString to_str(to); - return replace (from_str, to_str); -} - -//---------------------------------------------------------------------- -FString FString::replace (const char from, const char to) -{ - wchar_t* p; - FString s(string); - - // handle NULL and empty string - if ( ! (string && *string) ) - return s; - - p = s.string; - - while ( *p ) - { - if ( char(*p) == from ) - *p = to; - - p++; - } - - return s; -} - //---------------------------------------------------------------------- FString FString::replaceControlCodes() const { @@ -2477,61 +1540,12 @@ const FString& FString::overwrite (const FString& s, uInt pos) } //---------------------------------------------------------------------- -const FString& FString::overwrite (const wchar_t s[], int pos) +const FString& FString::remove (int pos, uInt len) { - if ( pos < 0 ) - return overwrite (s, 0); + if ( pos < 0 || len < 1 ) + return *this; - return overwrite (s, uInt(pos)); -} - -//---------------------------------------------------------------------- -const FString& FString::overwrite (const wchar_t s[], uInt pos) -{ - uInt len = uInt(std::wcslen(s)); - - if ( pos > length ) - pos = length; - - if ( length >= (pos + len) ) - { - std::wcsncpy (string + pos, s, len); - } - else - { - std::wcsncpy (string + pos, s, length - pos); - _insert (length, pos + len - length, s + length - pos); - } - - return *this; -} - -//---------------------------------------------------------------------- -const FString& FString::overwrite (const wchar_t c, int pos) -{ - if ( pos < 0 ) - return overwrite (c, 0); - - return overwrite (c, uInt(pos)); -} - -//---------------------------------------------------------------------- -const FString& FString::overwrite (const wchar_t c, uInt pos) -{ - if ( pos > length ) - pos = length; - - if ( length >= (pos + 1) ) - string[pos] = c; - else - { - wchar_t s[2]; - s[0] = c; - s[1] = L'\0'; - _insert (length, pos + 1 - length, s); - } - - return *this; + return remove (uInt(pos), len); } //---------------------------------------------------------------------- @@ -2560,62 +1574,6 @@ bool FString::includes (const FString& s) const return ( std::wcsstr(string, s.string) != 0 ); } -//---------------------------------------------------------------------- -bool FString::includes (const wchar_t s[]) const -{ - if ( ! s ) - return false; - - if ( ! ( string && s[0]) ) - return false; - - return ( std::wcsstr(string, s) != 0 ); -} - -//---------------------------------------------------------------------- -bool FString::includes (const char s[]) const -{ - if ( ! s ) - return false; - - if ( ! (string && s[0]) ) - return false; - - bool ret; - const wchar_t* wc_string = c_to_wc_str(s); - - if ( ! wc_string ) - return false; - - ret = bool(std::wcsstr(string, wc_string) != 0); - delete[] wc_string; - return ret; -} - -//---------------------------------------------------------------------- -bool FString::includes (const wchar_t c) const -{ - if ( ! (string && c) ) - return false; - - wchar_t s[2]; - s[0] = c; - s[1] = L'\0'; - return ( std::wcsstr(string, s) != 0 ); -} - -//---------------------------------------------------------------------- -bool FString::includes (const char c) const -{ - if ( ! (string && c) ) - return false; - - wchar_t s[2]; - s[0] = wchar_t(c & 0xff); - s[1] = L'\0'; - return ( std::wcsstr(string, s) != 0 ); -} - // private methods of FString //---------------------------------------------------------------------- diff --git a/src/ftermbuffer.cpp b/src/ftermbuffer.cpp index 62972e12..12a79b07 100644 --- a/src/ftermbuffer.cpp +++ b/src/ftermbuffer.cpp @@ -45,90 +45,23 @@ FTermBuffer::~FTermBuffer() // destructor // public methods of FTermBuffer //---------------------------------------------------------------------- -int FTermBuffer::writef (const wchar_t format[], ...) +int FTermBuffer::writef (const FString& format, ...) { - assert ( format != 0 ); - static const int BufSize = 1024; - wchar_t buffer[BufSize]; + static const int BUFSIZE = 4096; + wchar_t buffer[BUFSIZE]; va_list args; + if ( format.isEmpty() ) + return 0; + va_start (args, format); - std::vswprintf (buffer, BufSize, format, args); + std::vswprintf (buffer, BUFSIZE, format.wc_str(), args); va_end (args); FString str(buffer); return write(str); } -//---------------------------------------------------------------------- -int FTermBuffer::writef (const char format[], ...) -{ - assert ( format != 0 ); - int len; - char buf[512]; - char* buffer; - va_list args; - - buffer = buf; - va_start (args, format); - len = vsnprintf (buffer, sizeof(buf), format, args); - va_end (args); - - if ( len >= int(sizeof(buf)) ) - { - try - { - buffer = new char[uInt(len) + 1](); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return -1; - } - - va_start (args, format); - vsnprintf (buffer, uLong(len + 1), format, args); - va_end (args); - } - - FString str(buffer); - int ret = write(str); - - if ( buffer != buf ) - delete[] buffer; - - return ret; -} - -//---------------------------------------------------------------------- -int FTermBuffer::write (const std::wstring& s) -{ - assert ( ! s.empty() ); - return write (FString(s)); -} - -//---------------------------------------------------------------------- -int FTermBuffer::write (const wchar_t s[]) -{ - assert ( s != 0 ); - return write (FString(s)); -} - -//---------------------------------------------------------------------- -int FTermBuffer::write (const char s[]) -{ - assert ( s != 0 ); - FString str(s); - return write(str); -} - -//---------------------------------------------------------------------- -int FTermBuffer::write (const std::string& s) -{ - assert ( ! s.empty() ); - return write (FString(s)); -} - //---------------------------------------------------------------------- int FTermBuffer::write (const FString& s) { diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 0cba59ba..239fdb49 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -294,123 +294,23 @@ void FVTerm::delPreprocessingHandler (FVTerm* instance) } //---------------------------------------------------------------------- -int FVTerm::printf (const wchar_t format[], ...) +int FVTerm::printf (const FString& format, ...) { - assert ( format != 0 ); - static const int BufSize = 1024; - wchar_t buffer[BufSize]; + static const int BUFSIZE = 4096; + wchar_t buffer[BUFSIZE]; va_list args; + if ( format.isEmpty() ) + return 0; + va_start (args, format); - std::vswprintf (buffer, BufSize, format, args); + std::vswprintf (buffer, BUFSIZE, format.wc_str(), args); va_end (args); FString str(buffer); return print(str); } -//---------------------------------------------------------------------- -int FVTerm::printf (const char format[], ...) -{ - assert ( format != 0 ); - int len; - char buf[512]; - char* buffer; - va_list args; - - buffer = buf; - va_start (args, format); - len = vsnprintf (buffer, sizeof(buf), format, args); - va_end (args); - - if ( len >= int(sizeof(buf)) ) - { - try - { - buffer = new char[uInt(len) + 1](); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return -1; - } - - va_start (args, format); - vsnprintf (buffer, uLong(len + 1), format, args); - va_end (args); - } - - FString str(buffer); - int ret = print(str); - - if ( buffer != buf ) - delete[] buffer; - - return ret; -} - -//---------------------------------------------------------------------- -int FVTerm::print (const std::wstring& s) -{ - assert ( ! s.empty() ); - return print (FString(s)); -} - -//---------------------------------------------------------------------- -int FVTerm::print (term_area* area, const std::wstring& s) -{ - assert ( area != 0 ); - assert ( ! s.empty() ); - return print (area, FString(s)); -} - -//---------------------------------------------------------------------- -int FVTerm::print (const wchar_t s[]) -{ - assert ( s != 0 ); - return print (FString(s)); -} - -//---------------------------------------------------------------------- -int FVTerm::print (term_area* area, const wchar_t s[]) -{ - assert ( area != 0 ); - assert ( s != 0 ); - return print (area, FString(s)); -} - -//---------------------------------------------------------------------- -int FVTerm::print (const char s[]) -{ - assert ( s != 0 ); - FString str(s); - return print(str); -} - -//---------------------------------------------------------------------- -int FVTerm::print (term_area* area, const char s[]) -{ - assert ( area != 0 ); - assert ( s != 0 ); - FString str(s); - return print(area, str); -} - -//---------------------------------------------------------------------- -int FVTerm::print (const std::string& s) -{ - assert ( ! s.empty() ); - return print (FString(s)); -} - -//---------------------------------------------------------------------- -int FVTerm::print (term_area* area, const std::string& s) -{ - assert ( area != 0 ); - assert ( ! s.empty() ); - return print (area, FString(s)); -} - //---------------------------------------------------------------------- int FVTerm::print (const FString& s) { diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index 3a8194ac..584b80d7 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -506,7 +506,6 @@ class FMouseControl void xtermMouse (bool); void enableXTermMouse(); void disableXTermMouse(); - void putstring (const char[], int = 1); // Data Member std::map mouse_protocol; diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index c3e873ef..3eeac0cb 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -98,20 +98,8 @@ class FString // Overloaded operators FString& operator = (const FString&); - FString& operator = (const std::wstring&); - const FString& operator = (const wchar_t[]); - FString& operator = (const std::string&); - const FString& operator = (const char[]); - const FString& operator = (const wchar_t); - const FString& operator = (const char); const FString& operator += (const FString&); - const FString& operator += (const std::wstring&); - const FString& operator += (const wchar_t[]); - const FString& operator += (const std::string&); - const FString& operator += (const char[]); - const FString& operator += (const wchar_t); - const FString& operator += (const char); const FString operator + (const FString&); const FString operator + (const std::wstring&); @@ -153,47 +141,23 @@ class FString const FString& operator () (); bool operator < (const FString&) const; - bool operator < (const std::wstring&) const; - bool operator < (const wchar_t[]) const; - bool operator < (const std::string&) const; - bool operator < (const char[]) const; - bool operator < (const wchar_t) const; - bool operator < (const char) const; + template + bool operator < (CharT&) const; bool operator <= (const FString&) const; - bool operator <= (const std::wstring&) const; - bool operator <= (const wchar_t[]) const; - bool operator <= (const std::string&) const; - bool operator <= (const char[]) const; - bool operator <= (const wchar_t) const; - bool operator <= (const char) const; + template + bool operator <= (CharT&) const; bool operator == (const FString&) const; - bool operator == (const std::wstring&) const; - bool operator == (const wchar_t[]) const; - bool operator == (const std::string&) const; - bool operator == (const char[]) const; - bool operator == (const wchar_t) const; - bool operator == (const char) const; + template + bool operator == (CharT&) const; bool operator != (const FString&) const; - bool operator != (const std::wstring&) const; - bool operator != (const wchar_t[]) const; - bool operator != (const std::string&) const; - bool operator != (const char[]) const; - bool operator != (const wchar_t) const; - bool operator != (const char) const; + template + bool operator != (CharT&) const; bool operator >= (const FString&) const; - bool operator >= (const std::wstring&) const; - bool operator >= (const wchar_t[]) const; - bool operator >= (const std::string&) const; - bool operator >= (const char[]) const; - bool operator >= (const wchar_t) const; - bool operator >= (const char) const; + template + bool operator >= (CharT&) const; bool operator > (const FString&) const; - bool operator > (const std::wstring&) const; - bool operator > (const wchar_t[]) const; - bool operator > (const std::string&) const; - bool operator > (const char[]) const; - bool operator > (const wchar_t) const; - bool operator > (const char) const; + template + bool operator > (CharT&) const; operator const char* () const { return c_str(); } @@ -229,15 +193,7 @@ class FString wchar_t front() const; wchar_t back() const; - FString& sprintf (const FString, ...); - FString& sprintf (const wchar_t[], ...); - FString& sprintf (const char[], ...) -#if defined(__clang__) - __attribute__((__format__ (__printf__, 2, 3))) -#elif defined(__GNUC__) - __attribute__ ((format (printf, 2, 3))) -#endif - ; + FString& sprintf (const FString&, ...); FString clear(); const wchar_t* wc_str() const; @@ -270,15 +226,7 @@ class FString FString mid (uInt, uInt) const; FStringList split (const FString&); - FStringList split (const std::wstring&); - FStringList split (const wchar_t[]); - FStringList split (const std::string&); - FStringList split (const char[]); - FStringList split (const wchar_t); - FStringList split (const char); - - FString& setString (const wchar_t[]); - FString& setString (const char[]); + FString& setString (const FString&); FString& setNumber (sInt16); FString& setNumber (uInt16); @@ -297,61 +245,10 @@ class FString FString& setFormatedNumber (long, char = nl_langinfo(THOUSEP)[0]); FString& setFormatedNumber (uLong, char = nl_langinfo(THOUSEP)[0]); + const FString& insert (const FString&, int); const FString& insert (const FString&, uInt); - const FString& insert (const wchar_t[], uInt); - const FString& insert (const char[], uInt); - const FString& insert (const wchar_t, uInt); - const FString& insert (const char, uInt); FString replace (const FString&, const FString&); - FString replace (const FString&, const std::wstring&); - FString replace (const FString&, const wchar_t[]); - FString replace (const FString&, const std::string&); - FString replace (const FString&, const char[]); - FString replace (const FString&, const wchar_t); - FString replace (const FString&, const char); - FString replace (const std::wstring&, const FString&); - FString replace (const std::wstring&, const std::wstring&); - FString replace (const std::wstring&, const wchar_t[]); - FString replace (const std::wstring&, const std::string&); - FString replace (const std::wstring&, const char[]); - FString replace (const std::wstring&, const wchar_t); - FString replace (const std::wstring&, const char); - FString replace (const std::string&, const FString&); - FString replace (const std::string&, const std::wstring&); - FString replace (const std::string&, const wchar_t[]); - FString replace (const std::string&, const std::string&); - FString replace (const std::string&, const char[]); - FString replace (const std::string&, const wchar_t); - FString replace (const std::string&, const char); - FString replace (const wchar_t[], const FString&); - FString replace (const wchar_t[], const std::wstring&); - FString replace (const wchar_t[], const wchar_t[]); - FString replace (const wchar_t[], const std::string&); - FString replace (const wchar_t[], const char[]); - FString replace (const wchar_t[], const wchar_t); - FString replace (const wchar_t[], const char); - FString replace (const char[], const FString&); - FString replace (const char[], const std::wstring&); - FString replace (const char[], const wchar_t[]); - FString replace (const char[], const std::string&); - FString replace (const char[], const char[]); - FString replace (const char[], const wchar_t); - FString replace (const char[], const char); - FString replace (const wchar_t, const FString&); - FString replace (const wchar_t, const std::wstring&); - FString replace (const wchar_t, const wchar_t[]); - FString replace (const wchar_t, const std::string&); - FString replace (const wchar_t, const char[]); - FString replace (const wchar_t, const wchar_t); - FString replace (const wchar_t, const char); - FString replace (const char, const FString&); - FString replace (const char, const std::wstring&); - FString replace (const char, const wchar_t[]); - FString replace (const char, const std::string&); - FString replace (const char, const char[]); - FString replace (const char, const wchar_t); - FString replace (const char, const char); FString replaceControlCodes() const; FString expandTabs (int = 8) const; @@ -360,17 +257,10 @@ class FString const FString& overwrite (const FString&, int); const FString& overwrite (const FString&, uInt = 0); - const FString& overwrite (const wchar_t[], int); - const FString& overwrite (const wchar_t[], uInt = 0); - const FString& overwrite (const wchar_t, int); - const FString& overwrite (const wchar_t, uInt = 0); + const FString& remove (int, uInt); const FString& remove (uInt, uInt); bool includes (const FString&) const; - bool includes (const wchar_t[]) const; - bool includes (const char[]) const; - bool includes (const wchar_t) const; - bool includes (const char) const; private: // Constants @@ -402,6 +292,54 @@ class FString inline const char* FString::getClassName() { return "FString"; } +//---------------------------------------------------------------------- +template +inline bool FString::operator < (CharT& s) const +{ + const FString tmp(s); + return *this < tmp; +} + +//---------------------------------------------------------------------- +template +inline bool FString::operator <= (CharT& s) const +{ + const FString tmp(s); + return *this <= tmp; +} + +//---------------------------------------------------------------------- +template +inline bool FString::operator == (CharT& s) const +{ + const FString tmp(s); + return *this == tmp; +} + +//---------------------------------------------------------------------- +template +inline bool FString::operator != (CharT& s) const +{ + const FString tmp(s); + return *this != tmp; +} + +//---------------------------------------------------------------------- +template +inline bool FString::operator >= (CharT& s) const +{ + const FString tmp(s); + return *this >= tmp; +} + +//---------------------------------------------------------------------- +template +inline bool FString::operator > (CharT& s) const +{ + const FString tmp(s); + return *this > tmp; +} + //---------------------------------------------------------------------- inline bool FString::isNull() const { return ! string; } @@ -436,30 +374,6 @@ inline wchar_t FString::back() const return string[length - 1]; } -//---------------------------------------------------------------------- -inline FStringList FString::split (const std::wstring& s) -{ return split(FString(s)); } - -//---------------------------------------------------------------------- -inline FStringList FString::split (const wchar_t s[]) -{ return split(FString(s)); } - -//---------------------------------------------------------------------- -inline FStringList FString::split (const std::string& s) -{ return split(FString(s)); } - -//---------------------------------------------------------------------- -inline FStringList FString::split (const char s[]) -{ return split(FString(s)); } - -//---------------------------------------------------------------------- -inline FStringList FString::split (const wchar_t c) -{ return split(FString(c)); } - -//---------------------------------------------------------------------- -inline FStringList FString::split (const char c) -{ return split(FString(c)); } - //---------------------------------------------------------------------- inline FString& FString::setNumber (sInt16 num) { return setNumber (long(num)); } @@ -500,6 +414,7 @@ inline FString& FString::setFormatedNumber (int num, char separator) inline FString& FString::setFormatedNumber (uInt num, char separator) { return setFormatedNumber (uLong(num), separator); } + } // namespace finalcut #endif // FSTRING_H diff --git a/src/include/final/ftermbuffer.h b/src/include/final/ftermbuffer.h index 6ea9f762..d133556f 100644 --- a/src/include/final/ftermbuffer.h +++ b/src/include/final/ftermbuffer.h @@ -68,7 +68,7 @@ class FTermBuffer template FTermBuffer& operator << (const type&); // Non-member operators friend std::vector& operator << ( std::vector& - , const FTermBuffer& ); + , const FTermBuffer& ); // Accessors virtual const char* getClassName() const; @@ -79,18 +79,7 @@ class FTermBuffer // Methods void clear(); - int writef (const wchar_t[], ...); - int writef (const char[], ...) -#if defined(__clang__) - __attribute__((__format__ (__printf__, 2, 3))) -#elif defined(__GNUC__) - __attribute__ ((format (printf, 2, 3))) -#endif - ; - int write (const std::wstring&); - int write (const wchar_t[]); - int write (const char[]); - int write (const std::string&); + int writef (const FString&, ...); int write (const FString&); int write (int); FTermBuffer& write (); diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index 976339ce..8ab19ab0 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -235,22 +235,7 @@ class FVTerm : public FTerm , FPreprocessingHandler ); virtual void delPreprocessingHandler (FVTerm*); - int printf (const wchar_t[], ...); - int printf (const char[], ...) - #if defined(__clang__) - __attribute__((__format__ (__printf__, 2, 3))) - #elif defined(__GNUC__) - __attribute__ ((format (printf, 2, 3))) - #endif - ; - int print (const std::wstring&); - int print (term_area*, const std::wstring&); - int print (const wchar_t[]); - int print (term_area*, const wchar_t[]); - int print (const char[]); - int print (term_area*, const char[]); - int print (const std::string&); - int print (term_area*, const std::string&); + int printf (const FString&, ...); int print (const FString&); int print (term_area*, const FString&); int print (const std::vector&); diff --git a/test/fstring-test.cpp b/test/fstring-test.cpp index a3cb1881..2c5dd733 100644 --- a/test/fstring-test.cpp +++ b/test/fstring-test.cpp @@ -180,7 +180,7 @@ void FStringTest::noArgumentTest() CPPUNIT_ASSERT ( str.size() == 0 ); CPPUNIT_ASSERT ( str.empty() ); const finalcut::FString fstr = str; - CPPUNIT_ASSERT ( ! fstr.isNull() ); + CPPUNIT_ASSERT ( fstr.isNull() ); CPPUNIT_ASSERT ( fstr.isEmpty() ); cstr = 0; @@ -1628,8 +1628,8 @@ void FStringTest::includesTest() { const finalcut::FString str = "Look behind you, a three-headed monkey!"; const finalcut::FString empty1; - const wchar_t empty2[] = L""; - const char empty3[] = ""; + const wchar_t empty2[] = { }; + const char empty3[] = { }; const finalcut::FString search1 = "you"; const finalcut::FString search2 = "me"; const wchar_t search3[] = L"you";