Esempio n. 1
0
vector< pair<int,int> > parsePointList(string::const_iterator& p, const string::const_iterator& end) {
	vector< pair<int,int> > result;

	skipSpaces(p, end);
	if (p == end) {
		return vector< pair<int,int> >();  // error
	}

	if (*p == '[') {
		++p;
	} else {
		return vector< pair<int,int> >();  // error
	}

	while(p != end) {
		const pair<int,int>& pt = parsePoint(p, end);
		result.push_back(pt);

		skipSpaces(p, end);
		if (p == end) {
			return vector< pair<int,int> >();  // error
		}

		if (*p == ',') {
			++p;
		} else if (*p == ']') {
			++p;
			skipSpaces(p, end);  // read to end
		} else {
			return vector< pair<int,int> >();  // error
		}
	}

	return result;
}
Esempio n. 2
0
	JSONParser( const std::string& jsonStr ) : std::map< std::string, std::string >() {
		m_jsonStr = jsonStr;
		pos = 1;
		skipSpaces();

		long keyCount = 0;
		std::string key;
		while ( pos < m_jsonStr.length() ) {
			if ( ( m_jsonStr[ 0 ] == '[' ) || keyCount ) {
				key = numToStr( keyCount++ );
			}
			else {
				key = findKey();
			}
			if ( pos >= m_jsonStr.length() ) {
				return;
			}
			std::string value = findValue( keyCount != 0 );
			insert( std::pair< std::string, std::string >( key, value ) );
			if ( keyCount && ( m_jsonStr[ pos ] == ',' || m_jsonStr[ pos ] == ']' ) ) {
				++pos;
				skipSpaces();
			}
			else {
				moveToEndChar();
            }
		}
	}
Esempio n. 3
0
// Skips over intervening non-data elements in a netpbm file
static
void skipNonData(FILE *src)
{
    skipSpaces(src);
    skipComments(src);
    skipSpaces(src);
}
Esempio n. 4
0
double Calculator::parseSymbol(std::string_view &ref)
{
	double value = 0;
	skipSpaces(ref);
	if (!ref.empty() && ref[0] == '(')
	{
		ref.remove_prefix(1);
		value = parseExprSum(ref);
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == ')')
		{
			ref.remove_prefix(1);
			return value;
		}
		else
		{
			return std::numeric_limits<double>::quiet_NaN();
		}
	}
	else if (!ref.empty() && !std::isdigit(ref[0]) && ref[0] != '-')
	{
		return parseFunction(ref);
	}
	else
	{
		return parseDouble(ref);
	}
}
Esempio n. 5
0
void 
XmlUniformiser::copyElementAttributes()
{
  do
  {
    bool hadSpace = isSpace();
    skipSpaces();
    if ( startsWith( ">" ) )
      break;

    if ( hadSpace )
      m_stripped += ' ';

    copyAttributeName();
    skipSpaces();
    if ( startsWith( "=" ) )
    {
      copyNext();
      copyAttributeValue();
    }
    else    // attribute should always be valued, ne ?
      m_stripped += ' ';
  }
  while ( isValidIndex() );
  copyNext();
}
Esempio n. 6
0
File: Rjson.cpp Progetto: XoDeR/RE
		void parseArray(const char* json, JsonArray& array)
		{
			RIO_ASSERT_NOT_NULL(json);

			if (*json == '[')
			{
				json = getNext(json, '[');
				json = skipSpaces(json);

				if (*json == ']')
				{
					json = getNext(json, ']');
					return;
				}

				while (*json)
				{
					ArrayFn::pushBack(array, json);

					json = skipValue(json);
					json = skipSpaces(json);

					if (*json == ']')
					{
						json = getNext(json, ']');
						return;
					}

					json = skipSpaces(json);
				}
			}

			RIO_FATAL("Bad array");
		}
