MCPcopy Create free account
hub / github.com/clangen/musikcube / jsonToStringArray

Function jsonToStringArray

src/plugins/server/WebSocketServer.cpp:57–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57static std::shared_ptr<char*> jsonToStringArray(const json& jsonArray) {
58 char** result = nullptr;
59 size_t count = 0;
60
61 if (jsonArray.is_array()) {
62 count = jsonArray.size();
63 result = (char**) malloc(count * sizeof(char*));
64 for (size_t i = 0; i < count; i++) {
65 std::string str = jsonArray[i];
66 size_t size = str.size();
67 result[i] = (char*) malloc(size + 1);
68 strncpy(result[i], str.c_str(), size);
69 result[i][size] = 0;
70 }
71 }
72
73 return std::shared_ptr<char*>(result, [count](char** result) {
74 if (result) {
75 for (size_t i = 0; i < count; i++) {
76 free(result[i]);
77 }
78 free(result);
79 }
80 });
81}
82
83template <typename T>
84static std::shared_ptr<T> jsonToIntArray(json& arr) {

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected