diff --git a/include/rjp.h b/include/rjp.h index 90f0aaf..ba2dd7f 100644 --- a/include/rjp.h +++ b/include/rjp.h @@ -22,32 +22,53 @@ #ifdef __cplusplus extern "C"{ #endif - -#if defined(__GNUC__) || defined(__clang__) -#define DEPRECATED(str) __attribute__((deprecated(str))) +#ifndef __STDC_VERSION__ +# ifdef __cplusplus +# if __cplusplus >= 201402L +# define DEPRECATED(str) [[deprecated(str)]] +# elif defined(__GNUC__) || defined(__clang__) +# define DEPRECATED(str) __attribute__((deprecated(str))) +# else +# define DEPRECATED(str) +# endif +# endif #else -#define DEPRECATED(str) +# if __STDC_VERSION__ > 201710L +# define DEPRECATED(str) [[deprecated(str)]] +# elif defined(__GNUC__) || defined(__clang__) +# define DEPRECATED(str) __attribute__((deprecated(str))) +# else +# define DEPRECATED(str) +# endif #endif #ifndef RJP_int -#include -#define RJP_int int_fast64_t +# include +# define RJP_int int_fast64_t #endif #ifndef RJP_index -#include -#define RJP_index size_t +# include +# define RJP_index size_t #endif #ifndef RJP_float -#include -#define RJP_float double +# define RJP_float double #endif #ifndef RJP_bool -#define RJP_bool char +# define RJP_bool char #endif //used with rjp_to_json -#define RJP_FORMAT_NONE 0 -#define RJP_FORMAT_PRETTY 1 +typedef enum RJP_format_flag{ + RJP_FORMAT_NONE = 0, + RJP_FORMAT_PRETTY = 1 +}RJP_format_flag; + +typedef enum RJP_parse_flag{ + RJP_PARSE_NONE = 0, + RJP_PARSE_ALLOW_COMMENTS = 1, + RJP_PARSE_ALLOW_TRAILING_COMMA = 2, + RJP_PARSE_ALL_EXT = 3 +}RJP_parse_flag; //type of data typedef enum RJP_data_type{ @@ -84,11 +105,6 @@ typedef struct RJP_array_iterator{ RJP_value* current; }RJP_array_iterator; -typedef enum RJP_parse_flag{ - RJP_PARSE_NONE = 0, - RJP_PARSE_ALLOW_COMMENTS = 1, - RJP_PARSE_ALLOW_TRAILING_COMMA = 2 -}RJP_parse_flag; typedef struct RJP_parse_callback{ int(*read)(char*,int,void*); void* data; @@ -109,6 +125,7 @@ void rjp_free(void* dest); RJP_index rjp_escape_strcpy(char* dest, const char* src); //length of string including escape sequences RJP_index rjp_escape_strlen(const char* str); +RJP_string rjp_escape(const char* src); /***************** GENERIC OPERATIONS *******************/ //Convert C string consisting of json data into RJP's format diff --git a/src/rjp_string.c b/src/rjp_string.c index 5fbd982..92964dc 100644 --- a/src/rjp_string.c +++ b/src/rjp_string.c @@ -295,6 +295,12 @@ RJP_index rjp_escape_strlen(const char* str){ } return count; } +RJP_string rjp_escape(const char* src){ + RJP_index esclen = rjp_escape_strlen(src); + char* dest = rjp_alloc(esclen+1); + rjp_escape_strcpy(dest, src); + return (RJP_string){.value = dest, .length = esclen}; +} RJP_index irjp_array_strlen(const RJP_value* arr){ RJP_index count = 2; //[] RJP_array_iterator it;