void DocumentBuilder::consumeContent(Node *root){ while(peek() != -1){ consumeText(root); if (isElement()){ consumeElement(root); continue; } if (isComment()){ consumeComment(root); continue; } if (isCDataSection()){ consumeCDataSection(root); continue; } if(isPI()){ consumePI(root); continue; } if (isCharRef()){ StringBuffer *sb = new StringBuffer(2); sb->append(consumeCharRef()); appendToLastTextNode(root, sb); continue; } if (isEntityRef()){ String *entext = consumeEntityRef(true); appendToLastTextNode(root, entext); continue; } if (peek(0) == '<') break; }; }
void DocumentBuilder::consumeMisc(Node *root){ consumeSpaces(); bool hasTokens = true; while(hasTokens){ if(isComment()){ consumeComment(root); consumeSpaces(); }else if(isPI()){ consumePI(root); consumeSpaces(); }else{ hasTokens = false; } } }
// skip whitespace, then skip a comment, rinse, repeat void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab) { do { consumeWhiteSpace(foundNonSpaceTab); // if not starting a comment now, then done int c = peek(); if (c != '/' || c == EndOfInput) return; // skip potential comment foundNonSpaceTab = true; if (! consumeComment()) return; } while (true); }
void Tokenizer::shift() { mpCurrent.reset(); if (mBlockComment) { skipEOL(); } else { skipWhiteSpaces(); if (mpInput->eof()) return; } mpCurrent.reset(new Token); mpCurrent->setLine(line()); mpCurrent->setBeginColumn(column()); if (mBlockComment) { consumeCStyleBlockComment(); return; } auto ch = mpInput->get(); if (isLetter(ch) || isUnderscore(ch)) { consumeIdentifier(ch); } else if (isBiwiseOperatorSymbol(ch)) { mpCurrent->setType(Token::TYPE_BITWISE_OPERATOR); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isDot(ch) && consumeDot(ch)) { // nothing } else if ((isDecimalDigit(ch) || isDot(ch) || isSign(ch)) && consumeNumber(ch)) { // nothing } else if (isQuotationMark(ch)) { if (!consumeString(ch)) shift(); } else if (isCStyleInitialCommentChar(ch)) { consumeComment(ch); } else if (isArrowSymbol(ch) && consumeArrow(ch)) { // nothing } else if (isBracket(ch)) { mpCurrent->setType(Token::TYPE_BRACKET); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isAngleBracket(ch)) { mpCurrent->setType(Token::TYPE_ANGLE_BRACKET); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isDelimiter(ch)) { mpCurrent->setType(Token::TYPE_DELIMITER); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isOperator(ch) && consumeEqualOperator(ch)) { // nothing } else if (isOperator(ch)) { mpCurrent->setType(Token::TYPE_OPERATOR); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isAsterisk(ch)) { mpCurrent->setType(Token::TYPE_ASTERISK); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else { mpCurrent.reset(); } }
char* XMLStack::parseXMLStream(char *stream, XMLElement *parent) { if(!stream || !parent) return nullChar; NSString token; if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; if(!consumeWhiteSpaces(&stream)) return nullChar; if(*stream == '<' && (!consumeComment(&stream) && !consumeXMLHeader(&stream))) { stream++; if(!moveAndCheckProgress()) return nullChar; getIdentifier(&stream, token); parent->setName(token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; if(*stream == '>') { stream++; if(!moveAndCheckProgress()) return nullChar; } else { while((*stream != stx_getOsSeparator() && *(stream + 1) != '>') && (*stream != '>')) { XMLElement *newTag = new XMLElement(); getIdentifier(&stream, token); newTag->setName(token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; getStringValue(&stream, token); newTag->setValue(token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; parent->addChild(newTag); } if(*stream == stx_getOsSeparator() && *(stream + 1) == '>') { stream +=2; if(!moveAndCheckProgress(2)) return nullChar; return stream; } stream++; } if(parent->getName() != "RawData") { getStreamedValue(&stream, token); parent->setValue(token); } else { XMLElement *info = parent->getChildByName("length"); bool sucess = (!info) ? fillRawData(&stream, &parent->rawData) : fillRawData(&stream, &parent->rawData, info->getValuei()); if(!sucess) writeFatalLogInfo("\n<!>Failed to load raw data, check your XML file.\n"); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; } if(!consumeWhiteSpaces(&stream)) return nullChar; consumeComment(&stream); while(*stream == '<' && *(stream + 1) != stx_getOsSeparator()) { XMLElement *newTag = new XMLElement(); stream = parseXMLStream(stream, newTag); if(!stream || !consumeWhiteSpaces(&stream)) return nullChar; parent->addChild(newTag); } if(*stream == '<' && *(stream + 1)== stx_getOsSeparator()) { stream+=2; if(!moveAndCheckProgress(2)) return nullChar; getIdentifier(&stream, token); if(state == XML_FAILED || state == XML_BUFFER_OVERFLOW) return nullChar; } if(token != parent->getName() || *stream != '>') { /* //writeFatalLogInfoList LOG_PRINT("\n<!>Start tag <%s> & End Tag <%s> do not match,"\ "check your XML file.\n", parent->getName(), token); ??? */ return nullChar; } stream++; if(!consumeWhiteSpaces(&stream)) return nullChar; } return (state == XML_SUCCESS) ? stream : nullChar; }
void DocumentBuilder::consumeDTD(){ wchar c1 = peek(0); wchar c2 = peek(1); if (c1 != '<' || c2 != '!') return; consume("<!DOCTYPE", 9); consumeSpaces(1); delete consumeNCName(); consumeSpaces(); if (peek() == 'S'){ consume("SYSTEM", 6); consumeSpaces(1); delete consumeQoutedValue(); }else if (peek() == 'P'){ consume("PUBLIC", 6); consumeSpaces(1); delete consumeQoutedValue(); consumeSpaces(1); delete consumeQoutedValue(); } consumeSpaces(); //markup decl if (peek() == '['){ consume("[", 1); while(peek() != ']'){ if (peek(0) == '<' && peek(1) == '!' && peek(2) == 'E'){ consume("<!ENTITY", 8); consumeSpaces(1); String *entityName = consumeNCName(); consumeSpaces(1); String *entityValue = null; String *extEntityValue = null; if (peek() == 'S'){ consume("SYSTEM", 6); consumeSpaces(1); extEntityValue = consumeQoutedValue(); }else if (peek() == 'P'){ consume("PUBLIC", 6); consumeSpaces(1); delete consumeQoutedValue(); consumeSpaces(1); extEntityValue = consumeQoutedValue(); }else{ entityValue = consumeQoutedValue(); } if (entityValue != null){ entitiesHash.put(entityName, entityValue); } if (extEntityValue != null){ extEntitiesHash.put(entityName, extEntityValue); } delete entityName; }else if (isComment()){ consumeComment(null); } get(); } consume("]", 1); consumeSpaces(); } consume(">", 1); }