[escher] Fix signed/unsigned int comparison

Change-Id: I72b6dc3f46ee585814a540fc999001e113db0ea1
This commit is contained in:
Léa Saviot
2018-05-16 16:15:17 +02:00
committed by EmilieNumworks
parent 96310c75c8
commit 0294ebc448
3 changed files with 12 additions and 10 deletions

View File

@@ -2,10 +2,11 @@
#define ESCHER_TEXT_INPUT_HELPERS_H
#include <escher/i18n.h>
#include <stddef.h>
namespace TextInputHelpers {
int CursorIndexInCommand(const char * text);
size_t CursorIndexInCommand(const char * text);
/* Returns the index of the cursor position in a Command, which is the smallest
* index between :
* - The first EmptyChar index (which is the position of the first argument)

View File

@@ -294,7 +294,7 @@ TextArea::TextArea(Responder * parentResponder, char * textBuffer,
bool TextArea::handleEventWithText(const char * text, bool indentation) {
int nextCursorLocation = cursorLocation();
int cursorIndexInCommand = TextInputHelpers::CursorIndexInCommand(text);
size_t cursorIndexInCommand = TextInputHelpers::CursorIndexInCommand(text);
size_t eventTextSize = strlen(text) + 1;
char buffer[eventTextSize];

View File

@@ -4,16 +4,17 @@
namespace TextInputHelpers {
int CursorIndexInCommand(const char * text) {
int textLength = strlen(text);
for (int i = 0; i < textLength - 1; i++) {
if (text[i] == '\'' && text[i+1] == '\'') {
return i + 1;
} else if (text[i] == Ion::Charset::Empty) {
return i;
size_t CursorIndexInCommand(const char * text) {
size_t index = 0;
while (text[index] != 0) {
if (text[index] == '\'' && text[index+1] == '\'') {
return index + 1;
} else if (text[index] == Ion::Charset::Empty) {
return index;
}
index++;
}
return textLength;
return index;
}
}