Skip to content

Commit

Permalink
Added FormatV methods to json builder
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmauro committed Sep 19, 2024
1 parent e64ffe8 commit 6ac10ad
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
52 changes: 52 additions & 0 deletions LightJSonBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ BOOL CLightJSonBuilder::AddObjectFormattedString(_In_z_ LPCSTR szNameA, _Printf_
return AddObjectString(szNameA, (LPCSTR)cStrTempA, cStrTempA.GetLength());
}

BOOL CLightJSonBuilder::AddObjectFormattedStringV(_In_z_ LPCSTR szNameA, _Printf_format_string_ LPCSTR szFormatA, _In_ va_list argptr)
{
CStringA cStrTempA;

MX_ASSERT(szFormatA != NULL);

if (cStrTempA.FormatV(szFormatA, argptr) == FALSE)
return FALSE;

//done
return AddObjectString(szNameA, (LPCSTR)cStrTempA, cStrTempA.GetLength());
}

BOOL CLightJSonBuilder::AddObjectString(_In_z_ LPCSTR szNameA, _In_ LPCWSTR szValueW, _In_opt_ SIZE_T nValueLen)
{
MX_ASSERT(szNameA != NULL);
Expand Down Expand Up @@ -286,6 +299,19 @@ BOOL CLightJSonBuilder::AddObjectFormattedString(_In_z_ LPCSTR szNameA, _Printf_
return AddObjectString(szNameA, (LPCWSTR)cStrTempW, cStrTempW.GetLength());
}

BOOL CLightJSonBuilder::AddObjectFormattedStringV(_In_z_ LPCSTR szNameA, _Printf_format_string_ LPCWSTR szFormatW, _In_ va_list argptr)
{
CStringW cStrTempW;

MX_ASSERT(szFormatW != NULL);

if (cStrTempW.FormatV(szFormatW, argptr) == FALSE)
return FALSE;

//done
return AddObjectString(szNameA, (LPCWSTR)cStrTempW, cStrTempW.GetLength());
}

BOOL CLightJSonBuilder::AddObjectString(_In_z_ LPCSTR szNameA, _In_ PUNICODE_STRING Value)
{
MX_ASSERT(szNameA != NULL);
Expand Down Expand Up @@ -540,6 +566,19 @@ BOOL CLightJSonBuilder::AddArrayFormattedString(_Printf_format_string_ LPCSTR sz
return AddArrayString((LPCSTR)cStrTempA, cStrTempA.GetLength());
}

BOOL CLightJSonBuilder::AddArrayFormattedStringV(_Printf_format_string_ LPCSTR szFormatA, _In_ va_list argptr)
{
CStringA cStrTempA;

MX_ASSERT(szFormatA != NULL);

if (cStrTempA.FormatV(szFormatA, argptr) == FALSE)
return FALSE;

//done
return AddArrayString((LPCSTR)cStrTempA, cStrTempA.GetLength());
}

BOOL CLightJSonBuilder::AddArrayString(_In_ LPCWSTR szValueW, _In_opt_ SIZE_T nValueLen)
{
MX_ASSERT(aNestedTypes.GetCount() > 0);
Expand Down Expand Up @@ -584,6 +623,19 @@ BOOL CLightJSonBuilder::AddArrayFormattedString(_Printf_format_string_ LPCWSTR s
return AddArrayString((LPCWSTR)cStrTempW, cStrTempW.GetLength());
}

BOOL CLightJSonBuilder::AddArrayFormattedStringV(_Printf_format_string_ LPCWSTR szFormatW, _In_ va_list argptr)
{
CStringW cStrTempW;

MX_ASSERT(szFormatW != NULL);

if (cStrTempW.FormatV(szFormatW, argptr) == FALSE)
return FALSE;

//done
return AddArrayString((LPCWSTR)cStrTempW, cStrTempW.GetLength());
}

BOOL CLightJSonBuilder::AddArrayLong(_In_ LONG nValue)
{
CHAR szTempBufA[64];
Expand Down
4 changes: 4 additions & 0 deletions LightJSonBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class CLightJSonBuilder : public CBaseMemObj, public CNonCopyableObj
BOOL AddObjectBoolean(_In_z_ LPCSTR szNameA, _In_ BOOL bValue);
BOOL AddObjectString(_In_z_ LPCSTR szNameA, _In_ LPCSTR szValueA, _In_opt_ SIZE_T nValueLen = (SIZE_T)-1);
BOOL AddObjectFormattedString(_In_z_ LPCSTR szNameA, _Printf_format_string_ LPCSTR szFormatA, ...);
BOOL AddObjectFormattedStringV(_In_z_ LPCSTR szNameA, _Printf_format_string_ LPCSTR szFormatA, _In_ va_list argptr);
BOOL AddObjectString(_In_z_ LPCSTR szNameA, _In_ LPCWSTR szValueW, _In_opt_ SIZE_T nValueLen = (SIZE_T)-1);
BOOL AddObjectFormattedString(_In_z_ LPCSTR szNameA, _Printf_format_string_ LPCWSTR szFormatW, ...);
BOOL AddObjectFormattedStringV(_In_z_ LPCSTR szNameA, _Printf_format_string_ LPCWSTR szFormatW, _In_ va_list argptr);
BOOL AddObjectString(_In_z_ LPCSTR szNameA, _In_ PUNICODE_STRING Value);
BOOL AddObjectLong(_In_z_ LPCSTR szNameA, _In_ LONG nValue);
BOOL AddObjectULong(_In_z_ LPCSTR szNameA, _In_ ULONG nValue, _In_opt_ BOOL bAsHexa = FALSE);
Expand All @@ -61,8 +63,10 @@ class CLightJSonBuilder : public CBaseMemObj, public CNonCopyableObj
BOOL AddArrayBoolean(_In_ BOOL bValue);
BOOL AddArrayString(_In_ LPCSTR szValueA, _In_opt_ SIZE_T nValueLen = (SIZE_T)-1);
BOOL AddArrayFormattedString(_Printf_format_string_ LPCSTR szFormatA, ...);
BOOL AddArrayFormattedStringV(_Printf_format_string_ LPCSTR szFormatA, _In_ va_list argptr);
BOOL AddArrayString(_In_ LPCWSTR szValueW, _In_opt_ SIZE_T nValueLen = (SIZE_T)-1);
BOOL AddArrayFormattedString(_Printf_format_string_ LPCWSTR szFormatW, ...);
BOOL AddArrayFormattedStringV(_Printf_format_string_ LPCWSTR szFormatW, _In_ va_list argptr);
BOOL AddArrayLong(_In_ LONG nValue);
BOOL AddArrayULong(_In_ ULONG nValue, _In_opt_ BOOL bAsHexa = FALSE);
//IMPORTANT: ECMA-262 Sec 8.5 states max number is 9007199254740990 so, if larger, it is recommended to store it as string
Expand Down

0 comments on commit 6ac10ad

Please sign in to comment.