Skip to content

Commit

Permalink
Andreas Krennmair:
Browse files Browse the repository at this point in the history
	improved key mapping and entity decoding
  • Loading branch information
akrennmair committed Dec 7, 2006
1 parent 99de485 commit 4aefcf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/keymap.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <keymap.h>
#include <vector>
#include <iostream>

namespace noos {

Expand Down Expand Up @@ -44,7 +45,6 @@ operation keymap::get_opcode(const std::string& opstr) {
}

operation keymap::get_operation(const std::string& keycode) {
// TODO: decode ctrl combinations
std::string key;
if (keycode.length() > 0) {
if (keycode == "ENTER") {
Expand All @@ -58,8 +58,16 @@ operation keymap::get_operation(const std::string& keycode) {
unsigned int x;
char c;
sscanf(keycode.c_str(),"CHAR(%d)",&x);
c = static_cast<char>(x);
key.append(1,c);
// std::cerr << x << std::endl;
if (x >= 32 && x <= 126) {
c = static_cast<char>(x);
key.append(1,c);
} else if (x >= 0 && x<=26) {
key.append("^");
key.append(1,static_cast<char>(0x60 + x));
} else {
// TODO: handle special keys
}
}
} else {
key = "NIL";
Expand Down
18 changes: 12 additions & 6 deletions src/xmlpullparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <istream>
#include <sstream>
#include <iostream>
#include <cstdlib>

namespace noos
{
Expand Down Expand Up @@ -91,6 +92,7 @@ xmlpullparser::event xmlpullparser::next() {
getline(*inputstream,tmp,'<');
remove_trailing_whitespace(tmp);
text.append(tmp);
text = decode_entities(text);
current_event = TEXT;
} else {
std::string s;
Expand Down Expand Up @@ -310,18 +312,22 @@ std::string xmlpullparser::decode_entity(std::string s) {
return "&";
} else if (s.length() > 1 && s[0] == '#') {
std::string result;
unsigned int wc;
char mbc[MB_CUR_MAX];
if (s[1] == 'x') {
s.erase(0,2);
std::istringstream is(s);
unsigned int i;
is >> std::hex >> i;
result.append(1,static_cast<char>(i));
is >> std::hex >> wc;
} else {
s.erase(0,1);
std::istringstream is(s);
unsigned int i;
is >> i;
result.append(1,static_cast<char>(i));
is >> wc;
}
int pos = wctomb(mbc,static_cast<wchar_t>(wc));
// std::cerr << "value: " << wc << " " << static_cast<wchar_t>(wc) << " pos: " << pos << std::endl;
if (pos > 0) {
mbc[pos] = '\0';
result.append(mbc);
}
return result;
}
Expand Down

0 comments on commit 4aefcf4

Please sign in to comment.