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>
* At the end of the lifetime of an FMenuItem 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
[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

View File

@ -90,7 +90,6 @@ void preset (std::vector<finalcut::FRadioButton*>& 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

View File

@ -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--;

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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)
{

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 = 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)
{

View File

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

View File

@ -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 <typename CharT>
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 <typename CharT>
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 <typename CharT>
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 <typename CharT>
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 <typename CharT>
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 <typename CharT>
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 <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
{ 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

View File

@ -68,7 +68,7 @@ class FTermBuffer
template<class type> FTermBuffer& operator << (const type&);
// Non-member operators
friend std::vector<charData>& operator << ( std::vector<charData>&
, 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 ();

View File

@ -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<charData>&);

View File

@ -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";