You.i Engine
CYIKeyValuePairConverter Class Reference

Detailed Description

This class converts semi-colon separated key:value pairs strings into key:value vector and vice-versa.

Key-Value converter details

The expected rKeyValuePairsContent format is "key1:value1; key2:value2; keyX:valueX;" For example:

"font-style:Oblique; margin:10;"

Spaces before keys, after keys, before values and after values are ignored. For example, each of the following key-value pairs are equivalent: "key:value" " key:value" "key: value" "key: value " " key : value ". Keys shouldn't contain spaces.

Values can optionally be surrounded by double quotes to ensure that spaces do not get trimmed. Using double quotes is also required if the value contains the ';' which otherwise would demark the end of a key-value pair. Single quotes may not be used to quote strings. Within a quoted value, double quotes must be escaped using \" and backslashes must be escaped using \\ .

For example:

key:"value \"with\" \\quotes"

#include <utility/YiKeyValuePairConverter.h>

Static Public Member Functions

static std::vector< std::pair< CYIString, CYIString > > ExtractKeyValuePairs (const CYIString &rKeyValuePairsContent)
 
static CYIString ConvertKeyValuePairListToString (const std::vector< std::pair< CYIString, CYIString >> &rKeyValuePairList)
 

Member Function Documentation

◆ ConvertKeyValuePairListToString()

static CYIString CYIKeyValuePairConverter::ConvertKeyValuePairListToString ( const std::vector< std::pair< CYIString, CYIString >> &  rKeyValuePairList)
static

Creates a key-value pairs string representation from the provided keyValuePairsList. May return an empty list if none of the Key-Value pairs were valid or keys were whitespaces. The key and value pairs are separated with the : character. Each Key-Value pairs are separated with '; '

The input format expected is: { {"key1","value1"}, {"key2","value2"}, {"keyX","valueX"} } The output format is

key1:value1; key2:value2; 

The following characters are escaped during conversion:

" \ :  ; 

Both keys and values may contain spaces. The keys and values are wrapped with quotes if leading or trailing whitespaces are present.

Pairs with empty keys will be discarded and not added to the resulting string. A Key-Value pair without a value is considered valid.

◆ ExtractKeyValuePairs()

static std::vector<std::pair<CYIString, CYIString> > CYIKeyValuePairConverter::ExtractKeyValuePairs ( const CYIString rKeyValuePairsContent)
static

Extracts a list of key-value pairs from the provided rKeyValuePairsContent string. The keys and values will be trimmed as needed. May return an empty list if rKeyValuePairsContent is empty or contains only spaces or blank key-value pairs.

The expected format of the key-value pair is:

key1:value1;key2:value2 

Spaces before keys, after keys, before values and after values are ignored. For example, each of the following are equivalent: 'key:value' ' key:value' 'key: value' 'key: value ' ' key : value '. Both keys and values may contain spaces.

Keys and values can optionally be surrounded by double quotes to ensure that spaces do not get trimmed. Using double quotes is also required if the key or value contains the ':' or ';' characters, which otherwise would demark the end of a key or the end of a key-value pair. Single quotes may not be used to quote strings. Within a quoted value, double quotes must be escaped using \" and backslashes must be escaped using \\ . For example:

key:"value \"with\" \\quotes"

Pairs with empty keys will be discarded.


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