Skip to content

Commit

Permalink
Unify ampersand and BiDi normalization (bsc#1128091, bsc#1139747)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Jun 4, 2021
1 parent 9eaf1e4 commit f6216b5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions libyui-rest-api/src/YDumbTabActionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ YDumbTabActionHandler::findItem( const std::string &item_label,
YItemConstIterator begin,
YItemConstIterator end ) const
{
std::string item_label_sanitized = boost::erase_all_copy(item_label, ShortcutChar);
std::string item_label_sanitized = normalize_label(item_label);
for ( YItemConstIterator it = begin; it != end; ++it )
{
YItem * item = *it;

if ( boost::erase_all_copy(item->label(), ShortcutChar) == item_label_sanitized )
if ( normalize_label(item->label()) == item_label_sanitized )
{
return item;
}
Expand Down
2 changes: 1 addition & 1 deletion libyui-rest-api/src/YMenuWidgetActionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ YMenuWidgetActionHandler::findItem( std::vector<std::string>::iterator path_begi
if ( !item )
return nullptr;

if ( boost::erase_all_copy( item->label(), ShortcutChar ) == *path_begin )
if ( normalize_label( item->label() ) == *path_begin )
{
if ( std::next( path_begin ) == path_end )
{
Expand Down
2 changes: 1 addition & 1 deletion libyui-rest-api/src/YMenuWidgetActionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class YMenuWidgetActionHandler : public YWidgetActionHandler
template<typename T>
std::function<void (T*)> get_handler( T *widget, const std::string &value ) {
return [&] ( T *menu_selector ) {
std::string value_sanitized = boost::erase_all_copy( value, ShortcutChar );
std::string value_sanitized = normalize_label( value );
// Vector of string to store path to the tree item
std::vector<std::string> path;
boost::split( path, value_sanitized, boost::is_any_of( TreePathDelimiter ) );
Expand Down
8 changes: 6 additions & 2 deletions libyui-rest-api/src/YWidgetActionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ std::string normalize_label_bidi(const std::string& label)
return cleaned;
}

static
std::string normalize_label_shortcut(const std::string& label)
{
return boost::erase_all_copy(label, ShortcutChar);
}

std::string YWidgetActionHandler::normalize_label(const std::string & label)
{
// FIXME: also ampersand
return normalize_label_bidi(label);
return normalize_label_shortcut(normalize_label_bidi(label));
}
8 changes: 8 additions & 0 deletions libyui-rest-api/src/YWidgetActionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ class YWidgetActionHandler
// - remove shortcut characters (&)
// - remove BiDi control characters (added to certain table cells to render pathnames correctly)
static std::string normalize_label(const std::string & label);

// Apply normalize_label to both arguments and compare the result with ==.
static bool normalized_labels_equal(const std::string & a, const std::string & b)
{
std::string na = normalize_label(a);
std::string nb = normalize_label(b);
return na == nb;
}
};

#endif //YWidgetActionHandler_h
5 changes: 2 additions & 3 deletions libyui-rest-api/src/YWidgetFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <yui/YWidgetID.h>

#include "YWidgetFinder.h"
#include "YWidgetActionHandler.h"


// internal helper methods
Expand Down Expand Up @@ -94,14 +95,12 @@ void find_widgets(YWidget *w, WidgetArray &array, std::function<bool (YWidget*)>

static bool filter_by_label_rec(YWidget *w, const std::string &label)
{
std::string label_sanitized = boost::erase_all_copy( label, ShortcutChar );
// check the widget label if it is defined
if ( w->propertySet().contains("Label") )
{
std::string widget_label = w->getProperty("Label").stringVal();
boost::erase_all( widget_label, ShortcutChar );

if ( widget_label == label_sanitized )
if ( YWidgetActionHandler::normalized_labels_equal( widget_label, label ) )
return true;
}
return false;
Expand Down
2 changes: 0 additions & 2 deletions libyui-rest-api/src/YWidgetFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <string>
#include <vector>

#define ShortcutChar "&"

class YWidget;

typedef std::vector<YWidget*> WidgetArray;
Expand Down

0 comments on commit f6216b5

Please sign in to comment.