add player EOF detection
[uwplayer.git] / application / json.c
index 4dd672c..9bdea02 100644 (file)
@@ -614,9 +614,10 @@ int json_reader_isnull(JSONParser *p) {
 
 JSONLiteralType json_reader_literal(JSONParser *p) {
     const char *l = p->reader_token.content;
-    if(!strcmp(l, "true")) {
+    size_t token_len = p->reader_token.length;
+    if(token_len == 4 && !memcmp(l, "true", 4)) {
         return JSON_TRUE;
-    } else if(!strcmp(l, "false")) {
+    } else if(token_len == 5 && !memcmp(l, "false", 5)) {
         return JSON_FALSE;
     }
     return JSON_NULL;
@@ -885,3 +886,20 @@ void json_value_free(JSONValue *value) {
     }
     free(value);
 }
+
+int json_strcmp(JSONValue *jsstr, const char *str) {
+    return json_strncmp(jsstr, str, strlen(str));
+}
+
+int json_strncmp(JSONValue *jsstr, const char *str, size_t slen) {
+    if(jsstr->type != JSON_STRING) {
+        return -1;
+    }
+    size_t jsstrlen = jsstr->value.string.length;
+    
+    if(jsstrlen != slen) {
+        return jsstrlen > slen ? 1 : -1;
+    }
+    
+    return memcmp(jsstr->value.string.string, str, slen);
+}