Esempio n. 7
0
static const char PROGMEM *jsonParseArray(char **buffer, const t_json *currentStructure) {
    char *buf =  *buffer;
    jsonHandleEndArray endFunc = (jsonHandleEndArray) pgm_read_word(&currentStructure->handleEndArray);
    if (currentStructure && !endFunc) {
        return PSTR("Unexpected array");
    }
    uint8_t count = 0;
    do {
        buf = skipSpaces(&buf[1]); // skip '[' and then ',' on each loop
        if (buf[0] == ']') {
        	break;
        }
        const char PROGMEM *res = jsonParseValue(&buf, currentStructure, count);
        if (res) {
            return res;
        }
//        DEBUG_PRINT(">>>S>");
//        DEBUG_PRINT(buf[0]);
//        DEBUG_PRINTLN(buf[1]);
        buf = skipSpaces(buf);
        count++;
    } while (buf[0] == ',');
    buf = skipSpaces(buf);
    if (buf[0] != ']') { // end of object
        return JSON_ERROR_NO_ARRAY_END;
    }

    const char PROGMEM *res = endFunc(count);
    if (res) {
        return res;
    }
    buf = skipSpaces(&buf[1]); // going out of array
    *buffer = buf;
    return 0;
}
static std::vector<AlterMetaDataCommand> parseCommands( const std::string& source)
{
	std::vector<AlterMetaDataCommand> rt;
	std::string::const_iterator si = source.begin(), se = source.end();

	for (si = skipSpaces( si, se); si != se; si = skipSpaces( si, se))
	{
		std::string cmd( parseIdentifier( si, se, _TXT("command name")));
		if (strus::utils::caseInsensitiveEquals( cmd, "Alter"))
		{
			std::string name( parseIdentifier( si, se, _TXT("old element name")));
			std::string newname( parseIdentifier( si, se, _TXT("new element name")));
			std::string type( parseIdentifier( si, se, _TXT("new element type")));

			rt.push_back( AlterMetaDataCommand::AlterElement( name, newname, type));
		}
		else if (strus::utils::caseInsensitiveEquals( cmd, "Add"))
		{
			std::string name( parseIdentifier( si, se, _TXT("element name")));
			std::string type( parseIdentifier( si, se, _TXT("element type name")));

			rt.push_back( AlterMetaDataCommand::AddElement( name, type));
		}
		else if (strus::utils::caseInsensitiveEquals( cmd, "Rename"))
		{
			std::string name( parseIdentifier( si, se, _TXT("old element name")));
			std::string newname( parseIdentifier( si, se, _TXT("new element name")));

			rt.push_back( AlterMetaDataCommand::RenameElement( name, newname));
		}
		else if (strus::utils::caseInsensitiveEquals( cmd, "Delete"))
		{
			std::string name( parseIdentifier( si, se, _TXT("element name")));

			rt.push_back( AlterMetaDataCommand::DeleteElement( name));
		}
		else if (strus::utils::caseInsensitiveEquals( cmd, "Clear"))
		{
			std::string name( parseIdentifier( si, se, _TXT("element name")));
			
			rt.push_back( AlterMetaDataCommand::ClearValue( name));
		}
		si = skipSpaces( si, se);
		if (si == se)
		{
			break;
		}
		else if (*si == ';')
		{
			++si;
		}
		else
		{
			std::string str( si, si+30);
			throw strus::runtime_error( _TXT( "semicolon expected as separator of commands at '..."), str.c_str());
		}
	}
	return rt;
}
Esempio n. 9
0
static struct reglist_t const *registerDefs(void){
	static struct reglist_t *regs = 0 ;
	if( 0 == regs ){
		struct reglist_t *head = 0, *tail = 0 ;
		FILE *fDefs = fopen(devregsPath, "rt");
		if( fDefs ){
			char inBuf[256];
			int lineNum = 0 ;
			while( fgets(inBuf,sizeof(inBuf),fDefs) ){
				lineNum++ ;
				// skip unprintables
                                char *next = skipSpaces(inBuf);
				if( *next && ('#' != *next) ){
					trimCtrl(next);
					printf( "<%s>\n", next );
				} // not blank or comment
				if(isalpha(*next)){
					char *start = next++ ;
					while(isalnum(*next) || ('_' == *next)){
						next++ ;
					}
					if(isspace(*next)){
						char *end=next-1 ;
						next=skipSpaces(next);
						if(isxdigit(*next)){
							char *addrEnd ;
							unsigned long addr = strtoul(next,&addrEnd,16);
							if('\0'==*addrEnd){
								unsigned namelen = end-start ;
								char *name = (char *)malloc(namelen+1);
								memcpy(name,start,namelen);
								name[namelen] = '\0' ;
                                                                struct reglist_t *newone = new reglist_t ;
								newone->address=addr ;
								newone->reg = new registerDescription_t ;
								newone->reg->name = name ;
								newone->reg->fields = newone->fields = 0 ;
								if(tail){
									tail->next = newone ;
								} else
									head = newone ;
								tail = newone ;
								continue;
							}
						}
					}
					fprintf(stderr, "%s: syntax error on line %u\n", devregsPath, lineNum );
				} else if(tail){
				}
			}
			fclose(fDefs);
			regs = head ;
		}
		else
			perror(devregsPath);
	}
	return regs ;
}
Esempio n. 10
0
static wchar_t *parseItem (TCollection *dc, wchar_t * &line, wchar_t *kwd, wchar_t *value)
{
	if (IsCharAlpha (*skipSpaces (line)))
	{
		wchar_t	*k = kwd;
		while (*line && IsCharAlpha (*line)) *k++ = *line++;
		*k = *value = 0;
		if (*skipSpaces (line) == L'=')
		{
			line++;
			if (!dc)
			{
				getWord (line, value);
			}
			else
			{
				wchar_t	buf[MAX_STR_LEN], *pv = value;
				getWord (line, buf);
				for (wchar_t *pch = buf; *pch;)
				{
					if (L'&' != *pch)
					{
						*pv++ = *pch++;
					}
					else
					{
						++pch;						//skip '&'
						wchar_t	name[MAX_STR_LEN], *pname = name;
						while (*pch && *pch != L';') *pname++ = *pch++;
						*pname = 0;

						//if (!*pch) complain about entity reference syntax;
						if (*pch) ++pch;	//skip
															///';
															///'
						for (size_t i = 0; i < dc->getCount (); ++i)
						{
							TDefine *d = (TDefine *) ((*dc)[i]);
							if (0 == wcscmp (d->name, name))
							{
								for (const wchar_t *pdv = d->value; *pdv;) *pv++ = *pdv++;
								break;
							}
						}

						//if (i == dc->getCount()) complain about undefined entity;
					}
				}

				*pv = 0;
			}
		}

		return (line);
	}

	return (NULL);
}
KviKvsTreeNodeExpression * KviKvsParser::parseExpressionOperand(char terminator)
{
	switch(KVSP_curCharUnicode)
	{
		case 0:
		case '\r':
		case '\n':
			error(KVSP_curCharPointer, __tr2qs_ctx("Unexpected end of script in expression", "kvs"));
			return nullptr;
			break;
		case '(':
			KVSP_skipChar;
			skipSpaces();
			return parseExpression(')'); // sub expression
			break;
		case '-':
		{
			KVSP_skipChar;
			skipSpaces();
			KviKvsTreeNodeExpression * d = parseExpressionOperand(terminator);
			if(!d)
				return nullptr;
			return new KviKvsTreeNodeExpressionUnaryOperatorNegate(d->location(), d);
		}
		break;
		case '!':
		{
			KVSP_skipChar;
			skipSpaces();
			KviKvsTreeNodeExpression * d = parseExpressionOperand(terminator);
			if(!d)
				return nullptr;
			return new KviKvsTreeNodeExpressionUnaryOperatorLogicalNot(d->location(), d);
		}
		break;
		case '~':
		{
			KVSP_skipChar;
			skipSpaces();
			KviKvsTreeNodeExpression * d = parseExpressionOperand(terminator);
			if(!d)
				return nullptr;
			return new KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot(d->location(), d);
		}
		break;
		default:
			// anything else at this point is an operand core
			return parseExpressionOperandCore(terminator);
			break;
	}

	// not reached
	KVSP_ASSERT(false);
	return nullptr;
}
Esempio n. 12
0
bool parseContentType(const String& contentType, ReceiverType& receiver)
{
    unsigned index = 0;
    unsigned contentTypeLength = contentType.length();
    skipSpaces(contentType, index);
    if (index >= contentTypeLength)  {
        WTF_LOG_ERROR("Invalid Content-Type string '%s'", contentType.ascii().data());
        return false;
    }

    // There should not be any quoted strings until we reach the parameters.
    size_t semiColonIndex = contentType.find(';', index);
    if (semiColonIndex == kNotFound) {
        receiver.setContentType(SubstringRange(index, contentTypeLength - index));
        return true;
    }

    receiver.setContentType(SubstringRange(index, semiColonIndex - index));
    index = semiColonIndex + 1;
    while (true) {
        skipSpaces(contentType, index);
        SubstringRange keyRange = parseParameterPart(contentType, index);
        if (!keyRange.second || index >= contentTypeLength) {
            WTF_LOG_ERROR("Invalid Content-Type parameter name. (at %i)", index);
            return false;
        }

        // Should we tolerate spaces here?
        if (contentType[index++] != '=' || index >= contentTypeLength) {
            WTF_LOG_ERROR("Invalid Content-Type malformed parameter (at %i).", index);
            return false;
        }

        // Should we tolerate spaces here?
        SubstringRange valueRange = parseParameterPart(contentType, index);

        if (!valueRange.second) {
            WTF_LOG_ERROR("Invalid Content-Type, invalid parameter value (at %i, for '%s').", index, substringForRange(contentType, keyRange).stripWhiteSpace().ascii().data());
            return false;
        }

        // Should we tolerate spaces here?
        if (index < contentTypeLength && contentType[index++] != ';') {
            WTF_LOG_ERROR("Invalid Content-Type, invalid character at the end of key/value parameter (at %i).", index);
            return false;
        }

        receiver.setContentTypeParameter(keyRange, valueRange);

        if (index >= contentTypeLength)
            return true;
    }

    return true;
}
Esempio n. 13
0
File: epd.cpp Progetto: kmar/cheng4
// parse EPD from buffer
// note that this is not a real EPD parser, just a simplified one!
bool EPDFile::parse( const char *ptr )
{
	cheng4::Board b;
	while (ptr && *ptr)
	{
		skipSpaces( ptr );
		const char *res = b.fromFEN( ptr );
		if ( !res )
		{
			skipUntilEOL(ptr);
			continue;
		}
		EPDPosition pos;
		pos.fen = b.toFEN();
		ptr = res;
		for (;;)
		{
			skipSpaces( ptr );
			if ( isToken( ptr, "bm" ) )
			{
				// parse best moves
				for (;;)
				{
					skipSpaces(ptr);
					Move m = b.fromSAN(ptr);
					if ( m == mcNone )
						break;
					pos.best.push_back(m);
				}
				continue;
			}
			if ( isToken( ptr, "am" ) )
			{
				// parse avoid moves
				for (;;)
				{
					skipSpaces(ptr);
					Move m = b.fromSAN(ptr);
					if ( m == mcNone )
						break;
					pos.avoid.push_back(m);
				}
				continue;
			}
			if ( *ptr == 13 || *ptr == 10 || *ptr == ';')
			{
				skipUntilEOL( ptr );
				break;
			}
		}
		positions.push_back( pos );
	}
	return 1;
}
Esempio n. 14
0
 parse_result read_lvl(string input, int from, int lvl) {
     from = skipSpaces(input,from);
     if (from >= (int)input.length()) {
         throw "End of input reached before the parsing finished";
     }
     if (lvl <= 0) { // parens or variable
         if (input[from] == '(') {
             parse_result pr = read_lvl(input,from+1,START_LVL);
             pr.idx = skipSpaces(input, pr.idx);
             if (pr.idx >= (int)input.length()) {
                 throw "End of input reached before the parsing finished";
             } else if (input[pr.idx] != ')') {
                 throw "'(' at character "+pr.idx;
             }
             pr.idx = pr.idx+1;
             return pr;
         } else {
             return read_var(input, from);
         }
     } else {
         operateur op = operateur_for_level(lvl);
         string s_op = operateur2string(op);
         if (is_binary(op)) {
             parse_result pr1 = read_lvl(input,from,lvl-1);
             pr1.idx = skipSpaces(input,pr1.idx);
             if ( input.compare(pr1.idx, s_op.length(), s_op) == 0 ) {
                 parse_result pr2 = read_lvl(input,pr1.idx+(int)s_op.length(), lvl);
                 parse_result res;
                 res.f = new formule();
                 res.f -> op = op;
                 res.f -> arg1 = pr1.f;
                 res.f -> arg2 = pr2.f;
                 res.idx = pr2.idx;
                 return res;
             } else {
                 return pr1;
             }
         } else {
             if ( input.compare(from, s_op.length(), s_op) == 0 )  {
                 parse_result pr = read_lvl(input,from + (int)s_op.length(),lvl);
                 parse_result res;
                 res.idx = pr.idx;
                 res.f = new formule();
                 res.f->op = op;
                 res.f->arg = pr.f;
                 return res;
             } else {
                 return read_lvl(input,from,lvl-1);
             }
         }
     }
 }
