From d15f072e49b0d6d6b6a4ed7d0fbfbcd8c8110f4c Mon Sep 17 00:00:00 2001 From: erickson Date: Sun, 19 Jun 2005 16:30:02 +0000 Subject: [PATCH] using different header location git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@357 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libjson/arraylist.c | 4 +-- src/libjson/debug.c | 2 +- src/libjson/json_object.c | 58 +++++++++++++++++++-------------- src/libjson/json_tokener.c | 81 ++++++++++++++++++++++++---------------------- src/libjson/json_util.c | 20 ++++++------ src/libjson/linkhash.c | 2 +- src/libjson/oilsMessage.c | 2 +- src/libjson/oils_method.c | 2 +- src/libjson/printbuf.c | 6 ++-- src/libjson/test1.c | 2 +- src/libjson/test2.c | 2 +- 11 files changed, 96 insertions(+), 85 deletions(-) diff --git a/src/libjson/arraylist.c b/src/libjson/arraylist.c index e1593d5..6b42046 100644 --- a/src/libjson/arraylist.c +++ b/src/libjson/arraylist.c @@ -20,8 +20,8 @@ #include #include -#include "libjson/bits.h" -#include "libjson/arraylist.h" +#include "bits.h" +#include "arraylist.h" struct array_list* diff --git a/src/libjson/debug.c b/src/libjson/debug.c index 4bbc893..6212857 100644 --- a/src/libjson/debug.c +++ b/src/libjson/debug.c @@ -24,7 +24,7 @@ #include #include -#include "libjson/debug.h" +#include "debug.h" static int _syslog = 0; diff --git a/src/libjson/json_object.c b/src/libjson/json_object.c index 5c205db..0694fa4 100644 --- a/src/libjson/json_object.c +++ b/src/libjson/json_object.c @@ -20,13 +20,13 @@ #include #include -#include "libjson/debug.h" -#include "libjson/printbuf.h" -#include "libjson/linkhash.h" -#include "libjson/arraylist.h" -#include "libjson/json_object.h" -#include "libjson/ossupport.h" -#include "libjson/json_object_private.h" +#include "debug.h" +#include "printbuf.h" +#include "linkhash.h" +#include "arraylist.h" +#include "json_object.h" +#include "ossupport.h" +#include "json_object_private.h" /* #define REFCOUNT_DEBUG */ @@ -88,33 +88,41 @@ static int json_escape_str(struct printbuf *pb, char *str) do { c = str[pos]; switch(c) { - case '\b': - case '\n': - case '\r': - case '\t': - case '"': - if(pos - start_offset > 0) - printbuf_memappend(pb, str + start_offset, pos - start_offset); - if(c == '\b') printbuf_memappend(pb, "\\b", 2); - else if(c == '\n') printbuf_memappend(pb, "\\n", 2); - else if(c == '\r') printbuf_memappend(pb, "\\r", 2); - else if(c == '\t') printbuf_memappend(pb, "\\t", 2); - else if(c == '"') printbuf_memappend(pb, "\\\"", 2); + case '\b': + case '\n': + case '\r': + case '\t': + case '"': + + if(pos - start_offset > 0) + printbuf_memappend(pb, str + start_offset, pos - start_offset); + + if(c == '\b') printbuf_memappend(pb, "\\b", 2); + else if(c == '\n') printbuf_memappend(pb, "\\n", 2); + else if(c == '\r') printbuf_memappend(pb, "\\r", 2); + else if(c == '\t') printbuf_memappend(pb, "\\t", 2); + else if(c == '"') printbuf_memappend(pb, "\\\"", 2); + start_offset = ++pos; break; + default: if(c && 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; + 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++; } } while(c); + if(pos - start_offset > 0) printbuf_memappend(pb, str + start_offset, pos - start_offset); + return 0; } diff --git a/src/libjson/json_tokener.c b/src/libjson/json_tokener.c index 70a0147..277c88f 100644 --- a/src/libjson/json_tokener.c +++ b/src/libjson/json_tokener.c @@ -21,15 +21,15 @@ #include #include -#include "libjson/json_tokener.h" -#include "libjson/bits.h" -#include "libjson/debug.h" -#include "libjson/printbuf.h" -#include "libjson/linkhash.h" -#include "libjson/arraylist.h" -#include "libjson/json_object.h" -#include "libjson/ossupport.h" -#include "libjson/json_object_private.h" +#include "json_tokener.h" +#include "bits.h" +#include "debug.h" +#include "printbuf.h" +#include "linkhash.h" +#include "arraylist.h" +#include "json_object.h" +#include "ossupport.h" +#include "json_object_private.h" @@ -231,37 +231,40 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this) } break; - case json_tokener_state_escape_unicode: - if(strchr(json_hex_chars, c)) { - this->pos++; - if(this->pos - start_offset == 4) { - unsigned char utf_out[3]; - unsigned int ucs_char = - (hexdigit(*(this->source + start_offset)) << 12) + - (hexdigit(*(this->source + start_offset + 1)) << 8) + - (hexdigit(*(this->source + start_offset + 2)) << 4) + - hexdigit(*(this->source + start_offset + 3)); - if (ucs_char < 0x80) { - utf_out[0] = ucs_char; - printbuf_memappend(this->pb, utf_out, 1); - } else if (ucs_char < 0x800) { - utf_out[0] = 0xc0 | (ucs_char >> 6); - utf_out[1] = 0x80 | (ucs_char & 0x3f); - printbuf_memappend(this->pb, utf_out, 2); - } else { - utf_out[0] = 0xe0 | (ucs_char >> 12); - utf_out[1] = 0x80 | ((ucs_char >> 6) & 0x3f); - utf_out[2] = 0x80 | (ucs_char & 0x3f); - printbuf_memappend(this->pb, utf_out, 3); - } - start_offset = this->pos; - state = saved_state; + case json_tokener_state_escape_unicode: + + if(strchr(json_hex_chars, c)) { + this->pos++; + + if(this->pos - start_offset == 4) { + unsigned char utf_out[3]; + unsigned int ucs_char = + (hexdigit(*(this->source + start_offset)) << 12) + + (hexdigit(*(this->source + start_offset + 1)) << 8) + + (hexdigit(*(this->source + start_offset + 2)) << 4) + + hexdigit(*(this->source + start_offset + 3)); + + if (ucs_char < 0x80) { + utf_out[0] = ucs_char; + printbuf_memappend(this->pb, utf_out, 1); + } else if (ucs_char < 0x800) { + utf_out[0] = 0xc0 | (ucs_char >> 6); + utf_out[1] = 0x80 | (ucs_char & 0x3f); + printbuf_memappend(this->pb, utf_out, 2); + } else { + utf_out[0] = 0xe0 | (ucs_char >> 12); + utf_out[1] = 0x80 | ((ucs_char >> 6) & 0x3f); + utf_out[2] = 0x80 | (ucs_char & 0x3f); + printbuf_memappend(this->pb, utf_out, 3); + } + start_offset = this->pos; + state = saved_state; + } + } else { + err = json_tokener_error_parse_string; + goto out; } - } else { - err = json_tokener_error_parse_string; - goto out; - } - break; + break; case json_tokener_state_boolean: if(strncasecmp("true", this->source + start_offset, diff --git a/src/libjson/json_util.c b/src/libjson/json_util.c index 7cd4eb3..f014b7a 100644 --- a/src/libjson/json_util.c +++ b/src/libjson/json_util.c @@ -7,16 +7,16 @@ #include #include -#include "libjson/json_util.h" -#include "libjson/json_tokener.h" -#include "libjson/bits.h" -#include "libjson/debug.h" -#include "libjson/printbuf.h" -#include "libjson/linkhash.h" -#include "libjson/arraylist.h" -#include "libjson/json_object.h" -#include "libjson/ossupport.h" -#include "libjson/json_object_private.h" +#include "json_util.h" +#include "json_tokener.h" +#include "bits.h" +#include "debug.h" +#include "printbuf.h" +#include "linkhash.h" +#include "arraylist.h" +#include "json_object.h" +#include "ossupport.h" +#include "json_object_private.h" diff --git a/src/libjson/linkhash.c b/src/libjson/linkhash.c index 3066ec5..64f15a0 100644 --- a/src/libjson/linkhash.c +++ b/src/libjson/linkhash.c @@ -21,7 +21,7 @@ #include #include -#include "libjson/linkhash.h" +#include "linkhash.h" void lh_abort(const char *msg, ...) diff --git a/src/libjson/oilsMessage.c b/src/libjson/oilsMessage.c index 4af7ee3..cddb05b 100644 --- a/src/libjson/oilsMessage.c +++ b/src/libjson/oilsMessage.c @@ -1,6 +1,6 @@ #include #include -#include "libjson/json.h" +#include "json.h" struct oils_method_struct { diff --git a/src/libjson/oils_method.c b/src/libjson/oils_method.c index ffd2b8b..6a95dc4 100644 --- a/src/libjson/oils_method.c +++ b/src/libjson/oils_method.c @@ -2,7 +2,7 @@ #include #include -#include "libjson/json.h" +#include "json.h" int main(int argc, char **argv) diff --git a/src/libjson/printbuf.c b/src/libjson/printbuf.c index 1dfbccd..68c425c 100644 --- a/src/libjson/printbuf.c +++ b/src/libjson/printbuf.c @@ -21,9 +21,9 @@ #include #include -#include "libjson/bits.h" -#include "libjson/debug.h" -#include "libjson/printbuf.h" +#include "bits.h" +#include "debug.h" +#include "printbuf.h" struct printbuf* printbuf_new() diff --git a/src/libjson/test1.c b/src/libjson/test1.c index f4fecf9..b65a7cd 100644 --- a/src/libjson/test1.c +++ b/src/libjson/test1.c @@ -2,7 +2,7 @@ #include #include -#include "libjson/json.h" +#include "json.h" int main(int argc, char **argv) diff --git a/src/libjson/test2.c b/src/libjson/test2.c index 93ca0fb..b7bdf62 100644 --- a/src/libjson/test2.c +++ b/src/libjson/test2.c @@ -2,7 +2,7 @@ #include #include -#include "libjson/json.h" +#include "json.h" int main(int argc, char **argv) -- 2.11.0