Wrong UTF-8 string length fixed when attaching to FString

This commit is contained in:
Markus Gans 2017-09-09 22:03:17 +02:00
parent f941da79e7
commit 1cd1e521c3
12 changed files with 94 additions and 82 deletions

View File

@ -1,3 +1,6 @@
2017-09-09 Markus Gans <guru.mail@muenster.de>
* Wrong UTF-8 string length fixed when attaching to FString
2017-09-07 Markus Gans <guru.mail@muenster.de> 2017-09-07 Markus Gans <guru.mail@muenster.de>
* Type definition exported into a separate header file * Type definition exported into a separate header file

View File

@ -735,8 +735,8 @@ int FFileDialog::changeDir (const FString& dirname)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FFileDialog::printPath (const FString& txt) void FFileDialog::printPath (const FString& txt)
{ {
FString path = txt; const FString& path = txt;
uInt max_width = uInt(filebrowser->getWidth()) - 4; const uInt max_width = uInt(filebrowser->getWidth()) - 4;
if ( path.getLength() > max_width ) if ( path.getLength() > max_width )
filebrowser->setText(".." + path.right(max_width - 2)); filebrowser->setText(".." + path.right(max_width - 2));
@ -773,7 +773,7 @@ void FFileDialog::cb_processActivate (FWidget*, data_ptr)
if ( ! dir_entries.empty() ) if ( ! dir_entries.empty() )
{ {
std::vector<dir_entry>::const_iterator iter, end; std::vector<dir_entry>::const_iterator iter, end;
FString input = filename->getText().trim(); const FString& input = filename->getText().trim();
iter = dir_entries.begin(); iter = dir_entries.begin();
end = dir_entries.end(); end = dir_entries.end();
@ -800,12 +800,12 @@ void FFileDialog::cb_processActivate (FWidget*, data_ptr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FFileDialog::cb_processRowChanged (FWidget*, data_ptr) void FFileDialog::cb_processRowChanged (FWidget*, data_ptr)
{ {
int n = filebrowser->currentItem(); const int n = filebrowser->currentItem();
if ( n == 0 ) if ( n == 0 )
return; return;
FString name = dir_entries[uLong(n - 1)].name; const FString& name = dir_entries[uLong(n - 1)].name;
if ( dir_entries[uLong(n - 1)].type == DT_DIR ) if ( dir_entries[uLong(n - 1)].type == DT_DIR )
filename->setText( name + '/' ); filename->setText( name + '/' );
@ -818,7 +818,7 @@ void FFileDialog::cb_processRowChanged (FWidget*, data_ptr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FFileDialog::cb_processClicked (FWidget*, data_ptr) void FFileDialog::cb_processClicked (FWidget*, data_ptr)
{ {
uLong n = uLong(filebrowser->currentItem() - 1); const uLong n = uLong(filebrowser->currentItem() - 1);
if ( dir_entries[n].type == DT_DIR ) if ( dir_entries[n].type == DT_DIR )
changeDir(dir_entries[n].name); changeDir(dir_entries[n].name);

View File

@ -156,9 +156,9 @@ void FListViewItem::setText (int column, const FString& text)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListViewItem::insert (FListViewItem* child) void FListViewItem::insert (FListViewItem* child)
{ {
// Add a FListViewItem as child element // Add a FListViewItem as child element
if ( ! child || ! hasChildren() ) if ( ! child || ! hasChildren() )
return; return;
addChild (child); addChild (child);
expandable = true; expandable = true;
@ -190,8 +190,8 @@ int FListViewItem::getVisibleLines()
if ( ! isExpand() || ! hasChildren() ) if ( ! isExpand() || ! hasChildren() )
{ {
visible_lines = 1; visible_lines = 1;
return visible_lines; return visible_lines;
} }
FObjectList children = this->getChildren(); FObjectList children = this->getChildren();
@ -354,7 +354,6 @@ void FListView::insert (FListViewItem* item)
{ {
int width = (*iter).width; int width = (*iter).width;
bool fixed_width = (*iter).fixed_width; bool fixed_width = (*iter).fixed_width;
FString text = (*iter).name;
if ( ! fixed_width ) if ( ! fixed_width )
{ {
@ -1129,7 +1128,7 @@ void FListView::drawColumnLabels()
while ( iter != header.end() ) while ( iter != header.end() )
{ {
FString text = (*iter).name; const FString& text = (*iter).name;
int width = (*iter).width; int width = (*iter).width;
int column_width; int column_width;
@ -1158,8 +1157,8 @@ void FListView::drawColumnLabels()
if ( txt_length + tailing_space < uInt(column_width) ) if ( txt_length + tailing_space < uInt(column_width) )
{ {
setColor(); setColor();
FString line ( uInt(column_width) - tailing_space - txt_length const FString line ( uInt(column_width) - tailing_space - txt_length
, wchar_t(fc::BoxDrawingsHorizontal) ); , wchar_t(fc::BoxDrawingsHorizontal) );
headerline << line; // horizontal line headerline << line; // horizontal line
} }
} }
@ -1254,6 +1253,11 @@ void FListView::drawList()
// print the entry // print the entry
FString line = " "; FString line = " ";
if ( tree_view /*&& (*iter)->expandable*/ )
{
line += "";
}
// print columns // print columns
if ( ! (*iter)->column_value.empty() ) if ( ! (*iter)->column_value.empty() )
{ {
@ -1261,7 +1265,8 @@ void FListView::drawList()
{ {
static const int leading_space = 1; static const int leading_space = 1;
static const int ellipsis_length = 2; static const int ellipsis_length = 2;
FString text = (*iter)->column_value[i];
const FString& text = (*iter)->column_value[i];
int width = header[i].width; int width = header[i].width;
uInt txt_length = text.getLength(); uInt txt_length = text.getLength();
// Increment the value of i for the column position // Increment the value of i for the column position
@ -1270,23 +1275,27 @@ void FListView::drawList()
fc::text_alignment align = getColumnAlignment(int(i)); fc::text_alignment align = getColumnAlignment(int(i));
uInt align_offset = getAlignOffset (align, txt_length, uInt(width)); uInt align_offset = getAlignOffset (align, txt_length, uInt(width));
// Insert alignment spaces
if ( align_offset > 0 ) if ( align_offset > 0 )
line += FString(align_offset, ' '); line += FString(align_offset, ' ');
if ( align_offset + txt_length <= uInt(width) ) if ( align_offset + txt_length <= uInt(width) )
{ {
// Insert text and tailing space
line += text.left(width); line += text.left(width);
line += FString ( leading_space + width line += FString ( leading_space + width
- int(align_offset + txt_length), ' '); - int(align_offset + txt_length), ' ');
} }
else if ( align == fc::alignRight ) else if ( align == fc::alignRight )
{ {
// Ellipse right align text
line += FString (".."); line += FString ("..");
line += text.right(width - ellipsis_length); line += text.right(width - ellipsis_length);
line += ' '; line += ' ';
} }
else else
{ {
// Ellipse left align text and center text
line += text.left(width - ellipsis_length); line += text.left(width - ellipsis_length);
line += FString (".. "); line += FString (".. ");
} }

View File

@ -682,25 +682,25 @@ bool FMenuBar::hotkeyMenu (FKeyEvent*& ev)
if ( (*iter)->hasMenu() ) if ( (*iter)->hasMenu() )
{ {
FMenuItem* first_item; FMenuItem* first_item;
FMenu* menu = (*iter)->getMenu(); FMenu* menu = (*iter)->getMenu();
(*iter)->setSelected(); (*iter)->setSelected();
setSelectedItem(*iter); setSelectedItem(*iter);
(*iter)->setFocus(); (*iter)->setFocus();
(*iter)->openMenu(); (*iter)->openMenu();
menu->selectFirstItem(); menu->selectFirstItem();
first_item = menu->getSelectedItem(); first_item = menu->getSelectedItem();
if ( first_item ) if ( first_item )
first_item->setFocus(); first_item->setFocus();
menu->redraw(); menu->redraw();
if ( getStatusBar() ) if ( getStatusBar() )
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
redraw(); redraw();
drop_down = true; drop_down = true;
} }
else else
{ {

View File

@ -5,10 +5,10 @@ HEIGHT=16
FONTFILE="8x16graph.bdf" FONTFILE="8x16graph.bdf"
( (
echo -e "// newfont.h\n" echo -e "// newfont.h\\n"
echo -e "#ifndef FNEWFONT_H" echo -e "#ifndef FNEWFONT_H"
echo -e "#define FNEWFONT_H\n" echo -e "#define FNEWFONT_H\\n"
echo -e "\nstatic unsigned char __8x16graph[] =\n{" echo -e "\\nstatic unsigned char __8x16graph[] =\\n{"
grep -A${HEIGHT} ^BITMAP "$FONTFILE" \ grep -A${HEIGHT} ^BITMAP "$FONTFILE" \
| tr '\n' ',' \ | tr '\n' ',' \
@ -26,6 +26,6 @@ FONTFILE="8x16graph.bdf"
done done
echo -e "};" echo -e "};"
echo -e "\n#endif // FNEWFONT_H" echo -e "\\n#endif // FNEWFONT_H"
) > newfont.h ) > newfont.h

View File

@ -5,9 +5,9 @@ HEIGHT=16
FONTFILE="8x16std" FONTFILE="8x16std"
( (
echo -e "// vgafont.h\n" echo -e "// vgafont.h\\n"
echo -e "#ifndef FVGAFONT_H" echo -e "#ifndef FVGAFONT_H"
echo -e "#define FVGAFONT_H\n" echo -e "#define FVGAFONT_H\\n"
xxd -g 1 -i -c $HEIGHT $FONTFILE \ xxd -g 1 -i -c $HEIGHT $FONTFILE \
| sed -e 's/ {$/\n{/' \ | sed -e 's/ {$/\n{/' \
@ -24,5 +24,5 @@ FONTFILE="8x16std"
fi fi
done done
echo -e "\n#endif // FVGAFONT_H" echo -e "\\n#endif // FVGAFONT_H"
) > vgafont.h ) > vgafont.h

View File

@ -354,7 +354,7 @@ const FString& FString::operator += (const char* s)
if ( wc_string ) if ( wc_string )
{ {
_insert (length, uInt(std::strlen(s)), wc_string); _insert (length, uInt(std::wcslen(wc_string)), wc_string);
delete[] wc_string; delete[] wc_string;
} }

View File

@ -451,13 +451,13 @@ int FTerm::parseKeyString ( char buffer[]
// SGR mouse tracking // SGR mouse tracking
if ( buffer[1] == '[' && buffer[2] == '<' && buf_len >= 9 if ( buffer[1] == '[' && buffer[2] == '<' && buf_len >= 9
&& (buffer[buf_len - 1] == 'M' || buffer[buf_len - 1] == 'm') ) && (buffer[buf_len - 1] == 'M' || buffer[buf_len - 1] == 'm') )
return fc::Fkey_extended_mouse; return fc::Fkey_extended_mouse;
// urxvt mouse tracking // urxvt mouse tracking
if ( buffer[1] == '[' && buffer[2] >= '1' && buffer[2] <= '9' if ( buffer[1] == '[' && buffer[2] >= '1' && buffer[2] <= '9'
&& buffer[3] >= '0' && buffer[3] <= '9' && buf_len >= 9 && buffer[3] >= '0' && buffer[3] <= '9' && buf_len >= 9
&& buffer[buf_len - 1] == 'M' ) && buffer[buf_len - 1] == 'M' )
return fc::Fkey_urxvt_mouse; return fc::Fkey_urxvt_mouse;
// look for termcap keys // look for termcap keys
for (int i = 0; Fkey[i].tname[0] != 0; i++) for (int i = 0; Fkey[i].tname[0] != 0; i++)
@ -655,7 +655,7 @@ bool FTerm::setNewFont()
pc_charset_console = true; pc_charset_console = true;
Encoding = fc::PC; Encoding = fc::PC;
if ( xterm_terminal && utf8_console ) if ( xterm_terminal && utf8_console )
Fputchar = &FTerm::putchar_UTF8; Fputchar = &FTerm::putchar_UTF8;
else else
Fputchar = &FTerm::putchar_ASCII; Fputchar = &FTerm::putchar_ASCII;
@ -1271,7 +1271,7 @@ void FTerm::resetXTermDefaults()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::saveColorMap() void FTerm::saveColorMap()
{ {
// ioctl (0, GIO_CMAP, &color_map); //ioctl (0, GIO_CMAP, &color_map);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1688,7 +1688,7 @@ void FTerm::initLinuxConsoleCharMap()
|| charEncode(c2, fc::PC) == charEncode(c2, fc::ASCII) || charEncode(c2, fc::PC) == charEncode(c2, fc::ASCII)
|| charEncode(c3, fc::PC) == charEncode(c3, fc::ASCII) ) || charEncode(c3, fc::PC) == charEncode(c3, fc::ASCII) )
{ {
no_shadow_character = true; no_shadow_character = true;
} }
c4 = fc::RightHalfBlock; c4 = fc::RightHalfBlock;
@ -1697,7 +1697,7 @@ void FTerm::initLinuxConsoleCharMap()
if ( charEncode(c4, fc::PC) == charEncode(c4, fc::ASCII) if ( charEncode(c4, fc::PC) == charEncode(c4, fc::ASCII)
|| charEncode(c5, fc::PC) == charEncode(c5, fc::ASCII) ) || charEncode(c5, fc::PC) == charEncode(c5, fc::ASCII) )
{ {
no_half_block_character = true; no_half_block_character = true;
} }
} }
#endif #endif
@ -2661,7 +2661,7 @@ char* FTerm::parseAnswerbackMsg (char*& current_termtype)
return 0; return 0;
} }
if ( *answer_back == FString("PuTTY") ) if ( *answer_back == "PuTTY" )
{ {
putty_terminal = true; putty_terminal = true;
@ -2726,7 +2726,7 @@ char* FTerm::parseSecDA (char*& current_termtype)
if ( num_components >= 2 ) if ( num_components >= 2 )
{ {
FString* sec_da_components = &sec_da_split[0]; const FString* sec_da_components = &sec_da_split[0];
if ( ! sec_da_components[0].isEmpty() ) if ( ! sec_da_components[0].isEmpty() )
{ {

View File

@ -2509,7 +2509,7 @@ void FVTerm::updateTerminalLine (uInt y)
print_char->attr.bit.printed = true; print_char->attr.bit.printed = true;
// skip character with no changes // skip character with no changes
if ( print_char->attr.bit.no_changes ) if ( print_char->attr.bit.no_changes )
{ {
uInt count = 1; uInt count = 1;

View File

@ -727,7 +727,7 @@ void FWindow::switchToPrevWindow()
break; break;
} }
} }
while ( iter != begin ); while ( iter != begin );
} }
} }

View File

@ -34,91 +34,91 @@ int main (int, char**)
std::cout << " instream >> " << in << std::endl; std::cout << " instream >> " << in << std::endl;
// Test: output stream (operator <<) // Test: output stream (operator <<)
FString out = L"A test string for 0 \x20ac"; const FString& out = L"A test string for 0 \x20ac";
std::cout << " outstream << " << out << std::endl; std::cout << " outstream << " << out << std::endl;
// Test: c-string output // Test: c-string output
printf (" c_str: \"%s\"\n", out.c_str()); printf (" c_str: \"%s\"\n", out.c_str());
// Test: copy a c++ string // Test: copy a c++ string
FString cpp_str( std::string("c++ String") ); const FString& cpp_str( std::string("c++ String") );
std::cout << " cpp_str: \"" << cpp_str << "\"" << std::endl; std::cout << " cpp_str: \"" << cpp_str << "\"" << std::endl;
// Test: copy a character // Test: copy a character
FString ch('c'); const FString& ch('c');
std::cout << " char: '" << ch << "'" << std::endl; std::cout << " char: '" << ch << "'" << std::endl;
// Test: copy a wide character // Test: copy a wide character
FString wch(L'w'); const FString& wch(L'w');
std::cout << " wchar_t: '" << wch << "'" << std::endl; std::cout << " wchar_t: '" << wch << "'" << std::endl;
// Test: utf-8 string // Test: utf-8 string
FString len = "длина́"; const FString& len = "длина́";
std::cout << " length: \"" << len << "\" has " std::cout << " length: \"" << len << "\" has "
<< len.getLength() << " characters" << std::endl; << len.getLength() << " characters" << std::endl;
// Test: convert uppercase letter to lowercase // Test: convert uppercase letter to lowercase
FString lower = FString(L"InPut").toLower(); const FString& lower = FString(L"InPut").toLower();
std::wcout << L" toLower: " << lower << std::endl; std::wcout << L" toLower: " << lower << std::endl;
// Test: convert lowercase letter to uppercase // Test: convert lowercase letter to uppercase
FString upper = FString("inPut").toUpper(); const FString& upper = FString("inPut").toUpper();
std::cout << " toUpper: " << upper << std::endl; std::cout << " toUpper: " << upper << std::endl;
// Test: concatenate two FStrings (operator +) // Test: concatenate two FStrings (operator +)
FString add1 = FString("FString + ") + FString("FString"); const FString& add1 = FString("FString + ") + FString("FString");
std::cout << " add: " << add1 << std::endl; std::cout << " add: " << add1 << std::endl;
// Test: concatenate a FString and a c++ wide string (operator +) // Test: concatenate a FString and a c++ wide string (operator +)
FString add2 = FString("FString + ") + std::wstring(L"std::wstring"); const FString& add2 = FString("FString + ") + std::wstring(L"std::wstring");
std::cout << " add: " << add2 << std::endl; std::cout << " add: " << add2 << std::endl;
// Test: concatenate a FString and a wide string (operator +) // Test: concatenate a FString and a wide string (operator +)
FString add3 = FString("FString + ") + const_cast<wchar_t*>(L"wchar_t*"); const FString& add3 = FString("FString + ") + const_cast<wchar_t*>(L"wchar_t*");
std::cout << " add: " << add3 << std::endl; std::cout << " add: " << add3 << std::endl;
// Test: concatenate a FString and a c++ string (operator +) // Test: concatenate a FString and a c++ string (operator +)
FString add4 = FString("FString + ") + std::string("std::string"); const FString& add4 = FString("FString + ") + std::string("std::string");
std::cout << " add: " << add4 << std::endl; std::cout << " add: " << add4 << std::endl;
// Test: concatenate a FString and a c-string (operator +) // Test: concatenate a FString and a c-string (operator +)
FString add5 = FString("FString + ") + const_cast<char*>("char*"); const FString& add5 = FString("FString + ") + const_cast<char*>("char*");
std::cout << " add: " << add5 << std::endl; std::cout << " add: " << add5 << std::endl;
// Test: concatenate a FString and a wide character (operator +) // Test: concatenate a FString and a wide character (operator +)
FString add6 = FString("FString + ") + wchar_t(L'w'); const FString& add6 = FString("FString + ") + wchar_t(L'w');
std::cout << " add: " << add6 << std::endl; std::cout << " add: " << add6 << std::endl;
// Test: concatenate a FString and a character (operator +) // Test: concatenate a FString and a character (operator +)
FString add7 = FString("FString + ") + char('c'); const FString& add7 = FString("FString + ") + char('c');
std::cout << " add: " << add7 << std::endl; std::cout << " add: " << add7 << std::endl;
// Test: concatenate a character and a FString (operator +) // Test: concatenate a character and a FString (operator +)
FString add8 = 'c' + FString(" + FString"); const FString& add8 = 'c' + FString(" + FString");
std::cout << " add: " << add8 << std::endl; std::cout << " add: " << add8 << std::endl;
// Test: concatenate a wide character and a FString (operator +) // Test: concatenate a wide character and a FString (operator +)
FString add9 = L'w' + FString(" + FString"); const FString& add9 = L'w' + FString(" + FString");
std::cout << " add: " << add9 << std::endl; std::cout << " add: " << add9 << std::endl;
// Test: concatenate a c-string and a FString (operator +) // Test: concatenate a c-string and a FString (operator +)
FString add10 = const_cast<char*>("char*") + FString(" + FString"); const FString& add10 = const_cast<char*>("char*") + FString(" + FString");
std::cout << " add: " << add10 << std::endl; std::cout << " add: " << add10 << std::endl;
// Test: concatenate a c++ string and a FString (operator +) // Test: concatenate a c++ string and a FString (operator +)
FString add11 = std::string("std::string") + FString(" + FString"); const FString& add11 = std::string("std::string") + FString(" + FString");
std::cout << " add: " << add11 << std::endl; std::cout << " add: " << add11 << std::endl;
// Test: concatenate a wide string and a FString (operator +) // Test: concatenate a wide string and a FString (operator +)
FString add12 = const_cast<wchar_t*>(L"wchar_t*") + FString(" + FString"); const FString& add12 = const_cast<wchar_t*>(L"wchar_t*") + FString(" + FString");
std::cout << " add: " << add12 << std::endl; std::cout << " add: " << add12 << std::endl;
// Test: concatenate a c++ wide string and a FString (operator +) // Test: concatenate a c++ wide string and a FString (operator +)
FString add13 = std::wstring(L"std::wstring") + FString(" + FString"); const FString& add13 = std::wstring(L"std::wstring") + FString(" + FString");
std::cout << " add: " << add13 << std::endl; std::cout << " add: " << add13 << std::endl;
// Test: compare operators ==, <=, <, >=, >, != // Test: compare operators ==, <=, <, >=, >, !=
FString cmp = "compare"; const FString& cmp = "compare";
if ( cmp == FString("compare") ) if ( cmp == FString("compare") )
std::cout << " cmp: == Ok" << std::endl; std::cout << " cmp: == Ok" << std::endl;
@ -172,7 +172,7 @@ int main (int, char**)
// Test: convert a string to a unsigned long interger // Test: convert a string to a unsigned long interger
try try
{ {
uLong ulong_num = FString("123456789").toULong(); const uLong ulong_num = FString("123456789").toULong();
std::cout << " toULong: " << ulong_num << std::endl; std::cout << " toULong: " << ulong_num << std::endl;
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument& ex)
@ -187,7 +187,7 @@ int main (int, char**)
// Test: convert a string to a signed long interger // Test: convert a string to a signed long interger
try try
{ {
long long_num = FString("-9876543210").toLong(); const long long_num = FString("-9876543210").toLong();
std::cout << " toLong: " << long_num << std::endl; std::cout << " toLong: " << long_num << std::endl;
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument& ex)
@ -204,7 +204,7 @@ int main (int, char**)
try try
{ {
double double_num = FString("2.7182818284590452353").toDouble(); const double double_num = FString("2.7182818284590452353").toDouble();
std::ios_base::fmtflags save_flags = std::cout.flags(); std::ios_base::fmtflags save_flags = std::cout.flags();
std::cout << " toDouble: " << std::setprecision(11) std::cout << " toDouble: " << std::setprecision(11)
<< double_num << std::endl; << double_num << std::endl;
@ -249,7 +249,7 @@ int main (int, char**)
<< fnum2 << " (signed)" << std::endl; << fnum2 << " (signed)" << std::endl;
// Test: remove whitespace from the end of a string // Test: remove whitespace from the end of a string
FString trim_str = " A string \t"; const FString& trim_str = " A string \t";
std::wcout << " rtrim: \"" std::wcout << " rtrim: \""
<< trim_str.rtrim() << "\"" << std::endl; << trim_str.rtrim() << "\"" << std::endl;
@ -262,7 +262,7 @@ int main (int, char**)
<< trim_str.trim() << "\"" << std::endl; << trim_str.trim() << "\"" << std::endl;
// Test: 11 characters from the left of the string // Test: 11 characters from the left of the string
FString alphabet = "a b c d e f g h i j k l m n o p q r s t u v w x y z"; const FString& alphabet = "a b c d e f g h i j k l m n o p q r s t u v w x y z";
std::cout << " left: \"" std::cout << " left: \""
<< alphabet.left(11) << "\"" << std::endl; << alphabet.left(11) << "\"" << std::endl;
@ -304,7 +304,7 @@ int main (int, char**)
} }
// Test: character access with std::iterator // Test: character access with std::iterator
FString stringIterator = "iterator"; const FString& stringIterator = "iterator";
FString::iterator iter; FString::iterator iter;
iter = stringIterator.begin(); iter = stringIterator.begin();
std::cout << " " << stringIterator << ": "; std::cout << " " << stringIterator << ": ";
@ -353,22 +353,22 @@ int main (int, char**)
// Test: find and replace a substring // Test: find and replace a substring
FString source_str = "computer and software"; FString source_str = "computer and software";
FString replace_str = source_str.replace("computer", "hard-"); const FString& replace_str = source_str.replace("computer", "hard-");
std::cout << " replace: " std::cout << " replace: "
<< replace_str << std::endl; << replace_str << std::endl;
// Test: convert tabs to spaces // Test: convert tabs to spaces
FString tab_str = "1234\t5678"; const FString& tab_str = "1234\t5678";
std::cout << " tab: " std::cout << " tab: "
<< tab_str.expandTabs() << std::endl; << tab_str.expandTabs() << std::endl;
// Test: backspaces remove characters in the string // Test: backspaces remove characters in the string
FString bs_str = "t\b\bTesT\bt"; const FString& bs_str = "t\b\bTesT\bt";
std::cout << "backspace: " std::cout << "backspace: "
<< bs_str.removeBackspaces() << std::endl; << bs_str.removeBackspaces() << std::endl;
// Test: delete characters remove characters in the string // Test: delete characters remove characters in the string
FString del_str = "apple \177\177\177pietree"; const FString& del_str = "apple \177\177\177pietree";
std::cout << " delete: " std::cout << " delete: "
<< del_str.removeDel() << std::endl; << del_str.removeDel() << std::endl;
} }

View File

@ -75,13 +75,13 @@ smallWindow::smallWindow (FWidget* parent)
right_arrow->ignorePadding(); right_arrow->ignorePadding();
right_arrow->setGeometry (getWidth() - 1, 2, 1, 1); right_arrow->setGeometry (getWidth() - 1, 2, 1, 1);
FString top_left_label_text = "menu"; const FString& top_left_label_text = "menu";
top_left_label = new FLabel (top_left_label_text, this); top_left_label = new FLabel (top_left_label_text, this);
top_left_label->setForegroundColor (wc.label_inactive_fg); top_left_label->setForegroundColor (wc.label_inactive_fg);
top_left_label->setEmphasis(); top_left_label->setEmphasis();
top_left_label->setGeometry (1, 1, 6, 1); top_left_label->setGeometry (1, 1, 6, 1);
FString top_right_label_text = "zoom"; const FString& top_right_label_text = "zoom";
top_right_label = new FLabel (top_right_label_text, this); top_right_label = new FLabel (top_right_label_text, this);
top_right_label->setAlignment (fc::alignRight); top_right_label->setAlignment (fc::alignRight);
top_right_label->setForegroundColor (wc.label_inactive_fg); top_right_label->setForegroundColor (wc.label_inactive_fg);