Esempio n. 15
0
double Calculator::parseDouble(std::string_view &ref)
{
	double value = 0;
	bool isNegative = false;
	bool parsedAny = false;

	skipSpaces(ref);
	if (!ref.empty() && ref[0] == '-')
	{
		isNegative = true;
		ref.remove_prefix(1);
	}
	skipSpaces(ref);

	while (!ref.empty() && std::isdigit(ref[0]))
	{
		parsedAny = true;
		const int digit = ref[0] - '0';
		value = value * 10.0f + double(digit);
		ref.remove_prefix(1);
	}

	if (!parsedAny)
	{
		return std::numeric_limits<double>::quiet_NaN();
	}

	if (isNegative)
	{
		value *= -1;
	}

	if (ref.empty() || (ref[0] != '.'))
	{
		m_printStrategy->printNumber(value);
		return value;
	}

	ref.remove_prefix(1);
	double factor = 1.f;
	while (!ref.empty() && std::isdigit(ref[0]))
	{
		const int digit = ref[0] - '0';
		factor *= 0.1f;
		value += factor * double(digit);
		ref.remove_prefix(1);
	}

	m_printStrategy->printNumber(value);
	return value;
}
static int parseCommandLine(char *command, char *arguments[], int len) {
  command = skipSpaces(command);
  int count = 0;
  while (count < len - 1 && *command != '\0') {
    arguments[count++] = command;
    char *found = strchr(command, ' ');
    if (found == NULL) break;
    *found = '\0';
    command = found + 1;
    command = skipSpaces(command);
  }
  arguments[count] = NULL;
  return count;
}
Esempio n. 17
0
bool matchCommand(const char *src, const char *pattern)
{
   const char **par;
   for (par = params; par < params + MAX_PARAMS; par++)
   {
      *par = "";
   }
   for (src = skipSpaces(src); src != NULL && *pattern != '\0'; pattern++)
   {
      src = isupper(*pattern)
               ? matchParam(src, paramByLetter(*pattern), pattern[1] == '\0')
               : matchTerminal(src, *pattern);
   }
   return src != NULL && *skipSpaces(src) == '\0';
}
Esempio n. 18
0
Wt::WString TopicWidget::reindent(const Wt::WString& text)
{
  std::vector<std::string> lines;
  std::string s = text.toUTF8();
  boost::split(lines, s, boost::is_any_of("\n"));

  std::string result;
  int indent = -1;
  int newlines = 0;
  for (unsigned i = 0; i < lines.size(); ++i) {
    const std::string& line = lines[i];

    if (line.empty()) {
      ++newlines;
    } else {
      if (indent == -1) {
        indent = countSpaces(line);
      } else {
        for (int j = 0; j < newlines; ++j)
          result += '\n';
      }

      newlines = 0;

      if (!result.empty())
        result += '\n';

      result += skipSpaces(line, indent);
    }
  }
  return Wt::WString::fromUTF8(result);
}
Esempio n. 19
0
void 
CmdFraction(int code)
/******************************************************************************
 purpose: converts \frac{x}{y} (following Taupin's implementation in ltx2rtf)
******************************************************************************/
{
	char           *denominator, *numerator, *nptr, *dptr;

	numerator = getBraceParam();
	nptr = strdup_noendblanks(numerator);
	skipSpaces();
	denominator = getBraceParam();
	dptr = strdup_noendblanks(denominator);

	free(numerator);
	free(denominator);
	diagnostics(4,"CmdFraction -- numerator   = <%s>", nptr);
	diagnostics(4,"CmdFraction -- denominator = <%s>", dptr);

	fprintRTF(" \\\\F(");
	ConvertString(nptr);
	fprintRTF("%c", g_field_separator);
	ConvertString(dptr);
	fprintRTF(")");

	free(nptr);
	free(dptr);
}
Esempio n. 20
0
File: epd.cpp Progetto: kmar/cheng4
// load EPD file
bool EPDFile::load( const char *fnm )
{
	skipSpaces(fnm);
	positions.clear();
	streampos fsz;
	ifstream ifs( fnm, ios::binary );
	if ( !ifs )
		return 0;
	ifs.seekg( 0, ios::end );
	fsz = ifs.tellg();
	ifs.seekg( 0, ios::beg );
	char *buf = new (std::nothrow) char[ (size_t)(fsz+streampos(1)) ];
	if ( !buf )
		return 0;
	ifs.read( buf, fsz );
	if ( !ifs )
	{
		delete[] buf;
		return 0;
	}
	buf[ (size_t)fsz ] = 0;
	bool res = parse( buf );
	delete[] buf;
	return res;
}
Esempio n. 21
0
double Calculator::parseExprMul(std::string_view &ref)
{
	double value = parseSymbol(ref);
	while (true)
	{
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == '*')
		{
			ref.remove_prefix(1);
			value *= parseSymbol(ref);
			m_printStrategy->printMultiplication();
		}
		else if (!ref.empty() && ref[0] == '/')
		{
			ref.remove_prefix(1);
			value /= parseSymbol(ref);
			m_printStrategy->printDivision();
		}
		else
		{
			break;
		}
	}

	return value;
}
Esempio n. 22
0
double Calculator::parseExprSum(std::string_view &ref)
{
	double value = parseExprMul(ref);
	while (true)
	{
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == '+')
		{
			ref.remove_prefix(1);
			value += parseExprMul(ref);
			m_printStrategy->printAddition();
		}
		else if (!ref.empty() && ref[0] == '-')
		{
			ref.remove_prefix(1);
			value -= parseExprMul(ref);
			m_printStrategy->printSubstraction();
		}
		else
		{
			break;
		}
	}

	return value;
}
Esempio n. 23
0
	bool readInteger(const char*& text, unsigned& length, T& value)
	{
		if( text && length > 0 )
		{
			skipSpaces(text);
			value = T(0);
			const char* current = text;
			unsigned len = length;

			while( (len > 0) && *current && isdigit(*current) )
			{
				value = value * 10 + (*current - '0');
				++current;
				--len;
			}
			// If we hit the end of the text or hit some whitespace, we ate it completely.
			if( (current != text) && (!*current || isspace(*current)) )
			{
				length = len;
				text = current;
				return true;
			}
		}
		return false;
	}
