{"id":21498504,"url":"https://github.com/notapenguin0/fixed_string","last_synced_at":"2025-03-17T12:42:56.607Z","repository":{"id":117727484,"uuid":"137215526","full_name":"NotAPenguin0/fixed_string","owner":"NotAPenguin0","description":"compile-time size string class","archived":false,"fork":false,"pushed_at":"2018-06-14T17:19:41.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-23T22:24:49.203Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NotAPenguin0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-06-13T12:55:22.000Z","updated_at":"2018-07-18T16:24:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"6bd7dcb6-46df-48ad-b666-987f3224fda0","html_url":"https://github.com/NotAPenguin0/fixed_string","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAPenguin0%2Ffixed_string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAPenguin0%2Ffixed_string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAPenguin0%2Ffixed_string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAPenguin0%2Ffixed_string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NotAPenguin0","download_url":"https://codeload.github.com/NotAPenguin0/fixed_string/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244036940,"owners_count":20387606,"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-11-23T16:39:12.625Z","updated_at":"2025-03-17T12:42:56.602Z","avatar_url":"https://github.com/NotAPenguin0.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fixed_string\ncompile-time size string class\n\n# What is fixed_string\n\nThis class is an STL-like wrapper for C-style strings. It maintains a fixed-size character array\nand provides general string utilities, like replacing characters, filling it, adding two strings,\nfinding characters. \n\nfixed_string is guaranteed to be null terminated at all times, unless the user modifies the value at the end() iterator, \nor accesses the last index of the array and mofidies it.\n```cpp\nfixed_string\u003c16\u003e buf;\nbuf[16] = 'X' //BAD! fixed_string is no longer null terminated\n```\n\nIf you find a case where fixed_string is not null terminated, please open an issue so it can be fixed.\n\n# Usage\n\nThe header provides the `basic_fixed_string` class. It also provides the following typedefs:\n\n```cpp\ntemplate\u003cunsigned N\u003e\nusing fixed_string = basic_fixed_string\u003cN, char\u003e;\nusing fixed_string_16 = fixed_string\u003c16\u003e;\nusing fixed_string_32 = fixed_string\u003c32\u003e;\nusing fixed_string_64 = fixed_string\u003c64\u003e;\nusing fixed_string_128 = fixed_string\u003c128\u003e;\nusing fixed_string_256 = fixed_string\u003c256\u003e;\n\ntemplate\u003cunsigned N\u003e\nusing fixed_wstring = basic_fixed_string\u003cN, wchar_t\u003e;\nusing fixed_wstring_16 = fixed_wstring\u003c16\u003e;\nusing fixed_wstring_32 = fixed_wstring\u003c32\u003e;\nusing fixed_wstring_64 = fixed_wstring\u003c64\u003e;\nusing fixed_wstring_128 = fixed_wstring\u003c128\u003e;\nusing fixed_wstring_256 = fixed_wstring\u003c256\u003e;\n```\n\n# Examples\n\n**Constructors**\n\n```cpp\nfixed_string\u003c16\u003e empty; //Fills the string with 16 '\\0' characters\nfixed_string\u003c16\u003e fromCharArray = \"ThisIsAString\";\nfixed_string\u003c16\u003e fromStdString = std::string(\"Hello World\");\nfixed_string\u003c16\u003e copied = fromStdString;\nfixed_string\u003c32\u003e copiedWithDifferentSize = copied;\nfixed_string\u003c32\u003e copiedWithMove = std::move(copied);\n```\n\n**Element access**\n\n```cpp\nfixed_string\u003c32\u003e str = \"This is a string\";\n\n//[] does no bounds checking, just like with std::string\nstd::cout \u003c\u003c str[2];\nstr[3] = 'X';\n\ntry\n{\n  str.at(512) = 'X'; //out of range, at() throws an std::out_of_range\n}\ncatch(std::out_of_range\u0026 e)\n{\n  std::cout \u003c\u003c \"error: \" \u003c\u003c e.what() \u003c\u003c '\\n';\n}\n\nstr.front() = 'X'; //returns a reference to the first element of the string\nstr.back() = 'V'; //returns a reference to the last element of the string\n```\n\n**Size**\n\n```cpp\nfixed_string\u003c32\u003e str = \"This is a string\";\n\nstd::cout \u003c\u003c str.size(); //prints '31'. This is important to note, all size access functions do not count the null terminator\n\n//Note that a call to size() is the same as calling length() or max_size()\n\nfixed_string\u003c32\u003e str;\nif (str.empty())\n{\n  //empty() returns true if the string is filled with null characters\n}\n```\n\n**Iterators**\n\n```cpp\nfixed_string\u003c32\u003e str = \"This is a string\";\n\n//prints: 'This is a string'\nfor(auto\u0026 it = str.begin(); it != str.end(); ++it)\n{\n  std::cout \u003c\u003c *it; \n}\n\n//Because fixed_string has begin() and end() functions, it also supports range-based for loops!\nfor(auto const\u0026 it : str)\n{\n  std::cout \u003c\u003c *it;\n}\n```\n\n**Modifiers**\n\n```cpp\nfixed_string\u003c32\u003e str;\n\nstr.fill('P'); //str is now 32 'P' characters\nstr.fill(16, 'S'); //starting from index 16, to the end, str is filled with 'S' characters\n\nstr.clear(); //str is now 32 '\\0' characters\n\nstr.replace(2, 5, 'Z'); //the range of indices [2, 5] is now replaced with 'Z' characters\n\n//replace() can be chained, as it returns *this\nstr.replace(str.begin() + 6, str.begin() + 12, 'D').replace(0, 3, \"Hiya\");\n//after this replace call, string will look like this:\n\"Hiya\\0\\0DDDDDD\\0\\0...\"\n\nfixed_string\u003c32\u003e otherStr;\notherStr.swap(str); //swaps contents\n```\n\n**Basic utilities**\n\n```cpp\nfixed_string\u003c32\u003e str;\n\nfixed_string\u003c32\u003e::size_type pos = str.find(\"Hello\");\nif (pos != fixed_string\u003c32\u003e::npos)\n{\n  //do something\n}\n\nfixed_string\u003c32\u003e::size_type pos2 = str.find('=', 10); //start search at index 10\n\nchar buf[32];\nstr.copy(buf, 32);\n\n//buf now contains the same data as str\n\nchar buf2[16];\nstr.copy(buf, 16, 15); //start copying at index 15\n\nfixed_string\u003c32\u003e::size_type pos3 = str.substr(\"This_Is_A_Substring\"); //find the first occurrence of specified substring\n```\n\n**Overloaded operators**\n\n```cpp\nfixed_string\u003c32\u003e first = \"Hello there\";\nfixed_string\u003c32\u003e second = \"I'm another string!\";\n\nif (first == second) //compares two strings\n{\n  std::cout \u003c\u003c \"huh?\"\n}\n\nfixed_string\u003c32\u003e third = \"Hello there\";\nif (first != third)\n{\n  std::cout \u003c\u003c \"huh?\";\n}\n\nfixed_string\u003c6\u003e a = \"aaaaa\";\nfixed_string\u003c6\u003e b = \"bbbbb\";\n\nauto sum = a + b; //sum will be a fixed_string\u003c12\u003e\n```\n\n**I/O Operators**\n\n```cpp\nfixed_string\u003c32\u003e str;\nstd::cin \u003e\u003e str; //reads until next space or newline, just like std::string, or until str buffer is full\n\nstd::cout \u003c\u003c str;\n```\n\n# Contribution\n\nIf you find any bugs, please report them as an issue so I can fix them, or create a pull request.\n\nAny other feedback, like code improvements and new features are also greatly appreciated.\n\n# Licensing\n\nThis code is licenced under the GNU General Public License v3.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotapenguin0%2Ffixed_string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotapenguin0%2Ffixed_string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotapenguin0%2Ffixed_string/lists"}