76 if (!g_utf8_validate(
string, -1,
nullptr)) {
111 for (subtract = FALSE;
128 }
else if ( evaluated_terms.
dimension == 0
131 evaluated_terms.
value /= default_unit_factor.
value;
134 throwError(
"Dimension mismatch during addition");
138 evaluated_terms.
value += (subtract ? -new_term.
value : new_term.
value);
141 return evaluated_terms;
149 for ( division =
false;
158 evaluated_exp_terms.
value /= new_exp_term.
value;
161 evaluated_exp_terms.
value *= new_exp_term.
value;
166 return evaluated_exp_terms;
177 evaluated_signed_factors.
value = pow(evaluated_signed_factors.
value,
178 new_signed_factor.
value);
185 return evaluated_signed_factors;
212 return evaluated_factor;
229 identifier = g_newa(
char, consumed_token.
value.
size + 1);
231 strncpy(identifier, consumed_token.
value.
c, consumed_token.
value.
size);
232 identifier[consumed_token.
value.
size] =
'\0';
242 return evaluated_factor;
248 bool existed = FALSE;
253 if (consumed_token) {
272 if ( !s || s[0] ==
'\0' ) {
275 }
else if ( s[0] ==
'+' || s[0] ==
'-' ) {
281 char *endptr =
nullptr;
282 gdouble value = g_strtod(s, &endptr);
284 if ( endptr && endptr != s ) {
323 while (g_ascii_isspace(*
string)) {
330 return (g_unichar_isalpha (
c)
345 const char *
start = g_utf8_offset_to_pointer(
string, start_offset);
346 const char *s =
start;
351 s = g_utf8_next_char (s);
352 c = g_utf8_get_char (s);
356 s = g_utf8_next_char(s);
357 c = g_utf8_get_char(s);
362 return g_utf8_offset_to_pointer(
start, length) -
start;
374 }
else if (!identifier) {
378 }
else if (unit_table.hasUnit(identifier)) {
379 Unit const *identifier_unit = unit_table.getUnit(identifier);
Special exception class for the expression evaluator.
EvaluatorQuantity(double value=0, unsigned int dimension=0)
union Inkscape::Util::EvaluatorToken::@62 value
EvaluatorQuantity evaluateSignedFactor()
static bool isUnitIdentifierStart(gunichar c)
EvaluatorQuantity evaluateExpTerm()
EvaluatorQuantity evaluateTerm()
void throwError(const char *msg)
void isExpected(TokenType token_type, EvaluatorToken *value)
const char * start_of_current_token
void acceptTokenCount(int count, TokenType token_type)
void movePastWhiteSpace()
EvaluatorQuantity evaluate()
Evaluates the given arithmetic expression, along with an optional dimension analysis,...
static int getIdentifierSize(const char *s, int start)
getIdentifierSize: @s: @start:
static bool resolveUnit(const char *identifier, EvaluatorQuantity *result, Unit const *unit)
bool acceptToken(TokenType token_type, EvaluatorToken *consumed_token)
EvaluatorQuantity evaluateFactor()
ExpressionEvaluator(const char *string, Unit const *unit=nullptr)
EvaluatorToken current_token
EvaluatorQuantity evaluateExpression()
static double convert(double from_dist, Unit const *from, Unit const *to)
Convert distances.
TODO: insert short description here.
Miscellaneous supporting code.
Helper class to stream background task notifications as a series of messages.