From f90e709201abc2fc40e9381366800ea18ac2e297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 18 Jan 2019 10:29:10 +0100 Subject: [PATCH] [poincare/utf8_decoder] nextCodePointPointer is now stringPosition --- apps/shared/toolbox_helpers.cpp | 4 ++-- escher/src/text_input_helpers.cpp | 6 +++--- kandinsky/include/kandinsky/unicode/utf8_decoder.h | 4 +--- kandinsky/src/unicode/utf8_decoder.cpp | 4 ---- kandinsky/src/unicode/utf8_helper.cpp | 8 ++++---- poincare/src/layout_helper.cpp | 6 +++--- poincare/src/parsing/tokenizer.cpp | 6 +++--- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/apps/shared/toolbox_helpers.cpp b/apps/shared/toolbox_helpers.cpp index 9952847f6..10fb4a95b 100644 --- a/apps/shared/toolbox_helpers.cpp +++ b/apps/shared/toolbox_helpers.cpp @@ -11,8 +11,8 @@ int CursorIndexInCommandText(const char * text) { UTF8Decoder decoder(text); size_t index = 0; const char * currentPointer = text; - const char * nextPointer = decoder.nextCodePointPointer(); CodePoint codePoint = decoder.nextCodePoint(); + const char * nextPointer = decoder.stringPosition(); while (codePoint != KDCodePointNull) { if (codePoint == '(' || codePoint == '\'') { return index + 1; @@ -22,8 +22,8 @@ int CursorIndexInCommandText(const char * text) { } index+= nextPointer - currentPointer; currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); } return index; } diff --git a/escher/src/text_input_helpers.cpp b/escher/src/text_input_helpers.cpp index d6d39c632..5a653c3d3 100644 --- a/escher/src/text_input_helpers.cpp +++ b/escher/src/text_input_helpers.cpp @@ -8,8 +8,8 @@ size_t CursorIndexInCommand(const char * text) { size_t index = 0; UTF8Decoder decoder(text); const char * currentPointer = text; - const char * nextPointer = decoder.nextCodePointPointer(); CodePoint codePoint = decoder.nextCodePoint(); + const char * nextPointer = decoder.stringPosition(); while (codePoint != KDCodePointNull) { if (codePoint == KDCodePointEmpty) { return index; @@ -18,8 +18,8 @@ size_t CursorIndexInCommand(const char * text) { if (codePoint == '\'') { index+= nextPointer - currentPointer; currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); if (codePoint == '\'') { return index; } @@ -28,8 +28,8 @@ size_t CursorIndexInCommand(const char * text) { } index+= nextPointer - currentPointer; currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); } return index; } diff --git a/kandinsky/include/kandinsky/unicode/utf8_decoder.h b/kandinsky/include/kandinsky/unicode/utf8_decoder.h index 1f52cccb4..084765b9f 100644 --- a/kandinsky/include/kandinsky/unicode/utf8_decoder.h +++ b/kandinsky/include/kandinsky/unicode/utf8_decoder.h @@ -18,10 +18,8 @@ class UTF8Decoder { public: UTF8Decoder(const char * string) : m_string(string) {} - /* TODO: Rename methods? nextCodePoint increases m_string but - * nextCodePointPointer does not */ CodePoint nextCodePoint(); - const char * nextCodePointPointer(); + const char * stringPosition() const { return m_string; } static size_t CharSizeOfCodePoint(CodePoint c); static size_t CodePointToChars(CodePoint c, char * buffer, int bufferSize); private: diff --git a/kandinsky/src/unicode/utf8_decoder.cpp b/kandinsky/src/unicode/utf8_decoder.cpp index 288fcea92..5b23cbdb2 100644 --- a/kandinsky/src/unicode/utf8_decoder.cpp +++ b/kandinsky/src/unicode/utf8_decoder.cpp @@ -25,10 +25,6 @@ CodePoint UTF8Decoder::nextCodePoint() { return CodePoint(result); } -const char * UTF8Decoder::nextCodePointPointer() { - return m_string + leading_ones(*m_string); -} - size_t UTF8Decoder::CharSizeOfCodePoint(CodePoint c) { constexpr int bufferSize = CodePoint::MaxCodePointCharLength; char buffer[bufferSize]; diff --git a/kandinsky/src/unicode/utf8_helper.cpp b/kandinsky/src/unicode/utf8_helper.cpp index 3293e14fd..da2d47f2b 100644 --- a/kandinsky/src/unicode/utf8_helper.cpp +++ b/kandinsky/src/unicode/utf8_helper.cpp @@ -10,12 +10,12 @@ static inline int min(int x, int y) { return x < y ? x : y; } const char * CodePointSearch(const char * s, CodePoint c) { UTF8Decoder decoder(s); const char * currentPointer = s; - const char * nextPointer = decoder.nextCodePointPointer(); CodePoint codePoint = decoder.nextCodePoint(); + const char * nextPointer = decoder.stringPosition(); while (codePoint != KDCodePointNull && codePoint != c) { currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); } if (codePoint == c) { return currentPointer; @@ -26,9 +26,9 @@ const char * CodePointSearch(const char * s, CodePoint c) { void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c, size_t * indexToUpdate) { UTF8Decoder decoder(src); const char * currentPointer = src; - const char * nextPointer = decoder.nextCodePointPointer(); const char * maxPointer = src + strlen(src) + 1; CodePoint codePoint = decoder.nextCodePoint(); + const char * nextPointer = decoder.stringPosition(); size_t bufferIndex = 0; size_t codePointCharSize = UTF8Decoder::CharSizeOfCodePoint(c); @@ -43,8 +43,8 @@ void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePo *indexToUpdate-= codePointCharSize; } currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); } } diff --git a/poincare/src/layout_helper.cpp b/poincare/src/layout_helper.cpp index fd7919243..2b41a2b45 100644 --- a/poincare/src/layout_helper.cpp +++ b/poincare/src/layout_helper.cpp @@ -59,8 +59,8 @@ HorizontalLayout LayoutHelper::String(const char * buffer, int bufferLen, const HorizontalLayout resultLayout = HorizontalLayout::Builder(); UTF8Decoder decoder(buffer); const char * currentPointer = buffer; - const char * nextPointer = decoder.nextCodePointPointer(); CodePoint codePoint = decoder.nextCodePoint(); + const char * nextPointer = decoder.stringPosition(); assert(!codePoint.isCombining()); int layoutIndex = 0; int bufferIndex = 0; @@ -69,13 +69,13 @@ HorizontalLayout LayoutHelper::String(const char * buffer, int bufferLen, const layoutIndex++; bufferIndex+= nextPointer - currentPointer; currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); while (codePoint.isCombining()) { bufferIndex+= nextPointer - currentPointer; currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); } } return resultLayout; diff --git a/poincare/src/parsing/tokenizer.cpp b/poincare/src/parsing/tokenizer.cpp index d1812f48d..ea30387a4 100644 --- a/poincare/src/parsing/tokenizer.cpp +++ b/poincare/src/parsing/tokenizer.cpp @@ -15,18 +15,18 @@ static inline bool isDigit(const CodePoint c) { const CodePoint Tokenizer::nextCodePoint(PopTest popTest, CodePoint context, bool * testResult) { UTF8Decoder decoder(m_text); const char * currentPointer = m_text; - const char * nextPointer = decoder.nextCodePointPointer(); CodePoint firstCodePoint = decoder.nextCodePoint(); + const char * nextPointer = decoder.stringPosition(); size_t numberOfBytesForCodePoint = nextPointer - currentPointer; if (firstCodePoint != KDCodePointNull) { currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); CodePoint codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); while (codePoint.isCombining()) { numberOfBytesForCodePoint+= nextPointer - currentPointer; currentPointer = nextPointer; - nextPointer = decoder.nextCodePointPointer(); codePoint = decoder.nextCodePoint(); + nextPointer = decoder.stringPosition(); } } // TODO handle combined code points? For now the combining codepoints get dropped.