MCPcopy Create free account
hub / github.com/Nelarius/imnodes / LoadEditorStateFromIniString

Function LoadEditorStateFromIniString

imnodes.cpp:3079–3136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3077}
3078
3079void LoadEditorStateFromIniString(
3080 ImNodesEditorContext* const editor_ptr,
3081 const char* const data,
3082 const size_t data_size)
3083{
3084 if (data_size == 0u)
3085 {
3086 return;
3087 }
3088
3089 ImNodesEditorContext& editor = editor_ptr == NULL ? EditorContextGet() : *editor_ptr;
3090
3091 char* buf = (char*)ImGui::MemAlloc(data_size + 1);
3092 const char* buf_end = buf + data_size;
3093 memcpy(buf, data, data_size);
3094 buf[data_size] = 0;
3095
3096 void (*line_handler)(ImNodesEditorContext&, const char*);
3097 line_handler = NULL;
3098 char* line_end = NULL;
3099 for (char* line = buf; line < buf_end; line = line_end + 1)
3100 {
3101 while (*line == '\n' || *line == '\r')
3102 {
3103 line++;
3104 }
3105 line_end = line;
3106 while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
3107 {
3108 line_end++;
3109 }
3110 line_end[0] = 0;
3111
3112 if (*line == ';' || *line == '\0')
3113 {
3114 continue;
3115 }
3116
3117 if (line[0] == '[' && line_end[-1] == ']')
3118 {
3119 line_end[-1] = 0;
3120 if (strncmp(line + 1, "node", 4) == 0)
3121 {
3122 line_handler = NodeLineHandler;
3123 }
3124 else if (strcmp(line + 1, "editor") == 0)
3125 {
3126 line_handler = EditorLineHandler;
3127 }
3128 }
3129
3130 if (line_handler != NULL)
3131 {
3132 line_handler(editor, line);
3133 }
3134 }
3135 ImGui::MemFree(buf);
3136}

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected