Thanks to visit codestin.com
Credit goes to github.com

Skip to content

okba14/guiarstr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GuiarStr - Advanced String Manipulation Library for C

Version License: MIT

Build & Test UTF-8 Support

Language Platforms

SLSA Level 3 Provenance GitHub release (latest)

GitHub stars GitHub issues

πŸš€ Why GuiarStr?

GuiarStr is a comprehensive, professional-grade string manipulation library for C programmers.
While C has very basic string support, GuiarStr provides a rich set of modern string operations with:

  • Dynamic strings
  • Unicode/UTF-8 support
  • Memory safety
  • Efficient performance

Perfect for embedded systems to complex multilingual software β€” without external dependencies.


✨ Features

πŸ“ Core String Operations

| Function | Description |

| guiarstr_trim | Removes leading and trailing whitespace. |

| guiarstr_strip | Removes specified characters from both ends. |

| guiarstr_tolower / guiarstr_toupper | Converts string to lowercase/uppercase (in-place). |

| guiarstr_reverse | Reverses a string (UTF-8 safe). |

| guiarstr_replace | Replaces all occurrences of a substring.

| guiarstr_replace_n | Replaces with a limit on replacements.

| guiarstr_replace_char | Replaces all occurrences of a character. | guiarstr_remove_chars | Removes all specified characters.|


πŸ” Advanced Search & Inspection

  • guiarstr_starts_with / guiarstr_ends_with – Prefix/suffix checking.
  • guiarstr_starts_withi / guiarstr_endswithi – Case-insensitive variants.
  • guiarstr_contains – Checks if a string contains a substring.
  • guiarstr_count – Counts occurrences of a substring.
  • guiarstr_find / guiarstr_rfind – Find substring positions.
  • guiarstr_find_char / guiarstr_rfind_char – Find character positions.
  • guiarstr_find_any / guiarstr_find_not_any – Advanced character search.

πŸ”— Split & Join Operations

  • guiarstr_split – Splits by character delimiter.
  • guiarstr_split_str – Splits by string delimiter.
  • guiarstr_split_any – Splits by any of multiple delimiters.
  • guiarstr_split_lines – Splits by line endings (handles \n, \r\n).
  • guiarstr_join – Joins string array with separator.
  • guiarstr_join_views – Joins string views efficiently.

πŸ“Œ Dynamic Strings (GuiarStr)

  • guiarstr_create – Creates a dynamic string.
  • guiarstr_append – Appends to a dynamic string.
  • guiarstr_insert – Inserts at a specific position.
  • guiarstr_remove – Removes a range of characters.
  • guiarstr_reserve – Pre-allocates memory.
  • guiarstr_resize – Resizes with fill character.
  • guiarstr_shrink_to_fit – Optimizes memory usage.

πŸ— String Builder (GuiarStrBuilder)

  • guiarstr_builder_create – Creates an efficient string builder.
  • guiarstr_builder_append – Appends strings efficiently.
  • guiarstr_builder_append_fmt – Appends formatted strings.
  • guiarstr_builder_build – Builds the final string.

🌍 Unicode/UTF-8 Support

  • guiarstr_utf8_len – Gets UTF-8 character count.
  • guiarstr_utf8_char_len – Gets byte length of a UTF-8 character.
  • guiarstr_utf8_byte_pos – Converts character position to byte position.
  • guiarstr_utf8_validate – Validates UTF-8 sequences.
  • guiarstr_utf8_width – Gets display width for monospace fonts.
  • guiarstr_utf8_substring – Extracts UTF-8 substring.

βœ… Handles emojis, Arabic, and all Unicode characters correctly.


πŸ”’ Number Conversion

  • guiarstr_to_int / guiarstr_from_int
  • guiarstr_to_double / guiarstr_from_double
  • guiarstr_to_long / guiarstr_from_long
    βœ” Includes error handling.

πŸ–‹ Formatting

  • guiarstr_printf – Creates formatted strings.
  • guiarstr_append_printf – Appends formatted strings to dynamic strings.

πŸ“‚ File Operations

  • guiarstr_read_file – Reads entire file into a string.
  • guiarstr_write_file – Writes string content to file.

πŸ›‘ Error Handling

  • Comprehensive error codes with descriptive messages.
  • All functions return error status for safe operation.
  • guiarstr_error_message – Gets human-readable error descriptions.

🧠 UTF-8 Aware

  • Fully UTF-8 aware operations.
  • Works perfectly for multilingual apps and terminal-based UIs.
  • Supports byte-level and character-level manipulation.

