{"id":13730264,"url":"https://github.com/ocornut/str","last_synced_at":"2025-04-12T15:37:49.955Z","repository":{"id":49507085,"uuid":"47557781","full_name":"ocornut/str","owner":"ocornut","description":"Lightweight C++ string type with a configurable local buffer","archived":false,"fork":false,"pushed_at":"2024-11-04T18:10:44.000Z","size":52,"stargazers_count":254,"open_issues_count":5,"forks_count":39,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-27T15:14:47.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocornut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-07T14:42:54.000Z","updated_at":"2025-03-24T02:09:44.000Z","dependencies_parsed_at":"2024-12-09T03:08:53.292Z","dependency_job_id":"d1a07667-ec61-4ee9-9ad7-b7e58dc6b925","html_url":"https://github.com/ocornut/str","commit_stats":{"total_commits":45,"total_committers":7,"mean_commits":6.428571428571429,"dds":"0.37777777777777777","last_synced_commit":"23f29fdb743e8b1e236adbeaa1933300bdc00539"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocornut%2Fstr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocornut%2Fstr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocornut%2Fstr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocornut%2Fstr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocornut","download_url":"https://codeload.github.com/ocornut/str/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247033813,"owners_count":20872532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:12.424Z","updated_at":"2025-04-03T16:12:36.150Z","avatar_url":"https://github.com/ocornut.png","language":"C++","readme":"```\nStr\nSimple C++ string type with an optional local buffer, by Omar Cornut\nhttps://github.com/ocornut/str\n\nLICENSE\nThis software is in the public domain. Where that dedication is not\nrecognized, you are granted a perpetual, irrevocable license to copy,\ndistribute, and modify this file as you see fit.\n\nUSAGE\nInclude Str.h in whatever places need to refer to it.\nIn ONE .cpp file, write '#define STR_IMPLEMENTATION' before the #include.\nThis expands out the actual implementation into that C/C++ file.\n\nNOTES\n- This isn't a fully featured string class. \n- It is a simple, bearable replacement to std::string that isn't heap abusive nor bloated (can actually be debugged by humans!).\n- String are mutable. We don't maintain size so length() is not-constant time. \n- Maximum string size currently limited to 2 MB (we allocate 21 bits to hold capacity).\n- Local buffer size is currently limited to 1023 bytes (we allocate 10 bits to hold local buffer size).\n- We could easily raise those limits if we are ok to increase the structure overhead in 32-bits mode.\n- In \"non-owned\" mode for literals/reference we don't do any tracking/counting of references.\n- Overhead is 8-bytes in 32-bits, 16-bytes in 64-bits (12 + alignment).\n- I'm using this code but it hasn't been tested thoroughly.\n\nThe idea is that you can provide an arbitrary sized local buffer if you expect string to fit \nmost of the time, and then you avoid using costly heap.\n\nNo local buffer, always use heap, sizeof()==8~16 (depends if your pointers are 32-bits or 64-bits)\n\n   Str s = \"hey\";   // use heap\n\nWith a local buffer of 16 bytes, sizeof() == 8~16 + 16 bytes.\n\n   Str16 s = \"filename.h\"; // copy into local buffer\n   Str16 s = \"long_filename_not_very_long_but_longer_than_expected.h\";   // use heap\n\nWith a local buffer of 256 bytes, sizeof() == 8~16 + 256 bytes.\n\n   Str256 s = \"long_filename_not_very_long_but_longer_than_expected.h\";  // copy into local buffer\n\nCommon sizes are defined at the bottom of Str.h, you may define your own.\n\nFunctions:\n\n   Str256 s;\n   s.set(\"hello sailor\");                   // set (copy)\n   s.setf(\"%s/%s.tmp\", folder, filename);   // set (w/format)\n   s.append(\"hello\");                       // append. cost a length() calculation!\n   s.appendf(\"hello %d\", 42);               // append (w/format). cost a length() calculation!\n   s.set_ref(\"Hey!\");                       // set (literal/reference, just copy pointer, no tracking)\n\nConstructor helper for format string: add a trailing 'f' to the type. Underlying type is the same.\n\n   Str256f filename(\"%s/%s.tmp\", folder, filename);             // construct (w/format)\n   fopen(Str256f(\"%s/%s.tmp, folder, filename).c_str(), \"rb\");  // construct (w/format), use as function param, destruct\n\nConstructor helper for reference/literal:\n\n   StrRef ref(\"literal\");                   // copy pointer, no allocation, no string copy\n   StrRef ref2(GetDebugName());             // copy pointer. no tracking of anything whatsoever, know what you are doing!\n\nAll StrXXX types derives from Str and instance hold the local buffer capacity.\nSo you can pass e.g. Str256* to a function taking base type Str* and it will be functional!\n\n   void MyFunc(Str\u0026 s) { s = \"Hello\"; }     // will use local buffer if available in Str instance\n\n(Using a template e.g. Str\u003cN\u003e we could remove the LocalBufSize storage but it would make passing typed Str\u003c\u003e to functions tricky.\n Instead we don't use template so you can pass them around as the base type Str*. Also, templates are ugly.)\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focornut%2Fstr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focornut%2Fstr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focornut%2Fstr/lists"}