[apps/poincare] use Symbol::k_ans constexpr char *

This commit is contained in:
Léa Saviot
2018-09-27 14:52:36 +02:00
committed by Émilie Feral
parent 042cfca724
commit 2e2bf96bca
5 changed files with 9 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
#include "../shared/poincare_helpers.h"
#include "calculation_icon.h"
#include "../i18n.h"
#include <poincare/symbol.h>
using namespace Poincare;
@@ -95,7 +96,7 @@ bool App::textInputIsCorrect(const char * text) {
return false;
}
Expression ansExpression = static_cast<Snapshot *>(snapshot())->calculationStore()->ansExpression(localContext());
exp = exp.replaceSymbolWithExpression("ans", ansExpression);
exp = exp.replaceSymbolWithExpression(Symbol::k_ans, ansExpression);
char buffer[Calculation::k_printedExpressionSize];
int length = PoincareHelpers::Serialize(exp, buffer, sizeof(buffer));
/* if the buffer is totally full, it is VERY likely that writeTextInBuffer

View File

@@ -1,6 +1,7 @@
#include "calculation.h"
#include "calculation_store.h"
#include "../shared/poincare_helpers.h"
#include <poincare/symbol.h>
#include <string.h>
#include <cmath>
#include <poincare/symbol.h>
@@ -34,7 +35,7 @@ void Calculation::reset() {
void Calculation::setContent(const char * c, Context * context, Expression ansExpression) {
reset();
Expression input = Expression::parse(c).replaceSymbolWithExpression("ans", ansExpression);
Expression input = Expression::parse(c).replaceSymbolWithExpression(Symbol::k_ans, ansExpression);
/* We do not store directly the text enter by the user because we do not want
* to keep Ans symbol in the calculation store. */
PoincareHelpers::Serialize(input, m_inputText, sizeof(m_inputText));

View File

@@ -1,4 +1,5 @@
#include "expression_field.h"
#include <poincare/symbol.h>
namespace Calculation {
@@ -7,7 +8,7 @@ bool ExpressionField::handleEvent(Ion::Events::Event event) {
return false;
}
if (event == Ion::Events::Ans) {
handleEventWithText("ans");
handleEventWithText(Poincare::Symbol::k_ans);
return true;
}
if (isEditing() && isEmpty() &&
@@ -17,7 +18,7 @@ bool ExpressionField::handleEvent(Ion::Events::Event event) {
event == Ion::Events::Square ||
event == Ion::Events::Division ||
event == Ion::Events::Sto)) {
handleEventWithText("ans");
handleEventWithText(Poincare::Symbol::k_ans);
}
return(::ExpressionField::handleEvent(event));
}

View File

@@ -65,6 +65,7 @@ class Symbol final : public Expression {
friend class Expression;
friend class Store;
public:
static constexpr char k_ans[] = "ans";
enum SpecialSymbols : char {
/* We can use characters from 1 to 31 as they do not correspond to usual
* characters but events as 'end of text', 'backspace'... */

View File

@@ -154,7 +154,7 @@ exp : pow { $$ = $1; }
;
final_exp : exp { $$ = $1; }
| exp STO symb { if (static_cast<Symbol&>($3).name() == Symbol::SpecialSymbols::Ans) { YYERROR; } ; $$ = Store($1, static_cast<Symbol &>($3)); }
| exp STO symb { if (static_cast<Symbol&>($3).name() == Symbol::k_ans) { YYERROR; } ; $$ = Store($1, static_cast<Symbol &>($3)); }
| exp EQUAL exp { $$ = Equal($1, $3); }
;
%%