Skip to content

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo strview

StrView is a lightweight library to handle c strings created as a personal project. It can be added directly to your project and used wherever its features meet your requirements.

The library has not been extensively tested, so it may not be suitable for production-critical applications.

cc -DDEBUG -std=gnu11 -Wall -Wpedantic -Wextra -Werror -g -o strview main.c strview.c && ./strview

Usage examples

Create string view and print to stdout:

strview_t sv = sv_from_cstr("test-string");
sv_println_safe_stdout(sv);

Create string view, extract prefix and suffix:

strview_t suffix, prefix;
strview_t sv = sv_from_cstr("test-string");

sv_prefix(sv, 3, &prefix);
sv_suffix(sv, 5, &suffix);

printf("string prefix: ");
sv_println_safe_stdout(prefix);

printf("string suffix: ");
sv_println_safe_stdout(suffix);

Compare two string view:

strview_t sv_a = sv_from_cstr("abcd");
strview_t sv_b = sv_from_cstr("abcd");

printf("compare string (0 = equal, positive = left > right, negative = otherwise): ");
printf("%d\n", sv_cmp(sv_a, sv_b));

sv_rem_prefix(&sv_b, 2); /* remove prefix starting from character position 2 */

printf("compare string (0 = equal, positive = left > right, negative = otherwise): ");
printf("%d\n", sv_cmp(sv6, sv7));

Verify if a string view contains another string view as substring:

strview_t sv_a = sv_from_cstr("this is my library");
strview_t sv_b = sv_from_cstr("is");

printf("it contains (0 = yes, -1 = no): %d\n", sv_contains(sv_a, sv_b));

About

Simple library with couple of functions to view c strings

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages