Exemple #1
0
static void sWriteIndent(const ZStrimW& iStrimW, int iIndent)
	{
	ZAssert(iIndent >= 0);
	for (int x = 0; x < iIndent; ++x)
		iStrimW.WriteCP('\t');
	}
Exemple #2
0
static void sToStrim_TupleValue(const ZStrimW& s, const ZTupleValue& iTV,
                                size_t iLevel, const ZUtil_Tuple::Options& iOptions, bool iMayNeedInitialLF)
{
    switch (iTV.TypeOf())
    {
    case eZType_Vector:
    {
        sToStrim_Vector(s, iTV.GetVector(), iLevel, iOptions, iMayNeedInitialLF);
        break;
    }
    case eZType_Tuple:
    {
        sToStrim_Tuple(s, iTV.GetTuple(), iLevel, iOptions, iMayNeedInitialLF);
        break;
    }
    case eZType_Raw:
    {
        const void* theData;
        size_t theSize;
        iTV.GetRawAttributes(&theData, &theSize);
        if (theSize == 0)
        {
            // we've got an empty Raw
            s.Write("()");
        }
        else
        {
            ZStreamRPos_Memory dataStream(theData, theSize);

            if (iOptions.DoIndentation() && theSize > iOptions.fRawChunkSize)
            {
                if (iMayNeedInitialLF)
                    sWriteLFIndent(s, iLevel, iOptions);

                s.Writef("( // %d bytes", theSize);
                sWriteLFIndent(s, iLevel, iOptions);
                if (iOptions.fRawAsASCII)
                {
                    for (;;)
                    {
                        uint64 lastPos = dataStream.GetPosition();
                        uint64 countCopied;
                        ZStreamW_HexStrim(iOptions.fRawByteSeparator, "", 0, s)
                        .CopyFrom(dataStream, iOptions.fRawChunkSize, &countCopied, nil);

                        if (countCopied == 0)
                            break;

                        dataStream.SetPosition(lastPos);
                        if (size_t extraSpaces = iOptions.fRawChunkSize - countCopied)
                        {
                            // We didn't write a complete line of bytes, so pad it out.
                            while (extraSpaces--)
                            {
                                // Two spaces for the two nibbles
                                s.Write("  ");
                                // And then the separator sequence
                                s.Write(iOptions.fRawByteSeparator);
                            }
                        }

                        s.Write(" // ");
                        while (countCopied--)
                        {
                            char theChar = dataStream.ReadInt8();
                            if (theChar < 0x20 || theChar > 0x7E)
                                s.WriteCP('.');
                            else
                                s.WriteCP(theChar);
                        }
                        sWriteLFIndent(s, iLevel, iOptions);
                    }
                }
                else
                {
                    string eol = iOptions.fEOLString;
                    for (size_t x = 0; x < iLevel; ++x)
                        eol += iOptions.fIndentString;

                    ZStreamW_HexStrim(iOptions.fRawByteSeparator,
                                      eol, iOptions.fRawChunkSize, s).CopyAllFrom(dataStream);

                    sWriteLFIndent(s, iLevel, iOptions);
                }

                s.Write(")");
            }
            else
            {
                s.Write("(");

                ZStreamW_HexStrim(iOptions.fRawByteSeparator, "", 0, s)
                .CopyAllFrom(dataStream);

                if (iOptions.fRawAsASCII)
                {
                    dataStream.SetPosition(0);
                    s.Write(" /* ");
                    while (theSize--)
                    {
                        char theChar = dataStream.ReadInt8();
                        if (theChar < 0x20 || theChar > 0x7E)
                            s.WriteCP('.');
                        else
                            s.WriteCP(theChar);
                    }
                    s.Write(" */");
                }
                s.Write(")");
            }
        }
        break;
    }
    default:
    {
        // We've got something other than a tuple or a vector.
        sSimpleTupleValueToStrim(s, iTV, iLevel, iOptions);
        break;
    }
    }
}