Browse Source

update: demo for to json library

dev
Dnomd343 2 years ago
parent
commit
6b4b9390a0
  1. 18
      src/demo.c
  2. 4
      src/to-json/to_json.h

18
src/demo.c

@ -1,18 +1,24 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "to_json.h" #include "to_json.h"
int main() { int main() {
printf("start demo\n"); printf("start demo\n");
char raw_string[] = "hello"; char yaml_string[] = "test: ok\narray:\n - 123\n - 234\n - 345\n";
printf("----------------\n");
printf("%s", yaml_string);
printf("----------------\n");
const char *json_content = to_json_rust(raw_string); const char *raw_json_string = to_json_rust(yaml_string);
char *json_string = strdup(raw_json_string);
printf("return content -> `%s`\n", json_content); printf("----------------\n");
printf("%s\n", json_string);
printf("----------------\n");
free_rust_string(json_content); free_rust_string(raw_json_string);
printf("rust string free complete\n");
printf("rust string free success\n");
return 0; return 0;
} }

4
src/to-json/to_json.h

@ -3,6 +3,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
const char *to_json_rust(const char *content);
void free_rust_string(const char *string); void free_rust_string(const char *string);
const char *to_json_rust(const char *content);

Loading…
Cancel
Save