https://github.com/skullchap/chadstr Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Project management - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} skullchap / chadstr * Notifications * Star 74 * Fork 2 Chad Strings - The Chad way to handle strings in C. GPL-3.0 License 74 stars 2 forks Star Notifications * Code * Issues 1 * Pull requests 1 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 2 branches 0 tags Code Clone HTTPS GitHub CLI [https://github.com/s] Use Git or checkout with SVN using the web URL. [gh repo clone skullc] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit skullchap changed default behaviour of indexing in range() back to zero-based ... 5161c6b May 18, 2021 changed default behaviour of indexing in range() back to zero-based 5161c6b Git stats * 30 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time LICENSE Initial commit May 13, 2021 README.md changed default behaviour of indexing in range() back to zero-based May 18, 2021 chadstr.h changed default behaviour of indexing in range() back to zero-based May 18, 2021 gc.gif gif May 13, 2021 meme.png meme May 18, 2021 View code chadstr.h Chad Strings - The Chad way to handle strings in C. Examples Usage: Operations on Chad Strings: Examples Usage: PRs are welcomed. README.md chadstr.h Chad Strings - The Chad way to handle strings in C. One str(...) macro to handle them all. Examples Usage: int table = 13; int id = 37; str test1 = str("SELECT * FROM ", table, " where person_id ", id); str test2 = str(test1); //copies test1 to test2 str test3 = str(test2, test1); // returns concat of test2 and test1 test2 = test1; // acceptable, but wrong since test2 now points to test1 not copies it. str(*test1); // returns const char* to use in printf like functions Ex: puts(str(*test1)); // prints test1; "Why yes, i don't free(), OS cleans all memory for me, how did you know?" animated free(test1); // will free memory for whole str. "Whoa, whoa, wait bro. But how about freeing str->data field?" While allocating memory for 'str' struct itself it also reserves space beneath it to store that string. str->data points to that location. So freeing str itself also frees memory located at str-> data. If your coompiler does support "__attribute__((cleanup()))" ("aahem gcc/clang"), strings can be auto free'd while defined this way: autofree str test1 = str("apple"); ... // no free(test1); !!! or chadstr test2 = str("pineapple"); ... // no free(test2); !!! Operations on Chad Strings: Instead of writing shitload of different functions for some specific task, you can utilize already existing tools in your OS to do that for you. [meme] Examples Usage: cmd CMD = (cmd){"echo"} chadstr test1 = str("orange apple"); chadstr pipecmd = str(" | cut -z -d \" \" -f1 "); chadstr result = str(CMD, test1, pipecmd); // "echo orange apple | cut -z -d " " -f1" as you would do in shell /* chadstr result = str((cmd){"echo"}, test1, pipecmd); is also acceptable */ puts(str(*result)); File embedding never been so easy using this way: cmd CAT = (cmd){"cat"}; chadstr file = str(CAT, "README.md"); // cat README.md puts(str(*file)); ChadSTR also has utility function range() to select range of string: chadstr test1 = str("pineapple"); chadstr test1range = str((range)(test1, 3,6)); // eapp /* * If you are comfortable with range starting at index 1, * #define HUMAN_RANGE before #include "chadstr.h" * Note: negative end indices are still in "human" format * starting at 1 no matter HUMAN_RANGE defined or not. */ #define HUMAN_RANGE #include "chadstr.h" ... chadstr test1 = str("pineapple"); chadstr test1range = str((range)(test1, 3,6)); // neap Another example on generating random string with buffer and per char copying: #include #include #include #include #include "chadstr.h" str random_string(size_t length) { chadstr pool = str("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); size_t randindex; size_t i; struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); /* using nano-seconds instead of seconds */ srand((time_t)ts.tv_nsec); char buffer[length]; for(i = 0; i < length; ++i) { randindex = rand() % pool->len; buffer[i] = pool->data[randindex] ^ ((rand() % 2) ? 0 : 0x20); } buffer[i] = '\0'; return str(buffer); } int main(void) { for (int i = 0; i < 1000; ++i) { chadstr s = random_string(120); puts(str(*s)); } return 0; } PRs are welcomed. About Chad Strings - The Chad way to handle strings in C. Resources Readme License GPL-3.0 License Releases No releases published Packages 0 No packages published Languages * C 100.0% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.