Installation

Option 1: Build locally

make            # Builds static lib (libguiarstr.a) + shared lib (libguiarstr.so)
make test       # Runs the test suite
make example    # Builds usage demo

Option 2 : Install

make install PREFIX=$HOME/.local

This installs :

  • guiarstr.h β†’ $PREFIX/include

  • libguiarstr.a and libguiarstr.so β†’ $PREFIX/lib

  • guiarstr.pc β†’ $PREFIX/lib/pkgconfig

Option 3: Using CMake

mkdir build && cd build
cmake ..
make
sudo make install

πŸ§ͺ Example Usage

Basic Operations :

#include <stdio.h>
#include "guiarstr.h"

int main() {
    char text[] = "  Hello World  ";
    printf("Trimmed: '%s'\n", guiarstr_trim(text));

    size_t count;
    char** parts = guiarstr_split_str("oneXYZtwoXYZthree", "XYZ", &count);
    for (size_t i = 0; i < count; ++i) {
        printf("Part %zu: %s\n", i + 1, parts[i]);
    }
    guiarstr_split_free(parts, count);

    char* reversed = guiarstr_reverse("okba😊dev");
    printf("Reversed: %s\n", reversed);
    free(reversed);
}

Dynamic Strings

#include "guiarstr.h"

int main() {
    GuiarStr* str = guiarstr_create("Hello");
    guiarstr_append(str, " World");
    guiarstr_append_char(str, '!');
    guiarstr_insert(str, 5, " there");

    printf("Dynamic string: '%s'\n", str->data);

    guiarstr_free(str);
}

String Builder

#include "guiarstr.h"

int main() {
    GuiarStrBuilder* builder = guiarstr_builder_create(16);
    guiarstr_builder_append(builder, "The answer is: ");
    guiarstr_builder_append_fmt(builder, "%d", 42);

    GuiarStr* result = guiarstr_builder_build(builder);
    printf("Built: '%s'\n", result->data);

    guiarstr_free(result);
    guiarstr_builder_free(builder);
}

Unicode Operations

#include "guiarstr.h"

int main() {
    const char* text = "Ω…Ψ±Ψ­Ψ¨Ψ§ 😊";
    printf("UTF-8 length: %zu characters\n", guiarstr_utf8_len(text));
    printf("Byte length: %zu bytes\n", strlen(text));
    printf("Display width: %zu columns\n", guiarstr_utf8_width(text));

    char* substr = guiarstr_utf8_substring(text, 2, 2);
    printf("Substring [2:4]: '%s'\n", substr);
    free(substr);
}

πŸ”§ Using with pkg-config

gcc main.c $(pkg-config --cflags --libs guiarstr) -o app

Make sure : PKG_CONFIG_PATH is set if installed

to a custom location :

export PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig

πŸ“ Project Structure

makefile

guiarstr/
β”œβ”€β”€ include/              # Public headers
β”‚   └── guiarstr.h
β”œβ”€β”€ src/                  # Implementation
β”‚   └── guiarstr.c
β”œβ”€β”€ tests/                # Tests
β”‚   └── main.c
β”œβ”€β”€ examples/             # Example programs
β”‚   └── usage.c
β”œβ”€β”€ assets/               # Images
β”‚   └── build_and_test.png
β”œβ”€β”€ CMakeLists.txt
β”œβ”€β”€ guiarstr.pc
β”œβ”€β”€ guiarstr.pc.in
β”œβ”€β”€ Makefile
β”œβ”€β”€ README.md
β”œβ”€β”€ CHANGELOG.md
└── LICENSE

🀝Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Fork the repository Create your feature branch

(git checkout -b feature/amazing-feature)

Commit your changes

(git commit -m 'Add some amazing feature')

Push to the branch

(git push origin feature/amazing-feature)

Open a Pull Request.


πŸ“« Author

πŸ‘€ Name: GUIAR OQBA

πŸ“§ Email: [email protected]

🌐 ORCID: 0009-0008-1629-0002

πŸ’Ό LinkedIn: guiar-oqba

πŸ’» GitHub: okba14

πŸ“š Zenodo: 15786076

πŸ“ Hashnode: @okba

✈️ Telegram: @okba_elkantara

πŸ“± Phone: +2136-71-36-04-38


πŸ”„ Version History

See CHANGELOG.md for release notes.


πŸ“œ License

License: MIT
Β© 2025 GUIAR OQBA πŸ‡©πŸ‡Ώ
Made with πŸ’» & ❀️ from Algeria


Thank you for your support! πŸ™