LibreOffice Module tools (master) 1
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
tools::JsonWriter Class Reference

#include <json_writer.hxx>

Public Member Functions

 JsonWriter ()
 
 ~JsonWriter ()
 
ScopedJsonWriterNode startNode (std::string_view)
 
ScopedJsonWriterArray startArray (std::string_view)
 
ScopedJsonWriterStruct startStruct ()
 
void put (std::u16string_view pPropName, const OUString &rPropValue)
 
void put (std::string_view pPropName, const OUString &rPropValue)
 
void put (std::string_view pPropName, std::string_view rPropValue)
 
void put (std::string_view pPropName, const char *pPropVal)
 
template<size_t N>
void put (std::string_view pPropName, const char(&pPropVal)[N])
 
template<typename N , std::enable_if_t< std::is_arithmetic_v< N >, int > = 0>
void put (std::string_view pPropName, N n)
 
void put (std::string_view pPropName, bool)
 
void putSimpleValue (const OUString &rPropValue)
 
void putRaw (std::string_view)
 This assumes that this data belongs at this point in the stream, and is valid, and properly encoded. More...
 
OString finishAndGetAsOString ()
 Closes the tags, and returns data. More...
 
bool isDataEquals (std::string_view) const
 returns true if the current JSON data matches the string More...
 

Private Member Functions

void endNode ()
 
void endArray ()
 
void endStruct ()
 
void addCommaBeforeField ()
 
void writeEscapedOUString (const OUString &rPropVal)
 
void closeDocument ()
 
void ensureSpace (int noMoreBytesRequired)
 
void ensureSpaceAndWriteNameColon (std::string_view name, int valSize)
 
void putLiteral (std::string_view propName, std::string_view propValue)
 
void addValidationMark ()
 
void validate ()
 

Private Attributes

char * mpBuffer
 
char * mPos
 
int mSpaceAllocated
 
int mStartNodeCount
 
bool mbFirstFieldInNode
 
bool mbClosed
 

Static Private Attributes

static constexpr unsigned char JSON_WRITER_DEBUG_MARKER = 0xde
 

Friends

class ScopedJsonWriterNode
 
class ScopedJsonWriterArray
 
class ScopedJsonWriterStruct
 

Detailed Description

Definition at line 34 of file json_writer.hxx.

Constructor & Destructor Documentation

◆ JsonWriter()

tools::JsonWriter::JsonWriter ( )

Definition at line 21 of file json_writer.cxx.

References addValidationMark(), and mPos.

◆ ~JsonWriter()

tools::JsonWriter::~JsonWriter ( )

Definition at line 37 of file json_writer.cxx.

References mbClosed, and mpBuffer.

Member Function Documentation

◆ addCommaBeforeField()

void tools::JsonWriter::addCommaBeforeField ( )
private

Definition at line 331 of file json_writer.cxx.

References mbFirstFieldInNode, and mPos.

Referenced by ensureSpaceAndWriteNameColon(), put(), putRaw(), putSimpleValue(), and startStruct().

◆ addValidationMark()

void tools::JsonWriter::addValidationMark ( )
inlineprivate

Definition at line 102 of file json_writer.hxx.

Referenced by ensureSpace(), and JsonWriter().

◆ closeDocument()

void tools::JsonWriter::closeDocument ( )
private

◆ endArray()

void tools::JsonWriter::endArray ( )
private

◆ endNode()

void tools::JsonWriter::endNode ( )
private

◆ endStruct()

void tools::JsonWriter::endStruct ( )
private

◆ ensureSpace()

void tools::JsonWriter::ensureSpace ( int  noMoreBytesRequired)
private

◆ ensureSpaceAndWriteNameColon()

void tools::JsonWriter::ensureSpaceAndWriteNameColon ( std::string_view  name,
int  valSize 
)
private

Definition at line 359 of file json_writer.cxx.

References addCommaBeforeField(), ensureSpace(), mPos, and name.

Referenced by put(), and putLiteral().

◆ finishAndGetAsOString()

OString tools::JsonWriter::finishAndGetAsOString ( )

Closes the tags, and returns data.

After this no more document modifications may be written.

Definition at line 383 of file json_writer.cxx.

References ensureSpace(), mbClosed, mpBuffer, mPos, and mStartNodeCount.

◆ isDataEquals()

bool tools::JsonWriter::isDataEquals ( std::string_view  s) const

returns true if the current JSON data matches the string

Definition at line 399 of file json_writer.cxx.

References mpBuffer, and mPos.

◆ put() [1/7]

void tools::JsonWriter::put ( std::string_view  pPropName,
bool  nPropVal 
)

