Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mr-cheff/ultimate-string-library
The ultimate string library for C where it's purpose is to eliminate the use of null terminators but allow C stdlib interactivity without the use of structs and still use char* arrays
https://github.com/mr-cheff/ultimate-string-library
c-strings string-library
Last synced: 3 days ago
JSON representation
The ultimate string library for C where it's purpose is to eliminate the use of null terminators but allow C stdlib interactivity without the use of structs and still use char* arrays
- Host: GitHub
- URL: https://github.com/mr-cheff/ultimate-string-library
- Owner: mr-cheff
- License: mit
- Created: 2023-09-12T06:57:03.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-14T19:12:14.000Z (over 1 year ago)
- Last Synced: 2024-11-22T03:03:29.814Z (about 1 month ago)
- Topics: c-strings, string-library
- Language: C
- Homepage:
- Size: 19.5 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ultimate-string-library
The ultimate string library for C where it's purpose is to eliminate the use of null terminators but allow C stdlib interactivity# How to use
```c
#include "usl.h"int main() {
usl str = usl_from("Hello, World!");
usl str2 = usl_from("Hello, World!");
usl str3 = usl_concat(str, str2);
printf("%s\n", usl_as_str(str3));
usl_free(str);
usl_free(str2);
usl_free(str3);
}
```# How to install
```c
include(FetchContent)
FetchContent_Declare(usl
URL https://github.com/mauro-balades/ultimate-string-library.git
)FetchContent_MakeAvailable(usl)
target_link_libraries(${PROJECT_NAME} PRIVATE usl)
```# How does it work?
The library uses a tipical `char*` but it also stores the length of the string in the first 4 bytes of the pointer.
### Why?
I wanted to make a string library that was easy to use and didn't require the use of null terminators. I also wanted to make it so that it was easy to convert to a `char*` so that it could be used with the C stdlib.
The C stdlib kinda... *sucks* when it comes to strings. It's not very safe and it's very easy to make mistakes. I wanted to make a library that was easy to use and didn't require the use of null terminators. I also wanted to make it so that it was easy to convert to a `char*` so that it could be used with the C stdlib.
here's an example of the string representation:
```c
[4 bytes] [n bytes]
[length] [string]
``````c
"Hello"
[5 bytes] [5 bytes]
[0x05] [Hello]H E L L O
--------------
0 0 0 5 H E L L O
```