亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? json_object.c

?? JSON(JavaScript Object Notation) 是一種輕量級的數據交換格式。易于人閱讀和編寫。同時也易于機器解析和生成。它基于JavaScript(Standard ECMA-262
?? C
字號:
/*
 * $Id: json_object.c,v 1.17 2006/07/25 03:24:50 mclark Exp $
 *
 * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
 * Michael Clark <michael@metaparadigm.com>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See COPYING for details.
 *
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "debug.h"
#include "printbuf.h"
#include "linkhash.h"
#include "arraylist.h"
#include "json_object.h"
#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";
char *json_hex_chars = "0123456789abcdef";

#ifdef REFCOUNT_DEBUG
static char* json_type_name[] = {
  "null",
  "boolean",
  "double",
  "int",
  "object",
  "array",
  "string",
};
#endif /* REFCOUNT_DEBUG */

static void json_object_generic_delete(struct json_object* this);
static struct json_object* json_object_new(enum json_type o_type);


/* ref count debugging */

#ifdef REFCOUNT_DEBUG

static struct lh_table *json_object_table;

static void json_object_init() __attribute__ ((constructor));
static void json_object_init() {
  mc_debug("json_object_init: creating object table\n");
  json_object_table = lh_kptr_table_new(128, "json_object_table", NULL);
}

static void json_object_fini() __attribute__ ((destructor));
static void json_object_fini() {
  struct lh_entry *ent;
  if(mc_get_debug() && json_object_table->count) {
    mc_debug("json_object_fini: %d referenced objects at exit\n",
	     json_object_table->count);
    lh_foreach(json_object_table, ent) {
      struct json_object* obj = (struct json_object*)ent->v;
      mc_debug("\t%s:%p\n", json_type_name[obj->o_type], obj);
    }
  }
  mc_debug("json_object_fini: freeing object table\n");
  lh_table_free(json_object_table);
}
#endif /* REFCOUNT_DEBUG */


/* string escaping */

static int json_escape_str(struct printbuf *pb, char *str)
{
  int pos = 0, start_offset = 0;
  unsigned char c;
  do {
    c = str[pos];
    switch(c) {
    case '\0':
      break;
    case '\b':
    case '\n':
    case '\r':
    case '\t':
    case '"':
    case '\\':
    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);
      else if(c == '\\') printbuf_memappend(pb, "\\\\", 2);
      else if(c == '/') printbuf_memappend(pb, "\\/", 2);
      start_offset = ++pos;
      break;
    default:
      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 pos++;
    }
  } while(c);
  if(pos - start_offset > 0)
    printbuf_memappend(pb, str + start_offset, pos - start_offset);
  return 0;
}


/* reference counting */

extern struct json_object* json_object_get(struct json_object *this)
{
  if(this) {
    this->_ref_count++;
  }
  return this;
}

extern void json_object_put(struct json_object *this)
{
  if(this) {
    this->_ref_count--;
    if(!this->_ref_count) this->_delete(this);
  }
}


/* generic object construction and destruction parts */

static void json_object_generic_delete(struct json_object* this)
{
#ifdef REFCOUNT_DEBUG
  mc_debug("json_object_delete_%s: %p\n",
	   json_type_name[this->o_type], this);
  lh_table_delete(json_object_table, this);
#endif /* REFCOUNT_DEBUG */
  printbuf_free(this->_pb);
  free(this);
}

static struct json_object* json_object_new(enum json_type o_type)
{
  struct json_object *this = calloc(sizeof(struct json_object), 1);
  if(!this) return NULL;
  this->o_type = o_type;
  this->_ref_count = 1;
  this->_delete = &json_object_generic_delete;
#ifdef REFCOUNT_DEBUG
  lh_table_insert(json_object_table, this, this);
  mc_debug("json_object_new_%s: %p\n", json_type_name[this->o_type], this);
#endif /* REFCOUNT_DEBUG */
  return this;
}


/* type checking functions */

int json_object_is_type(struct json_object *this, enum json_type type)
{
  return (this->o_type == type);
}

enum json_type json_object_get_type(struct json_object *this)
{
  return this->o_type;
}


/* json_object_to_json_string */

char* json_object_to_json_string(struct json_object *this)
{
  if(!this) return "null";
  if(!this->_pb) {
    if(!(this->_pb = printbuf_new())) return NULL;
  } else {
    printbuf_reset(this->_pb);
  }
  if(this->_to_json_string(this, this->_pb) < 0) return NULL;
  return this->_pb->buf;
}


/* json_object_object */

static int json_object_object_to_json_string(struct json_object* this,
					     struct printbuf *pb)
{
  int i=0;
  struct json_object_iter iter;
  sprintbuf(pb, "{");

