MCPcopy Create free account
hub / github.com/defold/defold / LoadFromBufferInternal

Function LoadFromBufferInternal

engine/dlib/src/dlib/configfile.cpp:503–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

501 }
502
503 static Result LoadFromBufferInternal(const char* url, const char* buffer, uint32_t buffer_size, int argc, const char** argv, HConfig* config)
504 {
505 Context context;
506 // NOTE: We allocate n + 1 bytes in order to ensure that
507 // the file has a terminating newline
508 context.m_Buffer = new char[buffer_size + 1];
509 memcpy(context.m_Buffer, buffer, buffer_size);
510 // Ensure terminating newline.
511 context.m_Buffer[buffer_size] = '\n';
512 context.m_BufferSize = buffer_size + 1;
513 context.m_BufferPos = 0;
514 context.m_ValueBuffer = new char[buffer_size + 1];
515 context.m_ValueBuffer[buffer_size] = 0;
516
517 context.m_Argc = argc;
518 context.m_Argv = argv;
519 context.m_URI = url;
520 context.m_Entries.SetCapacity(128);
521 context.m_StringBuffer.SetCapacity(0400);
522 context.m_Line = 1;
523
524 int ret = setjmp(context.m_JmpBuf);
525 if (ret != RESULT_OK)
526 {
527 delete[] context.m_ValueBuffer;
528 delete[] context.m_Buffer;
529 return (Result) ret;
530 }
531 else
532 {
533 Parse(&context);
534
535 for (int i = 0; i < context.m_Argc; ++i)
536 {
537 const char* arg = context.m_Argv[i];
538 if (strncmp("--config=", arg, sizeof("--config=")-1) == 0)
539 {
540 const char* eq = strchr(arg, '=');
541 const char* eq2 = strchr(eq+1, '=');
542
543 if (!eq2)
544 {
545 dmLogWarning("Invalid config option: %s", arg);
546 continue;
547 }
548
549 uint64_t key_hash = dmHashBuffer64(eq+1, eq2 - (eq+1));
550 if (!ContainsKey(context.m_Entries, key_hash))
551 {
552 AddEntryWithHashedKey(&context, key_hash, eq2 + 1);
553 }
554 }
555 }
556
557 ConfigFile* c = new ConfigFile();
558
559 if (context.m_Entries.Size() > 0)
560 {

Callers 2

LoadFromFileInternalFunction · 0.70
LoadFromBufferFunction · 0.70

Calls 7

ContainsKeyFunction · 0.85
AddEntryWithHashedKeyFunction · 0.85
ParseFunction · 0.70
dmHashBuffer64Function · 0.70
SetCapacityMethod · 0.45
SizeMethod · 0.45
SetSizeMethod · 0.45

Tested by

no test coverage detected