Ejemplo n.º 1
0
void 
StyledStreamWriter::writeValue( const Value &value )
{
   switch ( value.type() )
   {
   case nullValue:
      pushValue( "null" );
      break;
   case intValue:
      pushValue( valueToString( value.asLargestInt() ) );
      break;
   case uintValue:
      pushValue( valueToString( value.asLargestUInt() ) );
      break;
   case realValue:
      pushValue( valueToString( value.asDouble() ) );
      break;
   case stringValue:
      //pushValue( valueToQuotedString( value.asCString() ) );
	   pushValue(value.asCString());
      break;
   case booleanValue:
      pushValue( valueToString( value.asBool() ) );
      break;
   case arrayValue:
      writeArrayValue( value);
      break;
   case objectValue:
      {
         Value::Members members( value.getMemberNames() );
         if ( members.empty() )
            pushValue( "{}" );
         else
         {
            writeWithIndent( "{" );
            indent();
            Value::Members::iterator it = members.begin();
            for (;;)
            {
               const std::string &name = *it;
               const Value &childValue = value[name];
               writeCommentBeforeValue( childValue );
               writeWithIndent( valueToQuotedString( name.c_str() ) );
               *document_ << " : ";
               writeValue( childValue );
               if ( ++it == members.end() )
               {
                  writeCommentAfterValueOnSameLine( childValue );
                  break;
               }
               *document_ << ",";
               writeCommentAfterValueOnSameLine( childValue );
            }
            unindent();
            writeWithIndent( "}" );
         }
      }
      break;
   }
}
Ejemplo n.º 2
0
void BuiltStyledStreamWriter::writeValue(Value const& value) {
    switch (value.type()) {
    case nullValue:
        pushValue(nullSymbol_);
        break;
    case intValue:
        pushValue(valueToString(value.asLargestInt()));
        break;
    case uintValue:
        pushValue(valueToString(value.asLargestUInt()));
        break;
    case realValue:
        pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_));
        break;
    case stringValue:
    {
        // Is NULL is possible for value.string_?
        char const* str;
        char const* end;
        bool ok = value.getString(&str, &end);
        if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
        else pushValue("");
        break;
    }
    case booleanValue:
        pushValue(valueToString(value.asBool()));
        break;
    case arrayValue:
        writeArrayValue(value);
        break;
    case objectValue: {
        Value::Members members(value.getMemberNames());
        if (members.empty())
            pushValue("{}");
        else {
            writeWithIndent("{");
            indent();
            Value::Members::iterator it = members.begin();
            for (;;) {
                std::string const& name = *it;
                Value const& childValue = value[name];
                writeCommentBeforeValue(childValue);
                writeWithIndent(valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length())));
                *sout_ << colonSymbol_;
                writeValue(childValue);
                if (++it == members.end()) {
                    writeCommentAfterValueOnSameLine(childValue);
                    break;
                }
                *sout_ << ",";
                writeCommentAfterValueOnSameLine(childValue);
            }
            unindent();
            writeWithIndent("}");
        }
    }
    break;
    }
}
Ejemplo n.º 3
0
void StyledStreamWriter::writeValue(const Value& value) {
    switch (value.type()) {
    case nullValue:
        pushValue("null");
        break;
    case intValue:
        pushValue(valueToString(value.asLargestInt()));
        break;
    case uintValue:
        pushValue(valueToString(value.asLargestUInt()));
        break;
    case realValue:
        pushValue(valueToString(value.asDouble()));
        break;
    case stringValue:
    {
        // Is NULL possible for value.string_?
        char const* str;
        char const* end;
        bool ok = value.getString(&str, &end);
        if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
        else pushValue("");
        break;
    }
    case booleanValue:
        pushValue(valueToString(value.asBool()));
        break;
    case arrayValue:
        writeArrayValue(value);
        break;
    case objectValue: {
        Value::Members members(value.getMemberNames());
        if (members.empty())
            pushValue("{}");
        else {
            writeWithIndent("{");
            indent();
            Value::Members::iterator it = members.begin();
            for (;;) {
                const std::string& name = *it;
                const Value& childValue = value[name];
                writeCommentBeforeValue(childValue);
                writeWithIndent(valueToQuotedString(name.c_str()));
                *document_ << " : ";
                writeValue(childValue);
                if (++it == members.end()) {
                    writeCommentAfterValueOnSameLine(childValue);
                    break;
                }
                *document_ << ",";
                writeCommentAfterValueOnSameLine(childValue);
            }
            unindent();
            writeWithIndent("}");
        }
    }
    break;
    }
}
Ejemplo n.º 4
0
void
StyledStreamWriter::writeArrayValue ( const Value& value )
{
    unsigned size = value.size ();

    if ( size == 0 )
        pushValue ( "[]" );
    else
    {
        bool isArrayMultiLine = isMultineArray ( value );

        if ( isArrayMultiLine )
        {
            writeWithIndent ( "[" );
            indent ();
            bool hasChildValue = !childValues_.empty ();
            unsigned index = 0;

            while ( true )
            {
                const Value& childValue = value[index];

                if ( hasChildValue )
                    writeWithIndent ( childValues_[index] );
                else
                {
                    writeIndent ();
                    writeValue ( childValue );
                }

                if ( ++index == size )
                    break;

                *document_ << ",";
            }

            unindent ();
            writeWithIndent ( "]" );
        }
        else // output on a single line
        {
            assert ( childValues_.size () == size );
            *document_ << "[ ";

            for ( unsigned index = 0; index < size; ++index )
            {
                if ( index > 0 )
                    *document_ << ", ";

                *document_ << childValues_[index];
            }

            *document_ << " ]";
        }
    }
}
Ejemplo n.º 5
0
void 
StyledWriter::writeArrayValue( const Value &value )
{
   unsigned size = value.size();
   if ( size == 0 )
      pushValue( "[]" );
   else
   {
      bool isArrayMultiLine = isMultineArray( value );
      if ( isArrayMultiLine )
      {
         writeWithIndent( "[" );
         indent();
         bool hasChildValue = !childValues_.empty();
         unsigned index =0;
         for (;;)
         {
            const Value &childValue = value[index];
            writeCommentBeforeValue( childValue );
            if ( hasChildValue )
               writeWithIndent( childValues_[index] );
            else
            {
               writeIndent();
               writeValue( childValue );
            }
            if ( ++index == size )
            {
               writeCommentAfterValueOnSameLine( childValue );
               break;
            }
            document_ += ",";
            writeCommentAfterValueOnSameLine( childValue );
         }
         unindent();
         writeWithIndent( "]" );
      }
      else // output on a single line
      {
         assert( childValues_.size() == size );
         document_ += "[ ";
         for ( unsigned index =0; index < size; ++index )
         {
            if ( index > 0 )
               document_ += ", ";
            document_ += childValues_[index];
         }
         document_ += " ]";
      }
   }
}
Ejemplo n.º 6
0
void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
  unsigned size = value.size();
  if (size == 0)
    pushValue("[]");
  else {
    bool isMultiLine = (cs_ == CommentStyle::All) || isMultineArray(value);
    if (isMultiLine) {
      writeWithIndent("[");
      indent();
      bool hasChildValue = !childValues_.empty();
      unsigned index = 0;
      for (;;) {
        Value const& childValue = value[index];
        writeCommentBeforeValue(childValue);
        if (hasChildValue)
          writeWithIndent(childValues_[index]);
        else {
          if (!indented_) writeIndent();
          indented_ = true;
          writeValue(childValue);
          indented_ = false;
        }
        if (++index == size) {
          writeCommentAfterValueOnSameLine(childValue);
          break;
        }
        sout_ << ",";
        writeCommentAfterValueOnSameLine(childValue);
      }
      unindent();
      writeWithIndent("]");
    } else // output on a single line
    {
      assert(childValues_.size() == size);
      sout_ << "[";
      if (!indentation_.empty()) sout_ << " ";
      for (unsigned index = 0; index < size; ++index) {
        if (index > 0)
          sout_ << ", ";
        sout_ << childValues_[index];
      }
      if (!indentation_.empty()) sout_ << " ";
      sout_ << "]";
    }
  }
}
Ejemplo n.º 7
0
void
StyledWriter::writeValue ( const Value& value )
{
    switch ( value.type () )
    {
    case nullValue:
        pushValue ( "null" );
        break;

    case intValue:
        pushValue ( valueToString ( value.asInt () ) );
        break;

    case uintValue:
        pushValue ( valueToString ( value.asUInt () ) );
        break;

    case realValue:
        pushValue ( valueToString ( value.asDouble () ) );
        break;

    case stringValue:
        pushValue ( valueToQuotedString ( value.asCString () ) );
        break;

    case booleanValue:
        pushValue ( valueToString ( value.asBool () ) );
        break;

    case arrayValue:
        writeArrayValue ( value);
        break;

    case objectValue:
    {
        Value::Members members ( value.getMemberNames () );

        if ( members.empty () )
            pushValue ( "{}" );
        else
        {
            writeWithIndent ( "{" );
            indent ();
            Value::Members::iterator it = members.begin ();

            while ( true )
            {
                std::string const& name = *it;
                const Value& childValue = value[name];
                writeWithIndent ( valueToQuotedString ( name.c_str () ) );
                document_ += " : ";
                writeValue ( childValue );

                if ( ++it == members.end () )
                    break;

                document_ += ",";
            }

            unindent ();
            writeWithIndent ( "}" );
        }
    }
    break;
    }
}