MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / LoadIniSettingsFromMemory

Method LoadIniSettingsFromMemory

plugins/Cardinal/src/DearImGui/imgui.cpp:11115–11183  ·  view source on GitHub ↗

Zero-tolerance, no error reporting, cheap .ini parsing

Source from the content-addressed store, hash-verified

11113
11114// Zero-tolerance, no error reporting, cheap .ini parsing
11115void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
11116{
11117 ImGuiContext& g = *GImGui;
11118 IM_ASSERT(g.Initialized);
11119 //IM_ASSERT(!g.WithinFrameScope && "Cannot be called between NewFrame() and EndFrame()");
11120 //IM_ASSERT(g.SettingsLoaded == false && g.FrameCount == 0);
11121
11122 // For user convenience, we allow passing a non zero-terminated string (hence the ini_size parameter).
11123 // For our convenience and to make the code simpler, we'll also write zero-terminators within the buffer. So let's create a writable copy..
11124 if (ini_size == 0)
11125 ini_size = strlen(ini_data);
11126 g.SettingsIniData.Buf.resize((int)ini_size + 1);
11127 char* const buf = g.SettingsIniData.Buf.Data;
11128 char* const buf_end = buf + ini_size;
11129 memcpy(buf, ini_data, ini_size);
11130 buf_end[0] = 0;
11131
11132 // Call pre-read handlers
11133 // Some types will clear their data (e.g. dock information) some types will allow merge/override (window)
11134 for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
11135 if (g.SettingsHandlers[handler_n].ReadInitFn)
11136 g.SettingsHandlers[handler_n].ReadInitFn(&g, &g.SettingsHandlers[handler_n]);
11137
11138 void* entry_data = NULL;
11139 ImGuiSettingsHandler* entry_handler = NULL;
11140
11141 char* line_end = NULL;
11142 for (char* line = buf; line < buf_end; line = line_end + 1)
11143 {
11144 // Skip new lines markers, then find end of the line
11145 while (*line == '\n' || *line == '\r')
11146 line++;
11147 line_end = line;
11148 while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
11149 line_end++;
11150 line_end[0] = 0;
11151 if (line[0] == ';')
11152 continue;
11153 if (line[0] == '[' && line_end > line && line_end[-1] == ']')
11154 {
11155 // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code.
11156 line_end[-1] = 0;
11157 const char* name_end = line_end - 1;
11158 const char* type_start = line + 1;
11159 char* type_end = (char*)(void*)ImStrchrRange(type_start, name_end, ']');
11160 const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL;
11161 if (!type_end || !name_start)
11162 continue;
11163 *type_end = 0; // Overwrite first ']'
11164 name_start++; // Skip second '['
11165 entry_handler = FindSettingsHandler(type_start);
11166 entry_data = entry_handler ? entry_handler->ReadOpenFn(&g, entry_handler, name_start) : NULL;
11167 }
11168 else if (entry_handler != NULL && entry_data != NULL)
11169 {
11170 // Let type handler parse the line
11171 entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
11172 }

Callers

nothing calls this directly

Calls 2

ImStrchrRangeFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected