diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 147bf923c..e80f66836 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -34,7 +34,7 @@ public: /* Simplification */ Expression shallowReduce(ReductionContext reductionContext) override; Expression shallowReplaceReplaceableSymbols(Context * context) override; - LayoutShape leftLayoutShape() const override { return strlen(m_name) > 1 ? LayoutShape::MoreLetters : LayoutShape::OneLetter; }; + LayoutShape leftLayoutShape() const override; /* Approximation */ Evaluation approximate(SinglePrecision p, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, complexFormat, angleUnit); } diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 1062d1e67..625523b2d 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -107,6 +107,15 @@ Expression SymbolNode::shallowReplaceReplaceableSymbols(Context * context) { return Symbol(this).shallowReplaceReplaceableSymbols(context); } +ExpressionNode::LayoutShape SymbolNode::leftLayoutShape() const { + UTF8Decoder decoder(m_name); + decoder.nextCodePoint(); + if (decoder.nextCodePoint() == UCodePointNull) { // nextCodePoint asserts that the first character is non-null + return LayoutShape::OneLetter; + } + return LayoutShape::MoreLetters; +} + template Evaluation SymbolNode::templatedApproximate(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { Symbol s(this);