Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
picojson Namespace Reference

Classes

class  default_parse_context
 
class  deny_parse_context
 
class  input
 
struct  last_error_t
 
struct  null
 
class  null_parse_context
 
struct  serialize_str_char
 
class  value
 

Typedefs

typedef value::array array
 
typedef value::object object
 

Enumerations

enum  {
  null_type , boolean_type , number_type , string_type ,
  array_type , object_type
}
 
enum  { INDENT_WIDTH = 2 }
 

Functions

template<typename Iter >
void copy (const std::string &s, Iter oi)
 
template<typename Iter >
void serialize_str (const std::string &s, Iter oi)
 
template<typename Iter >
int _parse_quadhex (input< Iter > &in)
 
template<typename String , typename Iter >
bool _parse_codepoint (String &out, input< Iter > &in)
 
template<typename String , typename Iter >
bool _parse_string (String &out, input< Iter > &in)
 
template<typename Context , typename Iter >
bool _parse_array (Context &ctx, input< Iter > &in)
 
template<typename Context , typename Iter >
bool _parse_object (Context &ctx, input< Iter > &in)
 
template<typename Iter >
std::string _parse_number (input< Iter > &in)
 
template<typename Context , typename Iter >
bool _parse (Context &ctx, input< Iter > &in)
 
template<typename Iter >
std::string parse (value &out, Iter &pos, const Iter &last)
 
template<typename Context , typename Iter >
Iter _parse (Context &ctx, const Iter &first, const Iter &last, std::string *err)
 
template<typename Iter >
Iter parse (value &out, const Iter &first, const Iter &last, std::string *err)
 
std::string parse (value &out, const std::string &s)
 
std::string parse (value &out, std::istream &is)
 
void set_last_error (const std::string &s)
 
const std::string & get_last_error ()
 
bool operator== (const value &x, const value &y)
 
bool operator!= (const value &x, const value &y)
 

Typedef Documentation

◆ array

Definition at line 221 of file spec_test_generator.cpp.

◆ object

Definition at line 222 of file spec_test_generator.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
null_type 
boolean_type 
number_type 
string_type 
array_type 
object_type 

Definition at line 123 of file spec_test_generator.cpp.

123 {
124 null_type,
129 object_type
130# ifdef PICOJSON_USE_INT64
131 ,
132 int64_type
133# endif
134};

◆ anonymous enum

anonymous enum
Enumerator
INDENT_WIDTH 

Definition at line 136 of file spec_test_generator.cpp.

Function Documentation

◆ _parse() [1/2]

template<typename Context , typename Iter >
Iter picojson::_parse ( Context & ctx,
const Iter & first,
const Iter & last,
std::string * err )
inline

Definition at line 1022 of file spec_test_generator.cpp.

1022 {
1023 input<Iter> in(first, last);
1024 if (!_parse(ctx, in) && err != NULL) {
1025 char buf[64];
1026 SNPRINTF(buf, sizeof(buf), "syntax error at line %d near: ", in.line());
1027 *err = buf;
1028 while (1) {
1029 int ch = in.getc();
1030 if (ch == -1 || ch == '\n') {
1031 break;
1032 } else if (ch >= ' ') {
1033 err->push_back(static_cast<char>(ch));
1034 }
1035 }
1036 }
1037 return in.cur();
1038}
bool _parse(Context &ctx, input< Iter > &in)
#define SNPRINTF
uint8_t buf[2048]
Here is the call graph for this function:

◆ _parse() [2/2]

template<typename Context , typename Iter >
bool picojson::_parse ( Context & ctx,
input< Iter > & in )
inline

Definition at line 844 of file spec_test_generator.cpp.

844 {
845 in.skip_ws();
846 int ch = in.getc();
847 switch (ch) {
848# define IS(ch, text, op) \
849 case ch: \
850 if (in.match(text) && op) { \
851 return true; \
852 } else { \
853 return false; \
854 }
855 IS('n', "ull", ctx.set_null());
856 IS('f', "alse", ctx.set_bool(false));
857 IS('t', "rue", ctx.set_bool(true));
858# undef IS
859 case '"': return ctx.parse_string(in);
860 case '[': return _parse_array(ctx, in);
861 case '{': return _parse_object(ctx, in);
862 default:
863 if (('0' <= ch && ch <= '9') || ch == '-') {
864 double f;
865 char* endp;
866 in.ungetc();
867 std::string num_str(_parse_number(in));
868 if (num_str.empty()) {
869 return false;
870 }
871# ifdef PICOJSON_USE_INT64
872 {
873 errno = 0;
874 intmax_t ival = strtoimax(num_str.c_str(), &endp, 10);
875 if (errno == 0 && std::numeric_limits<int64_t>::min() <= ival &&
876 ival <= std::numeric_limits<int64_t>::max() && endp == num_str.c_str() + num_str.size()) {
877 ctx.set_int64(ival);
878 return true;
879 }
880 }
881# endif
882 f = strtod(num_str.c_str(), &endp);
883 if (endp == num_str.c_str() + num_str.size()) {
884 ctx.set_number(f);
885 return true;
886 }
887 return false;
888 }
889 break;
890 }
891 in.ungetc();
892 return false;
893}
#define strtod
#define strtoimax
Definition inttypes.h:307
bool _parse_object(Context &ctx, input< Iter > &in)
std::string _parse_number(input< Iter > &in)
bool _parse_array(Context &ctx, input< Iter > &in)
#define IS(ctype, jtype)
int64_t intmax_t
Definition stdint.h:169
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_array()

