void NPC::_loadFromMarkup(const tag& tagObj) { // supported tags for NPC // attribute: can be name for tag // <name> // <desc> // <text> const tag* pTagIter = tagObj.next_child(); if ( tagObj.get_attribute().length() > 0 ) name = tagObj.get_attribute(); while (pTagIter != NULL) { const string& tagName = pTagIter->get_name(); if (tagName == "name") name = pTagIter->get_attribute().length()>0 ? pTagIter->get_attribute() : pTagIter->get_content(); else if (tagName == "desc") desc = pTagIter->get_attribute().length()>0 ? pTagIter->get_attribute() : pTagIter->get_content(); else if (tagName == "text") { string txt = pTagIter->get_attribute().length()>0 ? pTagIter->get_attribute() : pTagIter->get_content(); text.push_back(txt); } pTagIter = tagObj.next_child(); } textIter = text.begin(); }
PPPoE::vendor_spec_type PPPoE::vendor_spec_type::from_option(const tag& opt) { if (opt.data_size() < sizeof(uint32_t)) { throw malformed_option(); } vendor_spec_type output; InputMemoryStream stream(opt.data_ptr(), opt.data_size()); output.vendor_id = stream.read_be<uint32_t>(); stream.read(output.data, stream.size()); return output; }
PPPoE::vendor_spec_type PPPoE::vendor_spec_type::from_option(const tag &opt) { if(opt.data_size() < sizeof(uint32_t)) throw malformed_option(); vendor_spec_type output; std::memcpy(&output.vendor_id, opt.data_ptr(), sizeof(uint32_t)); output.vendor_id = Endian::be_to_host(output.vendor_id); output.data.assign( opt.data_ptr() + sizeof(uint32_t), opt.data_ptr() + opt.data_size() ); return output; }
void PPPoE::add_tag(const tag &option) { _tags_size += option.data_size() + sizeof(uint16_t) * 2; _tags.push_back(option); }
void PPPoE::add_tag(const tag& option) { tags_size_ += static_cast<uint16_t>(option.data_size() + sizeof(uint16_t) * 2); tags_.push_back(option); }
string xmlString::getSubTag( const tag &in, unsigned int tabNum ) { string ret; string tabs; if( (_format&Tabs) != FALSE ) { for( unsigned int x=0; x<tabNum; x++ ) { tabs += "\t"; } } if( in.type() == tag::None ) { ret += in.contents().toString(); /*if( (_format&NewLines) != FALSE ) { ret += "\n"; }*/ } else { if( in.type() == tag::Open && in.name() != "" ) { ret += tabs + getOpener( in.name(), in.attributes() ); } else if( in.type() == tag::Empty && in.name() != "" ) { ret += tabs + getOpener( in.name(), in.attributes(), TRUE ); } if( (_format&NewLines) != FALSE && ( in.size() > 1 || ( in.size() > 0 && in[0].type() != tag::None ) ) ) { ret += "\n"; } for( unsigned int x=0; x<in.size(); x++ ) { ret += getSubTag( in[x], tabNum + 1 ); } if( in.type() == tag::Open && in.name() != "" ) { if( in.size() > 1 || ( in.size() > 0 && in[0].type() != tag::None ) ) { ret += tabs; } ret += getClose( in.name() ); } if( (_format&NewLines) != FALSE ) { ret += "\n"; } } return ret; }
size_t xmlString::fromString( tag &parent, const string &data, int parentStartEnd ) { if( data != "" ) { tag &added = parent.add( ); size_t startStart = data.find( "<", parentStartEnd ); size_t startEnd = data.find( ">", startStart ); if( startStart == string::npos || startEnd == string::npos ) { jDebugNeat<<"Attempting to parse tag inside tag "<<parent.name()<<", starting at character "<<parent.name()<<endl; jDebugNeat << "Could not find the start or end of a tag" << endl; return data.size()-1; } if( data[startStart+1] != '/' ) { size_t temp = data.find( " ", startStart ); if( temp > startEnd ) { temp = startEnd; } string tagName; for( unsigned int x=(startStart+1); x<temp; x++ ) { tagName += data[x]; } added.name( tagName ); // attribute parsing { string temp; attributeList &attrs = added.attributes(); for( unsigned int x=startStart+tagName.length()+1; x<startEnd; x++ ) { temp += data[x]; } temp += " "; size_t equals = 0; while( TRUE ) { attribute tempAttribute; equals = temp.find( "=", equals + 1 ); if( equals == string::npos ) { break; } size_t identifierStart = temp.rfind( " ", equals-1 ); size_t valueEnd = temp.find( "\"", equals+2 ); string ident; for( unsigned int x=( identifierStart + 1 ); x<equals; x++ ) { ident += temp[x]; } tempAttribute.identifier( ident ); string val; for( unsigned int x=( equals + 2 ); x<( valueEnd ); x++ ) { val += temp[x]; } tempAttribute.value( val ); attrs.add( tempAttribute ); } } if( data[startEnd-1] == '/' ) { added.type( tag::Empty ); return startEnd; } added.type( tag::Open ); } size_t oldTag = startStart; size_t currentTag = data.find( "<", startEnd+1 ); while( currentTag != string::npos ) { size_t oldEnd = data.find( ">", oldTag ); if( currentTag > oldEnd + 1 ) { string stuff; size_t begin = 0, end = 0; for( size_t x=oldEnd+1; x<currentTag; x++ ) { if( !std::isspace( data[x] ) ) { if( begin == 0 ) { begin = x; } end = x; } } if( end != 0 ) { for( size_t x=begin; x<=end; x++ ) { stuff += data[x]; } } added.add( stuff ); } if( data[currentTag+1] == '/' ) { size_t endEnd = data.find( '>', currentTag ); string endName; for( size_t x=currentTag+2; x<endEnd; x++ ) { endName += data[x]; } if( endName == added.name() ) { return endEnd; } } else { currentTag = fromString( added, data, currentTag-1 ); } oldTag = currentTag; currentTag = data.find( "<", currentTag+1 ); } } return string::npos; }
void property_value(const str& value) { current_.add_prop( propname_, value.substr(1, value.size() - 2) ); }
void start_tag(size_t offset) { current_.clear(); current_.start = offset; }
void json_formatter::print(std::ostream& os, const tag& t) const { json_fmt_visitor v(os, *this); t.accept(v); }
void io::write(std::ostream& os, const std::string& key, const tag& t) { write_type(os, t.get_type()); write_str(os, key); t.write_payload(os); }