mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ion/kandinsky] Move unicode to ion
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "helpers.h"
|
||||
#include <string.h>
|
||||
#include <kandinsky/unicode/code_point.h>
|
||||
#include <ion/unicode/code_point.h>
|
||||
#include <ion.h>
|
||||
|
||||
namespace Code {
|
||||
@@ -16,7 +16,7 @@ private:
|
||||
const char * m_text;
|
||||
};
|
||||
|
||||
static_assert('\x11' == KDCodePointEmpty, "Unicode error");
|
||||
static_assert('\x11' == UCodePointEmpty, "Unicode error");
|
||||
static constexpr EventTextPair sEventTextMap[] = {
|
||||
EventTextPair(Ion::Events::XNT, "x"),
|
||||
EventTextPair(Ion::Events::Exp, "exp(\x11)"),
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
void reloadCell() override;
|
||||
const char * text() const override { return m_scriptNodeView.text(); }
|
||||
|
||||
static_assert('\x11' == KDCodePointEmpty, "Unicode error");
|
||||
static_assert('\x11' == UCodePointEmpty, "Unicode error");
|
||||
constexpr static char k_parentheses[] = "()";
|
||||
constexpr static char k_parenthesesWithEmpty[] = "(\x11)";
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using namespace Poincare;
|
||||
namespace Graph {
|
||||
|
||||
IntegralGraphController::IntegralGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, GraphView * graphView, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor) :
|
||||
StorageSumGraphController(parentResponder, inputEventHandlerDelegate, graphView, graphRange, cursor, KDCodePointIntegral)
|
||||
StorageSumGraphController(parentResponder, inputEventHandlerDelegate, graphView, graphRange, cursor, UCodePointIntegral)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ Layout CubicModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('3', KDFont::SmallFont),
|
||||
@@ -29,7 +29,7 @@ Layout CubicModel::layout() {
|
||||
),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('2', KDFont::SmallFont),
|
||||
@@ -37,7 +37,7 @@ Layout CubicModel::layout() {
|
||||
),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('c', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('d', KDFont::SmallFont),
|
||||
|
||||
@@ -13,12 +13,12 @@ Layout ExponentialModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('e', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
HorizontalLayout::Builder(
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont)
|
||||
),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
|
||||
@@ -13,7 +13,7 @@ Layout LinearModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
|
||||
@@ -13,7 +13,7 @@ Layout LogarithmicModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('l', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('n', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('(', KDFont::SmallFont),
|
||||
|
||||
@@ -15,14 +15,14 @@ Layout LogisticModel::layout() {
|
||||
Layout exponentLayoutChildren[] = {
|
||||
CodePointLayout::Builder('-', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont)
|
||||
};
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('1', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('e', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
HorizontalLayout::Builder(exponentLayoutChildren, 4),
|
||||
|
||||
@@ -14,7 +14,7 @@ Layout PowerModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
|
||||
@@ -21,7 +21,7 @@ Layout QuadraticModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('2', KDFont::SmallFont),
|
||||
@@ -29,7 +29,7 @@ Layout QuadraticModel::layout() {
|
||||
),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('c', KDFont::SmallFont),
|
||||
|
||||
@@ -21,7 +21,7 @@ Layout QuarticModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('4', KDFont::SmallFont),
|
||||
@@ -29,7 +29,7 @@ Layout QuarticModel::layout() {
|
||||
),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('3', KDFont::SmallFont),
|
||||
@@ -37,7 +37,7 @@ Layout QuarticModel::layout() {
|
||||
),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('c', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('2', KDFont::SmallFont),
|
||||
@@ -45,7 +45,7 @@ Layout QuarticModel::layout() {
|
||||
),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('d', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('e', KDFont::SmallFont),
|
||||
|
||||
@@ -22,13 +22,13 @@ Layout TrigonometricModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
Layout layoutChildren[] = {
|
||||
CodePointLayout::Builder('a', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('s', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('i', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('n', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('(', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('b', KDFont::SmallFont),
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot, KDFont::SmallFont),
|
||||
CodePointLayout::Builder('X', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('+', KDFont::SmallFont),
|
||||
CodePointLayout::Builder('c', KDFont::SmallFont),
|
||||
|
||||
@@ -18,7 +18,7 @@ using namespace Poincare;
|
||||
namespace Sequence {
|
||||
|
||||
TermSumController::TermSumController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, GraphView * graphView, CurveViewRange * graphRange, CurveViewCursor * cursor) :
|
||||
SumGraphController(parentResponder, inputEventHandlerDelegate, graphView, graphRange, cursor, KDCodePointNArySummation)
|
||||
SumGraphController(parentResponder, inputEventHandlerDelegate, graphView, graphRange, cursor, UCodePointNArySummation)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ void StorageSumGraphController::LegendView::setEditableZone(double d) {
|
||||
void StorageSumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, Layout functionLayout) {
|
||||
assert(step == Step::Result || functionLayout.isUninitialized());
|
||||
constexpr int sigmaLength = 2;
|
||||
const CodePoint sigma[sigmaLength] = {KDCodePointSpace, m_sumSymbol};
|
||||
const CodePoint sigma[sigmaLength] = {UCodePointSpace, m_sumSymbol};
|
||||
if (step == Step::FirstParameter) {
|
||||
m_sumLayout = LayoutHelper::CodePointString(sigma, sigmaLength);
|
||||
} else if (step == Step::SecondParameter) {
|
||||
|
||||
@@ -234,7 +234,7 @@ void SumGraphController::LegendView::setEditableZone(double d) {
|
||||
void SumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, Layout functionLayout) {
|
||||
assert(step == Step::Result || functionLayout.isUninitialized());
|
||||
constexpr int sigmaSize = 2;
|
||||
const CodePoint sigma[sigmaSize] = {KDCodePointSpace, m_sumSymbol};
|
||||
const CodePoint sigma[sigmaSize] = {UCodePointSpace, m_sumSymbol};
|
||||
if (step == Step::FirstParameter) {
|
||||
m_sumLayout = LayoutHelper::CodePointString(sigma, sigmaSize);
|
||||
} else if (step == Step::SecondParameter) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "text_field_delegate_app.h"
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <apps/apps_container.h>
|
||||
#include <apps/constant.h>
|
||||
#include <apps/shared/poincare_helpers.h>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "toolbox_helpers.h"
|
||||
#include <apps/i18n.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -13,7 +13,7 @@ int CursorIndexInCommandText(const char * text) {
|
||||
const char * currentPointer = text;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
while (codePoint != KDCodePointNull) {
|
||||
while (codePoint != UCodePointNull) {
|
||||
if (codePoint == '(' || codePoint == '\'') {
|
||||
return index + 1;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ void TextToInsertForCommandText(const char * command, char * buffer, int bufferS
|
||||
buffer[currentNewTextIndex++] = command[i];
|
||||
} else {
|
||||
if (replaceArgsWithEmptyChar && !argumentAlreadyReplaced) {
|
||||
currentNewTextIndex += UTF8Decoder::CodePointToChars(KDCodePointEmpty, buffer + currentNewTextIndex, bufferSize - currentNewTextIndex);
|
||||
currentNewTextIndex += UTF8Decoder::CodePointToChars(UCodePointEmpty, buffer + currentNewTextIndex, bufferSize - currentNewTextIndex);
|
||||
argumentAlreadyReplaced = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/unreal.h>
|
||||
#include <poincare/rational.h>
|
||||
#include <kandinsky/unicode/utf8_helper.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
@@ -50,7 +50,7 @@ Expression Equation::standardForm(Context * context) const {
|
||||
}
|
||||
|
||||
bool Equation::containsIComplex() const {
|
||||
return UTF8Helper::CodePointSearch(text(), KDCodePointMathematicalBoldSmallI) != nullptr;
|
||||
return UTF8Helper::CodePointSearch(text(), UCodePointMathematicalBoldSmallI) != nullptr;
|
||||
}
|
||||
|
||||
void Equation::tidyStandardForm() {
|
||||
|
||||
@@ -325,7 +325,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
// C = Root((delta1+sqrt(-27a^2*delta))/2, 3)
|
||||
Expression * mult11Operands[3] = {new Rational::Builder(-27), new Power::Builder(a->clone(), new Rational::Builder(2), false), (*delta)->clone()};
|
||||
Expression * c = new Power::Builder(new Division::Builder(new Addition(delta1, new SquareRoot(new Multiplication::Builder(mult11Operands, 3, false), false), false), new Rational::Builder(2), false), new Rational::Builder(1,3), false);
|
||||
Expression * unary3roots[2] = {new Addition(new Rational::Builder(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational::Builder(3), false), new Constant::Builder(KDCodePointMathematicalBoldSmallI), false), new Rational::Builder(2), false), false), new Subtraction::Builder(new Rational::Builder(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational::Builder(3), false), new Constant::Builder(KDCodePointMathematicalBoldSmallI), false), new Rational::Builder(2), false), false)};
|
||||
Expression * unary3roots[2] = {new Addition(new Rational::Builder(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational::Builder(3), false), new Constant::Builder(UCodePointMathematicalBoldSmallI), false), new Rational::Builder(2), false), false), new Subtraction::Builder(new Rational::Builder(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational::Builder(3), false), new Constant::Builder(UCodePointMathematicalBoldSmallI), false), new Rational::Builder(2), false), false)};
|
||||
// x_k = -1/(3a)*(b+C*z+delta0/(zC)) with z = unary cube root
|
||||
for (int k = 0; k < 3; k++) {
|
||||
Expression * ccopy = c;
|
||||
|
||||
@@ -112,10 +112,10 @@ QUIZ_CASE(equation_solve) {
|
||||
const char * solutions10[] = {"1", "0"};
|
||||
assert_equation_system_exact_solve_to(equations10, EquationStore::Error::NoError, EquationStore::Type::PolynomialMonovariable, (const char **)variablesx, solutions10, 2);
|
||||
|
||||
quiz_assert(KDCodePointLeftSuperscript == '\022');
|
||||
quiz_assert(KDCodePointLeftSuperscript == '\x12');
|
||||
quiz_assert(KDCodePointRightSuperscript == '\023');
|
||||
quiz_assert(KDCodePointRightSuperscript == '\x13');
|
||||
quiz_assert(UCodePointLeftSuperscript == '\022');
|
||||
quiz_assert(UCodePointLeftSuperscript == '\x12');
|
||||
quiz_assert(UCodePointRightSuperscript == '\023');
|
||||
quiz_assert(UCodePointRightSuperscript == '\x13');
|
||||
|
||||
// x^2+x+1=3×x^2+pi×x-√(5)
|
||||
const char * equations11[] = {"x^2+x+1=3×x^2+π×x-√(5)", 0};
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <assert.h>
|
||||
#include <poincare/matrix_layout.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Shared;
|
||||
@@ -200,7 +200,7 @@ bool VariableBoxController::selectLeaf(int selectedRow) {
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
nameToHandle[nameLength++] = '(';
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
nameLength+= UTF8Decoder::CodePointToChars(KDCodePointEmpty, nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
nameLength+= UTF8Decoder::CodePointToChars(UCodePointEmpty, nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
nameToHandle[nameLength++] = ')';
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <ion.h>
|
||||
#include <escher/input_event_handler.h>
|
||||
#include <kandinsky/unicode/code_point.h>
|
||||
#include <ion/unicode/code_point.h>
|
||||
|
||||
class EditableField : public InputEventHandler {
|
||||
public:
|
||||
|
||||
@@ -70,7 +70,7 @@ void LayoutField::ContentView::layoutCursorSubview() {
|
||||
|
||||
CodePoint LayoutField::XNTCodePoint(CodePoint defaultXNTCodePoint) {
|
||||
CodePoint xnt = m_contentView.cursor()->layoutReference().XNTCodePoint();
|
||||
if (xnt != KDCodePointNull) {
|
||||
if (xnt != UCodePointNull) {
|
||||
return xnt;
|
||||
}
|
||||
return defaultXNTCodePoint;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <escher/text_area.h>
|
||||
#include <escher/clipboard.h>
|
||||
#include <escher/text_input_helpers.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <kandinsky/unicode/utf8_helper.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
@@ -29,7 +29,7 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for
|
||||
char buffer[bufferSize];
|
||||
|
||||
// Remove the Empty code points
|
||||
UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, text, KDCodePointEmpty, &cursorPositionInCommand);
|
||||
UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, text, UCodePointEmpty, &cursorPositionInCommand);
|
||||
|
||||
// Insert the text
|
||||
if ((indentation && insertTextWithIndentation(buffer, cursorTextLocation())) || insertTextAtLocation(buffer, cursorTextLocation())) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <escher/text_field.h>
|
||||
#include <escher/text_input_helpers.h>
|
||||
#include <escher/clipboard.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <kandinsky/unicode/utf8_helper.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <assert.h>
|
||||
|
||||
static inline int minInt(int x, int y) { return x < y ? x : y; }
|
||||
@@ -112,7 +112,7 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, const char
|
||||
const char * codePointPointer = decoder.stringPosition();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
assert(!codePoint.isCombining());
|
||||
while (codePoint != KDCodePointNull) {
|
||||
while (codePoint != UCodePointNull) {
|
||||
assert(codePointPointer < m_draftTextBuffer + m_textBufferSize);
|
||||
if (codePoint == '\n') {
|
||||
*(const_cast<char *>(codePointPointer)) = 0;
|
||||
@@ -464,7 +464,7 @@ bool TextField::handleEventWithText(const char * eventText, bool indentation, bo
|
||||
// Remove the Empty code points
|
||||
constexpr int bufferSize = TextField::maxBufferSize();
|
||||
char buffer[bufferSize];
|
||||
UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, eventText, KDCodePointEmpty);
|
||||
UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, eventText, UCodePointEmpty);
|
||||
|
||||
const char * nextCursorLocation = m_contentView.draftTextBuffer() + draftTextLength();
|
||||
if (insertTextAtLocation(buffer, cursorTextLocation())) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <escher/text_input_helpers.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace TextInputHelpers {
|
||||
@@ -8,8 +8,8 @@ const char * CursorPositionInCommand(const char * text) {
|
||||
UTF8Decoder decoder(text);
|
||||
const char * currentPointer = text;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
while (codePoint != KDCodePointNull) {
|
||||
if (codePoint == KDCodePointEmpty) {
|
||||
while (codePoint != UCodePointNull) {
|
||||
if (codePoint == UCodePointEmpty) {
|
||||
return currentPointer;
|
||||
}
|
||||
//TODO make sure changing empty / ' order was OK
|
||||
|
||||
@@ -22,6 +22,8 @@ src += $(addprefix ion/src/shared/, \
|
||||
events.cpp \
|
||||
platform_info.cpp \
|
||||
storage.cpp \
|
||||
unicode/utf8_decoder.cpp\
|
||||
unicode/utf8_helper.cpp\
|
||||
)
|
||||
|
||||
src += ion/src/external/lz4/lz4.c
|
||||
@@ -31,4 +33,5 @@ tests += $(addprefix ion/test/,\
|
||||
events.cpp\
|
||||
keyboard.cpp\
|
||||
storage.cpp\
|
||||
utf8_decoder.cpp\
|
||||
)
|
||||
|
||||
53
ion/include/ion/unicode/code_point.h
Normal file
53
ion/include/ion/unicode/code_point.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef ION_UNICODE_CODE_POINT_H
|
||||
#define ION_UNICODE_CODE_POINT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class CodePoint {
|
||||
public:
|
||||
constexpr static int MaxCodePointCharLength = sizeof(uint32_t) / sizeof(char);
|
||||
constexpr CodePoint(uint32_t c) : m_code(c) {}
|
||||
constexpr operator uint32_t() const { return m_code; }
|
||||
|
||||
bool isCombining() const {
|
||||
return (m_code >= 0x300 && m_code <= 0x036F);
|
||||
}
|
||||
private:
|
||||
uint32_t m_code;
|
||||
};
|
||||
|
||||
|
||||
// TODO LEA Remove unneeded values
|
||||
static constexpr CodePoint UCodePointNull = 0x0;
|
||||
static constexpr CodePoint UCodePointTabulation = 0x9;
|
||||
static constexpr CodePoint UCodePointLineFeed = 0xa;
|
||||
|
||||
/* 0x11, 0x12, 0x13, 0x14 represent DEVICE CONTROL ONE TO FOUR. They are not
|
||||
* used, so we can use them for another purpose */
|
||||
static constexpr CodePoint UCodePointEmpty = 0x11; // Used to be parsed into EmptyExpression
|
||||
static constexpr CodePoint UCodePointLeftSuperscript = 0x12; // Used to parse Power
|
||||
static constexpr CodePoint UCodePointRightSuperscript = 0x13; // Used to parse Power
|
||||
static constexpr CodePoint UCodePointUnknownX = 0x14; // Used to store expressions
|
||||
|
||||
static constexpr CodePoint UCodePointSpace = 0x20; //
|
||||
static constexpr CodePoint UCodePointDegree = 0xb0; // °
|
||||
static constexpr CodePoint UCodePointMiddleDot = 0xb7; // ·
|
||||
static constexpr CodePoint UCodePointMultiplicationSign = 0xd7; // ×
|
||||
static constexpr CodePoint UCodePointGreekCapitalLetterGamma = 0x393; // Γ
|
||||
static constexpr CodePoint UCodePointGreekCapitalLetterDelta = 0x394; // Δ
|
||||
static constexpr CodePoint UCodePointGreekSmallLetterTheta = 0x3b8; // θ
|
||||
static constexpr CodePoint UCodePointGreekSmallLetterLambda = 0x3bb; // λ
|
||||
static constexpr CodePoint UCodePointGreekSmallLetterPi = 0x3c0; // π
|
||||
static constexpr CodePoint UCodePointGreekSmallLetterSigma = 0x3c3; // σ
|
||||
static constexpr CodePoint UCodePointLatinLetterSmallCapitalE = 0x1d07; // ᴇ
|
||||
static constexpr CodePoint UCodePointScriptSmallE = 0x212f; // ℯ
|
||||
static constexpr CodePoint UCodePointRightwardsArrow = 0x2192; // →
|
||||
static constexpr CodePoint UCodePointNArySummation = 0x2211; // ∑
|
||||
static constexpr CodePoint UCodePointSquareRoot = 0x221a; // √
|
||||
static constexpr CodePoint UCodePointIntegral = 0x222b; // ∫
|
||||
static constexpr CodePoint UCodePointAlmostEqualTo = 0x2248; // ≈
|
||||
static constexpr CodePoint UCodePointLessThanOrEqualTo = 0x2264; // ≤
|
||||
static constexpr CodePoint UCodePointGreaterThanOrEqualTo = 0x2265; // ≥
|
||||
static constexpr CodePoint UCodePointMathematicalBoldSmallI = 0x1d422; // 𝐢
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef KANDINSKY_UNICODE_UTF8_DECODER_H
|
||||
#define KANDINSKY_UNICODE_UTF8_DECODER_H
|
||||
#ifndef ION_UNICODE_UTF8_DECODER_H
|
||||
#define ION_UNICODE_UTF8_DECODER_H
|
||||
|
||||
#include "code_point.h"
|
||||
#include <stddef.h>
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef KANDINSKY_UNICODE_UTF8_HELPER_H
|
||||
#define KANDINSKY_UNICODE_UTF8_HELPER_H
|
||||
#ifndef ION_UNICODE_UTF8_HELPER_H
|
||||
#define ION_UNICODE_UTF8_HELPER_H
|
||||
|
||||
#include "code_point.h"
|
||||
#include <stddef.h>
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <ion/events.h>
|
||||
#include <kandinsky/unicode/code_point.h>
|
||||
#include <ion/unicode/code_point.h>
|
||||
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
#define U() EventData::Undefined()
|
||||
#define T(x) EventData::Text(x)
|
||||
|
||||
static_assert('\x11' == KDCodePointEmpty, "Unicode error");
|
||||
static_assert('\x11' == UCodePointEmpty, "Unicode error");
|
||||
static constexpr EventData s_dataForEvent[4*Event::PageSize] = {
|
||||
// Plain
|
||||
TL(), TL(), TL(), TL(), TL(), TL(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <assert.h>
|
||||
|
||||
static inline int leading_ones(uint8_t value) {
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <kandinsky/unicode/utf8_helper.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -12,7 +12,7 @@ const char * CodePointSearch(const char * s, CodePoint c) {
|
||||
const char * currentPointer = s;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
while (codePoint != KDCodePointNull && codePoint != c) {
|
||||
while (codePoint != UCodePointNull && codePoint != c) {
|
||||
currentPointer = nextPointer;
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
15
ion/test/utf8_decoder.cpp
Normal file
15
ion/test/utf8_decoder.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <quiz.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
void assert_decodes_to(const char * string, CodePoint c) {
|
||||
UTF8Decoder d(string);
|
||||
quiz_assert(d.nextCodePoint() == c);
|
||||
quiz_assert(d.nextCodePoint() == 0);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_utf8_decoder) {
|
||||
assert_decodes_to("\x20", 0x20);
|
||||
assert_decodes_to("\xC2\xA2", 0xA2);
|
||||
assert_decodes_to("\xED\x9F\xBF", 0xD7FF);
|
||||
assert_decodes_to("\xCC\x81", 0x301);
|
||||
}
|
||||
@@ -13,8 +13,6 @@ src += $(addprefix kandinsky/src/,\
|
||||
ion_context.cpp \
|
||||
point.cpp \
|
||||
rect.cpp \
|
||||
unicode/utf8_decoder.cpp\
|
||||
unicode/utf8_helper.cpp\
|
||||
)
|
||||
|
||||
src += $(addprefix kandinsky/fonts/, \
|
||||
@@ -26,7 +24,6 @@ tests += $(addprefix kandinsky/test/,\
|
||||
color.cpp\
|
||||
font.cpp\
|
||||
rect.cpp\
|
||||
utf8_decoder.cpp\
|
||||
)
|
||||
|
||||
RASTERIZER_CFLAGS := -std=c99 `pkg-config freetype2 --cflags`
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <stddef.h>
|
||||
#include <kandinsky/size.h>
|
||||
#include <kandinsky/coordinate.h>
|
||||
#include <kandinsky/unicode/code_point.h>
|
||||
#include <ion/unicode/code_point.h>
|
||||
#include "palette.h"
|
||||
|
||||
/* We use UTF-8 encoding. This means that a character is encoded as a code point
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#ifndef KANDINSKY_UNICODE_CODE_POINT_H
|
||||
#define KANDINSKY_UNICODE_CODE_POINT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class CodePoint {
|
||||
public:
|
||||
constexpr static int MaxCodePointCharLength = sizeof(uint32_t) / sizeof(char);
|
||||
constexpr CodePoint(uint32_t c) : m_code(c) {}
|
||||
constexpr operator uint32_t() const { return m_code; }
|
||||
|
||||
bool isCombining() const {
|
||||
return (m_code >= 0x300 && m_code <= 0x036F);
|
||||
}
|
||||
private:
|
||||
uint32_t m_code;
|
||||
};
|
||||
|
||||
|
||||
// TODO LEA Remove unneeded values
|
||||
static constexpr CodePoint KDCodePointNull = 0x0;
|
||||
static constexpr CodePoint KDCodePointTabulation = 0x9;
|
||||
static constexpr CodePoint KDCodePointLineFeed = 0xa;
|
||||
|
||||
/* 0x11, 0x12, 0x13, 0x14 represent DEVICE CONTROL ONE TO FOUR. They are not
|
||||
* used, so we can use them for another purpose */
|
||||
static constexpr CodePoint KDCodePointEmpty = 0x11; // Used to be parsed into EmptyExpression
|
||||
static constexpr CodePoint KDCodePointLeftSuperscript = 0x12; // Used to parse Power
|
||||
static constexpr CodePoint KDCodePointRightSuperscript = 0x13; // Used to parse Power
|
||||
static constexpr CodePoint KDCodePointUnknownX = 0x14; // Used to store expressions
|
||||
|
||||
static constexpr CodePoint KDCodePointSpace = 0x20; //
|
||||
static constexpr CodePoint KDCodePointDegree = 0xb0; // °
|
||||
static constexpr CodePoint KDCodePointMiddleDot = 0xb7; // ·
|
||||
static constexpr CodePoint KDCodePointMultiplicationSign = 0xd7; // ×
|
||||
static constexpr CodePoint KDCodePointGreekCapitalLetterGamma = 0x393; // Γ
|
||||
static constexpr CodePoint KDCodePointGreekCapitalLetterDelta = 0x394; // Δ
|
||||
static constexpr CodePoint KDCodePointGreekSmallLetterTheta = 0x3b8; // θ
|
||||
static constexpr CodePoint KDCodePointGreekSmallLetterLambda = 0x3bb; // λ
|
||||
static constexpr CodePoint KDCodePointGreekSmallLetterPi = 0x3c0; // π
|
||||
static constexpr CodePoint KDCodePointGreekSmallLetterSigma = 0x3c3; // σ
|
||||
static constexpr CodePoint KDCodePointLatinLetterSmallCapitalE = 0x1d07; // ᴇ
|
||||
static constexpr CodePoint KDCodePointScriptSmallE = 0x212f; // ℯ
|
||||
static constexpr CodePoint KDCodePointRightwardsArrow = 0x2192; // →
|
||||
static constexpr CodePoint KDCodePointNArySummation = 0x2211; // ∑
|
||||
static constexpr CodePoint KDCodePointSquareRoot = 0x221a; // √
|
||||
static constexpr CodePoint KDCodePointIntegral = 0x222b; // ∫
|
||||
static constexpr CodePoint KDCodePointAlmostEqualTo = 0x2248; // ≈
|
||||
static constexpr CodePoint KDCodePointLessThanOrEqualTo = 0x2264; // ≤
|
||||
static constexpr CodePoint KDCodePointGreaterThanOrEqualTo = 0x2265; // ≥
|
||||
static constexpr CodePoint KDCodePointMathematicalBoldSmallI = 0x1d422; // 𝐢
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <assert.h>
|
||||
#include <kandinsky/context.h>
|
||||
#include <kandinsky/font.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
constexpr static int k_tabCharacterWidth = 4;
|
||||
|
||||
@@ -14,11 +14,11 @@ KDPoint KDContext::drawString(const char * text, KDPoint p, const KDFont * font,
|
||||
|
||||
UTF8Decoder decoder(text);
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
while (codePoint != KDCodePointNull) {
|
||||
if (codePoint == KDCodePointLineFeed) {
|
||||
while (codePoint != UCodePointNull) {
|
||||
if (codePoint == UCodePointLineFeed) {
|
||||
position = KDPoint(0, position.y() + glyphSize.height());
|
||||
codePoint = decoder.nextCodePoint();
|
||||
} else if (codePoint == KDCodePointTabulation) {
|
||||
} else if (codePoint == UCodePointTabulation) {
|
||||
position = position.translatedBy(KDPoint(k_tabCharacterWidth * glyphSize.width(), 0));
|
||||
codePoint = decoder.nextCodePoint();
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <assert.h>
|
||||
#include <kandinsky/font.h>
|
||||
#include <ion.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
constexpr static int k_tabCharacterWidth = 4;
|
||||
|
||||
@@ -14,11 +14,11 @@ KDSize KDFont::stringSizeUntil(const char * text, const char * limit) const {
|
||||
UTF8Decoder decoder(text);
|
||||
const char * currentStringPosition = decoder.stringPosition();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
while (codePoint != KDCodePointNull && (limit == nullptr || currentStringPosition < limit)) {
|
||||
while (codePoint != UCodePointNull && (limit == nullptr || currentStringPosition < limit)) {
|
||||
KDSize cSize = KDSize(m_glyphSize.width(), 0);
|
||||
if (codePoint == KDCodePointLineFeed) {
|
||||
if (codePoint == UCodePointLineFeed) {
|
||||
cSize = KDSize(0, m_glyphSize.height());
|
||||
} else if (codePoint == KDCodePointTabulation) {
|
||||
} else if (codePoint == UCodePointTabulation) {
|
||||
cSize = KDSize(k_tabCharacterWidth * m_glyphSize.width(), 0);
|
||||
} else if (codePoint.isCombining()) {
|
||||
cSize = KDSizeZero;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef POINCARE_CODEPOINT_LAYOUT_NODE_H
|
||||
#define POINCARE_CODEPOINT_LAYOUT_NODE_H
|
||||
|
||||
#include <kandinsky/include/kandinsky/unicode/code_point.h>
|
||||
#include <ion/unicode/code_point.h>
|
||||
#include <poincare/layout_cursor.h>
|
||||
#include <poincare/layout.h>
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Poincare {
|
||||
class CodePointLayoutNode final : public LayoutNode {
|
||||
public:
|
||||
static constexpr const KDFont * k_defaultFont = KDFont::LargeFont;
|
||||
CodePointLayoutNode(CodePoint c = KDCodePointNull, const KDFont * font = k_defaultFont) :
|
||||
CodePointLayoutNode(CodePoint c = UCodePointNull, const KDFont * font = k_defaultFont) :
|
||||
LayoutNode(),
|
||||
m_codePoint(c),
|
||||
m_font(font)
|
||||
|
||||
@@ -38,9 +38,9 @@ public:
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, complexFormat, angleUnit); }
|
||||
|
||||
/* Symbol properties */
|
||||
bool isPi() const { return isConstantCodePoint(KDCodePointGreekSmallLetterPi); }
|
||||
bool isExponential() const { return isConstantCodePoint(KDCodePointScriptSmallE); }
|
||||
bool isIComplex() const { return isConstantCodePoint(KDCodePointMathematicalBoldSmallI); }
|
||||
bool isPi() const { return isConstantCodePoint(UCodePointGreekSmallLetterPi); }
|
||||
bool isExponential() const { return isConstantCodePoint(UCodePointScriptSmallE); }
|
||||
bool isIComplex() const { return isConstantCodePoint(UCodePointMathematicalBoldSmallI); }
|
||||
CodePoint codePoint() const;
|
||||
|
||||
// Comparison
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
virtual bool hasUpperLeftIndex() const { return false; }
|
||||
virtual CodePoint XNTCodePoint() const {
|
||||
LayoutNode * p = parent();
|
||||
return p == nullptr ? KDCodePointNull : p->XNTCodePoint();
|
||||
return p == nullptr ? UCodePointNull : p->XNTCodePoint();
|
||||
}
|
||||
|
||||
virtual bool willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) { return true; }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define POINCARE_SERIALIZATION_HELPER_H
|
||||
|
||||
#include <poincare/tree_node.h>
|
||||
#include <kandinsky/include/kandinsky/unicode/code_point.h>
|
||||
#include <ion/unicode/code_point.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ int CodePointLayoutNode::serialize(char * buffer, int bufferSize, Preferences::P
|
||||
bool CodePointLayoutNode::isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const {
|
||||
if (*numberOfOpenParenthesis <= 0) {
|
||||
if (m_codePoint == '+'
|
||||
|| m_codePoint == KDCodePointRightwardsArrow
|
||||
|| m_codePoint == UCodePointRightwardsArrow
|
||||
|| m_codePoint == '='
|
||||
|| m_codePoint == ',')
|
||||
{
|
||||
@@ -50,7 +50,7 @@ bool CodePointLayoutNode::isCollapsable(int * numberOfOpenParenthesis, bool goin
|
||||
if (indexOfThis > 0) {
|
||||
Layout leftBrother = parent.childAtIndex(indexOfThis-1);
|
||||
if (leftBrother.isCodePoint()
|
||||
&& static_cast<CodePointLayout&>(leftBrother).codePoint() == KDCodePointLatinLetterSmallCapitalE)
|
||||
&& static_cast<CodePointLayout&>(leftBrother).codePoint() == UCodePointLatinLetterSmallCapitalE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -94,8 +94,8 @@ void CodePointLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionC
|
||||
|
||||
bool CodePointLayoutNode::isMultiplicationCodePoint() const {
|
||||
return m_codePoint == '*'
|
||||
|| m_codePoint == KDCodePointMultiplicationSign
|
||||
|| m_codePoint == KDCodePointMiddleDot;
|
||||
|| m_codePoint == UCodePointMultiplicationSign
|
||||
|| m_codePoint == UCodePointMiddleDot;
|
||||
}
|
||||
|
||||
CodePointLayout CodePointLayout::Builder(CodePoint c, const KDFont * font) {
|
||||
|
||||
@@ -57,7 +57,7 @@ Expression ComplexArgument::shallowReduce(Context & context, Preferences::Comple
|
||||
return result;
|
||||
} else if (!std::isnan(app) && app <= -Expression::Epsilon<float>()) {
|
||||
// arg(x) = Pi if x < 0
|
||||
Expression result = Constant::Builder(KDCodePointGreekSmallLetterPi);
|
||||
Expression result = Constant::Builder(UCodePointGreekSmallLetterPi);
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFor
|
||||
}
|
||||
// Then, compute sign(b) * Pi/2 - arctan(a/b)
|
||||
Expression signb = SignFunction::Builder(b);
|
||||
Expression signbPi2 = Multiplication::Builder(Rational::Builder(1,2), signb, Constant::Builder(KDCodePointGreekSmallLetterPi));
|
||||
Expression signbPi2 = Multiplication::Builder(Rational::Builder(1,2), signb, Constant::Builder(UCodePointGreekSmallLetterPi));
|
||||
signb.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression sub = Subtraction::Builder(signbPi2, arcTangent);
|
||||
signbPi2.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
@@ -163,7 +163,7 @@ Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFor
|
||||
Expression signa = SignFunction::Builder(a).shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Subtraction sub = Subtraction::Builder(Rational::Builder(1), signa);
|
||||
signa.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication mul = Multiplication::Builder(Rational::Builder(1,2), Constant::Builder(KDCodePointGreekSmallLetterPi), sub);
|
||||
Multiplication mul = Multiplication::Builder(Rational::Builder(1,2), Constant::Builder(UCodePointGreekSmallLetterPi), sub);
|
||||
sub.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return mul;
|
||||
}
|
||||
@@ -330,7 +330,7 @@ ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & con
|
||||
rclone.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression thmuld = Multiplication::Builder(Rational::Builder(-1), thclone, d.clone());
|
||||
thclone.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Expression exp = Power::Builder(Constant::Builder(KDCodePointScriptSmallE), thmuld);
|
||||
Expression exp = Power::Builder(Constant::Builder(UCodePointScriptSmallE), thmuld);
|
||||
thmuld.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Multiplication norm = Multiplication::Builder(rpowc, exp);
|
||||
rpowc.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <ion.h>
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -31,11 +31,11 @@ bool ConstantNode::isReal(Context & context) const {
|
||||
|
||||
int rankOfConstant(CodePoint c) {
|
||||
switch (c) {
|
||||
case KDCodePointMathematicalBoldSmallI :
|
||||
case UCodePointMathematicalBoldSmallI :
|
||||
return 0;
|
||||
case KDCodePointGreekSmallLetterPi :
|
||||
case UCodePointGreekSmallLetterPi :
|
||||
return 1;
|
||||
case KDCodePointScriptSmallE :
|
||||
case UCodePointScriptSmallE :
|
||||
return 2;
|
||||
default:
|
||||
assert(false);
|
||||
@@ -46,7 +46,7 @@ int rankOfConstant(CodePoint c) {
|
||||
CodePoint ConstantNode::codePoint() const {
|
||||
UTF8Decoder decoder = UTF8Decoder(m_name);
|
||||
CodePoint result = decoder.nextCodePoint();
|
||||
assert(decoder.nextCodePoint() == KDCodePointNull);
|
||||
assert(decoder.nextCodePoint() == UCodePointNull);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ Expression ConstantNode::shallowReduce(Context & context, Preferences::ComplexFo
|
||||
bool ConstantNode::isConstantCodePoint(CodePoint c) const {
|
||||
UTF8Decoder decoder(m_name);
|
||||
bool result = (decoder.nextCodePoint() == c);
|
||||
assert(decoder.nextCodePoint() == KDCodePointNull);
|
||||
assert(decoder.nextCodePoint() == UCodePointNull);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
return currentChar;
|
||||
}
|
||||
if (currentChar >= bufferSize-1) { return bufferSize-1; }
|
||||
currentChar += SerializationHelper::CodePoint(buffer + currentChar, bufferSize - currentChar, KDCodePointLatinLetterSmallCapitalE);
|
||||
currentChar += SerializationHelper::CodePoint(buffer + currentChar, bufferSize - currentChar, UCodePointLatinLetterSmallCapitalE);
|
||||
if (currentChar >= bufferSize-1) { return bufferSize-1; }
|
||||
currentChar += Integer(exponent).serialize(buffer+currentChar, bufferSize-currentChar);
|
||||
return currentChar;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace Poincare {
|
||||
|
||||
int EmptyExpressionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
return SerializationHelper::CodePoint(buffer, bufferSize, KDCodePointEmpty);
|
||||
return SerializationHelper::CodePoint(buffer, bufferSize, UCodePointEmpty);
|
||||
}
|
||||
|
||||
Layout EmptyExpressionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/variable_context.h>
|
||||
#include <ion.h>
|
||||
#include <kandinsky/unicode/utf8_helper.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
|
||||
@@ -343,7 +343,7 @@ void Expression::SetEncounteredComplex(bool encounterComplex) {
|
||||
}
|
||||
|
||||
Preferences::ComplexFormat Expression::UpdatedComplexFormatWithTextInput(Preferences::ComplexFormat complexFormat, const char * textInput) {
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && UTF8Helper::CodePointSearch(textInput, KDCodePointMathematicalBoldSmallI) != nullptr) {
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && UTF8Helper::CodePointSearch(textInput, UCodePointMathematicalBoldSmallI) != nullptr) {
|
||||
return Preferences::ComplexFormat::Cartesian;
|
||||
}
|
||||
return complexFormat;
|
||||
@@ -520,12 +520,12 @@ Expression Expression::ExpressionWithoutSymbols(Expression e, Context & context)
|
||||
|
||||
Expression Expression::radianToDegree() {
|
||||
// e*180/Pi
|
||||
return Multiplication::Builder(*this, Rational::Builder(180), Power::Builder(Constant::Builder(KDCodePointGreekSmallLetterPi), Rational::Builder(-1)));
|
||||
return Multiplication::Builder(*this, Rational::Builder(180), Power::Builder(Constant::Builder(UCodePointGreekSmallLetterPi), Rational::Builder(-1)));
|
||||
}
|
||||
|
||||
Expression Expression::degreeToRadian() {
|
||||
// e*Pi/180
|
||||
return Multiplication::Builder(*this, Rational::Builder(1, 180), Constant::Builder(KDCodePointGreekSmallLetterPi));
|
||||
return Multiplication::Builder(*this, Rational::Builder(1, 180), Constant::Builder(UCodePointGreekSmallLetterPi));
|
||||
}
|
||||
|
||||
Expression Expression::reduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
@@ -627,9 +627,9 @@ Expression Expression::CreateComplexExpression(Expression ra, Expression tb, Pre
|
||||
}
|
||||
if (!isZeroTb) {
|
||||
if (isOneTb) {
|
||||
imag = Constant::Builder(KDCodePointMathematicalBoldSmallI);
|
||||
imag = Constant::Builder(UCodePointMathematicalBoldSmallI);
|
||||
} else {
|
||||
imag = Multiplication::Builder(tb , Constant::Builder(KDCodePointMathematicalBoldSmallI));
|
||||
imag = Multiplication::Builder(tb , Constant::Builder(UCodePointMathematicalBoldSmallI));
|
||||
}
|
||||
}
|
||||
if (imag.isUninitialized()) {
|
||||
@@ -658,14 +658,14 @@ Expression Expression::CreateComplexExpression(Expression ra, Expression tb, Pre
|
||||
if (!isZeroRa && !isZeroTb) {
|
||||
Expression arg;
|
||||
if (isOneTb) {
|
||||
arg = Constant::Builder(KDCodePointMathematicalBoldSmallI);
|
||||
arg = Constant::Builder(UCodePointMathematicalBoldSmallI);
|
||||
} else {
|
||||
arg = Multiplication::Builder(tb, Constant::Builder(KDCodePointMathematicalBoldSmallI));
|
||||
arg = Multiplication::Builder(tb, Constant::Builder(UCodePointMathematicalBoldSmallI));
|
||||
}
|
||||
if (isNegativeTb) {
|
||||
arg = Opposite::Builder(arg);
|
||||
}
|
||||
exp = Power::Builder(Constant::Builder(KDCodePointScriptSmallE), arg);
|
||||
exp = Power::Builder(Constant::Builder(UCodePointScriptSmallE), arg);
|
||||
}
|
||||
if (exp.isUninitialized()) {
|
||||
return norm;
|
||||
|
||||
@@ -216,13 +216,13 @@ void print_expression(const Expression e, int indentationLevel) {
|
||||
UTF8Decoder decoder(static_cast<const Symbol &>(e).name());
|
||||
CodePoint firstCodePoint = decoder.nextCodePoint();
|
||||
switch (firstCodePoint) {
|
||||
case KDCodePointGreekSmallLetterPi:
|
||||
case UCodePointGreekSmallLetterPi:
|
||||
std::cout << "PI";
|
||||
break;
|
||||
case KDCodePointMathematicalBoldSmallI:
|
||||
case UCodePointMathematicalBoldSmallI:
|
||||
std::cout << "i";
|
||||
break;
|
||||
case KDCodePointScriptSmallE:
|
||||
case UCodePointScriptSmallE:
|
||||
std::cout << "e";
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -134,7 +134,7 @@ int FractionLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pr
|
||||
|
||||
// Add a multiplication if omitted.
|
||||
if (idxInParent > 0 && p->isHorizontal() && p->childAtIndex(idxInParent - 1)->canBeOmittedMultiplicationLeftFactor()) {
|
||||
numberOfChar+= SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, KDCodePointMiddleDot);
|
||||
numberOfChar+= SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, UCodePointMiddleDot);
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1;}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ int FractionLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pr
|
||||
|
||||
// Add a multiplication if omitted.
|
||||
if (idxInParent >= 0 && idxInParent < (p->numberOfChildren() - 1) && p->isHorizontal() && p->childAtIndex(idxInParent + 1)->canBeOmittedMultiplicationRightFactor()) {
|
||||
numberOfChar+= SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, KDCodePointMiddleDot);
|
||||
numberOfChar+= SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, UCodePointMiddleDot);
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1;}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <poincare/nth_root_layout.h>
|
||||
#include <poincare/right_parenthesis_layout.h>
|
||||
#include <poincare/vertical_offset_layout.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
@@ -75,7 +75,7 @@ void LayoutCursor::move(MoveDirection direction, bool * shouldRecomputeLayout) {
|
||||
void LayoutCursor::addEmptyExponentialLayout() {
|
||||
EmptyLayout emptyLayout = EmptyLayout::Builder();
|
||||
HorizontalLayout sibling = HorizontalLayout::Builder(
|
||||
CodePointLayout::Builder(KDCodePointScriptSmallE),
|
||||
CodePointLayout::Builder(UCodePointScriptSmallE),
|
||||
VerticalOffsetLayout::Builder(emptyLayout, VerticalOffsetLayoutNode::Type::Superscript));
|
||||
m_layout.addSibling(this, sibling, false);
|
||||
m_layout = emptyLayout;
|
||||
@@ -114,7 +114,7 @@ void LayoutCursor::addEmptySquarePowerLayout() {
|
||||
void LayoutCursor::addEmptyTenPowerLayout() {
|
||||
EmptyLayout emptyLayout = EmptyLayout::Builder();
|
||||
HorizontalLayout sibling = HorizontalLayout::Builder(
|
||||
CodePointLayout::Builder(KDCodePointMiddleDot),
|
||||
CodePointLayout::Builder(UCodePointMiddleDot),
|
||||
CodePointLayout::Builder('1'),
|
||||
CodePointLayout::Builder('0'),
|
||||
VerticalOffsetLayout::Builder(
|
||||
@@ -141,18 +141,18 @@ void LayoutCursor::insertText(const char * text) {
|
||||
Layout pointedChild;
|
||||
UTF8Decoder decoder(text);
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
if (codePoint == KDCodePointNull) {
|
||||
if (codePoint == UCodePointNull) {
|
||||
return;
|
||||
}
|
||||
assert(!codePoint.isCombining());
|
||||
while (codePoint != KDCodePointNull) {
|
||||
if (codePoint == KDCodePointEmpty) {
|
||||
while (codePoint != UCodePointNull) {
|
||||
if (codePoint == UCodePointEmpty) {
|
||||
codePoint = decoder.nextCodePoint();
|
||||
assert(!codePoint.isCombining());
|
||||
continue;
|
||||
}
|
||||
if (codePoint == KDCodePointMultiplicationSign) {
|
||||
newChild = CodePointLayout::Builder(KDCodePointMiddleDot);
|
||||
if (codePoint == UCodePointMultiplicationSign) {
|
||||
newChild = CodePointLayout::Builder(UCodePointMiddleDot);
|
||||
} else if (codePoint == '(') {
|
||||
newChild = LeftParenthesisLayout::Builder();
|
||||
if (pointedChild.isUninitialized()) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <poincare/left_parenthesis_layout.h>
|
||||
#include <poincare/right_parenthesis_layout.h>
|
||||
#include <poincare/vertical_offset_layout.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Poincare {
|
||||
@@ -64,7 +64,7 @@ HorizontalLayout LayoutHelper::String(const char * buffer, int bufferLen, const
|
||||
assert(!codePoint.isCombining());
|
||||
int layoutIndex = 0;
|
||||
int bufferIndex = 0;
|
||||
while (codePoint != KDCodePointNull && bufferIndex < bufferLen) {
|
||||
while (codePoint != UCodePointNull && bufferIndex < bufferLen) {
|
||||
resultLayout.addChildAtIndex(CodePointLayout::Builder(codePoint, font), layoutIndex, layoutIndex, nullptr);
|
||||
layoutIndex++;
|
||||
bufferIndex+= nextPointer - currentPointer;
|
||||
|
||||
@@ -341,7 +341,7 @@ Expression Logarithm::splitLogarithmInteger(Integer i, bool isDenominator, Conte
|
||||
|
||||
Expression Logarithm::shallowBeautify() {
|
||||
assert(numberOfChildren() == 2);
|
||||
Constant e = Constant::Builder(KDCodePointScriptSmallE);
|
||||
Constant e = Constant::Builder(UCodePointScriptSmallE);
|
||||
if (childAtIndex(1).isIdenticalTo(e)) {
|
||||
NaperianLogarithm np = NaperianLogarithm::Builder(childAtIndex(0));
|
||||
replaceWithInPlace(np);
|
||||
|
||||
@@ -87,14 +87,14 @@ bool MultiplicationNode::childNeedsParenthesis(const TreeNode * child) const {
|
||||
Layout MultiplicationNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
constexpr int stringMaxSize = CodePoint::MaxCodePointCharLength + 1;
|
||||
char string[stringMaxSize];
|
||||
SerializationHelper::CodePoint(string, stringMaxSize, KDCodePointMiddleDot);
|
||||
SerializationHelper::CodePoint(string, stringMaxSize, UCodePointMiddleDot);
|
||||
return LayoutHelper::Infix(Multiplication(this), floatDisplayMode, numberOfSignificantDigits, string);
|
||||
}
|
||||
|
||||
int MultiplicationNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
constexpr int stringMaxSize = CodePoint::MaxCodePointCharLength + 1;
|
||||
char string[stringMaxSize];
|
||||
SerializationHelper::CodePoint(string, stringMaxSize, KDCodePointMultiplicationSign);
|
||||
SerializationHelper::CodePoint(string, stringMaxSize, UCodePointMultiplicationSign);
|
||||
return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, string);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::Comp
|
||||
return SimplificationHelper::Map(*this, context, angleUnit);
|
||||
}
|
||||
#endif
|
||||
Logarithm l = Logarithm::Builder(childAtIndex(0), Constant::Builder(KDCodePointScriptSmallE));
|
||||
Logarithm l = Logarithm::Builder(childAtIndex(0), Constant::Builder(UCodePointScriptSmallE));
|
||||
replaceWithInPlace(l);
|
||||
return l.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ int NthRootLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pri
|
||||
buffer[bufferSize-1] = 0;
|
||||
int numberOfChar = 0;
|
||||
|
||||
numberOfChar += SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, KDCodePointSquareRoot);
|
||||
numberOfChar += SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, UCodePointSquareRoot);
|
||||
if (numberOfChar >= bufferSize-1) {
|
||||
return bufferSize-1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "parser.h"
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
Undefined
|
||||
};
|
||||
|
||||
Token(Type type) : m_type(type), m_text(0), m_codePoint(KDCodePointNull) {};
|
||||
Token(Type type) : m_type(type), m_text(0), m_codePoint(UCodePointNull) {};
|
||||
|
||||
Type type() const { return m_type; }
|
||||
bool is(Type t) const { return m_type == t; }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "tokenizer.h"
|
||||
#include <poincare/number.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -18,7 +18,7 @@ const CodePoint Tokenizer::nextCodePoint(PopTest popTest, CodePoint context, boo
|
||||
CodePoint firstCodePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
size_t numberOfBytesForCodePoint = nextPointer - currentPointer;
|
||||
if (firstCodePoint != KDCodePointNull) {
|
||||
if (firstCodePoint != UCodePointNull) {
|
||||
currentPointer = nextPointer;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
@@ -92,7 +92,7 @@ Token Tokenizer::popNumber() {
|
||||
const char * exponentPartText = m_text;
|
||||
size_t exponentPartLength = 0;
|
||||
bool exponentIsNegative = false;
|
||||
if (canPopCodePoint(KDCodePointLatinLetterSmallCapitalE)) {
|
||||
if (canPopCodePoint(UCodePointLatinLetterSmallCapitalE)) {
|
||||
exponentIsNegative = canPopCodePoint('-');
|
||||
exponentPartText = m_text;
|
||||
exponentPartLength = popDigits();
|
||||
@@ -146,16 +146,16 @@ Token Tokenizer::popToken() {
|
||||
assert(c != '.');
|
||||
return Token(typeForCodePoint[c - '(']);
|
||||
}
|
||||
if (c == KDCodePointMultiplicationSign || c == KDCodePointMiddleDot) {
|
||||
if (c == UCodePointMultiplicationSign || c == UCodePointMiddleDot) {
|
||||
return Token(Token::Times);
|
||||
}
|
||||
if (c == '^') {
|
||||
return Token(Token::Caret);
|
||||
}
|
||||
if (c == KDCodePointLeftSuperscript) {
|
||||
if (c == UCodePointLeftSuperscript) {
|
||||
return Token(Token::LeftSuperscript);
|
||||
}
|
||||
if (c == KDCodePointRightSuperscript) {
|
||||
if (c == UCodePointRightSuperscript) {
|
||||
return Token(Token::RightSuperscript);
|
||||
}
|
||||
if (c == '!') {
|
||||
@@ -176,26 +176,26 @@ Token Tokenizer::popToken() {
|
||||
if (c == '}') {
|
||||
return Token(Token::RightBrace);
|
||||
}
|
||||
if (c == KDCodePointGreekSmallLetterPi
|
||||
|| c == KDCodePointMathematicalBoldSmallI
|
||||
|| c == KDCodePointScriptSmallE)
|
||||
if (c == UCodePointGreekSmallLetterPi
|
||||
|| c == UCodePointMathematicalBoldSmallI
|
||||
|| c == UCodePointScriptSmallE)
|
||||
{
|
||||
Token result(Token::Constant);
|
||||
result.setCodePoint(c);
|
||||
return result;
|
||||
}
|
||||
if (c == KDCodePointSquareRoot) {
|
||||
if (c == UCodePointSquareRoot) {
|
||||
Token result(Token::Identifier);
|
||||
// TODO compute size manually?
|
||||
constexpr int squareRootCharLength = 3;
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(KDCodePointSquareRoot) == squareRootCharLength);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(UCodePointSquareRoot) == squareRootCharLength);
|
||||
result.setString(start, squareRootCharLength);
|
||||
return result;
|
||||
}
|
||||
if (c == KDCodePointEmpty) {
|
||||
if (c == UCodePointEmpty) {
|
||||
return Token(Token::Empty);
|
||||
}
|
||||
if (c == KDCodePointRightwardsArrow) {
|
||||
if (c == UCodePointRightwardsArrow) {
|
||||
return Token(Token::Store);
|
||||
}
|
||||
if (c == 0) {
|
||||
|
||||
@@ -17,10 +17,10 @@ public:
|
||||
Token popToken();
|
||||
private:
|
||||
typedef bool (*PopTest)(CodePoint c, CodePoint context);
|
||||
const CodePoint nextCodePoint(PopTest popTest, CodePoint context = KDCodePointNull, bool * testResult = nullptr);
|
||||
const CodePoint nextCodePoint(PopTest popTest, CodePoint context = UCodePointNull, bool * testResult = nullptr);
|
||||
const CodePoint popCodePoint();
|
||||
bool canPopCodePoint(const CodePoint c);
|
||||
size_t popWhile(PopTest popTest, CodePoint context = KDCodePointNull);
|
||||
size_t popWhile(PopTest popTest, CodePoint context = UCodePointNull);
|
||||
size_t popDigits();
|
||||
size_t popIdentifier();
|
||||
Token popNumber();
|
||||
|
||||
@@ -521,7 +521,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co
|
||||
Multiplication m1 = Multiplication::Builder();
|
||||
replaceWithInPlace(m1);
|
||||
// Multiply m1 by i complex
|
||||
Constant i = Constant::Builder(KDCodePointMathematicalBoldSmallI);
|
||||
Constant i = Constant::Builder(UCodePointMathematicalBoldSmallI);
|
||||
m1.addChildAtIndexInPlace(i, 0, 0);
|
||||
i.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
m1.addChildAtIndexInPlace(*this, 1, 1);
|
||||
@@ -1136,17 +1136,17 @@ Expression Power::equivalentExpressionUsingStandardExpression() const {
|
||||
|
||||
Expression Power::CreateComplexExponent(const Expression & r, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
// Returns e^(i*pi*r)
|
||||
const Constant exp = Constant::Builder(KDCodePointScriptSmallE);
|
||||
Constant iComplex = Constant::Builder(KDCodePointMathematicalBoldSmallI);
|
||||
const Constant pi = Constant::Builder(KDCodePointGreekSmallLetterPi);
|
||||
const Constant exp = Constant::Builder(UCodePointScriptSmallE);
|
||||
Constant iComplex = Constant::Builder(UCodePointMathematicalBoldSmallI);
|
||||
const Constant pi = Constant::Builder(UCodePointGreekSmallLetterPi);
|
||||
Multiplication mExp = Multiplication::Builder(iComplex, pi, r.clone());
|
||||
iComplex.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
Power p = Power::Builder(exp, mExp);
|
||||
mExp.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
return p;
|
||||
#if 0
|
||||
const Constant iComplex = Constant::Builder(KDCodePointMathematicalBoldSmallI);
|
||||
const Constant pi = Constant::Builder(KDCodePointGreekSmallLetterPi);
|
||||
const Constant iComplex = Constant::Builder(UCodePointMathematicalBoldSmallI);
|
||||
const Constant pi = Constant::Builder(UCodePointGreekSmallLetterPi);
|
||||
Expression op = Multiplication::Builder(pi, r).shallowReduce(context, complexFormat, angleUnit, false);
|
||||
Cosine cos = Cosine(op).shallowReduce(context, complexFormat, angleUnit, false);;
|
||||
Sine sin = Sine(op).shallowReduce(context, complexFormat, angleUnit, false);
|
||||
|
||||
@@ -199,7 +199,7 @@ int PrintFloat::convertFloatToTextPrivate(T f, char * buffer, int bufferSize, in
|
||||
// Print exponent
|
||||
assert(numberOfCharsForMantissaWithSign < bufferSize);
|
||||
int currentNumberOfChar = numberOfCharsForMantissaWithSign;
|
||||
currentNumberOfChar+= SerializationHelper::CodePoint(buffer + currentNumberOfChar, bufferSize - currentNumberOfChar, KDCodePointLatinLetterSmallCapitalE);
|
||||
currentNumberOfChar+= SerializationHelper::CodePoint(buffer + currentNumberOfChar, bufferSize - currentNumberOfChar, UCodePointLatinLetterSmallCapitalE);
|
||||
assert(numberOfCharExponent+currentNumberOfChar < bufferSize);
|
||||
PrintFloat::printBase10IntegerWithDecimalMarker(buffer + currentNumberOfChar, numberOfCharExponent, Integer(exponentInBase10), -1);
|
||||
buffer[currentNumberOfChar + numberOfCharExponent] = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <kandinsky/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@ Expression StoreNode::shallowReduce(Context & context, Preferences::ComplexForma
|
||||
int StoreNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
constexpr int stringMaxSize = CodePoint::MaxCodePointCharLength + 1;
|
||||
char string[stringMaxSize];
|
||||
SerializationHelper::CodePoint(string, stringMaxSize, KDCodePointRightwardsArrow);
|
||||
SerializationHelper::CodePoint(string, stringMaxSize, UCodePointRightwardsArrow);
|
||||
return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, string);
|
||||
}
|
||||
|
||||
Layout StoreNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
HorizontalLayout result = HorizontalLayout::Builder();
|
||||
result.addOrMergeChildAtIndex(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false);
|
||||
result.addChildAtIndex(CodePointLayout::Builder(KDCodePointRightwardsArrow), result.numberOfChildren(), result.numberOfChildren(), nullptr);
|
||||
result.addChildAtIndex(CodePointLayout::Builder(UCodePointRightwardsArrow), result.numberOfChildren(), result.numberOfChildren(), nullptr);
|
||||
result.addOrMergeChildAtIndex(childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits), result.numberOfChildren(), false);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c
|
||||
* reduced to undef) */
|
||||
if (target == ExpressionNode::ReductionTarget::User || x.isNumber()) {
|
||||
Expression sign = SignFunction::Builder(x.clone());
|
||||
Multiplication m0 = Multiplication::Builder(Rational::Builder(1,2), sign, Constant::Builder(KDCodePointGreekSmallLetterPi));
|
||||
Multiplication m0 = Multiplication::Builder(Rational::Builder(1,2), sign, Constant::Builder(UCodePointGreekSmallLetterPi));
|
||||
sign.shallowReduce(context, complexFormat, angleUnit, target);
|
||||
e.replaceChildAtIndexInPlace(0, x);
|
||||
Addition a = Addition::Builder(m0);
|
||||
@@ -314,7 +314,7 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c
|
||||
// The argument was made positive
|
||||
// acos(-x) = π-acos(x)
|
||||
if (e.type() == ExpressionNode::Type::ArcCosine) {
|
||||
Expression pi = angleUnit == Preferences::AngleUnit::Radian ? static_cast<Expression>(Constant::Builder(KDCodePointGreekSmallLetterPi)) : static_cast<Expression>(Rational::Builder(180));
|
||||
Expression pi = angleUnit == Preferences::AngleUnit::Radian ? static_cast<Expression>(Constant::Builder(UCodePointGreekSmallLetterPi)) : static_cast<Expression>(Rational::Builder(180));
|
||||
Subtraction s = Subtraction::Builder();
|
||||
e.replaceWithInPlace(s);
|
||||
s.replaceChildAtIndexInPlace(0, pi);
|
||||
|
||||
@@ -174,12 +174,12 @@ int VerticalOffsetLayoutNode::serialize(char * buffer, int bufferSize, Preferenc
|
||||
}
|
||||
assert(m_type == Type::Superscript);
|
||||
/* If the layout is a superscript, write:
|
||||
* "KDCodePointLeftSuperscript indice KDCodePointRightSuperscript" */
|
||||
int numberOfChar = SerializationHelper::CodePoint(buffer, bufferSize, KDCodePointLeftSuperscript);
|
||||
* "UCodePointLeftSuperscript indice UCodePointRightSuperscript" */
|
||||
int numberOfChar = SerializationHelper::CodePoint(buffer, bufferSize, UCodePointLeftSuperscript);
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1; }
|
||||
numberOfChar += const_cast<VerticalOffsetLayoutNode *>(this)->indiceLayout()->serialize(buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfSignificantDigits);
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1; }
|
||||
numberOfChar += SerializationHelper::CodePoint(buffer+numberOfChar, bufferSize-numberOfChar, KDCodePointRightSuperscript);
|
||||
numberOfChar += SerializationHelper::CodePoint(buffer+numberOfChar, bufferSize-numberOfChar, UCodePointRightSuperscript);
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1; }
|
||||
|
||||
buffer[numberOfChar] = 0;
|
||||
|
||||
@@ -38,9 +38,9 @@ QUIZ_CASE(poincare_expression_order) {
|
||||
}
|
||||
{
|
||||
// e + pi + i
|
||||
Expression pi = Constant::Builder(KDCodePointGreekSmallLetterPi);
|
||||
Expression i = Constant::Builder(KDCodePointMathematicalBoldSmallI);
|
||||
Expression e = Constant::Builder(KDCodePointScriptSmallE);
|
||||
Expression pi = Constant::Builder(UCodePointGreekSmallLetterPi);
|
||||
Expression i = Constant::Builder(UCodePointMathematicalBoldSmallI);
|
||||
Expression e = Constant::Builder(UCodePointScriptSmallE);
|
||||
constexpr int numberOfChildren = 3;
|
||||
Expression children[numberOfChildren] = {pi.clone(), i.clone(), e.clone()};
|
||||
Expression childrenSorted[numberOfChildren] = {e, pi, i};
|
||||
@@ -91,16 +91,16 @@ QUIZ_CASE(poincare_expression_order) {
|
||||
}
|
||||
{
|
||||
// pi^a * pi^b
|
||||
Expression child1 = Power::Builder(Constant::Builder(KDCodePointGreekSmallLetterPi), Symbol::Builder('a'));
|
||||
Expression child2 = Power::Builder(Constant::Builder(KDCodePointGreekSmallLetterPi), Symbol::Builder('b'));
|
||||
Expression child1 = Power::Builder(Constant::Builder(UCodePointGreekSmallLetterPi), Symbol::Builder('a'));
|
||||
Expression child2 = Power::Builder(Constant::Builder(UCodePointGreekSmallLetterPi), Symbol::Builder('b'));
|
||||
Expression e1 = Multiplication::Builder(child2.clone(), child1.clone());
|
||||
Expression e2 = Multiplication::Builder(child1, child2);
|
||||
assert_multiplication_or_addition_is_ordered_as(e1, e2);
|
||||
}
|
||||
{
|
||||
// pi^2 * pi^3
|
||||
Expression child1 = Power::Builder(Constant::Builder(KDCodePointGreekSmallLetterPi), Rational::Builder(2));
|
||||
Expression child2 = Power::Builder(Constant::Builder(KDCodePointGreekSmallLetterPi), Rational::Builder(3));
|
||||
Expression child1 = Power::Builder(Constant::Builder(UCodePointGreekSmallLetterPi), Rational::Builder(2));
|
||||
Expression child2 = Power::Builder(Constant::Builder(UCodePointGreekSmallLetterPi), Rational::Builder(3));
|
||||
Expression e1 = Multiplication::Builder(child2.clone(), child1.clone());
|
||||
Expression e2 = Multiplication::Builder(child1, child2);
|
||||
assert_multiplication_or_addition_is_ordered_as(e1, e2);
|
||||
|
||||
@@ -265,11 +265,11 @@ QUIZ_CASE(poincare_parse_layouts) {
|
||||
// 2e^3
|
||||
l = HorizontalLayout::Builder(
|
||||
CodePointLayout::Builder('2'),
|
||||
CodePointLayout::Builder(KDCodePointScriptSmallE),
|
||||
CodePointLayout::Builder(UCodePointScriptSmallE),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CodePointLayout::Builder('3'),
|
||||
VerticalOffsetLayoutNode::Type::Superscript));
|
||||
e = Multiplication::Builder(Rational::Builder(2),Power::Builder(Constant::Builder(KDCodePointScriptSmallE),Parenthesis::Builder(Rational::Builder(3))));
|
||||
assert_parsed_expression_is("2ℯ^(3)", Multiplication::Builder(Rational::Builder(2),Power::Builder(Constant::Builder(KDCodePointScriptSmallE),Parenthesis::Builder(Rational::Builder(3)))));
|
||||
e = Multiplication::Builder(Rational::Builder(2),Power::Builder(Constant::Builder(UCodePointScriptSmallE),Parenthesis::Builder(Rational::Builder(3))));
|
||||
assert_parsed_expression_is("2ℯ^(3)", Multiplication::Builder(Rational::Builder(2),Power::Builder(Constant::Builder(UCodePointScriptSmallE),Parenthesis::Builder(Rational::Builder(3)))));
|
||||
assert_parsed_layout_is(l, e);
|
||||
}
|
||||
|
||||
@@ -257,9 +257,9 @@ QUIZ_CASE(poincare_parser_symbols_and_functions) {
|
||||
|
||||
// Reserved symbols
|
||||
assert_parsed_expression_is("ans", Symbol::Builder("ans", 3));
|
||||
assert_parsed_expression_is("𝐢", Constant::Builder(KDCodePointMathematicalBoldSmallI));
|
||||
assert_parsed_expression_is("π", Constant::Builder(KDCodePointGreekSmallLetterPi));
|
||||
assert_parsed_expression_is("ℯ", Constant::Builder(KDCodePointScriptSmallE));
|
||||
assert_parsed_expression_is("𝐢", Constant::Builder(UCodePointMathematicalBoldSmallI));
|
||||
assert_parsed_expression_is("π", Constant::Builder(UCodePointGreekSmallLetterPi));
|
||||
assert_parsed_expression_is("ℯ", Constant::Builder(UCodePointScriptSmallE));
|
||||
assert_parsed_expression_is(Infinity::Name(), Infinity::Builder(false));
|
||||
assert_parsed_expression_is(Undefined::Name(), Undefined::Builder());
|
||||
|
||||
@@ -364,7 +364,7 @@ QUIZ_CASE(poincare_parser_implicit_multiplication) {
|
||||
assert_parsed_expression_is("1ans", Multiplication::Builder(Rational::Builder(1),Symbol::Builder("ans", 3)));
|
||||
assert_parsed_expression_is("x1", Symbol::Builder("x1", 2));
|
||||
assert_parsed_expression_is("1x+2", Addition::Builder(Multiplication::Builder(Rational::Builder(1),Symbol::Builder("x", 1)),Rational::Builder(2)));
|
||||
assert_parsed_expression_is("1π", Multiplication::Builder(Rational::Builder(1),Constant::Builder(KDCodePointGreekSmallLetterPi)));
|
||||
assert_parsed_expression_is("1π", Multiplication::Builder(Rational::Builder(1),Constant::Builder(UCodePointGreekSmallLetterPi)));
|
||||
assert_parsed_expression_is("1x-2", Subtraction::Builder(Multiplication::Builder(Rational::Builder(1),Symbol::Builder("x", 1)),Rational::Builder(2)));
|
||||
assert_parsed_expression_is("-1x", Opposite::Builder(Multiplication::Builder(Rational::Builder(1),Symbol::Builder("x", 1))));
|
||||
assert_parsed_expression_is("2×1x", Multiplication::Builder(Rational::Builder(2),Multiplication::Builder(Rational::Builder(1),Symbol::Builder("x", 1))));
|
||||
@@ -377,7 +377,7 @@ QUIZ_CASE(poincare_parser_implicit_multiplication) {
|
||||
assert_parsed_expression_is("sin(1)2", Multiplication::Builder(Sine::Builder(Rational::Builder(1)),Rational::Builder(2)));
|
||||
assert_parsed_expression_is("1cos(2)", Multiplication::Builder(Rational::Builder(1),Cosine::Builder(Rational::Builder(2))));
|
||||
assert_parsed_expression_is("1!2", Multiplication::Builder(Factorial::Builder(Rational::Builder(1)),Rational::Builder(2)));
|
||||
assert_parsed_expression_is("2ℯ^(3)", Multiplication::Builder(Rational::Builder(2),Power::Builder(Constant::Builder(KDCodePointScriptSmallE),Parenthesis::Builder(Rational::Builder(3)))));
|
||||
assert_parsed_expression_is("2ℯ^(3)", Multiplication::Builder(Rational::Builder(2),Power::Builder(Constant::Builder(UCodePointScriptSmallE),Parenthesis::Builder(Rational::Builder(3)))));
|
||||
Expression m1[] = {Rational::Builder(1)}; Matrix M1 = BuildMatrix(1,1,m1);
|
||||
Expression m2[] = {Rational::Builder(2)}; Matrix M2 = BuildMatrix(1,1,m2);
|
||||
assert_parsed_expression_is("[[1]][[2]]", Multiplication::Builder(M1,M2));
|
||||
|
||||
@@ -14,7 +14,7 @@ QUIZ_CASE(poincare_vertical_offset_layout_serialize) {
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
)
|
||||
);
|
||||
assert(KDCodePointLeftSuperscript == '\x12');
|
||||
assert(KDCodePointRightSuperscript == '\x13');
|
||||
assert(UCodePointLeftSuperscript == '\x12');
|
||||
assert(UCodePointRightSuperscript == '\x13');
|
||||
assert_expression_layout_serialize_to(layout, "2\x12x+5\x13");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user