#223 Key codes in config file cannot be set to "none"

Gilles Reeves

This is a small bug in PearPc that I found :

Key codes defined in the PearPc's config file cannot be
set to "none".

However, if you look at the "convertStringToKeycode"
function in the file "system/keyboard.cc", you can see
the following code (lines 111 to 114), that is, as
evident, a provision for having the "none" value

if (s == (String)"none") {
keycode = 0xff;
return true;

But when tracing this code after putting the value
"none" in the String variable "s", the condition still
executes as "false".

If you reverse the test, defining it as : 'if
((String)"none" == s)', or if you cast it as 'if
((String)s == (String)"none")', it works correctly.

But the real reason is in the file "tools/str.h", line
113, where the class "String" is defined:
The function "operator ==" is not defined as "const"!

That means that this operator cannot be called if its
left argument is defined as "const String" (instead of
"String") because it is expected that its argument
could be modified by calling the definition of
"operator ==".

So the comparison above is executed on pointers after
converting the two "String" values to "const char *"
instead of comparing the contents of the two strings.
The result is not the one expected.

For correcting this problem, the definition on line 113 :
inline bool operator ==(const String &s);
should be replaced by
inline bool operator ==(const String &s) const;

... along with its definition, on line 265 of the same

This is also true with all other five comparison
operators in this "String" class, that would also
have to be corrected, on lines 109, 110, 111, 112, 114,
245, 250, 255, 260 and 270 of the file "tools/str.h".

Note that this is a problem that can potentially (and
maybe effectively in some unknown place...) affect all
other strings comparisons using the class "String" in
PearPc, not only the key codes in the config file.