bool SVGZoomAndPan::parseZoomAndPan(const UChar*& start, const UChar* end)
{
    if (skipString(start, end, disable, sizeof(disable) / sizeof(UChar)))
        setZoomAndPan(SVG_ZOOMANDPAN_DISABLE);
    else if (skipString(start, end, magnify, sizeof(magnify) / sizeof(UChar)))
        setZoomAndPan(SVG_ZOOMANDPAN_MAGNIFY);
    else
        return false;

    return true;
}
bool SVGZoomAndPan::parseZoomAndPan(const UChar*& start, const UChar* end)
{
    if (skipString(start, end, disable, WTF_ARRAY_LENGTH(disable)))
        setZoomAndPan(SVG_ZOOMANDPAN_DISABLE);
    else if (skipString(start, end, magnify, WTF_ARRAY_LENGTH(magnify)))
        setZoomAndPan(SVG_ZOOMANDPAN_MAGNIFY);
    else
        return false;

    return true;
}
Exemple #3
0
static bool parseZoomAndPanInternal(const CharType*& start, const CharType* end, SVGZoomAndPanType& zoomAndPan)
{
    if (skipString(start, end, disable, WTF_ARRAY_LENGTH(disable))) {
        zoomAndPan = SVGZoomAndPanDisable;
        return true;
    }
    if (skipString(start, end, magnify, WTF_ARRAY_LENGTH(magnify))) {
        zoomAndPan = SVGZoomAndPanMagnify;
        return true;
    }
    return false;
}
bool SVGZoomAndPan::parseZoomAndPan(const UChar*& start, const UChar* end, SVGZoomAndPanType& zoomAndPan)
{
    if (skipString(start, end, disable, WTF_ARRAY_LENGTH(disable))) {
        zoomAndPan = SVGZoomAndPanDisable;
        return true;
    }
    if (skipString(start, end, magnify, WTF_ARRAY_LENGTH(magnify))) {
        zoomAndPan = SVGZoomAndPanMagnify;
        return true;
    }
    return false;
}
Exemple #5
0
		static const char* parseKey(const char* json, DynamicString& key)
		{
			RIO_ASSERT_NOT_NULL(json);

			if (*json == '"')
			{
				parseString(json, key);
				return skipString(json);
			}
			else if (::isalpha(*json)) // TODO replace for internal string function
			{
				while (true)
				{
					// TODO replace for internal string function
					if (::isspace(*json) || *json == '=')
					{
						return json;
					}

					key += *json;
					++json;
				}
			}

			RIO_FATAL("Bad key");
		}
Exemple #6
0
bool Reference::updateOffset(FILE* file, long newOffset)
{
	if(getFilePosition() > 0)
	{
		// save the current offset
		long saveOffset = ftell(file);

		// update the offset data for us
		_offset = newOffset;
		// seek this Reference object in the file.
		fseek(file, getFilePosition(), SEEK_SET);

		//Skip over the id string
		skipString(file);

		// Skip
		skipUint(file);

		// write over the old offset.
		write(_offset, file);

		// restore the offset.
		fseek(file, saveOffset, SEEK_SET);
		return true;
	}

	return false;
}
Exemple #7
0
JSON::Pos JSON::skipElement() const
{
    //std::cerr << "skipElement()\t" << data() << std::endl;

    ElementType type = getType();

    switch(type)
    {
        case TYPE_NULL:
            return skipNull();
        case TYPE_BOOL:
            return skipBool();
        case TYPE_NUMBER:
            return skipNumber();
        case TYPE_STRING:
            return skipString();
        case TYPE_NAME_VALUE_PAIR:
            return skipNameValuePair();
        case TYPE_ARRAY:
            return skipArray();
        case TYPE_OBJECT:
            return skipObject();
        default:
            throw JSONException("Logical error in JSON: unknown element type: " + Poco::NumberFormatter::format(type));
    }
}
Exemple #8
0
  addressType
