diff --git a/escher/include/escher/text_input_helpers.h b/escher/include/escher/text_input_helpers.h index 219eaba74..8eab24830 100644 --- a/escher/include/escher/text_input_helpers.h +++ b/escher/include/escher/text_input_helpers.h @@ -2,10 +2,11 @@ #define ESCHER_TEXT_INPUT_HELPERS_H #include +#include 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) diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index afb3f773a..40eeda119 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -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]; diff --git a/escher/src/text_input_helpers.cpp b/escher/src/text_input_helpers.cpp index 3a878afbe..a9600b62b 100644 --- a/escher/src/text_input_helpers.cpp +++ b/escher/src/text_input_helpers.cpp @@ -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; } }