Esempio n. 24
0
bool 
Reader::readArray( Token &tokenStart )
{
   currentValue() = Value( arrayValue );
   skipSpaces();
   if ( *current_ == ']' ) // empty array
   {
      Token endArray;
      readToken( endArray );
      return true;
   }
   int index = 0;
   while ( true )
   {
      Value &value = currentValue()[ index++ ];
      nodes_.push( &value );
      bool ok = readValue();
      nodes_.pop();
      if ( !ok ) // error already set
         return recoverFromError( tokenArrayEnd );

      Token token;
      if ( !readToken( token ) 
           ||  ( token.type_ != tokenArraySeparator  &&  
                 token.type_ != tokenArrayEnd ) )
      {
         return addErrorAndRecover( "Missing ',' or ']' in array declaration", 
                                    token, 
                                    tokenArrayEnd );
      }
      if ( token.type_ == tokenArrayEnd )
         break;
   }
   return true;
}
Esempio n. 25
0
    OSReturn_t
    Parser::parseNumber(uint64_t& num)
    {
      uint64_t n;
      n = 0;

      uchar_t ch;
      ch = skipSpaces();

      for (; hasMoreContent(); advanceCurrent())
        {
          uchar_t ch;
          ch = getCurrentChar();

          if ('0' <= ch && ch <= '9')
            {
              n = n * 10 + (ch - '0');
            }
          else
            break;
        }
      num = n;

      return OSReturn::OS_OK;
    }
