commit 227d1f4e
The keyboard reader now has basic knowledge of UTF-8. Although it cannot be rendered at the moment
Changed files
| M | .travis.yml before |
| M | README.md before |
| M | source/code/ReadKeyboard.cpp before |
diff --git a/.travis.yml b/.travis.yml
index a80311a..340a67a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,6 +16,7 @@ addons:
- libphysfs-dev
- libboost1.55-dev
- scons
+ - libutfcpp-dev
cache:
apt: true
diff --git a/README.md b/README.md
index bf1378a..8c63982 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ A Tetris Attack Clone under the GPL.
* libenet
* libphysfs
* libboost (only needed for compiling)
+ * libutfcpp (only needed for compiling)
# Building
To build do:
diff --git a/source/code/ReadKeyboard.cpp b/source/code/ReadKeyboard.cpp
index be81726..0b70924 100644
--- a/source/code/ReadKeyboard.cpp
+++ b/source/code/ReadKeyboard.cpp
@@ -22,7 +22,7 @@ http://blockattack.sf.net
*/
#include "ReadKeyboard.h"
-
+#include "utf8.h"
using namespace std;
@@ -48,14 +48,16 @@ ReadKeyboard::ReadKeyboard(const char* oldName) {
void ReadKeyboard::putchar(char thing) {
if (text_string.length() < maxLength) {
text_string.insert(position, thing);
- position++;
+ utf8::advance(position, 1, text_string.end());
}
}
void ReadKeyboard::removeChar() {
if (position < text_string.end()) {
- text_string.erase(position);
+ string::iterator endChar= position;
+ utf8::advance(endChar, 1, text_string.end());
+ text_string.erase(position, endChar);
}
}
@@ -86,7 +88,7 @@ bool ReadKeyboard::ReadKey(SDLKey keyPressed) {
}
if (keyPressed == SDLK_BACKSPACE) {
if (position>text_string.begin()) {
- position--;
+ utf8::prior(position, text_string.begin());
ReadKeyboard::removeChar();
return true;
}
@@ -101,11 +103,11 @@ bool ReadKeyboard::ReadKey(SDLKey keyPressed) {
return true;
}
if ((keyPressed == SDLK_LEFT) && (position>text_string.begin())) {
- position--;
+ utf8::prior(position, text_string.begin());
return true;
}
if ((keyPressed == SDLK_RIGHT) && (position<text_string.end())) {
- position++;
+ utf8::next(position, text_string.end());
return true;
}
return true;