- const size_t len = label.length();
- wxString labelGTK;
- labelGTK.reserve(len);
- for ( size_t i = 0; i < len; i++ )
- {
- wxChar ch = label[i];
-
- switch ( ch )
- {
- case wxT('&'):
- if ( i == len - 1 )
- {
- // "&" at the end of string is an error
- wxLogDebug(wxT("Invalid label \"%s\"."), label.c_str());
- break;
- }
-
- ch = label[++i]; // skip '&' itself
- switch ( ch )
- {
- case wxT('&'):
- // special case: "&&" is not a mnemonic at all but just
- // an escaped "&"
- labelGTK += wxT('&');
- break;
-
- case wxT('_'):
- if ( flag == MNEMONICS_CONVERT )
- {
- // '_' can't be a GTK mnemonic apparently so
- // replace it with something similar
- labelGTK += wxT("_-");
- break;
- }
- //else: fall through
-
- default:
- if ( flag == MNEMONICS_CONVERT )
- labelGTK += wxT('_');
- labelGTK += ch;
- }
- break;
-
- case wxT('_'):
- if ( flag == MNEMONICS_CONVERT )
- {
- // escape any existing underlines in the string so that
- // they don't become mnemonics accidentally
- labelGTK += wxT("__");
- break;
- }
- //else: fall through
-
- default:
- labelGTK += ch;
- }
- }