2012-01-12 01:24:08 +01:00
|
|
|
/*
|
2012-01-12 03:46:16 +01:00
|
|
|
* This file is a part of PikoTools
|
2012-01-12 01:24:08 +01:00
|
|
|
* and is distributed under the (new) BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-03-15 19:36:49 +01:00
|
|
|
* Copyright (c) 2010-2021, Tomasz Sowa
|
2012-01-12 01:24:08 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
|
|
|
* project may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2012-07-12 17:01:15 +02:00
|
|
|
#ifndef headerfile_picotools_space_space
|
|
|
|
#define headerfile_picotools_space_space
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2021-03-15 19:36:49 +01:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cwchar>
|
2012-07-25 12:27:20 +02:00
|
|
|
#include "textstream/types.h"
|
2021-03-15 19:36:49 +01:00
|
|
|
#include "convert/inttostr.h"
|
|
|
|
//#include "utf8/utf8.h"
|
2012-07-25 12:27:20 +02:00
|
|
|
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace PT
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2021-03-16 18:36:59 +01:00
|
|
|
Simple form:
|
|
|
|
key = value
|
|
|
|
|
|
|
|
If value is equal to 'null' then the internal representation is equal to Type::type_null, e.g:
|
|
|
|
key = null
|
|
|
|
|
|
|
|
If value is either 'false' or 'true' then the internal representation is Type::type_bool, e.g:
|
|
|
|
key = false
|
|
|
|
key = true
|
|
|
|
|
|
|
|
If value is an integer number and not an overflow has occured while parsing then type of the value
|
|
|
|
is Type::type_long (type is 'long long' internally):
|
|
|
|
key = 1000
|
|
|
|
|
|
|
|
If value is a floating point number then type is Type::type_double (type is 'double' internally):
|
|
|
|
key = 123.45
|
|
|
|
key = 123.45e+10
|
|
|
|
|
|
|
|
In other cases value has Type::type_wstring type.
|
|
|
|
|
|
|
|
The form with quotation marks:
|
|
|
|
key = "value"
|
|
|
|
In such a case value has Type::type_wstring type and can be multiline e.g:
|
|
|
|
key = "multiline
|
|
|
|
value"
|
|
|
|
In this form you can have spaces around value, e.g.:
|
|
|
|
key = " value with spaces "
|
|
|
|
|
|
|
|
|
|
|
|
The value can be a list:
|
|
|
|
key = (value1,value2)
|
|
|
|
or the same written with spaces around:
|
|
|
|
key = ( value1 , value2 )
|
|
|
|
or written in multiline fashion:
|
|
|
|
key = (
|
|
|
|
value1,
|
|
|
|
value2,
|
|
|
|
)
|
|
|
|
a colon after value2 is optional.
|
|
|
|
|
|
|
|
List can be written with quotation marks too:
|
|
|
|
key = (
|
|
|
|
"value1",
|
|
|
|
"value2",
|
|
|
|
"value3
|
|
|
|
with a new line character inside",
|
|
|
|
)
|
|
|
|
|
|
|
|
List without value:
|
|
|
|
key = ()
|
|
|
|
is equal to simple form without value, e.g.:
|
|
|
|
key =
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-16 18:36:59 +01:00
|
|
|
Difference between a simple form and a list is when parsing the colon, in simple form the colon is a part of the value, e.g.:
|
|
|
|
key = value with , a colon inside
|
|
|
|
this is equal to:
|
|
|
|
key = "value with , a colon inside"
|
|
|
|
|
|
|
|
and in a form of a list it would have two values:
|
|
|
|
key = (value with , a colon inside)
|
|
|
|
would be equal to:
|
|
|
|
key = ("value with" , "a colon inside")
|
|
|
|
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Space
|
|
|
|
{
|
|
|
|
public:
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
typedef std::map<std::wstring, Space*> ObjectType;
|
|
|
|
typedef std::vector<Space*> TableType;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
enum Escape
|
|
|
|
{
|
|
|
|
no_escape,
|
|
|
|
escape_space,
|
|
|
|
escape_json,
|
|
|
|
};
|
2017-12-07 12:35:12 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
type_null,
|
|
|
|
type_bool,
|
|
|
|
type_long,
|
|
|
|
type_float,
|
|
|
|
type_double,
|
|
|
|
type_string,
|
|
|
|
type_wstring,
|
|
|
|
type_object,
|
|
|
|
type_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
union Value
|
|
|
|
{
|
|
|
|
bool value_bool;
|
|
|
|
long long value_long;
|
|
|
|
float value_float;
|
|
|
|
double value_double;
|
|
|
|
std::string value_string;
|
|
|
|
std::wstring value_wstring;
|
|
|
|
ObjectType value_object;
|
|
|
|
TableType value_table;
|
|
|
|
|
|
|
|
Value()
|
|
|
|
{
|
|
|
|
}
|
2017-12-07 12:35:12 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
~Value()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
Type type;
|
|
|
|
Value value;
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2012-10-17 21:55:16 +02:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
Space();
|
|
|
|
Space(const Space & space);
|
|
|
|
Space & operator=(const Space & space);
|
|
|
|
// add move cctor
|
|
|
|
~Space();
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
Space(bool val);
|
|
|
|
Space(short val);
|
|
|
|
Space(int val);
|
|
|
|
Space(long val);
|
|
|
|
Space(long long val);
|
|
|
|
Space(unsigned short val);
|
|
|
|
Space(unsigned int val);
|
|
|
|
Space(unsigned long val);
|
|
|
|
Space(unsigned long long val);
|
|
|
|
Space(float val);
|
|
|
|
Space(double val);
|
|
|
|
Space(const char * str);
|
|
|
|
Space(const wchar_t * str);
|
|
|
|
Space(const std::string & str);
|
|
|
|
Space(const std::wstring & str);
|
|
|
|
Space(const Space * space);
|
|
|
|
|
|
|
|
|
2021-03-16 18:36:59 +01:00
|
|
|
void clear();
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
// set a new value
|
2021-03-16 18:36:59 +01:00
|
|
|
void set_null();
|
|
|
|
void set_empty_string();
|
|
|
|
void set_empty_wstring();
|
|
|
|
void set_empty_table();
|
|
|
|
void set_empty_object();
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
void set(bool val);
|
|
|
|
void set(short val);
|
|
|
|
void set(int val);
|
|
|
|
void set(long val);
|
|
|
|
void set(long long val);
|
|
|
|
void set(unsigned short val);
|
|
|
|
void set(unsigned int val);
|
|
|
|
void set(unsigned long val);
|
|
|
|
void set(unsigned long long val);
|
|
|
|
void set(float val);
|
|
|
|
void set(double val);
|
|
|
|
void set(const char * str);
|
|
|
|
void set(const wchar_t * str);
|
|
|
|
void set(const std::string & str);
|
|
|
|
void set(const std::wstring & str);
|
2021-03-16 18:36:59 +01:00
|
|
|
void set(const Space * space);
|
2021-03-15 19:36:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
// add a value to the table, change to table if needed, return the reference to the new inserted item
|
|
|
|
Space & add(bool val);
|
|
|
|
Space & add(short val);
|
|
|
|
Space & add(int val);
|
|
|
|
Space & add(long val);
|
|
|
|
Space & add(long long val);
|
|
|
|
Space & add(unsigned short val);
|
|
|
|
Space & add(unsigned int val);
|
|
|
|
Space & add(unsigned long val);
|
|
|
|
Space & add(unsigned long long val);
|
|
|
|
Space & add(float val);
|
|
|
|
Space & add(double val);
|
|
|
|
Space & add(const char * val);
|
|
|
|
Space & add(const wchar_t * val);
|
|
|
|
Space & add(const std::string & val);
|
|
|
|
Space & add(const std::wstring & val);
|
|
|
|
Space & add(const Space * space);
|
|
|
|
|
|
|
|
// add a value to the object, change to object if needed, return the reference to the new inserted item
|
|
|
|
Space & add(const wchar_t * field, bool val);
|
|
|
|
Space & add(const wchar_t * field, short val);
|
|
|
|
Space & add(const wchar_t * field, int val);
|
|
|
|
Space & add(const wchar_t * field, long val);
|
|
|
|
Space & add(const wchar_t * field, long long val);
|
|
|
|
Space & add(const wchar_t * field, unsigned short val);
|
|
|
|
Space & add(const wchar_t * field, unsigned int val);
|
|
|
|
Space & add(const wchar_t * field, unsigned long val);
|
|
|
|
Space & add(const wchar_t * field, unsigned long long val);
|
|
|
|
Space & add(const wchar_t * field, float val);
|
|
|
|
Space & add(const wchar_t * field, double val);
|
|
|
|
Space & add(const wchar_t * field, const char * val);
|
|
|
|
Space & add(const wchar_t * field, const wchar_t * val);
|
|
|
|
Space & add(const wchar_t * field, const std::string & val);
|
|
|
|
Space & add(const wchar_t * field, const std::wstring & val);
|
|
|
|
Space & add(const wchar_t * field, const Space * space);
|
|
|
|
Space & add_empty_space(const wchar_t * field); // IMPROVEME rename me to something better
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool is_null() const;
|
|
|
|
bool is_bool() const;
|
|
|
|
bool is_llong() const;
|
|
|
|
bool is_long_long() const;
|
|
|
|
bool is_float() const;
|
|
|
|
bool is_double() const;
|
|
|
|
bool is_numeric() const;
|
|
|
|
bool is_str() const;
|
|
|
|
bool is_wstr() const;
|
|
|
|
bool is_text() const;
|
|
|
|
bool is_object() const;
|
|
|
|
bool is_table() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool to_bool() const;
|
|
|
|
short to_short() const;
|
|
|
|
int to_int() const;
|
|
|
|
long to_long() const;
|
|
|
|
long long to_llong() const;
|
|
|
|
long long to_long_long() const;
|
|
|
|
unsigned short to_ushort() const;
|
|
|
|
unsigned int to_uint() const;
|
|
|
|
unsigned long to_ulong() const;
|
|
|
|
unsigned long long to_ullong() const;
|
|
|
|
unsigned long long to_ulong_long() const;
|
|
|
|
std::string to_str() const;
|
|
|
|
std::wstring to_wstr() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool * get_bool();
|
|
|
|
long long * get_llong();
|
|
|
|
long long * get_long_long();
|
|
|
|
float * get_float();
|
|
|
|
double * get_double();
|
|
|
|
std::string * get_string();
|
|
|
|
std::wstring * get_wstring();
|
|
|
|
ObjectType * get_object();
|
|
|
|
TableType * get_table();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bool * get_bool() const;
|
|
|
|
const long long * get_llong() const;
|
|
|
|
const long long * get_long_long() const;
|
|
|
|
const float * get_float() const;
|
|
|
|
const double * get_double() const;
|
|
|
|
const std::string * get_string() const;
|
|
|
|
const std::wstring * get_wstring() const;
|
|
|
|
const ObjectType * get_object() const;
|
|
|
|
const TableType * get_table() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string serialize_to_space_str() const;
|
|
|
|
std::wstring serialize_to_space_wstr() const;
|
|
|
|
void serialize_to_space_to(std::string & str) const;
|
|
|
|
void serialize_to_space_to(std::wstring & str) const;
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_to_space_stream(StreamType & str) const
|
|
|
|
{
|
|
|
|
// IMPROVEME
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case type_null:
|
|
|
|
//serialize_null(str, escape);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_bool:
|
|
|
|
//serialize_bool(str, escape);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_long:
|
|
|
|
//serialize_long(str, escape);
|
|
|
|
break;
|
2018-05-25 19:12:28 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_float:
|
|
|
|
//serialize_float(str, escape);
|
|
|
|
break;
|
2018-05-25 19:12:28 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_double:
|
|
|
|
//serialize_double(str, escape);
|
|
|
|
break;
|
2018-05-25 19:12:28 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_string:
|
|
|
|
//serialize_string(str, escape);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_wstring:
|
|
|
|
//serialize_wstring(str, escape);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_object:
|
|
|
|
//serialize_object(str, escape);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_table:
|
|
|
|
//serialize_table(str, escape);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
std::string serialize_to_json_str() const;
|
|
|
|
std::wstring serialize_to_json_wstr() const;
|
|
|
|
void serialize_to_json_to(std::string & str) const;
|
|
|
|
void serialize_to_json_to(std::wstring & str) const;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_to_json_stream(StreamType & str) const
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case type_null:
|
|
|
|
serialize_json_null(str);
|
|
|
|
break;
|
2017-12-07 12:35:12 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_bool:
|
|
|
|
serialize_json_bool(str);
|
|
|
|
break;
|
2017-12-07 12:35:12 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_long:
|
|
|
|
serialize_json_long(str);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_float:
|
|
|
|
serialize_json_float(str);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_double:
|
|
|
|
serialize_json_double(str);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_string:
|
|
|
|
serialize_json_string(str);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_wstring:
|
|
|
|
serialize_json_wstring(str);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_object:
|
|
|
|
serialize_json_object(str);
|
|
|
|
break;
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
case type_table:
|
|
|
|
serialize_json_table(str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
protected:
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename ArgType>
|
|
|
|
Space & add_generic(ArgType val)
|
|
|
|
{
|
|
|
|
initialize_value_table_if_needed();
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
Space * new_space = new Space(val);
|
|
|
|
value.value_table.push_back(new_space);
|
2012-03-12 21:31:17 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
return *value.value_table.back();
|
|
|
|
}
|
2017-06-27 18:51:55 +02:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename ArgType>
|
|
|
|
Space & add_generic(const wchar_t * field, ArgType val)
|
|
|
|
{
|
|
|
|
initialize_value_object_if_needed();
|
2012-07-25 12:27:20 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
auto insert_res = value.value_object.insert(std::make_pair(field, nullptr));
|
|
|
|
insert_res.first->second = new Space(val);
|
2012-03-06 14:17:25 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
return *(insert_res.first->second);
|
|
|
|
}
|
2012-03-06 14:17:25 +01:00
|
|
|
|
2012-01-16 11:16:55 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename ArgType>
|
|
|
|
ArgType to_generic_numeric_signed_value() const
|
|
|
|
{
|
|
|
|
long long val = to_long_long();
|
2012-01-16 11:16:55 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
if( val < std::numeric_limits<ArgType>::min() || val > std::numeric_limits<ArgType>::max() )
|
|
|
|
val = 0;
|
2012-01-16 11:16:55 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
return val;
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename ArgType>
|
|
|
|
ArgType to_generic_numeric_unsigned_value() const
|
|
|
|
{
|
|
|
|
unsigned long long val = to_ulong_long();
|
2012-02-14 21:34:37 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
if( val > std::numeric_limits<ArgType>::max() )
|
|
|
|
val = 0;
|
2012-02-14 21:34:37 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
return val;
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
long long convert_string_to_long_long() const;
|
|
|
|
long long convert_wstring_to_long_long() const;
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
unsigned long long convert_string_to_ulong_long() const;
|
|
|
|
unsigned long long convert_wstring_to_ulong_long() const;
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
2012-10-17 21:55:16 +02:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void escape_to_space_format(int c, StreamType & out) const
|
|
|
|
{
|
|
|
|
// IMPLEMENT ME
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void escape_to_json_format(int c, StreamType & out) const
|
|
|
|
{
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case 0: out << '\\'; out << '0'; break;
|
|
|
|
case '\r': out << '\\'; out << 'r'; break;
|
|
|
|
case '\n': out << '\\'; out << 'n'; break;
|
|
|
|
case '\\': out << '\\'; out << '\\'; break;
|
|
|
|
case '"': out << '\\'; out << '\"'; break;
|
|
|
|
//case '(': out << '\\'; out << '('; break;
|
|
|
|
//case ')': out << '\\'; out << ')'; break;
|
|
|
|
//case '=': out << '\\'; out << '='; break;
|
|
|
|
default:
|
|
|
|
out << static_cast<typename StreamType::char_type>(c);
|
|
|
|
}
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2012-05-10 23:16:19 +02:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename CharT, typename StreamType>
|
|
|
|
void copy_input_string_to_output(const CharT * input_str, StreamType & out_str, Escape escape) const
|
|
|
|
{
|
|
|
|
while( *input_str )
|
|
|
|
{
|
|
|
|
if( escape == Escape::no_escape )
|
|
|
|
out_str << static_cast<typename StreamType::char_type>(*input_str);
|
|
|
|
else
|
|
|
|
if( escape == Escape::escape_space )
|
|
|
|
escape_to_space_format(*input_str, out_str);
|
|
|
|
else
|
|
|
|
if( escape == Escape::escape_json )
|
|
|
|
escape_to_json_format(*input_str, out_str);
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
input_str += 1;
|
|
|
|
}
|
|
|
|
}
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void copy_input_stream_to_output(const StreamType & input_str, StreamType & out_str, Escape escape) const
|
|
|
|
{
|
|
|
|
typename StreamType::const_iterator i = input_str.begin();
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
while( i != input_str.end() )
|
|
|
|
{
|
|
|
|
if( escape == Escape::no_escape )
|
|
|
|
out_str << static_cast<typename StreamType::char_type>(*i);
|
|
|
|
else
|
|
|
|
if( escape == Escape::escape_space )
|
|
|
|
escape_to_space_format(*i, out_str);
|
|
|
|
else
|
|
|
|
if( escape == Escape::escape_json )
|
|
|
|
escape_to_json_format(*i, out_str);
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2012-05-10 23:16:19 +02:00
|
|
|
|
added: functions for dealing with white characters:
bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
IsDigit(wchar_t c, int base, int * digit)
added: functions to converting from a string to an integer:
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
changed: some work in Space (new Api)
now Text() methods returns std::wstring by value (before they were returned by reference)
added std::wstring & TextRef() methods
added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
GetValue() renamed to GetFirstValue()
AText() renamed to TextA() and they return std::string by value now
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
2017-12-05 17:32:21 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_string_buffer(const char * input_str, StreamType & out_str, Escape escape) const
|
|
|
|
{
|
|
|
|
if constexpr ( sizeof(char) == sizeof(typename StreamType::char_type) )
|
|
|
|
{
|
|
|
|
// input and output are char (we assume it is utf8)
|
|
|
|
copy_input_string_to_output(input_str, out_str, escape);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StreamType temp_stream;
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
// input is utf8 but output is wide
|
|
|
|
UTF8ToWide(input_str, temp_stream, false);
|
|
|
|
copy_input_stream_to_output(temp_stream, out_str, escape);
|
|
|
|
}
|
|
|
|
}
|
added: to methods Toull(), Toll(), Toul(), Toui(), Tol(), Toi()
a new parameter: bool allow_skip_whitechars default true
added: new methods: Toull_b(), Toll_b(), Toul_b(), Toui_b(), Tol_b(), Toi_b()
automatically detects the base (radix):
4323 - base 10
0122 - base 8 (string starts with 0)
#fff - base 16 (string starts with #)
&101 - base 2 (string starts with &)
added: CharType * SkipWhiteFromBack(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
skipping white characters from the end of a string
changed: Toll_b(), Toull_b(), Tol_b() and Toul_b() are used in Space now
for methods ToInt() etc so we are able to use a different base now
changed: some work in Space (const correctness)
git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1070 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-01-05 21:03:11 +01:00
|
|
|
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_string_buffer(const wchar_t * input_str, StreamType & out_str, Escape escape) const
|
|
|
|
{
|
|
|
|
if constexpr ( sizeof(wchar_t) == sizeof(typename StreamType::char_type) )
|
|
|
|
{
|
|
|
|
// input and output are wide characters
|
|
|
|
copy_input_string_to_output(input_str, out_str, escape);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StreamType temp_stream;
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
// input is wide but output is utf8
|
|
|
|
WideToUTF8(input_str, temp_stream, false);
|
|
|
|
copy_input_stream_to_output(temp_stream, out_str, escape);
|
|
|
|
}
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_null(StreamType & str) const
|
2012-01-12 01:24:08 +01:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
serialize_string_buffer(L"null", str, Escape::escape_json);
|
2012-01-12 01:24:08 +01:00
|
|
|
}
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_bool(StreamType & str) const
|
2012-01-12 01:24:08 +01:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
if( value.value_bool )
|
2012-05-12 17:54:20 +02:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
serialize_string_buffer(L"true", str, Escape::escape_json);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
serialize_string_buffer(L"false", str, Escape::escape_json);
|
2012-05-12 17:54:20 +02:00
|
|
|
}
|
2012-05-10 23:16:19 +02:00
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_long(StreamType & str) const
|
|
|
|
{
|
|
|
|
wchar_t buffer[50];
|
|
|
|
size_t buffer_len = sizeof(buffer) / sizeof(char);
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
PT::Toa(value.value_long, buffer, buffer_len);
|
|
|
|
serialize_string_buffer(buffer, str, Escape::escape_json);
|
|
|
|
}
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_float(StreamType & str) const
|
|
|
|
{
|
2021-03-16 18:36:59 +01:00
|
|
|
wchar_t buffer[100];
|
2021-03-15 19:36:49 +01:00
|
|
|
size_t buffer_len = sizeof(buffer) / sizeof(char);
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-16 18:36:59 +01:00
|
|
|
int chars_written = std::swprintf(buffer, buffer_len, L"%e", static_cast<double>(value.value_float));
|
|
|
|
|
|
|
|
if( errno == EOVERFLOW || chars_written < 0 )
|
|
|
|
buffer[0] = 0;
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
serialize_string_buffer(buffer, str, Escape::escape_json);
|
|
|
|
}
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_double(StreamType & str) const
|
|
|
|
{
|
2021-03-16 18:36:59 +01:00
|
|
|
wchar_t buffer[100];
|
|
|
|
size_t buffer_len = sizeof(buffer) / sizeof(wchar_t);
|
|
|
|
|
|
|
|
int chars_written = std::swprintf(buffer, buffer_len, L"%e", value.value_double);
|
|
|
|
|
|
|
|
if( errno == EOVERFLOW || chars_written < 0 )
|
|
|
|
buffer[0] = 0;
|
2012-05-10 23:16:19 +02:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
serialize_string_buffer(buffer, str, Escape::escape_json);
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_string(StreamType & str) const
|
|
|
|
{
|
|
|
|
str << '"';
|
|
|
|
serialize_string_buffer(value.value_string.c_str(), str, Escape::escape_json);
|
|
|
|
str << '"';
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_wstring(StreamType & str) const
|
|
|
|
{
|
|
|
|
str << '"';
|
|
|
|
serialize_string_buffer(value.value_wstring.c_str(), str, Escape::escape_json);
|
|
|
|
str << '"';
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_object(StreamType & str) const
|
2012-01-12 01:24:08 +01:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
str << '{';
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
bool is_first = true;
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
for(auto & map_item : value.value_object)
|
2012-05-10 23:16:19 +02:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
if( !is_first )
|
|
|
|
{
|
|
|
|
str << ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
str << '"';
|
|
|
|
serialize_string_buffer(map_item.first.c_str(), str, Escape::escape_json);
|
|
|
|
str << '"';
|
|
|
|
str << ':';
|
|
|
|
map_item.second->serialize_to_json_stream(str);
|
|
|
|
is_first = false;
|
2012-05-10 23:16:19 +02:00
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
str << '}';
|
2012-01-12 01:24:08 +01:00
|
|
|
}
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<typename StreamType>
|
|
|
|
void serialize_json_table(StreamType & str) const
|
2012-01-12 01:24:08 +01:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
str << '[';
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
bool is_first = true;
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
for(Space * space : value.value_table)
|
2012-01-12 01:24:08 +01:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
if( !is_first )
|
|
|
|
{
|
|
|
|
str << ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
space->serialize_to_json_stream(str);
|
|
|
|
is_first = false;
|
2012-01-12 01:24:08 +01:00
|
|
|
}
|
2021-03-15 19:36:49 +01:00
|
|
|
|
|
|
|
str << ']';
|
2012-01-12 01:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////// remove me
|
|
|
|
template<class Stream>
|
|
|
|
void Serialize(Stream & out, bool use_indents = false, bool use_comments = false, int level = 0) const
|
2012-01-12 01:24:08 +01:00
|
|
|
{
|
2021-03-15 19:36:49 +01:00
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<class Stream>
|
|
|
|
void SerializeTableMulti(Stream & out, bool use_indents, int level) const
|
|
|
|
{
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<class Stream, class StringType>
|
|
|
|
static void PrintValue(Stream & out, const StringType & str, bool use_quote = true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Stream>
|
|
|
|
static void PrintKey(Stream & out, const std::wstring & str)
|
|
|
|
{
|
|
|
|
}
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
template<class Stream>
|
|
|
|
static void PrintLevel(Stream & out, bool use_indents, int level)
|
|
|
|
{
|
2012-01-12 01:24:08 +01:00
|
|
|
}
|
2021-03-15 19:36:49 +01:00
|
|
|
/////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
void copy_value_from(const Space & space);
|
|
|
|
void copy_value_object(const Value & value_from);
|
|
|
|
void copy_value_table(const Value & value_from);
|
2012-01-12 01:24:08 +01:00
|
|
|
|
2021-03-15 19:36:49 +01:00
|
|
|
void initialize_value_null_if_needed();
|
|
|
|
void initialize_value_bool_if_needed();
|
|
|
|
void initialize_value_long_if_needed();
|
|
|
|
void initialize_value_float_if_needed();
|
|
|
|
void initialize_value_double_if_needed();
|
|
|
|
void initialize_value_string_if_needed();
|
|
|
|
void initialize_value_wstring_if_needed();
|
|
|
|
void initialize_value_object_if_needed();
|
|
|
|
void initialize_value_table_if_needed();
|
|
|
|
|
|
|
|
void remove_value();
|
|
|
|
void remove_value_string();
|
|
|
|
void remove_value_wstring();
|
|
|
|
void remove_value_object();
|
|
|
|
void remove_value_table();
|
|
|
|
|
|
|
|
|
|
|
|
};
|
2012-07-25 12:27:20 +02:00
|
|
|
|
2012-01-12 01:24:08 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|