From aac78ca32a547653ef8e760e149233ec10f81fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 24 Jan 2019 11:06:07 +0100 Subject: [PATCH] [escher/ion] Standard methods in UTF8Helper used in text_area String manipulations need to be done using an UTF8 decoder, but some manipulations can be optimized if the code points we manipulate are only one char long. These optimizations are done inside UTF8Helper methods. --- apps/solver/equation.cpp | 2 +- escher/include/escher/text_area.h | 2 +- escher/src/text_area.cpp | 67 +++++++++------- ion/include/ion/unicode/utf8_helper.h | 29 ++++++- ion/src/shared/unicode/utf8_helper.cpp | 103 +++++++++++++++++++++---- poincare/src/expression.cpp | 2 +- 6 files changed, 153 insertions(+), 52 deletions(-) diff --git a/apps/solver/equation.cpp b/apps/solver/equation.cpp index df6212056..fa10a8c09 100644 --- a/apps/solver/equation.cpp +++ b/apps/solver/equation.cpp @@ -50,7 +50,7 @@ Expression Equation::standardForm(Context * context) const { } bool Equation::containsIComplex() const { - return UTF8Helper::CodePointSearch(text(), UCodePointMathematicalBoldSmallI) != nullptr; + return *(UTF8Helper::CodePointSearch(text(), UCodePointMathematicalBoldSmallI)) != 0; } void Equation::tidyStandardForm() { diff --git a/escher/include/escher/text_area.h b/escher/include/escher/text_area.h index 0f9fa8b77..d861d27e3 100644 --- a/escher/include/escher/text_area.h +++ b/escher/include/escher/text_area.h @@ -30,7 +30,7 @@ protected: m_buffer = buffer; m_bufferSize = bufferSize; } - const char * text() const { return const_cast(m_buffer); } + const char * text() const { return m_buffer; } class Line { public: diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index 9be7ccf52..cddf40b23 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -99,8 +99,8 @@ void TextArea::setText(char * textBuffer, size_t textBufferSize) { bool TextArea::insertTextWithIndentation(const char * textBuffer, const char * location) { // Compute the indentation int indentation = indentationBeforeCursor(); - const char * previousChar = cursorLocation()-1; - if (previousChar >= const_cast