template<typename Context , typename Iter >
bool picojson::_parse_array ( Context & ctx,
input< Iter > & in )
inline

Definition at line 785 of file spec_test_generator.cpp.

785 {
786 if (!ctx.parse_array_start()) {
787 return false;
788 }
789 size_t idx = 0;
790 if (in.expect(']')) {
791 return ctx.parse_array_stop(idx);
792 }
793 do {
794 if (!ctx.parse_array_item(in, idx)) {
795 return false;
796 }
797 idx++;
798 } while (in.expect(','));
799 return in.expect(']') && ctx.parse_array_stop(idx);
800}
Here is the caller graph for this function:

◆ _parse_codepoint()

template<typename String , typename Iter >
bool picojson::_parse_codepoint ( String & out,
input< Iter > & in )
inline

Definition at line 704 of file spec_test_generator.cpp.

704 {
705 int uni_ch;
706 if ((uni_ch = _parse_quadhex(in)) == -1) {
707 return false;
708 }
709 if (0xd800 <= uni_ch && uni_ch <= 0xdfff) {
710 if (0xdc00 <= uni_ch) {
711 // a second 16-bit of a surrogate pair appeared
712 return false;
713 }
714 // first 16-bit of surrogate pair, get the next one
715 if (in.getc() != '\\' || in.getc() != 'u') {
716 in.ungetc();
717 return false;
718 }
719 int second = _parse_quadhex(in);
720 if (!(0xdc00 <= second && second <= 0xdfff)) {
721 return false;
722 }
723 uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff);
724 uni_ch += 0x10000;
725 }
726 if (uni_ch < 0x80) {
727 out.push_back(static_cast<char>(uni_ch));
728 } else {
729 if (uni_ch < 0x800) {
730 out.push_back(static_cast<char>(0xc0 | (uni_ch >> 6)));
731 } else {
732 if (uni_ch < 0x10000) {
733 out.push_back(static_cast<char>(0xe0 | (uni_ch >> 12)));
734 } else {
735 out.push_back(static_cast<char>(0xf0 | (uni_ch >> 18)));
736 out.push_back(static_cast<char>(0x80 | ((uni_ch >> 12) & 0x3f)));
737 }
738 out.push_back(static_cast<char>(0x80 | ((uni_ch >> 6) & 0x3f)));
739 }
740 out.push_back(static_cast<char>(0x80 | (uni_ch & 0x3f)));
741 }
742 return true;
743}
int _parse_quadhex(input< Iter > &in)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_number()

template<typename Iter >
std::string picojson::_parse_number ( input< Iter > & in)
inline

Definition at line 823 of file spec_test_generator.cpp.

823 {
824 std::string num_str;
825 while (1) {
826 int ch = in.getc();
827 if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' || ch == 'e' || ch == 'E') {
828 num_str.push_back(static_cast<char>(ch));
829 } else if (ch == '.') {
830# if PICOJSON_USE_LOCALE
831 num_str += localeconv()->decimal_point;
832# else
833 num_str.push_back('.');
834# endif
835 } else {
836 in.ungetc();
837 break;
838 }
839 }
840 return num_str;
841}
Here is the caller graph for this function:

◆ _parse_object()

template<typename Context , typename Iter >
bool picojson::_parse_object ( Context & ctx,
input< Iter > & in )
inline

Definition at line 803 of file spec_test_generator.cpp.

803 {
804 if (!ctx.parse_object_start()) {
805 return false;
806 }
807 if (in.expect('}')) {
808 return true;
809 }
810 do {
811 std::string key;
812 if (!in.expect('"') || !_parse_string(key, in) || !in.expect(':')) {
813 return false;
814 }
815 if (!ctx.parse_object_item(in, key)) {
816 return false;
817 }
818 } while (in.expect(','));
819 return in.expect('}');
820}
bool _parse_string(String &out, input< Iter > &in)
uint8_t key[16]
Definition yubico_otp.c:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_quadhex()

template<typename Iter >
int picojson::_parse_quadhex ( input< Iter > & in)
inline

Definition at line 682 of file spec_test_generator.cpp.