evaluateAssert(void)
{
	if (!evaluateExpression())
		error(ASSERT_FAILED_ERROR, pc);
	skipString();
}
Exemple #9
0
JSON JSON::getValue() const
{
    Pos pos = skipString();
    checkPos(pos);
    if (*pos != ':')
        throw JSONException("JSON: expected :.");
    ++pos;
    checkPos(pos);
    return JSON(pos, ptr_end, level + 1);
}
static inline bool parseAndSkipType(const UChar*& currTransform, const UChar* end, unsigned short& type)
{
    if (currTransform >= end)
        return false;
    
    if (*currTransform == 's') {
        if (skipString(currTransform, end, skewXDesc, sizeof(skewXDesc) / sizeof(UChar)))
            type = SVGTransform::SVG_TRANSFORM_SKEWX;
        else if (skipString(currTransform, end, skewYDesc, sizeof(skewYDesc) / sizeof(UChar)))
            type = SVGTransform::SVG_TRANSFORM_SKEWY;
        else if (skipString(currTransform, end, scaleDesc, sizeof(scaleDesc) / sizeof(UChar)))
            type = SVGTransform::SVG_TRANSFORM_SCALE;
        else
            return false;
    } else if (skipString(currTransform, end, translateDesc, sizeof(translateDesc) / sizeof(UChar)))
        type = SVGTransform::SVG_TRANSFORM_TRANSLATE;
    else if (skipString(currTransform, end, rotateDesc, sizeof(rotateDesc) / sizeof(UChar)))
        type = SVGTransform::SVG_TRANSFORM_ROTATE;
    else if (skipString(currTransform, end, matrixDesc, sizeof(matrixDesc) / sizeof(UChar)))
        type = SVGTransform::SVG_TRANSFORM_MATRIX;
    else 
        return false;
    
    return true;
}
Exemple #11
0
static inline bool parseAndSkipType(const UChar*& currTransform, const UChar* end, SVGTransform::SVGTransformType& type)
{
    if (currTransform >= end)
        return false;

    if (*currTransform == 's') {
        if (skipString(currTransform, end, skewXDesc, WTF_ARRAY_LENGTH(skewXDesc)))
            type = SVGTransform::SVG_TRANSFORM_SKEWX;
        else if (skipString(currTransform, end, skewYDesc, WTF_ARRAY_LENGTH(skewYDesc)))
            type = SVGTransform::SVG_TRANSFORM_SKEWY;
        else if (skipString(currTransform, end, scaleDesc, WTF_ARRAY_LENGTH(scaleDesc)))
            type = SVGTransform::SVG_TRANSFORM_SCALE;
        else
            return false;
    } else if (skipString(currTransform, end, translateDesc, WTF_ARRAY_LENGTH(translateDesc)))
        type = SVGTransform::SVG_TRANSFORM_TRANSLATE;
    else if (skipString(currTransform, end, rotateDesc, WTF_ARRAY_LENGTH(rotateDesc)))
        type = SVGTransform::SVG_TRANSFORM_ROTATE;
    else if (skipString(currTransform, end, matrixDesc, WTF_ARRAY_LENGTH(matrixDesc)))
        type = SVGTransform::SVG_TRANSFORM_MATRIX;
    else
        return false;

    return true;
}
Exemple #12
0
bool parseAndSkipTransformType(const CharType*& ptr, const CharType* end, SVGTransformType& type)
{
    if (ptr >= end)
        return false;

    if (*ptr == 's') {
        if (skipString(ptr, end, skewXDesc, WTF_ARRAY_LENGTH(skewXDesc)))
            type = SVG_TRANSFORM_SKEWX;
        else if (skipString(ptr, end, skewYDesc, WTF_ARRAY_LENGTH(skewYDesc)))
            type = SVG_TRANSFORM_SKEWY;
        else if (skipString(ptr, end, scaleDesc, WTF_ARRAY_LENGTH(scaleDesc)))
            type = SVG_TRANSFORM_SCALE;
        else
            return false;
    } else if (skipString(ptr, end, translateDesc, WTF_ARRAY_LENGTH(translateDesc)))
        type = SVG_TRANSFORM_TRANSLATE;
    else if (skipString(ptr, end, rotateDesc, WTF_ARRAY_LENGTH(rotateDesc)))
        type = SVG_TRANSFORM_ROTATE;
    else if (skipString(ptr, end, matrixDesc, WTF_ARRAY_LENGTH(matrixDesc)))
        type = SVG_TRANSFORM_MATRIX;
    else
        return false;

    return true;
}
Exemple #13
0
void ungz (int ifd, int ofd) {
	uint8_t x[10];
	switch (readn (ifd, x, 10)) {
	case  0: return;
	case 10: break;
	default: errx (-1, "not in gz format");
	}
	if (x[0] != 0x1F || x[1] != 0x8B) errx (-1, "not in gz format");
	if (x[2] != 8) errx (-1, "unknown z-algorithm: 0x%0hhX", x[2]);
	if (x[3] & 1 << 2) /* FEXTRA */ {
		uint16_t n;
		uint8_t n_[2], _[1];
		readn (ifd, n_, 2);
		for (n = n_[0] << 0 | n_[1] << 8; n-- > 0; readn (ifd, _, 1));
	}
	if (x[3] & 1 << 3) /* FNAME    */ skipString (ifd);
	if (x[3] & 1 << 4) /* FCOMMENT */ skipString (ifd);
	if (x[3] & 1 << 1) /* FCRC */ {
		uint16_t _[1];
		readn (ifd, _, 2);
	}
	go (0, ifd, ofd);
}
Exemple #14
0
JSON::Pos JSON::skipNameValuePair() const
{
    //std::cerr << "skipNameValuePair()\t" << data() << std::endl;

    Pos pos = skipString();
    checkPos(pos);

    if (*pos != ':')
        throw JSONException("JSON: expected :.");
    ++pos;

    return JSON(pos, ptr_end, level + 1).skipElement();

}
Exemple #15
0
		static const char* skipValue(const char* json)
		{
			RIO_ASSERT_NOT_NULL(json);

			switch (*json)
			{
			case '"': json = skipString(json); break;
			case '[': json = skipBlock(json, '[', ']'); break;
			case '{': json = skipBlock(json, '{', '}'); break;
			default: for (; *json != ',' && *json != '\n' && *json != ' ' && *json != '}' && *json != ']'; ++json); break;
			}

			return json;
		}