  /* CAW: scope operator to make ANSI correctness */
  /* CAW: switched to json_object_object_foreachC which uses an iterator struct */
	json_object_object_foreachC(this, iter) {
			if(i) sprintbuf(pb, ",");
			sprintbuf(pb, " \"");
			json_escape_str(pb, iter.key);
			sprintbuf(pb, "\": ");
			if(iter.val == NULL) sprintbuf(pb, "null");
			else iter.val->_to_json_string(iter.val, pb);
			i++;
	}

  return sprintbuf(pb, " }");
}

static void json_object_lh_entry_free(struct lh_entry *ent)
{
  free(ent->k);
  json_object_put((struct json_object*)ent->v);
}

static void json_object_object_delete(struct json_object* this)
{
  lh_table_free(this->o.c_object);
  json_object_generic_delete(this);
}

struct json_object* json_object_new_object()
{
  struct json_object *this = json_object_new(json_type_object);
  if(!this) return NULL;
  this->_delete = &json_object_object_delete;
  this->_to_json_string = &json_object_object_to_json_string;
  this->o.c_object = lh_kchar_table_new(JSON_OBJECT_DEF_HASH_ENTIRES,
					NULL, &json_object_lh_entry_free);
  return this;
}

struct lh_table* json_object_get_object(struct json_object *this)
{
  if(!this) return NULL;
  switch(this->o_type) {
  case json_type_object:
    return this->o.c_object;
  default:
    return NULL;
  }
}

void json_object_object_add(struct json_object* this, char *key,
			    struct json_object *val)
{
  lh_table_delete(this->o.c_object, key);
  lh_table_insert(this->o.c_object, strdup(key), val);
}

struct json_object* json_object_object_get(struct json_object* this, char *key)
{
  return (struct json_object*) lh_table_lookup(this->o.c_object, key);
}

void json_object_object_del(struct json_object* this, char *key)
{
  lh_table_delete(this->o.c_object, key);
}


/* json_object_boolean */

static int json_object_boolean_to_json_string(struct json_object* this,
					      struct printbuf *pb)
{
  if(this->o.c_boolean) return sprintbuf(pb, "true");
  else return sprintbuf(pb, "false");
}

struct json_object* json_object_new_boolean(boolean b)
{
  struct json_object *this = json_object_new(json_type_boolean);
  if(!this) return NULL;
  this->_to_json_string = &json_object_boolean_to_json_string;
  this->o.c_boolean = b;
  return this;
}

boolean json_object_get_boolean(struct json_object *this)
{
  if(!this) return FALSE;
  switch(this->o_type) {
  case json_type_boolean:
    return this->o.c_boolean;
  case json_type_int:
    return (this->o.c_int != 0);
  case json_type_double:
    return (this->o.c_double != 0);
  case json_type_string:
    if(strlen(this->o.c_string)) return TRUE;
  default:
    return TRUE;
  }
}


/* json_object_int */

static int json_object_int_to_json_string(struct json_object* this,
					  struct printbuf *pb)
{
  return sprintbuf(pb, "%d", this->o.c_int);
}

struct json_object* json_object_new_int(int i)
{
  struct json_object *this = json_object_new(json_type_int);
  if(!this) return NULL;
  this->_to_json_string = &json_object_int_to_json_string;
  this->o.c_int = i;
  return this;
}

int json_object_get_int(struct json_object *this)
{
  int cint;

  if(!this) return 0;
  switch(this->o_type) {
  case json_type_int:
    return this->o.c_int;
  case json_type_double:
    return (int)this->o.c_double;
  case json_type_boolean:
    return this->o.c_boolean;
  case json_type_string:
    if(sscanf(this->o.c_string, "%d", &cint) == 1) return cint;
  default:
    return 0;
  }
}


/* json_object_double */

static int json_object_double_to_json_string(struct json_object* this,
					     struct printbuf *pb)
{
  return sprintbuf(pb, "%lf", this->o.c_double);
}

struct json_object* json_object_new_double(double d)
{
  struct json_object *this = json_object_new(json_type_double);
  if(!this) return NULL;
  this->_to_json_string = &json_object_double_to_json_string;
  this->o.c_double = d;
  return this;
}

double json_object_get_double(struct json_object *this)
{
  double cdouble;

  if(!this) return 0.0;
  switch(this->o_type) {
  case json_type_double:
    return this->o.c_double;
  case json_type_int:
    return this->o.c_int;
  case json_type_boolean:
    return this->o.c_boolean;
  case json_type_string:
    if(sscanf(this->o.c_string, "%lf", &cdouble) == 1) return cdouble;
  default:
    return 0.0;
  }
}


/* json_object_string */

static int json_object_string_to_json_string(struct json_object* this,
					     struct printbuf *pb)
{
  sprintbuf(pb, "\"");
  json_escape_str(pb, this->o.c_string);
  sprintbuf(pb, "\"");
  return 0;
}

static void json_object_string_delete(struct json_object* this)
{
  free(this->o.c_string);
  json_object_generic_delete(this);
}

struct json_object* json_object_new_string(char *s)
{
  struct json_object *this = json_object_new(json_type_string);
  if(!this) return NULL;
  this->_delete = &json_object_string_delete;
  this->_to_json_string = &json_object_string_to_json_string;
  this->o.c_string = strdup(s);
  return this;
}

struct json_object* json_object_new_string_len(char *s, int len)
{
  struct json_object *this = json_object_new(json_type_string);
  if(!this) return NULL;
  this->_delete = &json_object_string_delete;
  this->_to_json_string = &json_object_string_to_json_string;
  this->o.c_string = strndup(s, len);
  return this;
}

char* json_object_get_string(struct json_object *this)
{
  if(!this) return NULL;
  switch(this->o_type) {
  case json_type_string:
    return this->o.c_string;
  default:
    return json_object_to_json_string(this);
  }
}


/* json_object_array */

static int json_object_array_to_json_string(struct json_object* this,
					    struct printbuf *pb)
{
  int i;
  sprintbuf(pb, "[");
  for(i=0; i < json_object_array_length(this); i++) {
	  struct json_object *val;
	  if(i) { sprintbuf(pb, ", "); }
	  else { sprintbuf(pb, " "); }

      val = json_object_array_get_idx(this, i);
	  if(val == NULL) { sprintbuf(pb, "null"); }
	  else { val->_to_json_string(val, pb); }
  }
  return sprintbuf(pb, " ]");
}

static void json_object_array_entry_free(void *data)
{
  json_object_put((struct json_object*)data);
}

static void json_object_array_delete(struct json_object* this)
{
  array_list_free(this->o.c_array);
  json_object_generic_delete(this);
}

struct json_object* json_object_new_array()
{
  struct json_object *this = json_object_new(json_type_array);
  if(!this) return NULL;
  this->_delete = &json_object_array_delete;
  this->_to_json_string = &json_object_array_to_json_string;
  this->o.c_array = array_list_new(&json_object_array_entry_free);
  return this;
}

struct array_list* json_object_get_array(struct json_object *this)
{
  if(!this) return NULL;
  switch(this->o_type) {
  case json_type_array:
    return this->o.c_array;
  default:
    return NULL;
  }
}

int json_object_array_length(struct json_object *this)
{
  return array_list_length(this->o.c_array);
}

int json_object_array_add(struct json_object *this,struct json_object *val)
{
  return array_list_add(this->o.c_array, val);
}

int json_object_array_put_idx(struct json_object *this, int idx,
			      struct json_object *val)
{
  return array_list_put_idx(this->o.c_array, idx, val);
}