682 {
683 int uni_ch = 0, hex;
684 for (int i = 0; i < 4; i++) {
685 if ((hex = in.getc()) == -1) {
686 return -1;
687 }
688 if ('0' <= hex && hex <= '9') {
689 hex -= '0';
690 } else if ('A' <= hex && hex <= 'F') {
691 hex -= 'A' - 0xa;
692 } else if ('a' <= hex && hex <= 'f') {
693 hex -= 'a' - 0xa;
694 } else {
695 in.ungetc();
696 return -1;
697 }
698 uni_ch = uni_ch * 16 + hex;
699 }
700 return uni_ch;
701}
constexpr const char hex[]
Here is the caller graph for this function:

◆ _parse_string()

template<typename String , typename Iter >
bool picojson::_parse_string ( String & out,
input< Iter > & in )
inline

Definition at line 746 of file spec_test_generator.cpp.

746 {
747 while (1) {
748 int ch = in.getc();
749 if (ch < ' ') {
750 in.ungetc();
751 return false;
752 } else if (ch == '"') {
753 return true;
754 } else if (ch == '\\') {
755 if ((ch = in.getc()) == -1) {
756 return false;
757 }
758 switch (ch) {
759# define MAP(sym, val) \
760 case sym: out.push_back(val); break
761 MAP('"', '\"');
762 MAP('\\', '\\');
763 MAP('/', '/');
764 MAP('b', '\b');
765 MAP('f', '\f');
766 MAP('n', '\n');
767 MAP('r', '\r');
768 MAP('t', '\t');
769# undef MAP
770 case 'u':
771 if (!_parse_codepoint(out, in)) {
772 return false;
773 }
774 break;
775 default: return false;
776 }
777 } else {
778 out.push_back(static_cast<char>(ch));
779 }
780 }
781 return false;
782}
bool _parse_codepoint(String &out, input< Iter > &in)
#define MAP(val, sym)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy()

template<typename Iter >
void picojson::copy ( const std::string & s,
Iter oi )

Definition at line 498 of file spec_test_generator.cpp.

498 {
499 std::copy(s.begin(), s.end(), oi);
500}
char * s
Here is the caller graph for this function:

◆ get_last_error()

const std::string & picojson::get_last_error ( )
inline

◆ operator!=()

bool picojson::operator!= ( const value & x,
const value & y )
inline

Definition at line 1088 of file spec_test_generator.cpp.

1088{ return !(x == y); }

◆ operator==()

bool picojson::operator== ( const value & x,
const value & y )
inline

Definition at line 1069 of file spec_test_generator.cpp.

1069 {
1070 if (x.is<null>())
1071 return y.is<null>();
1072# define PICOJSON_CMP(type) \
1073 if (x.is<type>()) \
1074 return y.is<type>() && x.get<type>() == y.get<type>()
1075 PICOJSON_CMP(bool);
1076 PICOJSON_CMP(double);
1077 PICOJSON_CMP(std::string);
1079 PICOJSON_CMP(object);
1080# undef PICOJSON_CMP
1081 PICOJSON_ASSERT(0);
1082# ifdef _MSC_VER
1083 __assume(0);
1084# endif
1085 return false;
1086}
bool is() const
value::array array
#define PICOJSON_ASSERT(e)
#define PICOJSON_CMP(type)
Here is the call graph for this function:

◆ parse() [1/4]

template<typename Iter >
Iter picojson::parse ( value & out,
const Iter & first,
const Iter & last,
std::string * err )
inline

Definition at line 1041 of file spec_test_generator.cpp.

1041 {
1042 default_parse_context ctx(&out);
1043 return _parse(ctx, first, last, err);
1044}
Here is the call graph for this function:

◆ parse() [2/4]

std::string picojson::parse ( value & out,
const std::string & s )
inline

Definition at line 1046 of file spec_test_generator.cpp.

1046 {
1047 std::string err;
1048 parse(out, s.begin(), s.end(), &err);
1049 return err;
1050}
Here is the call graph for this function:

◆ parse() [3/4]

template<typename Iter >
std::string picojson::parse ( value & out,
Iter & pos,
const Iter & last )
inline

Definition at line 1015 of file spec_test_generator.cpp.

1015 {
1016 std::string err;
1017 pos = parse(out, pos, last, &err);
1018 return err;
1019}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse() [4/4]

std::string picojson::parse ( value & out,
std::istream & is )
inline

Definition at line 1052 of file spec_test_generator.cpp.

1052 {
1053 std::string err;
1054 parse(out, std::istreambuf_iterator<char>(is.rdbuf()), std::istreambuf_iterator<char>(), &err);
1055 return err;
1056}
Here is the call graph for this function:

◆ serialize_str()

template<typename Iter >
void picojson::serialize_str ( const std::string & s,
Iter oi )

Definition at line 532 of file spec_test_generator.cpp.

532 {
533 *oi++ = '"';
534 serialize_str_char<Iter> process_char = { oi };
535 std::for_each(s.begin(), s.end(), process_char);
536 *oi++ = '"';
537}

◆ set_last_error()

void picojson::set_last_error ( const std::string & s)
inline

Definition at line 1065 of file spec_test_generator.cpp.

Here is the caller graph for this function: