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_Object: int
|
||||||
cJSON_Raw: int
|
cJSON_Raw: int
|
||||||
def print(self) -> str: ...
|
def print(self) -> str: ...
|
||||||
def parse(self, value: str): ...
|
|
||||||
def __del__(self): ...
|
def __del__(self): ...
|
||||||
def __init__(self): ...
|
def __init__(self): ...
|
||||||
def getObjectItem(self, string: str) -> cJSON: ...
|
def getObjectItem(self, string: str) -> cJSON: ...
|
||||||
@ -41,6 +40,10 @@ class cJSON(TinyObj):
|
|||||||
def addItemToObject(self, string: str, item: cJSON): ...
|
def addItemToObject(self, string: str, item: cJSON): ...
|
||||||
|
|
||||||
|
|
||||||
|
class Parse(cJSON):
|
||||||
|
def __init__(self, value: str): ...
|
||||||
|
|
||||||
|
|
||||||
class Null(cJSON):
|
class Null(cJSON):
|
||||||
def __init__(self): ...
|
def __init__(self): ...
|
||||||
|
|
||||||
|
@ -1,17 +1,6 @@
|
|||||||
#include "pika_cjson_cJSON.h"
|
#include "pika_cjson_cJSON.h"
|
||||||
#include "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) {
|
char* pika_cjson_cJSON_print(PikaObj* self) {
|
||||||
cJSON* item = obj_getPtr(self, "item");
|
cJSON* item = obj_getPtr(self, "item");
|
||||||
char* res = cJSON_Print(item);
|
char* res = cJSON_Print(item);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "pika_cjson_Number.h"
|
#include "pika_cjson_Number.h"
|
||||||
#include "pika_cjson_Object.h"
|
#include "pika_cjson_Object.h"
|
||||||
#include "pika_cjson_ObjectReference.h"
|
#include "pika_cjson_ObjectReference.h"
|
||||||
|
#include "pika_cjson_Parse.h"
|
||||||
#include "pika_cjson_Raw.h"
|
#include "pika_cjson_Raw.h"
|
||||||
#include "pika_cjson_String.h"
|
#include "pika_cjson_String.h"
|
||||||
#include "pika_cjson_StringReference.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);
|
cJSON* item = cJSON_CreateArrayReference(child_item);
|
||||||
obj_setPtr(self, "item", item);
|
obj_setPtr(self, "item", item);
|
||||||
obj_setInt(self, "needfree", 1);
|
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 */
|
/* run */
|
||||||
obj_setStr(pikaMain, "testjson", testjson);
|
obj_setStr(pikaMain, "testjson", testjson);
|
||||||
obj_run(pikaMain,
|
obj_run(pikaMain,
|
||||||
"a = pika_cjson.cJSON()\n"
|
"a = pika_cjson.Parse(testjson)\n"
|
||||||
"a.parse(testjson)\n"
|
|
||||||
"a.print()\n");
|
"a.print()\n");
|
||||||
/* collect */
|
/* collect */
|
||||||
/* assert */
|
/* assert */
|
||||||
@ -67,8 +66,7 @@ TEST(cJSON, getItem) {
|
|||||||
obj_setStr(pikaMain, "testjson", testjson);
|
obj_setStr(pikaMain, "testjson", testjson);
|
||||||
__platform_printf("BEGIN\r\n");
|
__platform_printf("BEGIN\r\n");
|
||||||
obj_run(pikaMain,
|
obj_run(pikaMain,
|
||||||
"a = pika_cjson.cJSON()\n"
|
"a = pika_cjson.Parse(testjson)\n"
|
||||||
"a.parse(testjson)\n"
|
|
||||||
"age = a.getObjectItem('age')\n"
|
"age = a.getObjectItem('age')\n"
|
||||||
"age.print()\n");
|
"age.print()\n");
|
||||||
/* collect */
|
/* collect */
|
||||||
@ -101,8 +99,7 @@ TEST(cJSON, next) {
|
|||||||
obj_setStr(pikaMain, "testjson", testjson);
|
obj_setStr(pikaMain, "testjson", testjson);
|
||||||
__platform_printf("BEGIN\r\n");
|
__platform_printf("BEGIN\r\n");
|
||||||
obj_run(pikaMain,
|
obj_run(pikaMain,
|
||||||
"a = pika_cjson.cJSON()\n"
|
"a = pika_cjson.Parse(testjson)\n"
|
||||||
"a.parse(testjson)\n"
|
|
||||||
"node = a.getChild()\n"
|
"node = a.getChild()\n"
|
||||||
"for i in range(0, 3):\n"
|
"for i in range(0, 3):\n"
|
||||||
" node.print()\n"
|
" node.print()\n"
|
||||||
@ -140,8 +137,7 @@ TEST(cJSON, next_get_value) {
|
|||||||
obj_setStr(pikaMain, "testjson", testjson);
|
obj_setStr(pikaMain, "testjson", testjson);
|
||||||
__platform_printf("BEGIN\r\n");
|
__platform_printf("BEGIN\r\n");
|
||||||
obj_run(pikaMain,
|
obj_run(pikaMain,
|
||||||
"a = pika_cjson.cJSON()\n"
|
"a = pika_cjson.Parse(testjson)\n"
|
||||||
"a.parse(testjson)\n"
|
|
||||||
"node = a.getChild()\n"
|
"node = a.getChild()\n"
|
||||||
"val = PikaStdData.List()\n"
|
"val = PikaStdData.List()\n"
|
||||||
"for i in range(0, 3):\n"
|
"for i in range(0, 3):\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user