コード例 #1
0
ファイル: ASGlobalConfigParser.cpp プロジェクト: a-lunkov/cas
//
// Dump to string
//
void DumpData(UINT_32 iLevel, const CDT & oData, std::string &sResult)
{
	CHAR_8 szBuf[512 + 1];

	++iLevel;
	switch (oData.GetType())
	{
		case CDT::UNDEF:
		case CDT::INT_VAL:
		case CDT::REAL_VAL:
		case CDT::STRING_VAL:
		case CDT::POINTER_VAL:
			sResult += "\"" + oData.GetString() + "\"\n";
			break;

		case CDT::ARRAY_VAL:
			{
				sResult += "\n";
				for (UINT_32 iI = 0; iI < oData.Size(); ++iI)
				{
					for (UINT_32 iJ = 0; iJ < iLevel; iJ++) { sResult += "      "; }
					snprintf(szBuf, 512, "%u", iI);
					sResult += szBuf;
					sResult += " : ";
					DumpData(iLevel, oData.GetCDT(iI), sResult);
				}
			}
			break;

		case CDT::HASH_VAL:
			{
				sResult += "\n";
				CDT::ConstIterator itHash = oData.Begin();
				while (itHash != oData.End())
				{
					for (UINT_32 iJ = 0; iJ < iLevel; iJ++) { sResult += "      "; }
					sResult += itHash -> first;
					sResult += " => ";
					DumpData(iLevel, itHash -> second, sResult);
					++itHash;
				}
			}
			break;

		default:
			sResult += "Invalid type";
	}
}
コード例 #2
0
//
// Character
//
static void FmtChar(StringBuffer   & oBuffer,
                    const CDT      & oCurrentArgument,
                    const UINT_32    iFmtFlags,
                    const INT_32     iWidth,
                    CHAR_8           chPadSymbol)
{
	const CDT::eValType oValType = oCurrentArgument.GetType();
	if (oValType == CDT::UNDEF && iWidth > 0)
	{
		oBuffer.Append(iWidth, chPadSymbol);
		return;
	}

	UCHAR_8 ucTMP = ' ';
	if (oValType == CDT::INT_VAL || oValType == CDT::REAL_VAL)
	{
		ucTMP = oCurrentArgument.GetInt();
	}
	else if (oValType == CDT::STRING_VAL)
	{
		const STLW::string sTMP = oCurrentArgument.GetString();
		if (sTMP.empty() && iWidth > 0)
		{
			oBuffer.Append(iWidth, chPadSymbol);
			return;
		}
		ucTMP = sTMP[0];
	}
	else if (oValType == CDT::POINTER_VAL) { ucTMP = 'P'; }
	else if (oValType == CDT::ARRAY_VAL)   { ucTMP = 'A'; }
	else if (oValType == CDT::HASH_VAL)    { ucTMP = 'H'; }

	if (iFmtFlags & F_LEFT_ALIGN)
	{
		oBuffer.Append(1, ucTMP);
		if (iWidth > 1) { oBuffer.Append(iWidth - 1, chPadSymbol); }
	}
	else
	{
		if (iWidth > 1) { oBuffer.Append(iWidth - 1, chPadSymbol); }
		oBuffer.Append(1, ucTMP);
	}
}