struct json_object* json_object_array_get_idx(struct json_object *this,
					      int idx)
{
  return (struct json_object*)array_list_get_idx(this->o.c_array, idx);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区免费看| 国产欧美日韩不卡| 国产精品夜夜爽| 一区二区三区不卡视频| 日韩欧美的一区二区| av网站免费线看精品| 日韩精品免费专区| 国产精品二区一区二区aⅴ污介绍| 欧美日本视频在线| 成人免费视频网站在线观看| 视频一区二区三区中文字幕| 中文字幕制服丝袜一区二区三区 | 性欧美大战久久久久久久久| 国产欧美日韩视频在线观看| 91精品国产综合久久小美女| 色综合久久天天| 国产一区二区精品久久| 性做久久久久久久免费看| 中文字幕日本乱码精品影院| 久久综合狠狠综合久久综合88| 欧美午夜在线一二页| 成人高清视频在线| 国产精品一区在线观看你懂的| 日韩二区在线观看| 亚洲成在线观看| 亚洲精品午夜久久久| 国产精品女主播av| 国产视频在线观看一区二区三区| 日韩午夜激情av| 欧美另类变人与禽xxxxx| 91高清视频在线| 色综合久久综合| 一本色道久久综合精品竹菊 | 欧美综合欧美视频| 一本大道久久a久久综合| 成av人片一区二区| 成人免费av在线| 99综合电影在线视频| 成人午夜在线免费| 成人午夜伦理影院| 不卡一区二区三区四区| 国产99久久久国产精品免费看| 国精产品一区一区三区mba视频 | 欧美tickling挠脚心丨vk| 欧美电影在线免费观看| 欧美巨大另类极品videosbest| 欧美日韩亚洲综合| 欧美高清www午色夜在线视频| 欧美日韩大陆在线| 欧美一区二区三区性视频| 欧美精品第1页| 欧美一区二区三区视频在线观看| 国产麻豆视频一区| 国产91精品欧美| 97精品国产露脸对白| 欧美亚男人的天堂| 91精品国产一区二区三区蜜臀 | 一本久道久久综合中文字幕| 在线免费观看成人短视频| 欧美日韩国产bt| 日韩三级视频中文字幕| 精品美女在线播放| 日本一区二区在线不卡| 亚洲日本成人在线观看| 亚洲国产日韩a在线播放| 日日骚欧美日韩| 国产在线精品一区在线观看麻豆| 岛国av在线一区| 在线视频国内一区二区| 日韩亚洲欧美在线观看| 国产亚洲精品aa| 亚洲女与黑人做爰| 日本美女一区二区| 国产高清久久久| 日本高清不卡视频| 欧美一级艳片视频免费观看| 国产精品视频第一区| 亚洲图片欧美视频| 国产一区二区三区精品视频| 91同城在线观看| 欧美一区二区三区啪啪| 国产目拍亚洲精品99久久精品| 亚洲自拍偷拍图区| 激情国产一区二区| 91成人国产精品| 精品捆绑美女sm三区| 一区精品在线播放| 男女激情视频一区| 成人午夜激情影院| 欧美日韩一区二区在线观看| 久久久久久久久久久久久女国产乱 | 成人激情校园春色| 欧美日韩精品免费| 国产精品美女久久久久aⅴ| 亚洲bt欧美bt精品| 粉嫩欧美一区二区三区高清影视 | 91女人视频在线观看| 日韩区在线观看| 一区二区三区四区精品在线视频| 久久av资源站| 欧美日韩中文国产| 亚洲欧美日韩久久| 国产成人8x视频一区二区| 8x8x8国产精品| 亚洲综合色噜噜狠狠| 国产成人精品免费看| 欧美一卡二卡三卡| 亚洲成人综合视频| 色噜噜狠狠色综合欧洲selulu| 久久久久久久久99精品| 日产国产欧美视频一区精品| 色婷婷综合久久久久中文一区二区| 久久久久亚洲蜜桃| 久久精品久久综合| 欧美三级日韩在线| 亚洲人123区| 亚洲综合色区另类av| 97精品久久久午夜一区二区三区| 日韩欧美国产午夜精品| 亚洲黄色在线视频| 国产一区二区三区日韩| 欧美性色黄大片| 国产精品视频九色porn| 午夜精品免费在线| 欧美视频在线一区二区三区 | 亚洲美女一区二区三区| 卡一卡二国产精品 | 国产精品美女一区二区在线观看| 午夜精品久久一牛影视| 91美女福利视频| 欧美成人video| 麻豆精品视频在线观看| 欧美性猛交xxxx乱大交退制版| 国产精品久久久爽爽爽麻豆色哟哟| 久久99精品久久久久久动态图| 欧美视频自拍偷拍| 亚洲成a人v欧美综合天堂下载| 色婷婷av一区二区三区大白胸 | 国产成人精品一区二区三区网站观看| 91福利小视频| 丝袜亚洲另类欧美综合| 欧洲一区二区三区免费视频| 国产精品视频观看| 成人综合在线观看| 国产人妖乱国产精品人妖| 在线看一区二区| 中文字幕一区av| 国产成人综合自拍| 久久精品欧美日韩精品| 久久超碰97中文字幕| 国产亚洲欧美一级| 国产综合久久久久久鬼色 | 韩国av一区二区三区在线观看| 欧美一区二区视频在线观看| 亚洲高清一区二区三区| 欧美日韩国产一区| 午夜私人影院久久久久| 欧美专区日韩专区| 亚洲国产wwwccc36天堂| 欧美羞羞免费网站| 捆绑调教一区二区三区| 日韩一区二区高清| 久久99热狠狠色一区二区| 欧美大片拔萝卜| 精品一区二区在线播放| 国产精品久久二区二区| 99精品国产99久久久久久白柏| 亚洲免费在线视频一区 二区| 97精品国产露脸对白| 国产精品卡一卡二| 色嗨嗨av一区二区三区| 亚洲一区二区视频在线观看| 99re这里只有精品视频首页| 亚洲色图制服诱惑| 色8久久精品久久久久久蜜| 一区二区三区久久久| 在线播放亚洲一区| 国产盗摄一区二区| 国产精品国产三级国产aⅴ原创| 99视频有精品| 亚洲福利视频三区| 日韩你懂的在线观看| 成人永久看片免费视频天堂| 久久久三级国产网站| 欧美性三三影院| 久久99精品视频| 国产精品你懂的在线| 欧美性猛交xxxx乱大交退制版| 国产精品一区在线观看你懂的| 亚洲视频在线一区二区| 欧美裸体bbwbbwbbw| 国产一区二区按摩在线观看| 亚洲精品成人在线| 日韩一区二区视频| 成人99免费视频| 奇米四色…亚洲| 日韩一区二区三区观看| 99久久久无码国产精品| 久久99精品国产麻豆不卡| 亚洲欧洲国产专区|