Definition at line 304 of file json_writer.cxx.

References putLiteral().

◆ put() [2/7]

void tools::JsonWriter::put ( std::string_view  pPropName,
const char *  pPropVal 
)
inline

Definition at line 60 of file json_writer.hxx.

◆ put() [3/7]

template<size_t N>
void tools::JsonWriter::put ( std::string_view  pPropName,
const char(&)  pPropVal[N] 
)
inline

Definition at line 64 of file json_writer.hxx.

References N.

◆ put() [4/7]

void tools::JsonWriter::put ( std::string_view  pPropName,
const OUString &  rPropValue 
)

Definition at line 243 of file json_writer.cxx.

References ensureSpaceAndWriteNameColon(), and writeEscapedOUString().

◆ put() [5/7]

template<typename N , std::enable_if_t< std::is_arithmetic_v< N >, int > = 0>
void tools::JsonWriter::put ( std::string_view  pPropName,
N  n 
)
inline

Definition at line 70 of file json_writer.hxx.

References n.

◆ put() [6/7]

void tools::JsonWriter::put ( std::string_view  pPropName,
std::string_view  rPropValue 
)

◆ put() [7/7]

void tools::JsonWriter::put ( std::u16string_view  pPropName,
const OUString &  rPropValue 
)

◆ putLiteral()

void tools::JsonWriter::putLiteral ( std::string_view  propName,
std::string_view  propValue 
)
private

Definition at line 374 of file json_writer.cxx.

References ensureSpaceAndWriteNameColon(), mPos, and validate().

Referenced by put(), startArray(), and startNode().

◆ putRaw()

void tools::JsonWriter::putRaw ( std::string_view  rRawBuf)

This assumes that this data belongs at this point in the stream, and is valid, and properly encoded.

Definition at line 319 of file json_writer.cxx.

References addCommaBeforeField(), ensureSpace(), mPos, and validate().

◆ putSimpleValue()

void tools::JsonWriter::putSimpleValue ( const OUString &  rPropValue)

Definition at line 309 of file json_writer.cxx.

References addCommaBeforeField(), ensureSpace(), and writeEscapedOUString().

◆ startArray()

ScopedJsonWriterArray tools::JsonWriter::startArray ( std::string_view  pNodeName)

◆ startNode()

ScopedJsonWriterNode tools::JsonWriter::startNode ( std::string_view  pNodeName)

◆ startStruct()

ScopedJsonWriterStruct tools::JsonWriter::startStruct ( )

◆ validate()

void tools::JsonWriter::validate ( )
inlineprivate

◆ writeEscapedOUString()

void tools::JsonWriter::writeEscapedOUString ( const OUString &  rPropVal)
private

Definition at line 171 of file json_writer.cxx.

References ch, i, mPos, validate(), and tools::writeEscapedSequence().

Referenced by put(), and putSimpleValue().

Friends And Related Function Documentation

◆ ScopedJsonWriterArray

friend class ScopedJsonWriterArray
friend

Definition at line 37 of file json_writer.hxx.

Referenced by startArray().

◆ ScopedJsonWriterNode

friend class ScopedJsonWriterNode
friend

Definition at line 36 of file json_writer.hxx.

Referenced by startNode().

◆ ScopedJsonWriterStruct

friend class ScopedJsonWriterStruct
friend

Definition at line 38 of file json_writer.hxx.

Referenced by startStruct().

Member Data Documentation

◆ JSON_WRITER_DEBUG_MARKER

constexpr unsigned char tools::JsonWriter::JSON_WRITER_DEBUG_MARKER = 0xde
staticconstexprprivate

Definition at line 100 of file json_writer.hxx.

◆ mbClosed

bool tools::JsonWriter::mbClosed
private

Definition at line 45 of file json_writer.hxx.

Referenced by ensureSpace(), finishAndGetAsOString(), and ~JsonWriter().

◆ mbFirstFieldInNode

bool tools::JsonWriter::mbFirstFieldInNode
private

◆ mpBuffer

char* tools::JsonWriter::mpBuffer
private

Definition at line 40 of file json_writer.hxx.

Referenced by ensureSpace(), finishAndGetAsOString(), isDataEquals(), and ~JsonWriter().

◆ mPos

char* tools::JsonWriter::mPos
private

◆ mSpaceAllocated

int tools::JsonWriter::mSpaceAllocated
private

Definition at line 42 of file json_writer.hxx.

Referenced by ensureSpace().

◆ mStartNodeCount

int tools::JsonWriter::mStartNodeCount
private

The documentation for this class was generated from the following files: