예제 #1
0
void testSkipToken(void)
{
	Tokenizer tokenizer;
	Token *token;

	initTokenizer(&tokenizer, "1 a ( ) [ ]");
	token = skipToken(&tokenizer, 4);
	ASSERT(token->type == TOKEN_OPEN_SQUARE_BRACKET);

	token = skipToken(&tokenizer, -1);
}
예제 #2
0
bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr,
                                        const CharType* end) {
  if (!skipToken(ptr, end, "svgView"))
    return false;

  if (!skipExactly<CharType>(ptr, end, '('))
    return false;

  while (ptr < end && *ptr != ')') {
    ViewSpecFunctionType functionType = scanViewSpecFunction(ptr, end);
    if (functionType == Unknown)
      return false;

    if (!skipExactly<CharType>(ptr, end, '('))
      return false;

    switch (functionType) {
      case ViewBox: {
        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));
        break;
      }
      case ViewTarget: {
        const CharType* viewTargetStart = ptr;
        skipUntil<CharType>(ptr, end, ')');
        if (ptr == viewTargetStart)
          return false;
        m_viewTargetString = String(viewTargetStart, ptr - viewTargetStart);
        break;
      }
      case ZoomAndPan:
        if (!parseZoomAndPan(ptr, end))
          return false;
        break;
      case PreserveAspectRatio:
        if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false))
          return false;
        break;
      case Transform:
        m_transform->baseValue()->parse(ptr, end);
        break;
      default:
        NOTREACHED();
        break;
    }

    if (!skipExactly<CharType>(ptr, end, ')'))
      return false;

    skipExactly<CharType>(ptr, end, ';');
  }
  return skipExactly<CharType>(ptr, end, ')');
}
예제 #3
0
파일: swap.c 프로젝트: rockmetoo/monitad
/**
 * XXX: IMPORTANt - result will show in Kb
 */