Exemple #16
0
int checkSegment(FILE *f, char ending)
{
    struct ht_Table *status = ht_create(NUMBER_OF_SYMBOLS);
    struct ht_Table *opposites = ht_create(NUMBER_OF_OPPOSITES);
    initializeStatus(status);
    initializeOpposites(opposites);
    char CLOSERS[] = {')', '>', ']', '}'};
    char OPENERS[] = {'(', '<', '[', '{'};
    const int LISTS_LENGTH = 4;
    char last = 'a';
    char curr;
    while((curr = fgetc(f)) != EOF)
    {
        printf("%c", curr);
        if(curr == '#')
            skipLineComment(f);
        else if(curr == '*' && last == '/')
            skipBlockComment(f);
        else if(curr == '/' && last == '/')
            skipLineComment(f);
        else if(curr == '\'' || curr == '"')
        {
            if(skipString(f, curr) != 0)
                return 1;
        }
        else if(search(OPENERS, LISTS_LENGTH, curr) != -1)
        {
            (*ht_get(status, curr))++;
        }
        // Struct pointer references screw up the normal algorithm. Don't tell Tim Peters or Linus Torvalds
        else if(curr == '>' && last == '-')
        {}
        else if(search(CLOSERS, LISTS_LENGTH, curr) != -1)
        {
            char correspondingOpener = (char) (*ht_get(opposites, curr));
            int *num = ht_get(status, correspondingOpener);
            if(*num == 0)
            {
                printf("There is an unmatched %c!\n", curr);
                return 1;
            }
            else
            {
                (*num)--;
            }
        }
        last = curr;
    }
    return 0;
}
Exemple #17
0
/*****************************************************************************
 Skip everything up to an identifier start.
 *****************************************************************************/
const char *Parser_Perl::skipEverything (const char *cp)
{
    for (; *cp; cp++)
    {
        if (*cp == '"' || *cp == '\'')
        {
            cp = skipString(cp);
            if (!*cp) break;
        }
        if (isIdentifierFirstCharacter ((int) *cp))
            return cp;
    }
    return cp;
}
Exemple #18
0
    const char* readLine(const char *c){
      const char *c0 = c;
      bool breakNextLine = true;

      while(*c != '\0'){
        skipString(c);

        if(*c == '\0')
          break;

        if(*c == '\n'){
          if(breakNextLine)
            break;

          breakNextLine = false;
        }
        // Append next line
        else if((c[0] == '\\') && isWhitespace(c[1])){
          breakNextLine = true;
          ++c;
        }
        else if(c[0] == '/'){
          if(c[1] == '/'){
            while((*c != '\n') && (*c != '\0'))
              ++c;

            return c;
          }
          else if(c[1] == '*'){
            c += 2;

            while( !((c[0] == '*') && (c[1] == '/')) &&
                   (*c != '\0') )
              ++c;

            if(*c == '*')
              c += 2;

            return c;
          }
        }

        ++c;
      }

      return (c + 1);
    }
