MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / LoadIniSettingsFromMemory

Method LoadIniSettingsFromMemory

KBotExt/imgui/imgui.cpp:12971–13039  ·  view source on GitHub ↗

Zero-tolerance, no error reporting, cheap .ini parsing Set ini_size==0 to let us use strlen(ini_data). Do not call this function with a 0 if your buffer is actually empty!

Source from the content-addressed store, hash-verified

12969// Zero-tolerance, no error reporting, cheap .ini parsing
12970// Set ini_size==0 to let us use strlen(ini_data). Do not call this function with a 0 if your buffer is actually empty!
12971void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
12972{
12973 ImGuiContext& g = *GImGui;
12974 IM_ASSERT(g.Initialized);
12975 //IM_ASSERT(!g.WithinFrameScope && "Cannot be called between NewFrame() and EndFrame()");
12976 //IM_ASSERT(g.SettingsLoaded == false && g.FrameCount == 0);
12977
12978 // For user convenience, we allow passing a non zero-terminated string (hence the ini_size parameter).
12979 // 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..
12980 if (ini_size == 0)
12981 ini_size = strlen(ini_data);
12982 g.SettingsIniData.Buf.resize((int)ini_size + 1);
12983 char* const buf = g.SettingsIniData.Buf.Data;
12984 char* const buf_end = buf + ini_size;
12985 memcpy(buf, ini_data, ini_size);
12986 buf_end[0] = 0;
12987
12988 // Call pre-read handlers
12989 // Some types will clear their data (e.g. dock information) some types will allow merge/override (window)
12990 for (ImGuiSettingsHandler& handler : g.SettingsHandlers)
12991 if (handler.ReadInitFn != NULL)
12992 handler.ReadInitFn(&g, &handler);
12993
12994 void* entry_data = NULL;
12995 ImGuiSettingsHandler* entry_handler = NULL;
12996
12997 char* line_end = NULL;
12998 for (char* line = buf; line < buf_end; line = line_end + 1)
12999 {
13000 // Skip new lines markers, then find end of the line
13001 while (*line == '\n' || *line == '\r')
13002 line++;
13003 line_end = line;
13004 while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
13005 line_end++;
13006 line_end[0] = 0;
13007 if (line[0] == ';')
13008 continue;
13009 if (line[0] == '[' && line_end > line && line_end[-1] == ']')
13010 {
13011 // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code.
13012 line_end[-1] = 0;
13013 const char* name_end = line_end - 1;
13014 const char* type_start = line + 1;
13015 char* type_end = (char*)(void*)ImStrchrRange(type_start, name_end, ']');
13016 const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL;
13017 if (!type_end || !name_start)
13018 continue;
13019 *type_end = 0; // Overwrite first ']'
13020 name_start++; // Skip second '['
13021 entry_handler = FindSettingsHandler(type_start);
13022 entry_data = entry_handler ? entry_handler->ReadOpenFn(&g, entry_handler, name_start) : NULL;
13023 }
13024 else if (entry_handler != NULL && entry_data != NULL)
13025 {
13026 // Let type handler parse the line
13027 entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
13028 }

Callers

nothing calls this directly

Calls 1

ImStrchrRangeFunction · 0.85

Tested by

no test coverage detected