diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 | 
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 | 
| commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
| tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/tafwriter.cpp | |
| parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
| download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip | |
Code is all reorganized.  We're about ready to release.  I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/tafwriter.cpp')
| -rw-r--r-- | src/tafwriter.cpp | 114 | 
1 files changed, 0 insertions, 114 deletions
| diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp deleted file mode 100644 index b24bd1e..0000000 --- a/src/tafwriter.cpp +++ /dev/null | |||
| @@ -1,114 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/taf.h" | ||
| 9 | #include "bu/stream.h" | ||
| 10 | |||
| 11 | Bu::TafWriter::TafWriter( Bu::Stream &sOut ) : | ||
| 12 | sOut( sOut ), | ||
| 13 | iDepth( 0 ) | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | Bu::TafWriter::~TafWriter() | ||
| 18 | { | ||
| 19 | } | ||
| 20 | |||
| 21 | void Bu::TafWriter::ident() | ||
| 22 | { | ||
| 23 | for( int j = 0; j < iDepth; j++ ) | ||
| 24 | sOut.write(" ", 4 ); | ||
| 25 | } | ||
| 26 | |||
| 27 | void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) | ||
| 28 | { | ||
| 29 | ident(); | ||
| 30 | sOut.write("{", 1 ); | ||
| 31 | if( pRoot->getName().isSet() ) | ||
| 32 | writeString( pRoot->getName() ); | ||
| 33 | sOut.write(":\n", 2 ); | ||
| 34 | iDepth++; | ||
| 35 | const Bu::TafGroup::NodeList &nl = pRoot->getChildren(); | ||
| 36 | for( Bu::TafGroup::NodeList::const_iterator i = nl.begin(); i != nl.end(); i++ ) | ||
| 37 | { | ||
| 38 | switch( (*i)->getType() ) | ||
| 39 | { | ||
| 40 | case Bu::TafNode::typeGroup: | ||
| 41 | writeGroup( (Bu::TafGroup *)(*i) ); | ||
| 42 | break; | ||
| 43 | |||
| 44 | case Bu::TafNode::typeProperty: | ||
| 45 | writeProperty( (Bu::TafProperty *)(*i) ); | ||
| 46 | break; | ||
| 47 | |||
| 48 | case Bu::TafNode::typeComment: | ||
| 49 | writeComment( (Bu::TafComment *)(*i) ); | ||
| 50 | break; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | iDepth--; | ||
| 54 | ident(); | ||
| 55 | sOut.write("}\n", 2 ); | ||
| 56 | } | ||
| 57 | |||
| 58 | void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) | ||
| 59 | { | ||
| 60 | ident(); | ||
| 61 | if( !pProp->getName().isEmpty() ) | ||
| 62 | { | ||
| 63 | writeString( pProp->getName() ); | ||
| 64 | sOut.write("=", 1 ); | ||
| 65 | writeString( pProp->getValue() ); | ||
| 66 | } | ||
| 67 | else | ||
| 68 | { | ||
| 69 | writeString( pProp->getValue() ); | ||
| 70 | } | ||
| 71 | sOut.write("\n", 1 ); | ||
| 72 | } | ||
| 73 | |||
| 74 | void Bu::TafWriter::writeComment( const Bu::TafComment *pComment ) | ||
| 75 | { | ||
| 76 | ident(); | ||
| 77 | if( pComment->isEOLStyle() ) | ||
| 78 | { | ||
| 79 | sOut.write("//", 2 ); | ||
| 80 | sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); | ||
| 81 | sOut.write("\n", 1 ); | ||
| 82 | } | ||
| 83 | else | ||
| 84 | { | ||
| 85 | sOut.write("/*", 2 ); | ||
| 86 | sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); | ||
| 87 | sOut.write("*/ ", 3 ); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | void Bu::TafWriter::writeString( const Bu::String &str ) | ||
| 92 | { | ||
| 93 | sOut.write("\"", 1 ); | ||
| 94 | for( Bu::String::const_iterator s = str.begin(); s != str.end(); s++ ) | ||
| 95 | { | ||
| 96 | if( *s == '\"' ) | ||
| 97 | sOut.write("\\\"", 2 ); | ||
| 98 | else if( *s == '\\' ) | ||
| 99 | sOut.write("\\\\", 2 ); | ||
| 100 | else if( *s < 32 || *s > 126 ) | ||
| 101 | { | ||
| 102 | char buf[5]; | ||
| 103 | sprintf( buf, "\\x%02X", (unsigned char)*s ); | ||
| 104 | sOut.write(buf, 4 ); | ||
| 105 | } | ||
| 106 | else | ||
| 107 | { | ||
| 108 | const char buf = *s; | ||
| 109 | sOut.write( &buf, 1 ); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | sOut.write("\"", 1 ); | ||
| 113 | } | ||
| 114 | |||