void getSwapUsage(monita_swap* buf)
{
    char buffer [BUFSIZ];
    char* p;

    memset(buf, 0, sizeof (monita_swap));

    fileToBuffer(buffer, sizeof buffer, MEMINFO);

    // XXX: IMPORTANT - Kernel 2.6 with multiple lines
    buf->total	= getScaled(buffer, "SwapTotal:");
    buf->free	= getScaled(buffer, "SwapFree:");
    buf->cached	= getScaled(buffer, "Cached:");
    buf->used	= buf->total - buf->free;

    unsigned long osVersionCode = getLinuxVersionCode();

    if(osVersionCode >= LINUX_VERSION_CODE(2, 6, 0))
    {
        fileToBuffer(buffer, sizeof buffer, PROC_VMSTAT);

        p = strstr(buffer, "\npswpin");

        if(p)
        {
            p = skipToken(p);
            buf->pagein  = strtoull(p, &p, 0);

            p = skipToken(p);
            buf->pageout = strtoull(p, &p, 0);
        }
    }
    else // Linux 2.4
    {
        fileToBuffer(buffer, sizeof buffer, PROC_STAT);

        p = strstr(buffer, "\nswap");

        if(p)
        {
            p = skipToken(p);

            buf->pagein  = strtoull(p, &p, 0);
            buf->pageout = strtoull(p, &p, 0);
        }
    }
}
예제 #4
0
bool spark::JSONArrayIterator::next() {
    if (!n_) {
        return false;
    }
    v_ = t_;
    --n_;
    if (n_) {
        t_ = skipToken(t_);
    }
    return true;
}
예제 #5
0
bool spark::JSONObjectIterator::next() {
    if (!n_) {
        return false;
    }
    k_ = t_; // Name
    ++t_;
    v_ = t_; // Value
    --n_;
    if (n_) {
        t_ = skipToken(t_);
    }
    return true;
}
예제 #6
0
파일: parser.cpp 프로젝트: dunk8888/Cube4
byte parseCommand(
  char       *message,
  byte        length,
  byte       *position,
  command_t **command) {

  byte errorCode = 5;

  for (byte commandType = 0;  commandType < commandCount;  commandType ++) {
    *command = & commands[commandType];

    if (stringCompare((*command)->name, & message[*position])) {
      skipToken(message, length, position);
      errorCode = 0;
      break;
    }
  }

  return(errorCode);
}
daeBool
daeAtomicType::stringToArray(daeChar* src, daeArray& array) {
	array.clear();
	array.setElementSize(_size);

	if (src == 0)
		return false;

	// We're about to insert null terminators into the string so that scanf doesn't take forever
	// doing strlens. Since the memory might not be writable, I need to duplicate the string and
	// write into the duplicate, or else I might get access violations.
	// This sucks... surely we can do better than this.
	daeChar* srcDup = new daeChar[strlen(src)+1];
	strcpy(srcDup, src);
	src = srcDup;

	while (*src != 0)
	{
		src = skipWhitespace(src);
		if(*src != 0)
		{
			daeChar* token = src;
			src = skipToken(src);
			daeChar temp = *src;
			*src = 0;
			size_t count = array.getCount();
			array.setCount(count+1);
			if (!stringToMemory(token, array.getRaw(count))) {
				delete[] srcDup;
				return false;
			}

			*src = temp;
		}
	}

	delete[] srcDup;
	return true;
}
예제 #8
0
ContentSecurityPolicy::ReflectedXSSDisposition parseXSSProtectionHeader(const String& header, String& failureReason, unsigned& failurePosition, String& reportURL)
{
    DEFINE_STATIC_LOCAL(String, failureReasonInvalidToggle, (ASCIILiteral("expected 0 or 1")));
    DEFINE_STATIC_LOCAL(String, failureReasonInvalidSeparator, (ASCIILiteral("expected semicolon")));
    DEFINE_STATIC_LOCAL(String, failureReasonInvalidEquals, (ASCIILiteral("expected equals sign")));
    DEFINE_STATIC_LOCAL(String, failureReasonInvalidMode, (ASCIILiteral("invalid mode directive")));
    DEFINE_STATIC_LOCAL(String, failureReasonInvalidReport, (ASCIILiteral("invalid report directive")));
    DEFINE_STATIC_LOCAL(String, failureReasonDuplicateMode, (ASCIILiteral("duplicate mode directive")));
    DEFINE_STATIC_LOCAL(String, failureReasonDuplicateReport, (ASCIILiteral("duplicate report directive")));
    DEFINE_STATIC_LOCAL(String, failureReasonInvalidDirective, (ASCIILiteral("unrecognized directive")));

    unsigned pos = 0;

    if (!skipWhiteSpace(header, pos, false))
        return ContentSecurityPolicy::ReflectedXSSUnset;

    if (header[pos] == '0')
        return ContentSecurityPolicy::AllowReflectedXSS;

    if (header[pos++] != '1') {
        failureReason = failureReasonInvalidToggle;
        return ContentSecurityPolicy::ReflectedXSSInvalid;
    }

    ContentSecurityPolicy::ReflectedXSSDisposition result = ContentSecurityPolicy::FilterReflectedXSS;
    bool modeDirectiveSeen = false;
    bool reportDirectiveSeen = false;

    while (1) {
        // At end of previous directive: consume whitespace, semicolon, and whitespace.
        if (!skipWhiteSpace(header, pos, false))
            return result;

        if (header[pos++] != ';') {
            failureReason = failureReasonInvalidSeparator;
            failurePosition = pos;
            return ContentSecurityPolicy::ReflectedXSSInvalid;
        }

        if (!skipWhiteSpace(header, pos, false))
            return result;

        // At start of next directive.
        if (skipToken(header, pos, "mode")) {
            if (modeDirectiveSeen) {
                failureReason = failureReasonDuplicateMode;
                failurePosition = pos;
                return ContentSecurityPolicy::ReflectedXSSInvalid;
            }
            modeDirectiveSeen = true;
            if (!skipEquals(header, pos)) {
                failureReason = failureReasonInvalidEquals;
                failurePosition = pos;
                return ContentSecurityPolicy::ReflectedXSSInvalid;
            }
            if (!skipToken(header, pos, "block")) {
                failureReason = failureReasonInvalidMode;
                failurePosition = pos;
                return ContentSecurityPolicy::ReflectedXSSInvalid;
            }
            result = ContentSecurityPolicy::BlockReflectedXSS;
        } else if (skipToken(header, pos, "report")) {
            if (reportDirectiveSeen) {
                failureReason = failureReasonDuplicateReport;
                failurePosition = pos;
                return ContentSecurityPolicy::ReflectedXSSInvalid;
            }
            reportDirectiveSeen = true;
            if (!skipEquals(header, pos)) {
                failureReason = failureReasonInvalidEquals;
                failurePosition = pos;
                return ContentSecurityPolicy::ReflectedXSSInvalid;
            }
            size_t startPos = pos;
            if (!skipValue(header, pos)) {
                failureReason = failureReasonInvalidReport;
                failurePosition = pos;
                return ContentSecurityPolicy::ReflectedXSSInvalid;
            }
            reportURL = header.substring(startPos, pos - startPos);
            failurePosition = startPos; // If later semantic check deems unacceptable.
        } else {
            failureReason = failureReasonInvalidDirective;
            failurePosition = pos;
            return ContentSecurityPolicy::ReflectedXSSInvalid;
        }
    }
}