示例#1
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Properties::load(istream& in)
{
  setDefaults();

  // Loop reading properties
  string key, value;
  for(;;)
  {
    // Get the key associated with this property
    key = readQuotedString(in);

    // Make sure the stream is still okay
    if(!in)
      return;

    // A null key signifies the end of the property list
    if(key == "")
      break;

    // Get the value associated with this property
    value = readQuotedString(in);

    // Make sure the stream is still okay
    if(!in)
      return;

    // Set the property 
    PropertyType type = getPropertyType(key);
    set(type, value);
  }
}
示例#2
0
文件: Parser.cpp 项目: SJasson/vle
void Parser::readBlock(Block& block)
{
    do {
        std::string str = readKeyword();

        switch (nextToken()) {
        case Parser::Error:
            return;
        case Parser::Begin:
            readBegin();
            readBlock(block.addBlock(str));
            readEnd();
            break;
        case Parser::Equal:
            readEqual();
            if (nextToken() == QuoteStr) {
                block.addString(str, readQuotedString());
                while (nextToken() == Parser::Comma) {
                    readComma();
                    block.addString(str, readQuotedString());
                }
            } else if (nextToken() == Real) {
                block.addReal(str, readReal());
                while (nextToken() == Parser::Comma) {
                    readComma();
                    block.addReal(str, readReal());
                }
            } else if (nextToken() == RelativeReal) {
                block.addRelativeReal(str, readRelativeReal());
                while (nextToken() == Parser::Comma) {
                    readComma();
                    block.addRelativeReal(str, readRelativeReal());
                }
            } else if (nextToken() == Str) {
                block.addString(str, readString());
                while (nextToken() == Parser::Comma) {
                    readComma();
                    block.addString(str, readString());
                }
            } else {
                throw utils::InternalError();
            }
            readSemicolon();
            break;
        default:
            throw utils::InternalError("bad file");
        };
    } while (nextToken() != Parser::End and mStream);
}
bool ParserStringLiteral::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
	Pos begin = pos;
	String s;

	if (pos == end || *pos != '\'')
	{
		expected = "opening single quote";
		return false;
	}

	ReadBuffer in(const_cast<char *>(pos), end - pos, 0);

	try
	{
		readQuotedString(s, in);
	}
	catch (const Exception & e)
	{
		expected = "string literal";
		return false;
	}

	pos += in.count();
	node = std::make_shared<ASTLiteral>(StringRange(begin, pos), s);
	return true;
}
void DataTypeAggregateFunction::deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const
{
	String s;
	readQuotedString(s, istr);
	deserializeFromString(function, column, s);
}
示例#5
0
short Scanner::getToken( YYSTYPE & lval )
//---------------------------------------
// get the next token from the input stream.
// at each call, the next character should be
// in _current.
{
    const int   MaxBufLen = 512;
    char        buffer[ MaxBufLen ];
    int         bufPos;                 // position in buffer
    char        special;

    gobble();

    if( isEOF() ) {
        return 0;
    }

    if( isSpecial() ) {
        special = (char) _current;
        get();                      // set up for next call
        return special;   // <-------- early return
    }

    if( isQuote() ) {
        readQuotedString( lval );
        return T_String;   // <-------- early return
    }

    if( _current == '0' ) {
        get();
        if( toupper( _current ) == 'X' ) {
            readHex( lval );
        } else {
            if( isDigit() ) {
                readDecimal( lval );
            } else {
                lval = 0;
            }
        }
        return T_Number;   // <-------- early return
    }

    if( isDigit() ) {
        readDecimal( lval );
        return T_Number;   // <-------- early return
    }

    for( bufPos = 0; bufPos < MaxBufLen; bufPos += 1 ) {
        buffer[ bufPos ] = (char) _current;

        get();
        if( isEOF() || isSpace() || isSpecial() ) break;
    }

    bufPos += 1;

    assert( bufPos < MaxBufLen );

    buffer[ bufPos ] = '\0';

    return tokenValue( buffer, lval );
}
示例#6
0
XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
{
    XmlElement* node = nullptr;

    skipNextWhiteSpace();
    if (outOfData)
        return nullptr;

    if (*input == '<')
    {
        ++input;
        String::CharPointerType endOfToken (XmlIdentifierChars::findEndOfToken (input));

        if (endOfToken == input)
        {
            // no tag name - but allow for a gap after the '<' before giving an error
            skipNextWhiteSpace();
            endOfToken = XmlIdentifierChars::findEndOfToken (input);

            if (endOfToken == input)
            {
                setLastError ("tag name missing", false);
                return node;
            }
        }

        node = new XmlElement (input, endOfToken);
        input = endOfToken;
        LinkedListPointer<XmlElement::XmlAttributeNode>::Appender attributeAppender (node->attributes);

        // look for attributes
        for (;;)
        {
            skipNextWhiteSpace();

            const juce_wchar c = *input;

            // empty tag..
            if (c == '/' && input[1] == '>')
            {
                input += 2;
                break;
            }

            // parse the guts of the element..
            if (c == '>')
            {
                ++input;

                if (alsoParseSubElements)
                    readChildElements (*node);

                break;
            }

            // get an attribute..
            if (XmlIdentifierChars::isIdentifierChar (c))
            {
                String::CharPointerType attNameEnd (XmlIdentifierChars::findEndOfToken (input));

                if (attNameEnd != input)
                {
                    const String::CharPointerType attNameStart (input);
                    input = attNameEnd;

                    skipNextWhiteSpace();

                    if (readNextChar() == '=')
                    {
                        skipNextWhiteSpace();

                        const juce_wchar nextChar = *input;

                        if (nextChar == '"' || nextChar == '\'')
                        {
                            XmlElement::XmlAttributeNode* const newAtt
                                = new XmlElement::XmlAttributeNode (attNameStart, attNameEnd);

                            readQuotedString (newAtt->value);
                            attributeAppender.append (newAtt);
                            continue;
                        }
                    }
                    else
                    {
                        setLastError ("expected '=' after attribute '"
                                        + String (attNameStart, attNameEnd) + "'", false);
                        return node;
                    }
                }
            }
            else
            {
                if (! outOfData)
                    setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
            }

            break;
        }
    }

    return node;
}
示例#7
0
XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
{
    XmlElement* node = nullptr;

    skipNextWhiteSpace();
    if (outOfData)
        return nullptr;

    const int openBracket = input.indexOf ((juce_wchar) '<');

    if (openBracket >= 0)
    {
        input += openBracket + 1;
        int tagLen = findNextTokenLength();

        if (tagLen == 0)
        {
            // no tag name - but allow for a gap after the '<' before giving an error
            skipNextWhiteSpace();
            tagLen = findNextTokenLength();

            if (tagLen == 0)
            {
                setLastError ("tag name missing", false);
                return node;
            }
        }

        node = new XmlElement (String (input, (size_t) tagLen));
        input += tagLen;
        LinkedListPointer<XmlElement::XmlAttributeNode>::Appender attributeAppender (node->attributes);

        // look for attributes
        for (;;)
        {
            skipNextWhiteSpace();

            const juce_wchar c = *input;

            // empty tag..
            if (c == '/' && input[1] == '>')
            {
                input += 2;
                break;
            }

            // parse the guts of the element..
            if (c == '>')
            {
                ++input;

                if (alsoParseSubElements)
                    readChildElements (node);

                break;
            }

            // get an attribute..
            if (XmlIdentifierChars::isIdentifierChar (c))
            {
                const int attNameLen = findNextTokenLength();

                if (attNameLen > 0)
                {
                    const String::CharPointerType attNameStart (input);
                    input += attNameLen;

                    skipNextWhiteSpace();

                    if (readNextChar() == '=')
                    {
                        skipNextWhiteSpace();

                        const juce_wchar nextChar = *input;

                        if (nextChar == '"' || nextChar == '\'')
                        {
                            XmlElement::XmlAttributeNode* const newAtt
                                = new XmlElement::XmlAttributeNode (String (attNameStart, (size_t) attNameLen),
                                                                    String::empty);

                            readQuotedString (newAtt->value);
                            attributeAppender.append (newAtt);
                            continue;
                        }
                    }
                }
            }
            else
            {
                if (! outOfData)
                    setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
            }

            break;
        }
    }

    return node;
}
示例#8
0
bool MenuConf::readItemCaption(FILE* f, Item* item)
{
    eatWhitespace(f);
    return readQuotedString(f, item->data->caption, ItemData::CaptionSize);
}
示例#9
0
void DataTypeEnum<Type>::deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const
{
    std::string name;
    readQuotedString(name, istr);
    static_cast<ColumnType &>(column).getData().push_back(getValue(StringRef(name)));
}
示例#10
0
文件: gff.c 项目: JinfengChen/pblat
static void parseGtfEnd(char *s, struct gffFile *gff, struct gffLine *gl, 
    char *fileName, int lineIx)
