[yast-commit] r60338 - in /trunk/ncurses: VERSION package/yast2-ncurses.changes src/NCstring.cc
Author: kmachalkova Date: Tue Jan 12 19:49:52 2010 New Revision: 60338 URL: http://svn.opensuse.org/viewcvs/yast?rev=60338&view=rev Log: Improved && un-escaping (bnc#559226) Modified: trunk/ncurses/VERSION trunk/ncurses/package/yast2-ncurses.changes trunk/ncurses/src/NCstring.cc Modified: trunk/ncurses/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/VERSION?rev=60338&r1=60337&r2=60338&view=diff ============================================================================== --- trunk/ncurses/VERSION (original) +++ trunk/ncurses/VERSION Tue Jan 12 19:49:52 2010 @@ -1 +1 @@ -2.19.1 +2.19.2 Modified: trunk/ncurses/package/yast2-ncurses.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/package/yast2-ncurses.changes?rev=60338&r1=60337&r2=60338&view=diff ============================================================================== --- trunk/ncurses/package/yast2-ncurses.changes (original) +++ trunk/ncurses/package/yast2-ncurses.changes Tue Jan 12 19:49:52 2010 @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Mon Jan 11 19:31:20 CET 2010 - kmachalkova@suse.cz + +- Improved algorithm for double '&&' escaping (this one hopefully + does not "eat" chars in some Frames anymore - still bnc#559226) +- V 2.19.2 + +------------------------------------------------------------------- Fri Dec 18 12:55:49 CET 2009 - ma@suse.de - Work around 32768 lines limit in ncurses table. (bnc #550733) Modified: trunk/ncurses/src/NCstring.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCstring.cc?rev=60338&r1=60337&r2=60338&view=diff ============================================================================== --- trunk/ncurses/src/NCstring.cc (original) +++ trunk/ncurses/src/NCstring.cc Tue Jan 12 19:49:52 2010 @@ -315,47 +315,67 @@ void NCstring::getHotkey( ) const -{ - +{ + hotp = wstring::npos; const wchar_t shortcutMarker = L'&'; - // strip hotkey from wstr and convert &&s - wstring::size_type tpos = 0; - wstring::size_type pos = tpos; - - // borrowed from libyui (libyui inserts "&"s if none is there, - // but fortunately it keeps "&&" in place) - while ( ( pos = wstr.find( shortcutMarker, pos ) ) != wstring::npos ) + const wchar_t replacementShortcutMarker = L'_'; + + // I'm not really happy with using replacement markers and copying the string + // but is there an other way? + // If hotkey is looked up before un-escaping, its position won't be up-to-date anymore + // as chars got deleted from the string + // And vice versa: if un-escaping is done before looking up hotkey position, it's no + // longer possible to tell hotkey marker and regular & (previous &&) apart (this is + // the 'Foo&&Bar&Geeez' case) fB. + + bool have_shortcut = false; + wstring::size_type len = wstr.length(); + wstring newstr; + newstr.reserve( len ); + + for (wstring::iterator it = wstr.begin(); it != wstr.end(); it++) { + if ( *it == shortcutMarker && + (it + 1 != wstr.end()) ) { + + // double && un-escaping - bnc#559226 + // foo&&bar => foo&bar + if ( *(it+1) == shortcutMarker) { + newstr += shortcutMarker; // add only one & + it++; // .. and jump forth to skip the 2nd one + } + // regular hotkey &X + else { + // take the first one only (we can't do multiple hotkeys per 1 line + // so we just discard the rest, argh) + if ( !have_shortcut) { + newstr += replacementShortcutMarker; + have_shortcut = true; + } + } + } + else + newstr += *it; + } + + wstr = newstr; + + wstring::size_type tpos = wstr.find_first_of( replacementShortcutMarker ); + + if ( tpos != wstring::npos && tpos != wstr.size() - 1 ) { - if ( pos+1 < wstr.length() ) - { - // regular hotkey ( "&P" ) - if ( wstr[ pos+1 ] != shortcutMarker ) - tpos = pos; - // escape marker ("&&" ) - else - wstr.erase(pos,1); // make it only one & - - pos += 1; // and search for more - } - else - { - // A pathological case: The string ends with '& '. - // This is invalid anyway, but prevent endless loop even in this case. - pos = string::npos; - } + size_t realpos = 0, t; + + for ( t = 0; t < tpos; t++ ) + realpos += wcwidth( wstr[t] ); + + wstr.erase( tpos, 1 ); + + hotk = wstr[tpos]; + + hotp = realpos; } - - size_t realpos = 0, t; - - for ( t = 0; t < tpos; t++ ) - realpos += wcwidth( wstr[t] ); - - wstr.erase( tpos, 1 ); - - hotk = wstr[tpos]; - - hotp = realpos; + } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
kmachalkova@svn.opensuse.org