MCPcopy Create free account
hub / github.com/RenderKit/embree / LoadIniSettingsFromMemory

Method LoadIniSettingsFromMemory

tutorials/common/imgui/imgui.cpp:12433–12501  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

12431
12432// Zero-tolerance, no error reporting, cheap .ini parsing
12433void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
12434{
12435 ImGuiContext& g = *GImGui;
12436 IM_ASSERT(g.Initialized);
12437 //IM_ASSERT(!g.WithinFrameScope && "Cannot be called between NewFrame() and EndFrame()");
12438 //IM_ASSERT(g.SettingsLoaded == false && g.FrameCount == 0);
12439
12440 // For user convenience, we allow passing a non zero-terminated string (hence the ini_size parameter).
12441 // 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..
12442 if (ini_size == 0)
12443 ini_size = strlen(ini_data);
12444 g.SettingsIniData.Buf.resize((int)ini_size + 1);
12445 char* const buf = g.SettingsIniData.Buf.Data;
12446 char* const buf_end = buf + ini_size;
12447 memcpy(buf, ini_data, ini_size);
12448 buf_end[0] = 0;
12449
12450 // Call pre-read handlers
12451 // Some types will clear their data (e.g. dock information) some types will allow merge/override (window)
12452 for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
12453 if (g.SettingsHandlers[handler_n].ReadInitFn)
12454 g.SettingsHandlers[handler_n].ReadInitFn(&g, &g.SettingsHandlers[handler_n]);
12455
12456 void* entry_data = NULL;
12457 ImGuiSettingsHandler* entry_handler = NULL;
12458
12459 char* line_end = NULL;
12460 for (char* line = buf; line < buf_end; line = line_end + 1)
12461 {
12462 // Skip new lines markers, then find end of the line
12463 while (*line == '\n' || *line == '\r')
12464 line++;
12465 line_end = line;
12466 while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
12467 line_end++;
12468 line_end[0] = 0;
12469 if (line[0] == ';')
12470 continue;
12471 if (line[0] == '[' && line_end > line && line_end[-1] == ']')
12472 {
12473 // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code.
12474 line_end[-1] = 0;
12475 const char* name_end = line_end - 1;
12476 const char* type_start = line + 1;
12477 char* type_end = (char*)(void*)ImStrchrRange(type_start, name_end, ']');
12478 const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL;
12479 if (!type_end || !name_start)
12480 continue;
12481 *type_end = 0; // Overwrite first ']'
12482 name_start++; // Skip second '['
12483 entry_handler = FindSettingsHandler(type_start);
12484 entry_data = entry_handler ? entry_handler->ReadOpenFn(&g, entry_handler, name_start) : NULL;
12485 }
12486 else if (entry_handler != NULL && entry_data != NULL)
12487 {
12488 // Let type handler parse the line
12489 entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
12490 }

Callers

nothing calls this directly

Calls 2

ImStrchrRangeFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected