/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* Original file from libgimpwidgets: gimpeevl.c
* Copyright (C) 2008 Fredrik Alstromer <roe@excu.se>
* Copyright (C) 2008 Martin Nordholts <martinn@svn.gnome.org>
* Modified for Inkscape by Johan Engelen
* Copyright (C) 2011 Johan Engelen
* Copyright (C) 2013 Matthew Petroff
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
*/
#include "config.h"
#include "util/expression-evaluator.h"
#include <math.h>
#include <string.h>
namespace Inkscape {
namespace Util {
{
}
{
type = 0;
}
{
// Preload symbol
}
/**
* Evaluates the given arithmetic expression, along with an optional dimension
* analysis, and basic unit conversions.
*
* All units conversions factors are relative to some implicit
* base-unit. This is also the unit of the returned value.
*
* Returns: An EvaluatorQuantity with a value given in the base unit along with
* the order of the dimension (e.g. if the base unit is inches, a dimension
* order of two means in^2).
*
* @return Result of evaluation.
* @throws Inkscape::Util::EvaluatorException There was a parse error.
**/
{
}
// Empty expression evaluates to 0
return result;
}
result = evaluateExpression();
// There should be nothing left to parse by now
isExpected(TOKEN_END, 0);
// Entire expression is dimensionless, apply default unit if applicable
}
return result;
}
{
bool subtract;
// Continue evaluating terms, chained with + or -.
{
// If dimensions mismatch, attempt default unit assignent
{
} else if ( evaluated_terms.dimension == 0
{
} else {
throwError("Dimension mismatch during addition");
}
}
}
return evaluated_terms;
}
{
bool division;
for ( division = false;
division = false )
{
if (division) {
} else {
}
}
return evaluated_exp_terms;
}
{
if (new_signed_factor.dimension == 0) {
} else {
throwError("Unit in exponent");
}
}
return evaluated_signed_factors;
}
{
}
result = evaluateFactor();
if (negate) {
}
return result;
}
{
isExpected(')', 0);
} else {
throwError("Expected number or '('");
}
char *identifier;
} else {
throwError("Unit was not resolved");
}
}
return evaluated_factor;
}
{
if (consumed_token) {
}
// Parse next token
}
return existed;
}
{
const char *s;
s = string;
if ( !s || s[0] == '\0' ) {
// We're all done
} else if ( s[0] == '+' || s[0] == '-' ) {
// Snatch these before the g_strtod() does, othewise they might
// be used in a numeric conversion.
acceptTokenCount(1, s[0]);
} else {
// Attempt to parse a numeric value
// A numeric could be parsed, use it
} else if (isUnitIdentifierStart(s[0])) {
// Unit identifier
current_token.value.c = s;
} else {
// Everything else is a single character token
acceptTokenCount(1, s[0]);
}
}
}
{
}
{
throwError("Unexpected token");
}
}
{
if (!string) {
return;
}
while (g_ascii_isspace(*string)) {
string++;
}
}
{
return (g_unichar_isalpha (c)
|| c == (gunichar) '%'
|| c == (gunichar) '\'');
}
/**
* getIdentifierSize:
* @s:
* @start:
*
* Returns: Size of identifier in bytes (not including NULL
* terminator).
**/
{
const char *s = start;
gunichar c = g_utf8_get_char(s);
int length = 0;
if (isUnitIdentifierStart(c)) {
s = g_utf8_next_char (s);
c = g_utf8_get_char (s);
length++;
while ( isUnitIdentifierStart (c) || g_unichar_isdigit (c) ) {
s = g_utf8_next_char(s);
c = g_utf8_get_char(s);
length++;
}
}
}
{
if (!unit) {
return true;
}else if (!identifier) {
return true;
return true;
} else {
return false;
}
}
{
}
} // namespace Util
} // namespace Inkscape