Remove redundant program code from FString

This commit is contained in:
Markus Gans 2018-10-05 05:15:54 +02:00
parent c8abcce79a
commit 8e2c32ebdc
13 changed files with 128 additions and 1453 deletions

View File

@ -1,3 +1,6 @@
2018-10-05 Markus Gans <guru.mail@muenster.de>
* Remove redundant program code from FString
2018-10-03 Markus Gans <guru.mail@muenster.de> 2018-10-03 Markus Gans <guru.mail@muenster.de>
* At the end of the lifetime of an FMenuItem object, * At the end of the lifetime of an FMenuItem object,
delete its entry from the object list of the parent object delete its entry from the object list of the parent object

View File

@ -35,7 +35,7 @@ The C++ class design was inspired by the Qt framework. It provides common contro
### First steps ### 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 ### Screenshots

View File

@ -90,7 +90,6 @@ void preset (std::vector<finalcut::FRadioButton*>& os)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
int x, y, w, h;
finalcut::FString label_text = "no OS"; finalcut::FString label_text = "no OS";
// Create the application object // Create the application object
@ -100,10 +99,10 @@ int main (int argc, char* argv[])
finalcut::FDialog dgl(&app); finalcut::FDialog dgl(&app);
dgl.setModal(); dgl.setModal();
dgl.setText ("UNIX select"); dgl.setText ("UNIX select");
w = 20; int w = 20;
h = 13; int h = 13;
x = (app.getDesktopWidth() - w) / 2; int x = (app.getDesktopWidth() - w) / 2;
y = (app.getDesktopHeight() - h) / 2; int y = (app.getDesktopHeight() - h) / 2;
dgl.setGeometry (x, y, w, h); dgl.setGeometry (x, y, w, h);
// Create a button group // Create a button group

View File

@ -842,7 +842,7 @@ inline void FLineEdit::keyDel()
if ( len > 0 && cursor_pos < len ) if ( len > 0 && cursor_pos < len )
{ {
text.remove(uInt(cursor_pos), 1); text.remove(cursor_pos, 1);
processChanged(); processChanged();
} }
@ -861,7 +861,7 @@ inline void FLineEdit::keyBackspace()
{ {
if ( text.getLength() > 0 && cursor_pos > 0 ) if ( text.getLength() > 0 && cursor_pos > 0 )
{ {
text.remove(uInt(cursor_pos - 1), 1); text.remove(cursor_pos - 1, 1);
processChanged(); processChanged();
cursor_pos--; cursor_pos--;

View File

@ -1642,10 +1642,4 @@ void FMouseControl::xtermMouse (bool on)
FTermXTerminal::setMouseSupport (on); FTermXTerminal::setMouseSupport (on);
} }
//----------------------------------------------------------------------
void FMouseControl::putstring (const char s[], int affcnt)
{
FTerm::putstring (s, affcnt);
}
} // namespace finalcut } // namespace finalcut

File diff suppressed because it is too large Load Diff

View File

@ -45,90 +45,23 @@ FTermBuffer::~FTermBuffer() // destructor
// public methods of FTermBuffer // public methods of FTermBuffer
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FTermBuffer::writef (const wchar_t format[], ...) int FTermBuffer::writef (const FString& format, ...)
{ {
assert ( format != 0 ); static const int BUFSIZE = 4096;
static const int BufSize = 1024; wchar_t buffer[BUFSIZE];
wchar_t buffer[BufSize];
va_list args; va_list args;
if ( format.isEmpty() )
return 0;
va_start (args, format); va_start (args, format);
std::vswprintf (buffer, BufSize, format, args); std::vswprintf (buffer, BUFSIZE, format.wc_str(), args);
va_end (args); va_end (args);
FString str(buffer); FString str(buffer);
return write(str); 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) int FTermBuffer::write (const FString& s)
{ {

View File

@ -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 = 4096;
static const int BufSize = 1024; wchar_t buffer[BUFSIZE];
wchar_t buffer[BufSize];
va_list args; va_list args;
if ( format.isEmpty() )
return 0;
va_start (args, format); va_start (args, format);
std::vswprintf (buffer, BufSize, format, args); std::vswprintf (buffer, BUFSIZE, format.wc_str(), args);
va_end (args); va_end (args);
FString str(buffer); FString str(buffer);
return print(str); 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) int FVTerm::print (const FString& s)
{ {

View File

@ -506,7 +506,6 @@ class FMouseControl
void xtermMouse (bool); void xtermMouse (bool);
void enableXTermMouse(); void enableXTermMouse();
void disableXTermMouse(); void disableXTermMouse();
void putstring (const char[], int = 1);
// Data Member // Data Member
std::map<FMouse::mouse_type, FMouse*> mouse_protocol; std::map<FMouse::mouse_type, FMouse*> mouse_protocol;

View File

@ -98,20 +98,8 @@ class FString
// Overloaded operators // Overloaded operators
FString& operator = (const FString&); 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 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 FString&);
const FString operator + (const std::wstring&); const FString operator + (const std::wstring&);
@ -153,47 +141,23 @@ class FString
const FString& operator () (); const FString& operator () ();
bool operator < (const FString&) const; bool operator < (const FString&) const;
bool operator < (const std::wstring&) const; template <typename CharT>
bool operator < (const wchar_t[]) const; bool operator < (CharT&) const;
bool operator < (const std::string&) const;
bool operator < (const char[]) const;
bool operator < (const wchar_t) const;
bool operator < (const char) const;
bool operator <= (const FString&) const; bool operator <= (const FString&) const;
bool operator <= (const std::wstring&) const; template <typename CharT>
bool operator <= (const wchar_t[]) const; bool operator <= (CharT&) const;
bool operator <= (const std::string&) const;
bool operator <= (const char[]) const;
bool operator <= (const wchar_t) const;
bool operator <= (const char) const;
bool operator == (const FString&) const; bool operator == (const FString&) const;
bool operator == (const std::wstring&) const; template <typename CharT>
bool operator == (const wchar_t[]) const; bool operator == (CharT&) const;
bool operator == (const std::string&) const;
bool operator == (const char[]) const;
bool operator == (const wchar_t) const;
bool operator == (const char) const;
bool operator != (const FString&) const; bool operator != (const FString&) const;
bool operator != (const std::wstring&) const; template <typename CharT>
bool operator != (const wchar_t[]) const; bool operator != (CharT&) const;
bool operator != (const std::string&) const;
bool operator != (const char[]) const;
bool operator != (const wchar_t) const;
bool operator != (const char) const;
bool operator >= (const FString&) const; bool operator >= (const FString&) const;
bool operator >= (const std::wstring&) const; template <typename CharT>
bool operator >= (const wchar_t[]) const; bool operator >= (CharT&) const;
bool operator >= (const std::string&) const;
bool operator >= (const char[]) const;
bool operator >= (const wchar_t) const;
bool operator >= (const char) const;
bool operator > (const FString&) const; bool operator > (const FString&) const;
bool operator > (const std::wstring&) const; template <typename CharT>
bool operator > (const wchar_t[]) const; bool operator > (CharT&) const;
bool operator > (const std::string&) const;
bool operator > (const char[]) const;
bool operator > (const wchar_t) const;
bool operator > (const char) const;
operator const char* () const { return c_str(); } operator const char* () const { return c_str(); }
@ -229,15 +193,7 @@ class FString
wchar_t front() const; wchar_t front() const;
wchar_t back() const; wchar_t back() const;
FString& sprintf (const FString, ...); 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 clear(); FString clear();
const wchar_t* wc_str() const; const wchar_t* wc_str() const;
@ -270,15 +226,7 @@ class FString
FString mid (uInt, uInt) const; FString mid (uInt, uInt) const;
FStringList split (const FString&); FStringList split (const FString&);
FStringList split (const std::wstring&); FString& setString (const FString&);
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& setNumber (sInt16); FString& setNumber (sInt16);
FString& setNumber (uInt16); FString& setNumber (uInt16);
@ -297,61 +245,10 @@ class FString
FString& setFormatedNumber (long, char = nl_langinfo(THOUSEP)[0]); FString& setFormatedNumber (long, char = nl_langinfo(THOUSEP)[0]);
FString& setFormatedNumber (uLong, 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 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 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 replaceControlCodes() const;
FString expandTabs (int = 8) const; FString expandTabs (int = 8) const;
@ -360,17 +257,10 @@ class FString
const FString& overwrite (const FString&, int); const FString& overwrite (const FString&, int);
const FString& overwrite (const FString&, uInt = 0); 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); const FString& remove (uInt, uInt);
bool includes (const FString&) const; 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: private:
// Constants // Constants
@ -402,6 +292,54 @@ class FString
inline const char* FString::getClassName() inline const char* FString::getClassName()
{ return "FString"; } { return "FString"; }
//----------------------------------------------------------------------
template <class CharT>
inline bool FString::operator < (CharT& s) const
{
const FString tmp(s);
return *this < tmp;
}
//----------------------------------------------------------------------
template <class CharT>
inline bool FString::operator <= (CharT& s) const
{
const FString tmp(s);
return *this <= tmp;
}
//----------------------------------------------------------------------
template <class CharT>
inline bool FString::operator == (CharT& s) const
{
const FString tmp(s);
return *this == tmp;
}
//----------------------------------------------------------------------
template <class CharT>
inline bool FString::operator != (CharT& s) const
{
const FString tmp(s);
return *this != tmp;
}
//----------------------------------------------------------------------
template <class CharT>
inline bool FString::operator >= (CharT& s) const
{
const FString tmp(s);
return *this >= tmp;
}
//----------------------------------------------------------------------
template <class CharT>
inline bool FString::operator > (CharT& s) const
{
const FString tmp(s);
return *this > tmp;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FString::isNull() const inline bool FString::isNull() const
{ return ! string; } { return ! string; }
@ -436,30 +374,6 @@ inline wchar_t FString::back() const
return string[length - 1]; 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) inline FString& FString::setNumber (sInt16 num)
{ return setNumber (long(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) inline FString& FString::setFormatedNumber (uInt num, char separator)
{ return setFormatedNumber (uLong(num), separator); } { return setFormatedNumber (uLong(num), separator); }
} // namespace finalcut } // namespace finalcut
#endif // FSTRING_H #endif // FSTRING_H

View File

@ -79,18 +79,7 @@ class FTermBuffer
// Methods // Methods
void clear(); void clear();
int writef (const wchar_t[], ...); int writef (const FString&, ...);
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 write (const FString&); int write (const FString&);
int write (int); int write (int);
FTermBuffer& write (); FTermBuffer& write ();

View File

@ -235,22 +235,7 @@ class FVTerm : public FTerm
, FPreprocessingHandler ); , FPreprocessingHandler );
virtual void delPreprocessingHandler (FVTerm*); virtual void delPreprocessingHandler (FVTerm*);
int printf (const wchar_t[], ...); int printf (const FString&, ...);
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 print (const FString&); int print (const FString&);
int print (term_area*, const FString&); int print (term_area*, const FString&);
int print (const std::vector<charData>&); int print (const std::vector<charData>&);

View File

@ -180,7 +180,7 @@ void FStringTest::noArgumentTest()
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.isNull() );
CPPUNIT_ASSERT ( fstr.isEmpty() ); CPPUNIT_ASSERT ( fstr.isEmpty() );
cstr = 0; cstr = 0;
@ -1628,8 +1628,8 @@ void FStringTest::includesTest()
{ {
const finalcut::FString str = "Look behind you, a three-headed monkey!"; const finalcut::FString str = "Look behind you, a three-headed monkey!";
const finalcut::FString empty1; const finalcut::FString empty1;
const wchar_t empty2[] = L""; const wchar_t empty2[] = { };
const char empty3[] = ""; const char empty3[] = { };
const finalcut::FString search1 = "you"; const finalcut::FString search1 = "you";
const finalcut::FString search2 = "me"; const finalcut::FString search2 = "me";
const wchar_t search3[] = L"you"; const wchar_t search3[] = L"you";