浏览代码

Removed constness from find_json_token()

Sergey Lyubka 11 年之前
父节点
当前提交
7adbd48b71
共有 2 个文件被更改,包括 4 次插入8 次删除
  1. 3 4
      frozen.c
  2. 1 4
      frozen.h

+ 3 - 4
frozen.c

@@ -321,8 +321,7 @@ static int path_part_len(const char *p) {
   return i;
   return i;
 }
 }
 
 
-const struct json_token *find_json_token(const struct json_token *toks,
-                                         const char *path) {
+struct json_token *find_json_token(struct json_token *toks, const char *path) {
   while (path != 0 && path[0] != '\0') {
   while (path != 0 && path[0] != '\0') {
     int i, ind2 = 0, ind = -1, skip = 2, n = path_part_len(path);
     int i, ind2 = 0, ind = -1, skip = 2, n = path_part_len(path);
     if (path[0] == '[') {
     if (path[0] == '[') {
@@ -400,7 +399,7 @@ int json_emit_unquoted_str(char *buf, int buf_len, const char *str, int len) {
 }
 }
 
 
 int json_emit_va(char *s, int s_len, const char *fmt, va_list ap) {
 int json_emit_va(char *s, int s_len, const char *fmt, va_list ap) {
-  const char *end = s + s_len, *str;
+  const char *end = s + s_len, *str, *orig = s;
   size_t len;
   size_t len;
 
 
   while (*fmt != '\0') {
   while (*fmt != '\0') {
@@ -451,7 +450,7 @@ int json_emit_va(char *s, int s_len, const char *fmt, va_list ap) {
 
 
   if (s < end) *s = '\0';
   if (s < end) *s = '\0';
 
 
-  return end - s;
+  return s - orig;
 }
 }
 
 
 int json_emit(char *buf, int buf_len, const char *fmt, ...) {
 int json_emit(char *buf, int buf_len, const char *fmt, ...) {

+ 1 - 4
frozen.h

@@ -49,11 +49,8 @@ struct json_token {
 
 
 int parse_json(const char *json_string, int json_string_length,
 int parse_json(const char *json_string, int json_string_length,
                struct json_token *tokens_array, int size_of_tokens_array);
                struct json_token *tokens_array, int size_of_tokens_array);
-
 struct json_token *parse_json2(const char *json_string, int string_length);
 struct json_token *parse_json2(const char *json_string, int string_length);
-
-const struct json_token *find_json_token(const struct json_token *toks,
-                                         const char *path);
+struct json_token *find_json_token(struct json_token *toks, const char *path);
 
 
 int json_emit_long(char *buf, int buf_len, long value);
 int json_emit_long(char *buf, int buf_len, long value);
 int json_emit_double(char *buf, int buf_len, double value);
 int json_emit_double(char *buf, int buf_len, double value);