Exemple #19
0
    void property::skip(bitstream& stream, sendprop* prop) {
        switch (prop->getType()) {
            // Skip over Integer
            case sendprop::T_Int:
                skipInt(stream, prop);
                break;

            // Skip over Float
            case sendprop::T_Float:
                skipFloat(stream, prop);
                break;

            // Skip over 3D Vector
            case sendprop::T_Vector:
                skipVector(stream, prop);
                break;

            // Skip 2D Vector
            case sendprop::T_VectorXY:
                skipVectorXY(stream, prop);
                break;

            // Skip String
            case sendprop::T_String:
                skipString(stream);
                break;

            // Skip Array
            case sendprop::T_Array:
                skipArray(stream, prop);
                break;

            // Skip 64 bit Integer
            case sendprop::T_Int64:
                skipInt64(stream, prop);
                break;

            default:
                BOOST_THROW_EXCEPTION( propertyInvalidType()
                    << (EArgT<1, uint32_t>::info(prop->getType()))
                );
                break;
        }
    }
Exemple #20
0
void
MIFrfile::skipStatement()
{
  int ch;
  uns level = 1;

  while ((ch = getChar()) != EOF) {
    if (ch == '>') {
      if (--level == 0)
      break;
    }
    else if (ch == '<')
      level++;
    else if (ch == '\\')
      getChar();
    else if (ch == '`')
      skipString();
  }
  skipWhite();
}
Exemple #21
0
    int stripComments(std::string &line){
      std::string line2  = line;
      line = "";

      const char *cLeft  = line2.c_str();
      const char *cRight = cLeft;

      int status = readingCode;

      while(cRight != '\0'){
        skipString(cRight);

        if((*cRight == '\0') || (*cRight == '\n'))
          break;

        if((cRight[0] == '/') && (cRight[1] == '/')){
          line += std::string(cLeft, cRight - cLeft);
          return readingCode;
        }
        else if((cRight[0] == '/') && (cRight[1] == '*')){
          line += std::string(cLeft, cRight - cLeft);
          status = insideCommentBlock;
          cLeft = cRight + 2;
        }
        else if((cRight[0] == '*') && (cRight[1] == '/')){
          if(status == insideCommentBlock)
            status = readingCode;
          else
            status = finishedCommentBlock;
          cLeft = cRight + 2;
        }

        ++cRight;
      }

      if(cLeft != cRight)
        line += std::string(cLeft, cRight - cLeft);

      return status;
    }
Exemple #22
0
/**
 * skipPredicate:
 * @cur: the current pointer
 * @end: the current offset
 *
 * skip a predicate
 *
 * Returns the byte after the predicate or -1 in case of error
 */
