{"id":20963791,"url":"https://github.com/mitjafelicijan/cord.h","last_synced_at":"2025-05-14T09:31:30.643Z","repository":{"id":148923329,"uuid":"583837679","full_name":"mitjafelicijan/cord.h","owner":"mitjafelicijan","description":"Small C library for handling strings","archived":false,"fork":false,"pushed_at":"2024-05-11T06:58:30.000Z","size":32,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-11T07:40:51.268Z","etag":null,"topics":["c","header","library","stb","string"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitjafelicijan.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":"2022-12-31T05:21:42.000Z","updated_at":"2024-05-11T06:58:34.000Z","dependencies_parsed_at":"2024-05-11T07:49:16.771Z","dependency_job_id":null,"html_url":"https://github.com/mitjafelicijan/cord.h","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/mitjafelicijan%2Fcord.h","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitjafelicijan%2Fcord.h/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitjafelicijan%2Fcord.h/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitjafelicijan%2Fcord.h/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitjafelicijan","download_url":"https://codeload.github.com/mitjafelicijan/cord.h/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225284582,"owners_count":17449928,"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":["c","header","library","stb","string"],"created_at":"2024-11-19T02:48:26.113Z","updated_at":"2024-11-19T02:48:26.595Z","avatar_url":"https://github.com/mitjafelicijan.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Small C library for handling strings\n\n**Table of Contents**\n\n- [Quick Example](#quick-example)\n- [Current Features](#current-features)\n- [Observations \\\u0026 Critics](#observations--critics)\n- [Planned Features](#planned-features)\n- [Demo](#demo)\n- [Alternative Libraries](#alternative-libraries)\n- [License](#license)\n\n\n**IMPORTANT! THIS LIBRARY IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! USE THIS LIBRARY AT YOUR OWN RISK!**\n\nThis is a STB style header which also includes the implementation part. You can enable the implementation part by defining `CORD_IMPLEMENTATION` before including the header. It does not [follow strict STB style](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt), but it is close enough.\n\nLibrary is not using any external dependencies and uses only standards C libraries.\n\n## Quick Example\n\n```c\n#define CORD_IMPLEMENTATION\n#include \"cord.h\"\n\nint main(void)\n{\n    cordString str = cord_new_string(\"Some string\");\n    cord_append_char(\u0026str, 'a');\n    cord_append_string(\u0026str, \" and some more text    \");\n    cord_trim(\u0026str);\n    cord_ireplace_char(\u0026str, 'O', '-');\n    cord_free_string(\u0026str);\n\n    // And so on...\n}\n```\n\nBecause of the use of `realloc` and the string header, you use the function that comes with the library called `cord_new_string` and `cord_free_string` to free the string. Other than that, the string behaves like a normal C string. So all the function that come with `string.h` can be used with it.\n\n## Current Features\n- `cordString cord_new_string(char *str);`\n- `cordString cord_new_string_reserve(size_t len);`\n- `void cord_free_string(cordString* str);`\n- `cordString cord_realloc_string(cordString* str, size_t newSize);`\n- `size_t cord_string_len(cordString str);`\n- `void cord_append_char(cordString* str, char c);`\n- `void cord_append_string(cordString* str, char *str2);`\n- `void cord_to_uppercase(cordString* str);`\n- `void cord_to_lowercase(cordString* str);`\n- `void cord_trim(cordString* str);`\n- `void cord_ltrim(cordString* str);`\n- `void cord_rtrim(cordString* str);`\n- `char cord_char_at(cordString* str, size_t index);`\n- `size_t cord_index_of(cordString* str, char c);`\n- `void cord_repeat_char(cordString* str, char c, size_t count);`\n- `void cord_reverse(cordString* str);`\n- `void cord_replace_char(cordString* str, char c, char new_c);`\n- `void cord_ireplace_char(cordString* str, char c, char new_c);`\n- `void cord_pad_start(cordString* str, char c, size_t count);`\n- `void cord_pad_end(cordString* str, char c, size_t count);`\n- `bool cord_starts_with(cordString* str, char *start);`\n- `bool cord_ends_with(cordString* str, char *end);`\n- `void cord_wrap(cordString* str, size_t length);`\n- `void cord_remove_char(cordString* str, char c);`\n- `void cord_iremove_char(cordString* str, char c);`\n- `bool cord_includes(cordString* str, char *substr);`\n\nNOTE : all functions with c-string (char*) input have their own respective `_len()` functions\\\neg. `bool cord_includes(cordString* str, char *substr);` -\u003e `bool cord_includes_len(cordString* str, const char* substr, size_t len);`\n\n## Observations \u0026 Critics\n\n- `cord_includes` should probably return the index of the first occurrence instead of `true` or `false`.\n- `cord_pad_start` and `cord_pad_end` are weird and should be fixed to be more like `ljust` and `rjust` from Ruby.\n\n## Planned Features\n\n- `split()`\n- `join()`\n\n## Demo\n\nBy default it uses `clang` and you can change it by editing the `Makefile`, specifically `CC` variable. Or you can also override it by passing it as an argument to `make` command like `make CC=gcc`.\n\n```sh\nmake # will use clang\n\nmake CC=gcc # will use gcc\n\n./test # will run the test program\n```\n\nThis will run the test program and print the output to the console. The output should look like this:\n\n```text\nf:new_string :: l:11 =\u003e v:`  Hello    `\nf:ltrim :: l:9 =\u003e v:`Hello    `\nf:rtrim :: l:5 =\u003e v:`Hello`\nf:append_char :: l:6 =\u003e v:`HelloA`\nf:append_string :: l:9 =\u003e v:`HelloABCD`\nf:to_uppercase :: l:9 =\u003e v:`HELLOABCD`\nf:to_lowercase :: l:9 =\u003e v:`helloabcd`\nf:char_at char_at: l\nf:index_of index_of: 2\nf:repeat_char :: l:19 =\u003e v:`helloabcdXXXXXXXXXX`\nf:reverse :: l:19 =\u003e v:`XXXXXXXXXXdcbaolleh`\nf:replace_char :: l:19 =\u003e v:`++++++++++dcbaolleh`\nf:ireplace_char :: l:19 =\u003e v:`++++++++++dcbaoQQeh`\nf:pad_start :: l:24 =\u003e v:`_____++++++++++dcbaoQQeh`\nf:pad_end :: l:29 =\u003e v:`_____++++++++++dcbaoQQeh_____`\nf:starts_with (__): 1\nf:starts_with ( ): 0\nf:ends_with (__): 1\nf:ends_with ( ): 0\nf:wrap (80): Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i\nncididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostru\nd exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aut\ne irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat n\nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui\n officia deserunt mollit anim id est laborum.\nf:remove_char :: l:408 =\u003e v:`Lorem psum dolor st amet, consectetur adpscng elt, sed do eusmod tempor \nncddunt ut labore et dolore magna alqua. Ut enm ad mnm venam, qus nostru\nd exerctaton ullamco labors ns ut alqup ex ea commodo consequat. Dus aut\ne rure dolor n reprehendert n voluptate velt esse cllum dolore eu fugat n\nulla paratur. Excepteur snt occaecat cupdatat non prodent, sunt n culpa qu\n offca deserunt mollt anm d est laborum.`\nf:cord_includes (c): 1\nf:cord_includes (::): 0\n```\n\n## Alternative Libraries\n- [EimaMei/sili - a cross-platform standard library for modern C programming (including string manipulation)](https://github.com/EimaMei/sili)\n- [antirez/sds - Simple Dynamic Strings library for C](https://github.com/antirez/sds)\n- [tsoding/sv - Simple String_View implementation for C programming language.](https://github.com/tsoding/sv)\n- [MichaelJWelsh/SmartString - A Lightweight, Fast, and Safe C Library Meant to Mimic String Functionality Present in C++](https://github.com/MichaelJWelsh/SmartString)\n\n## License\n\n[cord.h](https://github.com/mitjafelicijan/cord.h) was written by [Mitja Felicijan](https://mitjafelicijan.com/) and is released under the BSD two-clause license, see the LICENSE file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitjafelicijan%2Fcord.h","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitjafelicijan%2Fcord.h","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitjafelicijan%2Fcord.h/lists"}