* Fix bug in escaping of control characters

Johan Bj�rklund, johbjo09 at kth dot se
  * Remove include "config.h" from headers (should only
    be included from .c files)
    Michael Clark <michael@metaparadigm.com>


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@12 327403b1-1117-474d-bef2-5cb71233fd97
This commit is contained in:
Michael Clark
2007-03-13 08:26:25 +00:00
parent f6a6e486ff
commit 837240f75f
11 changed files with 39 additions and 60 deletions

View File

@@ -1,3 +1,10 @@
0.6
* Fix bug in escaping of control characters
Johan Bj<42>rklund, johbjo09 at kth dot se
* Remove include "config.h" from headers (should only
be included from .c files)
Michael Clark <michael@metaparadigm.com>
0.5
* Make headers C++ compatible by change *this to *obj
* Add ifdef C++ extern "C" to headers

View File

@@ -8,7 +8,7 @@
</head>
<body>
<h2>JSON-C - A JSON implementation in C</h2>
<p>Latest release: <a href="json-c-0.5.tar.gz">json-c-0.5.tar.gz</a></p>
<p>Latest release: <a href="json-c-0.6.tar.gz">json-c-0.6.tar.gz</a></p>
<p>JSON-C implements a reference counting object model that allows you to easily
construct JSON objects in C, output them as JSON formatted strings and parse
JSON formatted strings back into the C representation of JSON objects.</p>

13
bits.h
View File

@@ -1,5 +1,5 @@
/*
* $Id: bits.h,v 1.9 2006/01/26 02:16:28 mclark Exp $
* $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -12,17 +12,6 @@
#ifndef _bits_h_
#define _bits_h_
#include "config.h"
#if STDC_HEADERS
# include <stddef.h>
#endif /* STDC_HEADERS */
/* CAW: wrapped in ifndef's to make win32 compliant
** this fails to take over GCC specifics, but this
** seems to be unimportant.
*/
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif

10
debug.h
View File

@@ -1,5 +1,5 @@
/*
* $Id: debug.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
* $Id: debug.h,v 1.5 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -12,14 +12,6 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_
#include "config.h"
#if HAVE_STRERROR
#define errstr strerror(errno)
#else /* !HAVE_STRERROR */
#define errstr
#endif /* HAVE_STRERROR */
extern void mc_set_debug(int debug);
extern int mc_get_debug();

View File

@@ -1,5 +1,5 @@
/*
* $Id: json_object.c,v 1.14 2006/01/26 02:16:28 mclark Exp $
* $Id: json_object.c,v 1.15 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -23,6 +23,10 @@
#include "json_object_private.h"
#include "json_tokener.h"
#if !HAVE_STRNDUP
char* strndup(const char* str, size_t n);
#endif /* !HAVE_STRNDUP */
/* #define REFCOUNT_DEBUG 1 */
char *json_number_chars = "0123456789.+-e";
@@ -78,10 +82,12 @@ static void json_object_fini() {
static int json_escape_str(struct printbuf *pb, char *str)
{
int pos = 0, start_offset = 0;
char c;
unsigned char c;
do {
c = str[pos];
switch(c) {
case '\0':
break;
case '\b':
case '\n':
case '\r':
@@ -97,14 +103,14 @@ static int json_escape_str(struct printbuf *pb, char *str)
start_offset = ++pos;
break;
default:
if(c && c < ' ') {
if(c < ' ') {
if(pos - start_offset > 0)
printbuf_memappend(pb, str + start_offset, pos - start_offset);
sprintbuf(pb, "\\u00%c%c",
json_hex_chars[c >> 4],
json_hex_chars[c & 0xf]);
start_offset = ++pos;
} else if(c) pos++;
} else pos++;
}
} while(c);
if(pos - start_offset > 0)

View File

@@ -1,5 +1,5 @@
/*
* $Id: json_object.h,v 1.11 2006/01/26 02:16:28 mclark Exp $
* $Id: json_object.h,v 1.12 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -12,8 +12,6 @@
#ifndef _json_object_h_
#define _json_object_h_
#include "config.h"
#define JSON_OBJECT_DEF_HASH_ENTIRES 16
#undef FALSE

View File

@@ -1,5 +1,5 @@
/*
* $Id: json_tokener.c,v 1.18 2006/01/26 02:16:28 mclark Exp $
* $Id: json_tokener.c,v 1.19 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -23,6 +23,14 @@
#include "json_object.h"
#include "json_tokener.h"
#if !HAVE_STRNCASECMP && defined(_MSC_VER)
/* MSC has the version as _strnicmp */
# define strncasecmp _strnicmp
#elif !HAVE_STRNCASECMP
# error You do not have strncasecmp on your system.
#endif /* HAVE_STRNCASECMP */
static struct json_object* json_tokener_do_parse(struct json_tokener *this);
struct json_object* json_tokener_parse(char * s)

View File

@@ -1,5 +1,5 @@
/*
* $Id: json_tokener.h,v 1.8 2006/01/26 02:16:28 mclark Exp $
* $Id: json_tokener.h,v 1.9 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -12,7 +12,6 @@
#ifndef _json_tokener_h_
#define _json_tokener_h_
#include "config.h"
#include "json_object.h"
enum json_tokener_error {
@@ -59,17 +58,6 @@ struct json_tokener
struct printbuf *pb;
};
#if !HAVE_STRNCASECMP && defined(_MSC_VER)
/* MSC has the version as _strnicmp */
# define strncasecmp _strnicmp
#elif !HAVE_STRNCASECMP
# error You do not have strncasecmp on your system.
#endif /* HAVE_STRNCASECMP */
#if !HAVE_STRNDUP
char* strndup(const char* str, size_t n);
#endif /* !HAVE_STRNDUP */
extern struct json_object* json_tokener_parse(char *s);
#endif

View File

@@ -1,5 +1,5 @@
/*
* $Id: json_util.c,v 1.3 2006/01/26 02:16:28 mclark Exp $
* $Id: json_util.c,v 1.4 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -39,6 +39,11 @@
# include <io.h>
#endif /* defined(WIN32) */
#if !HAVE_OPEN && defined(WIN32)
# define open _open
#endif
#include "bits.h"
#include "debug.h"
#include "printbuf.h"

View File

@@ -1,5 +1,5 @@
/*
* $Id: json_util.h,v 1.3 2006/01/26 02:16:28 mclark Exp $
* $Id: json_util.h,v 1.4 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -12,20 +12,8 @@
#ifndef _json_util_h_
#define _json_util_h_
#include "config.h"
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <io.h>
#endif
#include "json_object.h"
#if !HAVE_OPEN && defined(WIN32)
# define open _open
#endif
#define JSON_FILE_BUF_SIZE 4096
/* utlitiy functions */

View File

@@ -1,5 +1,5 @@
/*
* $Id: linkhash.h,v 1.5 2006/01/26 02:16:28 mclark Exp $
* $Id: linkhash.h,v 1.6 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
@@ -12,8 +12,6 @@
#ifndef _linkhash_h_
#define _linkhash_h_
#include "config.h"
/**
* golden prime used in hash functions
*/