| 20 | } |
| 21 | |
| 22 | static bool test(const char* in, bool once, const char* name) |
| 23 | { |
| 24 | acl::json json; |
| 25 | const char* ptr = NULL, *p1 = in; |
| 26 | char buf[2]; |
| 27 | |
| 28 | if (once) |
| 29 | ptr = json.update(p1); |
| 30 | else |
| 31 | { |
| 32 | while (*p1) |
| 33 | { |
| 34 | buf[0] = *p1; |
| 35 | buf[1] = 0; |
| 36 | ptr = json.update(buf); |
| 37 | p1++; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | printf("------------------ input json ------------------------\r\n"); |
| 42 | printf("%s\r\n", in); |
| 43 | printf("-------------------------------------------------------\r\n"); |
| 44 | |
| 45 | printf("json finish: %s, left: |%s|, len: %d\r\n", |
| 46 | json.finish() ? "yes" : "no", ptr, (int) strlen(ptr)); |
| 47 | |
| 48 | printf("------------------ rebuild json -----------------------\r\n"); |
| 49 | printf("%s\r\n", json.to_string().c_str()); |
| 50 | printf("-------------------------------------------------------\r\n"); |
| 51 | |
| 52 | acl::string ibuf(in); |
| 53 | ibuf.trim_space().trim_right_line(); |
| 54 | |
| 55 | acl::string obuf = json.to_string(); |
| 56 | obuf.trim_space(); |
| 57 | |
| 58 | if (ibuf == obuf) |
| 59 | printf("\r\n-----OK----\r\n\r\n"); |
| 60 | else |
| 61 | printf("\r\n-----Error----\r\n\r\n"); |
| 62 | |
| 63 | if (name && *name) |
| 64 | test_type(json, name); |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | static void usage(const char* procname) |
| 70 | { |