static int
skipPredicate(const xmlChar *cur, int end) {
    if ((cur == NULL) || (end < 0)) return(-1);
    if (cur[end] != '[') return(end);
    end++;
    while (cur[end] != 0) {
        if ((cur[end] == '\'') || (cur[end] == '"')) {
	    end = skipString(cur, end);
	    if (end <= 0)
	        return(-1);
	    continue;
	} else if (cur[end] == '[') {
	    end = skipPredicate(cur, end);
	    if (end <= 0)
	        return(-1);
	    continue;
	} else if (cur[end] == ']')
	    return(end + 1);
	end++;
    }
    return(-1);
}
Exemple #23
0
JSON::ElementType JSON::getType() const
{
    switch (*ptr_begin)
    {
        case '{':
            return TYPE_OBJECT;
        case '[':
            return TYPE_ARRAY;
        case 't':
        case 'f':
            return TYPE_BOOL;
        case 'n':
            return TYPE_NULL;
        case '-':
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            return TYPE_NUMBER;
        case '"':
        {
            /// Проверим - это просто строка или name-value pair
            Pos after_string = skipString();
            if (after_string < ptr_end && *after_string == ':')
                return TYPE_NAME_VALUE_PAIR;
            else
                return TYPE_STRING;
        }
        default:
            throw JSONException(std::string("JSON: unexpected char ") + *ptr_begin + ", expected one of '{[tfn-0123456789\"'");
    }
}
Exemple #24
0
bool SVGViewSpec::parseViewSpec(const String& viewSpec)
{
    const UChar* currViewSpec = viewSpec.deprecatedCharacters();
    const UChar* end = currViewSpec + viewSpec.length();

    if (currViewSpec >= end || !m_contextElement)
        return false;

    if (!skipString(currViewSpec, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec)))
        return false;

    if (currViewSpec >= end || *currViewSpec != '(')
        return false;
    currViewSpec++;

    while (currViewSpec < end && *currViewSpec != ')') {
        if (*currViewSpec == 'v') {
            if (skipString(currViewSpec, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))) {
                if (currViewSpec >= end || *currViewSpec != '(')
                    return false;
                currViewSpec++;
                FloatRect viewBox;
                if (!SVGFitToViewBox::parseViewBox(&m_contextElement->document(), currViewSpec, end, viewBox, false))
                    return false;
                setViewBoxBaseValue(viewBox);
                if (currViewSpec >= end || *currViewSpec != ')')
                    return false;
                currViewSpec++;
            } else if (skipString(currViewSpec, end, viewTargetSpec, WTF_ARRAY_LENGTH(viewTargetSpec))) {
                if (currViewSpec >= end || *currViewSpec != '(')
                    return false;
                const UChar* viewTargetStart = ++currViewSpec;
                while (currViewSpec < end && *currViewSpec != ')')
                    currViewSpec++;
                if (currViewSpec >= end)
                    return false;
                setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart));
                currViewSpec++;
            } else
                return false;
        } else if (*currViewSpec == 'z') {
            if (!skipString(currViewSpec, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPanSpec)))
                return false;
            if (currViewSpec >= end || *currViewSpec != '(')
                return false;
            currViewSpec++;
            if (!parseZoomAndPan(currViewSpec, end, m_zoomAndPan))
                return false;
            if (currViewSpec >= end || *currViewSpec != ')')
                return false;
            currViewSpec++;
        } else if (*currViewSpec == 'p') {
            if (!skipString(currViewSpec, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(preserveAspectRatioSpec)))
                return false;
            if (currViewSpec >= end || *currViewSpec != '(')
                return false;
            currViewSpec++;
            SVGPreserveAspectRatio preserveAspectRatio;
            if (!preserveAspectRatio.parse(currViewSpec, end, false))
                return false;
            setPreserveAspectRatioBaseValue(preserveAspectRatio);
            if (currViewSpec >= end || *currViewSpec != ')')
                return false;
            currViewSpec++;
        } else if (*currViewSpec == 't') {
            if (!skipString(currViewSpec, end, transformSpec, WTF_ARRAY_LENGTH(transformSpec)))
                return false;
            if (currViewSpec >= end || *currViewSpec != '(')
                return false;
            currViewSpec++;
            SVGTransformable::parseTransformAttribute(m_transform, currViewSpec, end, SVGTransformable::DoNotClearList);
            if (currViewSpec >= end || *currViewSpec != ')')
                return false;
            currViewSpec++;
        } else
            return false;

        if (currViewSpec < end && *currViewSpec == ';')
            currViewSpec++;
    }
    
    if (currViewSpec >= end || *currViewSpec != ')')
        return false;

    return true;
}
bool SVGPreserveAspectRatio::parseInternal(const CharType*& ptr, const CharType* end, bool validate)
{
    // FIXME: Rewrite this parser, without gotos!
    if (!skipOptionalSVGSpaces(ptr, end))
        goto bailOut;

    if (*ptr == 'd') {
        if (!skipString(ptr, end, "defer"))
            goto bailOut;

        // FIXME: We just ignore the "defer" here.
        if (ptr == end)
            return true;

        if (!skipOptionalSVGSpaces(ptr, end))
            goto bailOut;
    }

    if (*ptr == 'n') {
        if (!skipString(ptr, end, "none"))
            goto bailOut;
        m_align = SVG_PRESERVEASPECTRATIO_NONE;
        skipOptionalSVGSpaces(ptr, end);
    } else if (*ptr == 'x') {
        if ((end - ptr) < 8)
            goto bailOut;
        if (ptr[1] != 'M' || ptr[4] != 'Y' || ptr[5] != 'M')
            goto bailOut;
        if (ptr[2] == 'i') {
            if (ptr[3] == 'n') {
                if (ptr[6] == 'i') {
                    if (ptr[7] == 'n')
                        m_align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
                    else if (ptr[7] == 'd')
                        m_align = SVG_PRESERVEASPECTRATIO_XMINYMID;
                    else
                        goto bailOut;
                } else if (ptr[6] == 'a' && ptr[7] == 'x')
                     m_align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
                else
                     goto bailOut;
            } else if (ptr[3] == 'd') {
                if (ptr[6] == 'i') {
                    if (ptr[7] == 'n')
                        m_align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
                    else if (ptr[7] == 'd')
                        m_align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
                    else
                        goto bailOut;
                } else if (ptr[6] == 'a' && ptr[7] == 'x')
                    m_align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
                else
                    goto bailOut;
            } else
                goto bailOut;
        } else if (ptr[2] == 'a' && ptr[3] == 'x') {
            if (ptr[6] == 'i') {
                if (ptr[7] == 'n')
                    m_align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
                else if (ptr[7] == 'd')
                    m_align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
                else
                    goto bailOut;
            } else if (ptr[6] == 'a' && ptr[7] == 'x')
                m_align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
            else
                goto bailOut;
        } else
            goto bailOut;
        ptr += 8;
        skipOptionalSVGSpaces(ptr, end);
    } else
        goto bailOut;

    if (ptr < end) {
        if (*ptr == 'm') {
            if (!skipString(ptr, end, "meet"))
                goto bailOut;
            skipOptionalSVGSpaces(ptr, end);
        } else if (*ptr == 's') {
            if (!skipString(ptr, end, "slice"))
                goto bailOut;
            skipOptionalSVGSpaces(ptr, end);
            if (m_align != SVG_PRESERVEASPECTRATIO_NONE)
                m_meetOrSlice = SVG_MEETORSLICE_SLICE;
        }
    }

    if (end != ptr && validate) {
bailOut:
        m_align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
        m_meetOrSlice = SVG_MEETORSLICE_MEET;
        return false;
    }
    return true;
}
Exemple #26
0
bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr, const CharType* end)
{
    if (!skipString(ptr, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec)))
        return false;

    if (ptr >= end || *ptr != '(')
        return false;
    ptr++;

    while (ptr < end && *ptr != ')') {
        if (*ptr == 'v') {
            if (skipString(ptr, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))) {
                if (ptr >= end || *ptr != '(')
                    return false;
                ptr++;
                float x = 0.0f;
                float y = 0.0f;
                float width = 0.0f;
                float height = 0.0f;
                if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && parseNumber(ptr, end, width) && parseNumber(ptr, end, height, DisallowWhitespace)))
                    return false;
                updateViewBox(FloatRect(x, y, width, height));
                if (ptr >= end || *ptr != ')')
                    return false;
                ptr++;
            } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(viewTargetSpec))) {
                if (ptr >= end || *ptr != '(')
                    return false;
                const CharType* viewTargetStart = ++ptr;
                while (ptr < end && *ptr != ')')
                    ptr++;
                if (ptr >= end)
                    return false;
                m_viewTargetString = String(viewTargetStart, ptr - viewTargetStart);
                ptr++;
            } else
                return false;
        } else if (*ptr == 'z') {
            if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPanSpec)))
                return false;
            if (ptr >= end || *ptr != '(')
                return false;
            ptr++;
            if (!parseZoomAndPan(ptr, end))
                return false;
            if (ptr >= end || *ptr != ')')
                return false;
            ptr++;
        } else if (*ptr == 'p') {
            if (!skipString(ptr, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(preserveAspectRatioSpec)))
                return false;
            if (ptr >= end || *ptr != '(')
                return false;
            ptr++;
            if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false))
                return false;
            if (ptr >= end || *ptr != ')')
                return false;
            ptr++;
        } else if (*ptr == 't') {
            if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformSpec)))
                return false;
            if (ptr >= end || *ptr != '(')
                return false;
            ptr++;
            m_transform->baseValue()->parse(ptr, end);
            if (ptr >= end || *ptr != ')')
                return false;
            ptr++;
        } else
            return false;

        if (ptr < end && *ptr == ';')
            ptr++;
    }

    if (ptr >= end || *ptr != ')')
        return false;

    return true;
}
std::shared_ptr<Operand> PredicateParser::createPrimitive(const std::string& fullExpression, size_t from, size_t to)
{
    from = skipSpace(fullExpression, from, to);
    while(to > from && std::isspace(fullExpression.at(to - 1)))
    {
        --to;
    }

    if(from >= to)
    {
        return nullptr;
    }

    char c = fullExpression.at(from);
    switch(c)
    {
    case '"':
    {
        auto last = skipString(fullExpression, from + 1, to);
        auto str = fullExpression.substr(from + 1, last - from - 1);
        if(last == to)
        {
            throw std::logic_error(str + " not a string");
        }

        return std::make_shared<StringOperand>(str);
    }
    case '^':
    case '.':
    {
        Compiler subCompiler;
        auto subExpression = subCompiler.compile(fullExpression, from, to);
        return std::make_shared<LocationOperand>(subExpression);
    }
    case '{':
    case '[':
    {
        std::stack<char> unmatched;
        unmatched.push(c);
        auto last = skip2MatchParenthesis(unmatched, fullExpression, from + 1, to);
        auto str = fullExpression.substr(from, last - from + 1);
        if(last == to)
        {
            throw std::logic_error(str + " not a json");
        }

        json value = json::parse(str);
        return std::make_shared<JsonOperand>(value);
    }
    case '/':
    {
        auto toPos = skip2(fullExpression, from + 1, '/', to);
        auto regex = fullExpression.substr(from + 1, toPos - from - 1);
        return std::make_shared<RegexOperand>(regex);
    }
    case '$':
    {
        auto variableName = fullExpression.substr(from + 1, to - from - 1);
        return std::make_shared<VariableOperand>(variableName);
    }
    default:
        if(isBool(fullExpression, from, to) && '0' != fullExpression.at(from) && '1' != fullExpression.at(from))
        {
            bool v = convert2Bool(fullExpression, from, to);
            return std::make_shared<BoolOperand>(v);
        }
        else if(isInt(fullExpression, from, to))
        {
            int v = convert2Int(fullExpression, from, to);
            return std::make_shared<IntOperand>(v);
        }
        else if(isReal(fullExpression, from, to))
        {
            double v = convert2Real(fullExpression, from, to);
            return std::make_shared<RealOperand>(v);
        }
        else
        {
            throw std::logic_error(fullExpression.substr(from, to - from) + " can't be interpreted as an operand");
        }
    }
}
Exemple #28
0
SVGPreserveAspectRatio SVGPreserveAspectRatio::parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate, bool& result)
{
    SVGPreserveAspectRatio aspectRatio;
    aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_NONE;
    aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_MEET;
    result = false;

    // FIXME: Rewrite this parser, without gotos!
    if (!skipOptionalSpaces(currParam, end))
        goto bail_out;

    if (*currParam == 'd') {
        if (!skipString(currParam, end, "defer"))
            goto bail_out;
        // FIXME: We just ignore the "defer" here.
        if (!skipOptionalSpaces(currParam, end))
            goto bail_out;
    }

    if (*currParam == 'n') {
        if (!skipString(currParam, end, "none"))
            goto bail_out;
        skipOptionalSpaces(currParam, end);
    } else if (*currParam == 'x') {
        if ((end - currParam) < 8)
            goto bail_out;
        if (currParam[1] != 'M' || currParam[4] != 'Y' || currParam[5] != 'M')
            goto bail_out;
        if (currParam[2] == 'i') {
            if (currParam[3] == 'n') {
                if (currParam[6] == 'i') {
                    if (currParam[7] == 'n')
                        aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
                    else if (currParam[7] == 'd')
                        aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMID;
                    else
                        goto bail_out;
                } else if (currParam[6] == 'a' && currParam[7] == 'x')
                     aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
                else
                     goto bail_out;
             } else if (currParam[3] == 'd') {
                if (currParam[6] == 'i') {
                    if (currParam[7] == 'n')
                        aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
                    else if (currParam[7] == 'd')
                        aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
                    else
                        goto bail_out;
                } else if (currParam[6] == 'a' && currParam[7] == 'x')
                    aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
                else
                    goto bail_out;
            } else
                goto bail_out;
        } else if (currParam[2] == 'a' && currParam[3] == 'x') {
            if (currParam[6] == 'i') {
                if (currParam[7] == 'n')
                    aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
                else if (currParam[7] == 'd')
                    aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
                else
                    goto bail_out;
            } else if (currParam[6] == 'a' && currParam[7] == 'x')
                aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
            else
                goto bail_out;
        } else
            goto bail_out;
        currParam += 8;
        skipOptionalSpaces(currParam, end);
    } else
        goto bail_out;

    if (currParam < end) {
        if (*currParam == 'm') {
            if (!skipString(currParam, end, "meet"))
                goto bail_out;
            skipOptionalSpaces(currParam, end);
        } else if (*currParam == 's') {
            if (!skipString(currParam, end, "slice"))
                goto bail_out;
            skipOptionalSpaces(currParam, end);
            if (aspectRatio.m_align != SVG_PRESERVEASPECTRATIO_NONE)
                aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_SLICE;    
        }
    }

    if (end != currParam && validate) {
bail_out:
        // FIXME: Should the two values be set to UNKNOWN instead?
        aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_NONE;
        aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_MEET;
    } else
        result = true;

    return aspectRatio;
}
bool SVGViewSpec::parseViewSpec(const String& viewSpec)
{
    const UChar* currViewSpec = viewSpec.characters();
    const UChar* end = currViewSpec + viewSpec.length();

    if (currViewSpec >= end)
        return false;

    if (!skipString(currViewSpec, end, svgViewSpec, sizeof(svgViewSpec) / sizeof(UChar)))
        return false;

    if (currViewSpec >= end || *currViewSpec != '(' )
        return false;
    currViewSpec++;

    while (currViewSpec < end && *currViewSpec != ')') {
        if (*currViewSpec == 'v') {
            if (skipString(currViewSpec, end, viewBoxSpec, sizeof(viewBoxSpec) / sizeof(UChar))) {
                if (currViewSpec >= end || *currViewSpec != '(')
                    return false;
                currViewSpec++;
                float x, y, w, h;
                if (!parseViewBox(currViewSpec, end, x, y, w, h, false))
                    return false;
                setViewBoxBaseValue(FloatRect(x, y, w, h));
                if (currViewSpec >= end || *currViewSpec != ')')
                    return false;
                currViewSpec++;
            } else if (skipString(currViewSpec, end, viewTargetSpec, sizeof(viewTargetSpec) / sizeof(UChar))) {
                if (currViewSpec >= end || *currViewSpec != '(')
                    return false;
                const UChar* viewTargetStart = ++currViewSpec;
                while (currViewSpec < end && *currViewSpec != ')')
                    currViewSpec++;
                if (currViewSpec >= end)
                    return false;
                setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart));
                currViewSpec++;
            } else
                return false;
        } else if (*currViewSpec == 'z') {
            if (!skipString(currViewSpec, end, zoomAndPanSpec, sizeof(zoomAndPanSpec) / sizeof(UChar)))
                return false;
            if (currViewSpec >= end || *currViewSpec != '(')
                return false;
            currViewSpec++;
            if (!parseZoomAndPan(currViewSpec, end))
                return false;
            if (currViewSpec >= end || *currViewSpec != ')')
                return false;
            currViewSpec++;
        } else if (*currViewSpec == 'p') {
            if (!skipString(currViewSpec, end, preserveAspectRatioSpec, sizeof(preserveAspectRatioSpec) / sizeof(UChar)))
                return false;
            if (currViewSpec >= end || *currViewSpec != '(')
                return false;
            currViewSpec++;
            if (!preserveAspectRatioBaseValue()->parsePreserveAspectRatio(currViewSpec, end, false))
                return false;
            if (currViewSpec >= end || *currViewSpec != ')')
                return false;
            currViewSpec++;
        } else if (*currViewSpec == 't') {
            if (!skipString(currViewSpec, end, transformSpec, sizeof(transformSpec) / sizeof(UChar)))
                return false;
            if (currViewSpec >= end || *currViewSpec != '(')
                return false;
            currViewSpec++;
            SVGTransformable::parseTransformAttribute(m_transform.get(), currViewSpec, end);
            if (currViewSpec >= end || *currViewSpec != ')')
                return false;
            currViewSpec++;
        } else
            return false;

        if (currViewSpec < end && *currViewSpec == ';')
            currViewSpec++;
    }
    
    if (currViewSpec >= end || *currViewSpec != ')')
        return false;

    return true;
}
Exemple #30
0
  void
putSymbolPointersIntoAssert(void)
{
	putSymbolPointersIntoExpression();
	skipString();
}