// It is used to get:
// - version
// - record type
// - value name
// - '=' character
std::string  getCMLCommentToken( const std::string &  comment,
                                 ssize_t &  pos )
{
    skipSpaces( comment, pos );

    ssize_t         lastPos( comment.size() - 1 );
    std::string     token;

    while ( pos <= lastPos )
    {
        char    symbol( comment[ pos ] );

        if ( symbol == '=' )
        {
            if ( token.empty() )
            {
                ++pos;
                return "=";     // This is a key-value separator
            }
            break;              // A key has ended
        }
        if ( isspace( symbol ) != 0 )
        {
            break;              // A token has ended
        }

        token += symbol;
        ++pos;
    }
    return token;
}
Esempio n. 27
0
void Header::setFromLine(const char * p)
{
    uint8_t i = 0;
    
    if (!p) { return; }
    
    // Get the name (up to the colon character)
    while( *p && *p != ':' && i < MAX_HTTP_HEADER_NAME_LENGTH)
    {
        m_name[i++] = tolower( *p++ );
        m_name[i] = '\0';
    }
    
	// skip ':' and any spaces 
	if( *p )
		++p;
	p = skipSpaces(p);

	// Get value
    i = 0;
	while( *p && *p != '\0' && i < MAX_HTTP_HEADER_VALUE_LENGTH)
    {
		m_value[i++] = *p++;
        m_value[i] = '\0';
    }
}
Esempio n. 28
0
int parseInt(string::const_iterator& p, const string::const_iterator& end) {
	skipSpaces(p, end);

	if (p == end) {
		// some error occurred, but no way to report.
		return 0;
	}

	// Look for a `-` or `+`
	int mult = 1;
	switch (*p) {
	case '-':
		mult = -1;
		++p;
		break;
	case '+':
		mult = 1;
		++p;
	default:
		break;
	}

	// Parse remaining digits
	int number = 0;
	while (p != end &&
	       '0' <= *p && *p <= '9') {
		int digit = (int) (*p - '0');
		number = (10 * number) + digit;
		++p;
	}

	return mult * number;
}
Esempio n. 29
0
	inline
	void
	moveToClosingSymbolOf( char openSymbol ) {
		char closeSymbol;
		if ( openSymbol == '{' ) {
			closeSymbol = '}';
		}
		else {
			if ( openSymbol == '[' ) {
				closeSymbol = ']';
			}
			else {
				throw Error( "Unknown closing symbol" );
			}
		}
		int count = 0;
		while ( ( pos < m_jsonStr.length() ) && ( ( m_jsonStr[ pos ] != closeSymbol ) || ( count != 0) ) ) {
			if ( m_jsonStr[ pos + 1 ] == openSymbol ) {
				++count;
			}
			if ( count && ( m_jsonStr[ pos ] == closeSymbol) ) {
				--count;
			}
			++pos;
		}
		++pos;
		skipSpaces();
	}
Esempio n. 30
0
	inline
	std::string
	findValue( bool isInsideArray ) {
		if ( !isInsideArray )
			moveToValue();
		skipSpaces();

		size_t start = pos;
		// is string
		if ( m_jsonStr[ pos ] == '"' ) {
			start = ++pos;
			moveToNextQuote();
		}
		else
		{
			// is object or array
			if ( m_jsonStr[ pos ] == '{' || m_jsonStr[ pos ] == '[' ) {
				moveToClosingSymbolOf( m_jsonStr[ pos ] );
			}
			else {
				// is number
				while ( ( pos < m_jsonStr.length() ) && ( ( m_jsonStr[ pos ] != '}' && m_jsonStr[ pos ] != ',' && m_jsonStr[ pos ] != ']' ) ) ) {
					++pos;
				}
			}
		}
		return m_jsonStr.substr( start, pos - start );
	}