openddl-parser: latest greatest.
Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>pull/547/head
parent
eb1ee61420
commit
ce939b5126
|
@ -153,7 +153,7 @@ Property *DDLNode::findPropertyByName( const std::string &name ) {
|
|||
}
|
||||
Property *current( m_properties );
|
||||
while( ddl_nullptr != current ) {
|
||||
int res = strncmp( current->m_id->m_buffer, name.c_str(), name.size() );
|
||||
int res = strncmp( current->m_key->m_text.m_buffer, name.c_str(), name.size() );
|
||||
if( 0 == res ) {
|
||||
return current;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ static DDLNode *createDDLNode( Identifier *id, OpenDDLParser *parser ) {
|
|||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
const std::string type( id->m_buffer );
|
||||
const std::string type( id->m_text.m_buffer );
|
||||
DDLNode *parent( parser->top() );
|
||||
DDLNode *node = DDLNode::create( type, "", parent );
|
||||
|
||||
|
@ -191,8 +191,6 @@ bool OpenDDLParser::parse() {
|
|||
|
||||
normalizeBuffer( m_buffer );
|
||||
|
||||
std::cout << &m_buffer[0] << std::endl;
|
||||
|
||||
m_context = new Context;
|
||||
m_context->m_root = DDLNode::create( "root", "", ddl_nullptr );
|
||||
pushNode( m_context->m_root );
|
||||
|
@ -217,7 +215,7 @@ char *OpenDDLParser::parseNextNode( char *in, char *end ) {
|
|||
|
||||
static void dumpId( Identifier *id ) {
|
||||
if( ddl_nullptr != id ) {
|
||||
std::cout << id->m_buffer << std::endl;
|
||||
std::cout << id->m_text.m_buffer << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,7 +275,7 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
|
|||
Name *name( ddl_nullptr );
|
||||
in = OpenDDLParser::parseName( in, end, &name );
|
||||
if( ddl_nullptr != name ) {
|
||||
const std::string nodeName( name->m_id->m_buffer );
|
||||
const std::string nodeName( name->m_id->m_text.m_buffer );
|
||||
node->setName( nodeName );
|
||||
}
|
||||
}
|
||||
|
@ -500,10 +498,8 @@ char *OpenDDLParser::parseIdentifier( char *in, char *end, Identifier **id ) {
|
|||
idLen++;
|
||||
}
|
||||
|
||||
const size_t len( idLen + 1 );
|
||||
Identifier *newId = new Identifier( len, new char[ len ] );
|
||||
::strncpy( newId->m_buffer, start, newId->m_len-1 );
|
||||
newId->m_buffer[ newId->m_len - 1 ] = '\0';
|
||||
const size_t len( idLen );
|
||||
Identifier *newId = new Identifier( start, len );
|
||||
*id = newId;
|
||||
|
||||
return in;
|
||||
|
@ -714,7 +710,7 @@ char *OpenDDLParser::parseStringLiteral( char *in, char *end, Value **stringData
|
|||
static void createPropertyWithData( Identifier *id, Value *primData, Property **prop ) {
|
||||
if( ddl_nullptr != primData ) {
|
||||
( *prop ) = new Property( id );
|
||||
( *prop )->m_primData = primData;
|
||||
( *prop )->m_value = primData;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,41 +77,83 @@ enum NameType {
|
|||
LocalName
|
||||
};
|
||||
|
||||
struct Token {
|
||||
public:
|
||||
Token( const char *token )
|
||||
: m_token( token )
|
||||
, m_size( 0 ){
|
||||
if( ddl_nullptr != token ) {
|
||||
m_size = strlen( m_token );
|
||||
struct Text {
|
||||
size_t m_capacity;
|
||||
size_t m_len;
|
||||
char *m_buffer;
|
||||
|
||||
Text( const char *buffer, size_t numChars )
|
||||
: m_capacity( 0 )
|
||||
, m_len( 0 )
|
||||
, m_buffer( ddl_nullptr ) {
|
||||
set( buffer, numChars );
|
||||
}
|
||||
|
||||
~Text() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
delete[] m_buffer;
|
||||
m_buffer = ddl_nullptr;
|
||||
m_capacity = 0;
|
||||
m_len = 0;
|
||||
}
|
||||
|
||||
void set( const char *buffer, size_t numChars ) {
|
||||
clear();
|
||||
if( numChars > 0 ) {
|
||||
m_len = numChars;
|
||||
m_capacity = m_len + 1;
|
||||
m_buffer = new char[ m_capacity ];
|
||||
strncpy( m_buffer, buffer, numChars );
|
||||
m_buffer[ numChars ] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
~Token() {
|
||||
// empty
|
||||
bool operator == ( const std::string &name ) const {
|
||||
if( m_len != name.size() ) {
|
||||
return false;
|
||||
}
|
||||
const int res( strncmp( m_buffer, name.c_str(), name.size() ) );
|
||||
return ( 0 == res );
|
||||
|
||||
}
|
||||
|
||||
size_t length() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
bool operator == ( const Token &rhs ) const {
|
||||
if( m_size != rhs.m_size ) {
|
||||
bool operator == ( const Text &rhs ) const {
|
||||
if( m_len != rhs.m_len ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int res( strncmp( m_token, rhs.m_token, m_size ) );
|
||||
return ( res == 0 );
|
||||
const int res ( strncmp( m_buffer, rhs.m_buffer, m_len ) );
|
||||
return ( 0 == res );
|
||||
}
|
||||
|
||||
private:
|
||||
Token();
|
||||
Token( const Token & );
|
||||
Token &operator = ( const Token & );
|
||||
Text( const Text & );
|
||||
Text &operator = ( const Text & );
|
||||
};
|
||||
|
||||
struct Identifier {
|
||||
Text m_text;
|
||||
|
||||
Identifier( char buffer[], size_t len )
|
||||
: m_text( buffer, len ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Identifier( char buffer[] )
|
||||
: m_text( buffer, strlen( buffer ) ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
bool operator == ( const Identifier &rhs ) const {
|
||||
return m_text == rhs.m_text;
|
||||
}
|
||||
|
||||
private:
|
||||
const char *m_token;
|
||||
size_t m_size;
|
||||
Identifier( const Identifier & );
|
||||
Identifier &operator = ( const Identifier & );
|
||||
};
|
||||
|
||||
struct Name {
|
||||
|
@ -154,30 +196,15 @@ private:
|
|||
Reference &operator = ( const Reference & );
|
||||
};
|
||||
|
||||
struct Identifier {
|
||||
size_t m_len;
|
||||
char *m_buffer;
|
||||
|
||||
Identifier( size_t len, char buffer[] )
|
||||
: m_len( len )
|
||||
, m_buffer( buffer ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
private:
|
||||
Identifier( const Identifier & );
|
||||
Identifier &operator = ( const Identifier & );
|
||||
};
|
||||
|
||||
struct Property {
|
||||
Identifier *m_id;
|
||||
Value *m_primData;
|
||||
Identifier *m_key;
|
||||
Value *m_value;
|
||||
Reference *m_ref;
|
||||
Property *m_next;
|
||||
|
||||
Property( Identifier *id )
|
||||
: m_id( id )
|
||||
, m_primData( ddl_nullptr )
|
||||
: m_key( id )
|
||||
, m_value( ddl_nullptr )
|
||||
, m_ref( ddl_nullptr )
|
||||
, m_next( ddl_nullptr ) {
|
||||
// empty
|
||||
|
|
Loading…
Reference in New Issue