mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
move Parse as the constructor
This commit is contained in:
parent
f888b32e92
commit
349422afe3
@ -12,7 +12,6 @@ class cJSON(TinyObj):
|
||||
cJSON_Object: int
|
||||
cJSON_Raw: int
|
||||
def print(self) -> str: ...
|
||||
def parse(self, value: str): ...
|
||||
def __del__(self): ...
|
||||
def __init__(self): ...
|
||||
def getObjectItem(self, string: str) -> cJSON: ...
|
||||
@ -41,6 +40,10 @@ class cJSON(TinyObj):
|
||||
def addItemToObject(self, string: str, item: cJSON): ...
|
||||
|
||||
|
||||
class Parse(cJSON):
|
||||
def __init__(self, value: str): ...
|
||||
|
||||
|
||||
class Null(cJSON):
|
||||
def __init__(self): ...
|
||||
|
||||
|
@ -1,17 +1,6 @@
|
||||
#include "pika_cjson_cJSON.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
void pika_cjson_cJSON_parse(PikaObj* self, char* value) {
|
||||
cJSON* item = cJSON_Parse(value);
|
||||
if (NULL == item) {
|
||||
obj_setErrorCode(self, 3);
|
||||
__platform_printf("Error: cJSON parse faild.\r\n");
|
||||
return;
|
||||
}
|
||||
obj_setPtr(self, "item", item);
|
||||
obj_setInt(self, "needfree", 1);
|
||||
}
|
||||
|
||||
char* pika_cjson_cJSON_print(PikaObj* self) {
|
||||
cJSON* item = obj_getPtr(self, "item");
|
||||
char* res = cJSON_Print(item);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "pika_cjson_Number.h"
|
||||
#include "pika_cjson_Object.h"
|
||||
#include "pika_cjson_ObjectReference.h"
|
||||
#include "pika_cjson_Parse.h"
|
||||
#include "pika_cjson_Raw.h"
|
||||
#include "pika_cjson_String.h"
|
||||
#include "pika_cjson_StringReference.h"
|
||||
@ -97,4 +98,15 @@ void pika_cjson_ArrayReference___init__(PikaObj* self, PikaObj* child) {
|
||||
cJSON* item = cJSON_CreateArrayReference(child_item);
|
||||
obj_setPtr(self, "item", item);
|
||||
obj_setInt(self, "needfree", 1);
|
||||
}
|
||||
}
|
||||
|
||||
void pika_cjson_Parse___init__(PikaObj* self, char* value) {
|
||||
cJSON* item = cJSON_Parse(value);
|
||||
if (NULL == item) {
|
||||
obj_setErrorCode(self, 3);
|
||||
__platform_printf("Error: cJSON parse faild.\r\n");
|
||||
return;
|
||||
}
|
||||
obj_setPtr(self, "item", item);
|
||||
obj_setInt(self, "needfree", 1);
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ TEST(cJSON, parse_print) {
|
||||
/* run */
|
||||
obj_setStr(pikaMain, "testjson", testjson);
|
||||
obj_run(pikaMain,
|
||||
"a = pika_cjson.cJSON()\n"
|
||||
"a.parse(testjson)\n"
|
||||
"a = pika_cjson.Parse(testjson)\n"
|
||||
"a.print()\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
@ -67,8 +66,7 @@ TEST(cJSON, getItem) {
|
||||
obj_setStr(pikaMain, "testjson", testjson);
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"a = pika_cjson.cJSON()\n"
|
||||
"a.parse(testjson)\n"
|
||||
"a = pika_cjson.Parse(testjson)\n"
|
||||
"age = a.getObjectItem('age')\n"
|
||||
"age.print()\n");
|
||||
/* collect */
|
||||
@ -101,8 +99,7 @@ TEST(cJSON, next) {
|
||||
obj_setStr(pikaMain, "testjson", testjson);
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"a = pika_cjson.cJSON()\n"
|
||||
"a.parse(testjson)\n"
|
||||
"a = pika_cjson.Parse(testjson)\n"
|
||||
"node = a.getChild()\n"
|
||||
"for i in range(0, 3):\n"
|
||||
" node.print()\n"
|
||||
@ -140,8 +137,7 @@ TEST(cJSON, next_get_value) {
|
||||
obj_setStr(pikaMain, "testjson", testjson);
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"a = pika_cjson.cJSON()\n"
|
||||
"a.parse(testjson)\n"
|
||||
"a = pika_cjson.Parse(testjson)\n"
|
||||
"node = a.getChild()\n"
|
||||
"val = PikaStdData.List()\n"
|
||||
"for i in range(0, 3):\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user