diff --git a/examples/event-log.cpp b/examples/event-log.cpp index 3a24019e..b0c81b30 100644 --- a/examples/event-log.cpp +++ b/examples/event-log.cpp @@ -284,13 +284,13 @@ EventLog::~EventLog() noexcept = default; // destructor //---------------------------------------------------------------------- void EventLog::onTimer (finalcut::FTimerEvent*) { - if ( ! str().empty() ) - { - scrolltext.append(str()); - str(""); - scrolltext.scrollToEnd(); - redraw(); - } + if ( str().empty() ) + return; + + scrolltext.append(str()); + str(""); + scrolltext.scrollToEnd(); + redraw(); } //---------------------------------------------------------------------- diff --git a/examples/mouse.cpp b/examples/mouse.cpp index 77fcdf9d..9131a98f 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -120,7 +120,7 @@ void ColorChooser::draw() setColor(); drawBorder(); - for (FColor c{FColor::Black}; c < 16; c++) + for (FColor c{FColor::Black}; c < 16; ++c) { print() << FPoint{2 + (int(c) / 8) * 3, 3 + int(c) % 8}; diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index 2bcf6274..3a252da5 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -143,7 +143,7 @@ void AttribDlg::cb_next() else if ( bgcolor == FColor::Default ) bgcolor = FColor::Black; else - bgcolor++; + ++bgcolor; redraw(); } @@ -159,7 +159,7 @@ void AttribDlg::cb_back() else if ( bgcolor == FColor::Default ) bgcolor = FColor(finalcut::FTerm::getMaxColor() - 1); else - bgcolor--; + --bgcolor; redraw(); } @@ -272,7 +272,7 @@ void AttribDemo::printColorLine() { const auto& parent = static_cast(getParent()); - for (FColor color{FColor::Black}; color < last_color; color++) + for (FColor color{FColor::Black}; color < last_color; ++color) { print() << FColorPair{color, parent->getBGColor()} << " # "; } @@ -479,7 +479,7 @@ void AttribDemo::draw() if ( bg == FColor::Default ) print (" default"); else - printf ( " %d", bg); + printf ( " %u", bg); print() << FPoint{16, 17} << "Change background color ->"; } diff --git a/examples/ui.cpp b/examples/ui.cpp index 3e1b41fc..898b2e65 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 9506688d..61194bb8 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -529,7 +529,7 @@ void FApplication::cmdOptions (const Args& args) CmdMap cmd_map{}; setCmdOptionsMap(cmd_map); - auto argc = int(args.size()); + auto argc = args.size(); std::vector argv(argc); std::transform ( args.begin() , args.end() @@ -547,14 +547,16 @@ void FApplication::cmdOptions (const Args& args) std::vector long_options{}; setLongOptions(long_options); auto p = reinterpret_cast(long_options.data()); - auto argv_data = const_cast(argv.data()); - const int opt = getopt_long (argc, argv_data, "", p, &idx); + auto argv_data = const_cast(argv.data()); + const int opt = getopt_long (int(argc), argv_data, "", p, &idx); if ( opt == -1 ) break; - if ( cmd_map.find(opt) != cmd_map.end() ) - cmd_map[opt](optarg); + const auto& entry = cmd_map[opt]; + + if ( entry ) + entry(optarg); } cmd_map.clear(); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 3b58f39d..4b2bbf5e 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -1417,10 +1417,10 @@ inline void FDialog::passEventToSubMenu ( const MouseStates& ms //---------------------------------------------------------------------- inline void FDialog::moveSizeKey (FKeyEvent* ev) { - const auto key = ev->key(); + const auto& entry = key_map[ev->key()]; - if ( key_map.find(key) != key_map.end() ) - key_map[key](); + if ( entry ) + entry(); // Accept for all, so that parent widgets will not receive keystrokes ev->accept(); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index a6497683..91cd2781 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -297,10 +297,11 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) return; const auto key = ev->key(); + const auto& entry = key_map[key]; - if ( key_map.find(key) != key_map.end() ) + if ( entry ) { - key_map[key](); + entry(); ev->accept(); } else if ( key == FKey::Tab ) diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 232488c6..aeb3305f 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -660,20 +660,26 @@ inline void FListBox::mapKeyFunctions() void FListBox::processKeyAction (FKeyEvent* ev) { const auto idx = ev->key(); + const auto& entry = key_map[idx]; - if ( key_map.find(idx) != key_map.end() ) + if ( entry ) { - key_map[idx](); + entry(); ev->accept(); } - else if ( key_map_result.find(idx) != key_map_result.end() ) + else { - if ( key_map_result[idx]() ) + const auto& entry_result = key_map_result[idx]; + + if ( entry_result ) + { + if ( entry_result() ) + ev->accept(); + } + else if ( keyIncSearchInput(idx) ) + { ev->accept(); - } - else if ( keyIncSearchInput(ev->key()) ) - { - ev->accept(); + } } } diff --git a/src/flistview.cpp b/src/flistview.cpp index 8a199fc1..e2125fe8 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -1445,20 +1445,26 @@ inline void FListView::mapKeyFunctions() void FListView::processKeyAction (FKeyEvent* ev) { const auto idx = ev->key(); + const auto& entry = key_map[idx]; - if ( key_map.find(idx) != key_map.end() ) + if ( entry ) { - key_map[idx](); + entry(); ev->accept(); } - else if ( key_map_result.find(idx) != key_map_result.end() ) - { - if ( key_map_result[idx]() ) - ev->accept(); - } else { - ev->ignore(); + const auto& entry_result = key_map_result[idx]; + + if ( entry_result ) + { + if ( entry_result() ) + ev->accept(); + } + else + { + ev->ignore(); + } } } diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 83e0ffb8..4c1d0052 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -473,11 +473,11 @@ void FScrollView::drawBorder() //---------------------------------------------------------------------- void FScrollView::onKeyPress (FKeyEvent* ev) { - const auto idx = ev->key(); + const auto& entry = key_map[ev->key()]; - if ( key_map.find(idx) != key_map.end() ) + if ( entry ) { - key_map[idx](); + entry(); ev->accept(); } } diff --git a/src/fterm.cpp b/src/fterm.cpp index fc44b30f..e7c3294b 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1065,15 +1065,15 @@ wchar_t FTerm::charEncode (wchar_t c) wchar_t FTerm::charEncode (wchar_t c, Encoding enc) { wchar_t ch_enc = c; + auto found = std::find_if ( fc::character.begin() + , fc::character.end() + , [&c] (const fc::CharEncodeMap& entry) + { + return entry.unicode == c; + } ); - for (auto&& entry : fc::character) - { - if ( entry.unicode == c ) - { - ch_enc = getCharacter(entry, enc); - break; - } - } + if ( found != fc::character.end() ) + ch_enc = getCharacter(*found, enc); if ( enc == Encoding::PC && ch_enc == c ) ch_enc = finalcut::unicode_to_cp437(c); diff --git a/src/fterm_functions.cpp b/src/fterm_functions.cpp index 57c5ce44..f170036e 100644 --- a/src/fterm_functions.cpp +++ b/src/fterm_functions.cpp @@ -285,15 +285,15 @@ wchar_t cp437_to_unicode (uChar c) constexpr std::size_t CP437 = 0; constexpr std::size_t UNICODE = 1; wchar_t ucs = c; + auto found = std::find_if ( fc::cp437_ucs.begin() + , fc::cp437_ucs.end() + , [&c] (const std::array& entry) + { + return entry[CP437] == c; + } ); - for (auto&& entry : fc::cp437_ucs) - { - if ( entry[CP437] == c ) // found - { - ucs = entry[UNICODE]; - break; - } - } + if ( found != fc::cp437_ucs.end() ) + ucs = (*found)[UNICODE]; return ucs; } @@ -305,14 +305,15 @@ uChar unicode_to_cp437 (wchar_t ucs) constexpr std::size_t UNICODE = 1; uChar c{'?'}; - for (auto&& entry : fc::cp437_ucs) - { - if ( entry[UNICODE] == ucs ) // found - { - c = uChar(entry[CP437]); - break; - } - } + auto found = std::find_if ( fc::cp437_ucs.begin() + , fc::cp437_ucs.end() + , [&ucs] (const std::array& entry) + { + return entry[UNICODE] == ucs; + } ); + + if ( found != fc::cp437_ucs.end() ) + c = static_cast((*found)[CP437]); return c; } @@ -327,12 +328,15 @@ FString getFullWidth (const FString& str) { constexpr std::size_t HALF = 0; constexpr std::size_t FULL = 1; + auto found = std::find_if ( fc::halfwidth_fullwidth.begin() + , fc::halfwidth_fullwidth.end() + , [&c] (const std::array& entry) + { + return entry[HALF] == c; + } ); - for (auto&& entry : fc::halfwidth_fullwidth) - { - if ( entry[HALF] == c ) // found - c = entry[FULL]; - } + if ( found != fc::halfwidth_fullwidth.end() ) + c = (*found)[FULL]; }; for (auto&& c : s) @@ -356,12 +360,15 @@ FString getHalfWidth (const FString& str) { constexpr std::size_t HALF = 0; constexpr std::size_t FULL = 1; + auto found = std::find_if ( fc::halfwidth_fullwidth.begin() + , fc::halfwidth_fullwidth.end() + , [&c] (const std::array& entry) + { + return entry[FULL] == c; + } ); - for (auto&& entry : fc::halfwidth_fullwidth) - { - if ( entry[FULL] == c ) // found - c = entry[HALF]; - } + if ( found != fc::halfwidth_fullwidth.end() ) + c = (*found)[HALF]; }; for (auto&& c : s) diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index f9a900a9..f53fa2f2 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -448,11 +448,11 @@ FKey FTermLinux::modifierKeyCorrection (const FKey& key_id) // Get the current modifier key state const Pair pair{getModifierKey(), key_id}; - const auto iter = key_map.find(pair); + const auto& key = key_map[pair]; - if ( iter == key_map.cend() ) // Not found + if ( key == FKey(0) ) // Not found return key_id; - else // Found + else // Found return key_map[pair]; } @@ -896,12 +896,14 @@ void FTermLinux::setVGADefaultPalette() {0x55, 0xff, 0xff}, {0xff, 0xff, 0xff} }}; - for (std::size_t index{0}; index < 16; index++) - { - cmap.color[index].red = defaultColor[index].red; - cmap.color[index].green = defaultColor[index].green; - cmap.color[index].blue = defaultColor[index].blue; - } + std::transform ( defaultColor.begin() + , defaultColor.end() + , cmap.color.begin() + , [] (const RGB& rgb) + { + return rgb; + } + ); } //---------------------------------------------------------------------- diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 46508a0d..2c854bf5 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -333,11 +333,11 @@ void FTextView::clear() //---------------------------------------------------------------------- void FTextView::onKeyPress (FKeyEvent* ev) { - const auto idx = ev->key(); + const auto& entry = key_map[ev->key()]; - if ( key_map.find(idx) != key_map.end() ) + if ( entry ) { - key_map[idx](); + entry(); ev->accept(); } } diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 63f59069..417260f9 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -465,8 +465,7 @@ int FVTerm::print (FTermArea* area, wchar_t c) if ( ! area ) return -1; - FChar nc{}; // next character - nc = FVTerm::getAttribute(); + FChar nc = FVTerm::getAttribute(); // next character nc.ch[0] = c; nc.attr.byte[2] = 0; nc.attr.byte[3] = 0; @@ -1114,7 +1113,7 @@ void FVTerm::scrollAreaForward (FTermArea* area) const auto bottom_right = std::size_t((y_max * total_width) - area->right_shadow - 1); const auto& lc = area->data[bottom_right]; // last character std::memcpy (&nc, &lc, sizeof(nc)); - nc.ch[0] = ' '; + nc.ch[0] = L' '; auto& dc = area->data[y_max * total_width]; // destination character std::fill_n (&dc, area->width, nc); area->changes[y_max].xmin = 0; @@ -1166,7 +1165,7 @@ void FVTerm::scrollAreaReverse (FTermArea* area) const FChar nc{}; // next character const auto& lc = area->data[total_width]; // last character std::memcpy (&nc, &lc, sizeof(nc)); - nc.ch[0] = ' '; + nc.ch[0] = L' '; auto& dc = area->data[0]; // destination character std::fill_n (&dc, area->width, nc); area->changes[0].xmin = 0; @@ -1313,7 +1312,7 @@ inline void FVTerm::resetTextAreaToDefault ( const FTermArea* area FChar default_char; FLineChanges unchanged; - default_char.ch[0] = ' '; + default_char.ch[0] = L' '; default_char.fg_color = FColor::Default; default_char.bg_color = FColor::Default; default_char.attr.byte[0] = 0; @@ -1454,7 +1453,7 @@ inline void FVTerm::updateOverlappedColor ( const FChar& area_char || nc.ch[0] == UniChar::RightHalfBlock || nc.ch[0] == UniChar::MediumShade || nc.ch[0] == UniChar::FullBlock ) - nc.ch[0] = ' '; + nc.ch[0] = L' '; nc.attr.bit.no_changes = bool(vterm_char.attr.bit.printed && vterm_char == nc); std::memcpy (&vterm_char, &nc, sizeof(vterm_char)); @@ -1489,7 +1488,7 @@ inline void FVTerm::updateShadedCharacter ( const FChar& area_char || cover_char.ch[0] == UniChar::RightHalfBlock || cover_char.ch[0] == UniChar::MediumShade || cover_char.ch[0] == UniChar::FullBlock ) - cover_char.ch[0] = ' '; + cover_char.ch[0] = L' '; cover_char.attr.bit.no_changes = \ bool(vterm_char.attr.bit.printed && vterm_char == cover_char); @@ -1728,7 +1727,7 @@ FChar FVTerm::generateCharacter (const FPoint& pos) || s_ch.ch[0] == UniChar::RightHalfBlock || s_ch.ch[0] == UniChar::MediumShade || s_ch.ch[0] == UniChar::FullBlock ) - s_ch.ch[0] = ' '; + s_ch.ch[0] = L' '; sc = &s_ch; } @@ -1981,7 +1980,7 @@ void FVTerm::putAreaCharacter ( const FPoint& pos, const FTermArea* area || ch.ch[0] == UniChar::RightHalfBlock || ch.ch[0] == UniChar::MediumShade || ch.ch[0] == UniChar::FullBlock ) - ch.ch[0] = ' '; + ch.ch[0] = L' '; std::memcpy (&vterm_char, &ch, sizeof(vterm_char)); } @@ -2146,7 +2145,7 @@ bool FVTerm::canClearToEOL (uInt xmin, uInt y) const auto& ce = TCAP(t_clr_eol); const auto& min_char = vt->data[y * uInt(vt->width) + xmin]; - if ( ce && min_char.ch[0] == ' ' ) + if ( ce && min_char.ch[0] == L' ' ) { uInt beginning_whitespace = 1; const bool normal = FTerm::isNormal(min_char); @@ -2181,7 +2180,7 @@ bool FVTerm::canClearLeadingWS (uInt& xmin, uInt y) const auto& cb = TCAP(t_clr_bol); const auto& first_char = vt->data[y * uInt(vt->width)]; - if ( cb && first_char.ch[0] == ' ' ) + if ( cb && first_char.ch[0] == L' ' ) { uInt leading_whitespace = 1; const bool normal = FTerm::isNormal(first_char); @@ -2219,7 +2218,7 @@ bool FVTerm::canClearTrailingWS (uInt& xmax, uInt y) const auto& ce = TCAP(t_clr_eol); const auto& last_char = vt->data[(y + 1) * uInt(vt->width) - 1]; - if ( ce && last_char.ch[0] == ' ' ) + if ( ce && last_char.ch[0] == L' ' ) { uInt trailing_whitespace = 1; const bool normal = FTerm::isNormal(last_char); @@ -2299,7 +2298,7 @@ void FVTerm::printRange ( uInt xmin, uInt xmax, uInt y continue; // Erase character - if ( ec && print_char.ch[0] == ' ' ) + if ( ec && print_char.ch[0] == L' ' ) { PrintState erase_state = \ eraseCharacters(x, xmax, y, draw_trailing_ws); @@ -2510,7 +2509,7 @@ FVTerm::PrintState FVTerm::eraseCharacters ( uInt& x, uInt xmax, uInt y const auto& ec = TCAP(t_erase_chars); auto& print_char = vt->data[y * uInt(vt->width) + x]; - if ( ! ec || print_char.ch[0] != ' ' ) + if ( ! ec || print_char.ch[0] != L' ' ) return PrintState::NothingPrinted; uInt whitespace{1}; @@ -3140,10 +3139,11 @@ void FVTerm::appendLowerRight (FChar& last_char) const //---------------------------------------------------------------------- inline void FVTerm::characterFilter (FChar& next_char) const { - charSubstitution& sub_map = fterm->getCharSubstitutionMap(); + auto& sub_map = fterm->getCharSubstitutionMap(); + const auto& entry = sub_map[next_char.encoded_char[0]]; - if ( sub_map.find(next_char.encoded_char[0]) != sub_map.end() ) - next_char.encoded_char[0] = sub_map[next_char.encoded_char[0]]; + if ( entry ) + next_char.encoded_char[0] = entry; } //---------------------------------------------------------------------- diff --git a/src/fwidget.cpp b/src/fwidget.cpp index c0b6d18f..7458b5a8 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -2006,7 +2006,7 @@ void FWidget::drawWindows() const { // redraw windows FChar default_char{}; - default_char.ch[0] = ' '; + default_char.ch[0] = L' '; default_char.fg_color = FColor::Black; default_char.bg_color = FColor::Black; default_char.attr.byte[0] = 0; diff --git a/src/include/final/fc.h b/src/include/final/fc.h index 0d033246..c8ff5afb 100644 --- a/src/include/final/fc.h +++ b/src/include/final/fc.h @@ -801,9 +801,9 @@ enum class FKey : uInt32 struct FKeyHash { - std::size_t operator () (const FKey& p) const noexcept + std::size_t operator () (const FKey& k) const noexcept { - return std::hash()(uInt32(p)); + return std::hash()(uInt32(k)); } }; diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index e02d9236..10fba5b7 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -111,7 +111,6 @@ #include #include #include -#include #include #include #include