The Octopus Feature
___
.-' `'.
/ \
| ;
| | ___.--,
_.._ |0) ~ (0) | _.---'`__.-( (_.
__.--'`_.. '.__.\ '--. \_.-' ,.--'` `""`
( ,.--'` ',__ /./; ;, '.__.'` __
_`) ) .---.__.' / | |\ \__..--"" """--.,_
`---' .'.''-._.-'`_./ /\ '. \ _.-~~~````~~~-._`-.__.'
| | .' _.-' | | \ \ '. `~---`
\ \/ .' \ \ '. '-._)
\/ / \ \ `=.__`~-.
jgs / /\ `) ) / / `"".`\
, _.-'.'\ \ / / ( ( / /
`--~` ) ) .-'.' '.'. | (
(/` ( (` ) ) '-;
` '-; (-'
This commit is contained in:
@@ -50,6 +50,7 @@ LLStdStringTable LLXmlTree::sAttributeKeys(1024);
|
||||
|
||||
LLXmlTree::LLXmlTree()
|
||||
: mRoot( NULL ),
|
||||
mParser(0),
|
||||
mNodeNames(512)
|
||||
{
|
||||
}
|
||||
@@ -83,6 +84,39 @@ BOOL LLXmlTree::parseFile(const std::string &path, BOOL keep_contents)
|
||||
return success;
|
||||
}
|
||||
|
||||
bool LLXmlTree::parseBufferStart(bool keep_contents)
|
||||
{
|
||||
if (mRoot) delete mRoot;
|
||||
mRoot = NULL;
|
||||
|
||||
if (mParser) delete mParser;
|
||||
mParser = new LLXmlTreeParser(this);
|
||||
mParser->parseBufferStart(keep_contents);
|
||||
return (mParser != 0);
|
||||
}
|
||||
|
||||
bool LLXmlTree::parseBuffer(const char *buf, int len)
|
||||
{
|
||||
bool success = mParser->parseBuffer(buf, len);
|
||||
if (!success) {
|
||||
S32 line_number = mParser->getCurrentLineNumber();
|
||||
const char* error = mParser->getErrorString();
|
||||
llwarns << "LLXmlTree parse failed in line " << line_number << ": " << error << llendl;
|
||||
delete mParser;
|
||||
mParser = 0;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool LLXmlTree::parseBufferFinalize()
|
||||
{
|
||||
bool success = mParser->parseBufferFinalize(&mRoot);
|
||||
delete mParser;
|
||||
mParser = 0;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
void LLXmlTree::dump()
|
||||
{
|
||||
if( mRoot )
|
||||
@@ -102,6 +136,25 @@ void LLXmlTree::dumpNode( LLXmlTreeNode* node, const std::string& prefix )
|
||||
}
|
||||
}
|
||||
|
||||
void LLXmlTree::write(std::string &buffer) const
|
||||
{
|
||||
if (mRoot) writeNode(mRoot, buffer, "");
|
||||
}
|
||||
|
||||
void LLXmlTree::writeNode(LLXmlTreeNode *node, std::string &buffer, const std::string &indent) const
|
||||
{
|
||||
if (!node->getFirstChild()) {
|
||||
node->writeNoChild(buffer, indent);
|
||||
} else {
|
||||
node->writeStart(buffer, indent);
|
||||
std::string newIndent = indent + " ";
|
||||
for (LLXmlTreeNode *child=node->getFirstChild(); child; child=node->getNextChild())
|
||||
writeNode(child, buffer, newIndent);
|
||||
node->writeEnd(buffer, indent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// LLXmlTreeNode
|
||||
|
||||
@@ -139,6 +192,43 @@ void LLXmlTreeNode::dump( const std::string& prefix )
|
||||
llcont << llendl;
|
||||
}
|
||||
|
||||
void LLXmlTreeNode::writeNoChild(std::string &buffer, const std::string &indent) const
|
||||
{
|
||||
if (!mContents.empty()) {
|
||||
writeStart(buffer, indent);
|
||||
writeEnd(buffer, indent);
|
||||
} else {
|
||||
buffer += indent + '<' + mName;
|
||||
writeAttributes(buffer);
|
||||
buffer += "/>\n";
|
||||
}
|
||||
}
|
||||
|
||||
void LLXmlTreeNode::writeStart(std::string &buffer, const std::string &indent) const
|
||||
{
|
||||
buffer += indent + '<' + mName;
|
||||
writeAttributes(buffer);
|
||||
buffer += ">\n";
|
||||
}
|
||||
|
||||
void LLXmlTreeNode::writeEnd(std::string &buffer, const std::string &indent) const
|
||||
{
|
||||
if (!mContents.empty()) {
|
||||
buffer += indent + " " + mContents + '\n';
|
||||
}
|
||||
buffer += indent + "</" + mName + ">\n";
|
||||
}
|
||||
|
||||
void LLXmlTreeNode::writeAttributes(std::string &buffer) const
|
||||
{
|
||||
attribute_map_t::const_iterator it, end = mAttributes.end();
|
||||
for (it=mAttributes.begin(); it!=end; ++it) {
|
||||
LLStdStringHandle key = it->first;
|
||||
const std::string *value = it->second;
|
||||
buffer += ' ' + *key + "=\"" + *value + '"';
|
||||
}
|
||||
}
|
||||
|
||||
BOOL LLXmlTreeNode::hasAttribute(const std::string& name)
|
||||
{
|
||||
LLStdStringHandle canonical_name = LLXmlTree::sAttributeKeys.addString( name );
|
||||
@@ -528,7 +618,7 @@ BOOL LLXmlTreeParser::parseFile(const std::string &path, LLXmlTreeNode** root, B
|
||||
|
||||
BOOL success = LLXmlParser::parseFile(path);
|
||||
|
||||
*root = mRoot;
|
||||
if (root) *root = mRoot;
|
||||
mRoot = NULL;
|
||||
|
||||
if( success )
|
||||
@@ -540,6 +630,31 @@ BOOL LLXmlTreeParser::parseFile(const std::string &path, LLXmlTreeNode** root, B
|
||||
return success;
|
||||
}
|
||||
|
||||
void LLXmlTreeParser::parseBufferStart(BOOL keep_contents)
|
||||
{
|
||||
llassert(!mRoot);
|
||||
llassert(!mCurrent);
|
||||
mKeepContents = keep_contents;
|
||||
}
|
||||
|
||||
bool LLXmlTreeParser::parseBuffer(const char *buf, int len)
|
||||
{
|
||||
return (LLXmlParser::parse(buf, len, false) != 0);
|
||||
}
|
||||
|
||||
bool LLXmlTreeParser::parseBufferFinalize(LLXmlTreeNode** root)
|
||||
{
|
||||
bool success = (LLXmlParser::parse(0, 0, true) != 0);
|
||||
|
||||
if (root) *root = mRoot;
|
||||
mRoot = NULL;
|
||||
|
||||
llassert(!success || !mCurrent);
|
||||
mCurrent = NULL;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
const std::string& LLXmlTreeParser::tabs()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user