/* Read the semi-colon separated end bits of a GTF line into gl and
 * hashes. */
{
char *type, *val;
struct hashEl *hel;
bool gotSemi;

for (;;)
   {
   gotSemi = FALSE;
   if ((type = nextWord(&s)) == NULL)
       break;
   s = skipLeadingSpaces(s);
   if (NULL == s || s[0] == 0)
       errAbort("Unpaired type(%s)/val on end of gtf line %d of %s", type, lineIx, fileName);
   if (s[0] == '"' || s[0] == '\'')
       {
       val = s;
       readQuotedString(fileName, lineIx, s, val, &s);
       }
   else
       {
       int len;
       val = nextWord(&s);
       len = strlen(val) - 1;
       if (val[len] == ';')
	   {
	   val[len] = 0;
	   len -= 1;
           gotSemi = TRUE;
	   }
       if (len < 0)
           errAbort("Empty value for %s line %d of %s", type, lineIx, fileName);
       }
   if (s != NULL && !gotSemi)
      {
      s = strchr(s, ';');
      if (s != NULL)
         ++s;
      }
   /* only use the first occurance of gene_id and transcript_id */
   if (sameString("gene_id", type) && (gl->geneId == NULL))
       {
       struct gffGeneId *gg;
       if ((hel = hashLookup(gff->geneIdHash, val)) == NULL)
	   {
	   AllocVar(gg);
           hel = hashAdd(gff->geneIdHash, val, gg);
	   gg->name = hel->name;
	   slAddHead(&gff->geneIdList, gg);
	   }
	else
	   {
	   gg = hel->val;
	   }
       gl->geneId = gg->name;
       }
   else if (sameString("transcript_id", type) && (gl->group == NULL))
       {
       struct gffGroup *gg;
       if ((hel = hashLookup(gff->groupHash, val)) == NULL)
	   {
	   AllocVar(gg);
           hel = hashAdd(gff->groupHash, val, gg);
	   gg->name = hel->name;
	   gg->seq = gl->seq;
	   gg->source = gl->source;
	   slAddHead(&gff->groupList, gg);
	   }
	else
	   {
	   gg = hel->val;
	   }
       gl->group = gg->name;
       }
   else if (sameString("exon_id", type))
       gl->exonId = gffFileGetStr(gff, val);
   else if (sameString("exon_number", type))
       {
       if (!isdigit(val[0]))
           errAbort("Expecting number after exon_number, got %s line %d of %s", val, lineIx, fileName);
       gl->exonNumber = atoi(val);
       }
   else if (sameString("intron_id", type))
       gl->intronId = gffFileGetStr(gff, val);
   else if (sameString("intron_status", type))
       gl->intronStatus = gffFileGetStr(gff, val);
   else if (sameString("protein_id", type))
       gl->proteinId = gffFileGetStr(gff, val);
   else if (sameString("gene_name", type))
       gl->geneName = gffFileGetStr(gff, val);
   else if (sameString("transcript_name", type))
       gl->transcriptName = gffFileGetStr(gff, val);
   }
if (gl->group == NULL)
    {
    if (gl->geneId == NULL)
        warn("No gene_id or transcript_id line %d of %s", lineIx, fileName);
    }
}