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