1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-11-09 22:08:40 +01:00
libcproject/README.md
Théo LUDWIG 72645da4b2
perf: mutate strings instead of copy when possible
BREAKING CHANGE: Most of string functions mutates the string instead of copying now.
This allows better performance when copy is not needed.
It also allows more granual control.
If copy is wanted, simply use `string_copy` before calling the function.

Impacted functions are:
`string_to_uppercase`, `string_to_lowercase`, `string_replace`,
`string_trim_start`, `string_trim_end`, `string_trim`,
`string_capitalize`, `string_reverse`
2023-08-06 23:17:07 +02:00

3.6 KiB

libcproject

C static library easier to use than `libc` (C standard library).

Licence MIT Contributor Covenant
Conventional Commits semantic-release

About

libcproject is a C static library for learning purposes. It tries to implement useful functions/data structures while being easier to use than libc (C standard library) as much as possible.

C is a low-level programming language and we often end up reinventing the wheel as the C standard library (libc) is quite small and in my humble opinion, not well designed.

libcproject solve this by providing common functions or data structures (hash_map, array_list, linked_list, queue, stack, etc.), we might need in our C projects.

Online documentation.

Prerequisites

For example on GNU/Linux Ubuntu:

# Install Build Tools
sudo apt-get install build-essential gcc make clang-format

# Install Documentation Tools
sudo apt-get install doxygen doxygen-gui doxygen-doc graphviz

Usage

make # to compile
make run # to run main
make test # to run unit tests
make lint # to lint the code
make documentation # to generate the documentation
make clean # to clean up

nm ./build/libcproject.a # to see the symbols

Steps to create a new C project that uses libcproject:

Step 1: Create a new project

mkdir my-project
cd my-project

Step 2: Install and Compile libcproject in the project

# Clone the repository
git clone git@github.com:theoludwig/libcproject.git

# Go to libcproject directory
cd libcproject

# Compile the library
make

Step 3: Create a new C file

cd ..
touch main.c
#include <stdio.h>
#include <stdlib.h>

#include "libcproject/libcproject.h"

int main() {
  string_t string = "Hello, world!"; // `string_t` is a typedef from `libcproject`
  printf("%s\n", string);
  printf("string_length = %ld\n", string_get_length(string)); // `string_get_length` is a function from `libcproject`
  return EXIT_SUCCESS;
}
gcc -o ./main ./main.c -L. -l:./libcproject/build/libcproject.a

💡 Contributing

Anyone can help to improve the project, submit a Feature Request, a bug report or even correct a simple spelling mistake.

The steps to contribute can be found in the CONTRIBUTING.md file.

📄 License

MIT