Skip to content

Autumn64/smartstr.h

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SMARTSTR.H

Pull requests Issues Stars License

A free, open-source, simple, memory-safe and lightweight Strings library for C.

Description

SMARTSTR.H is a library that provides an interface to work with text strings as in common high-level programming languages. SMARTSTR.H stands for "SMART Strings Header file"

Features

  • Fast and efficient.
  • Easy to use.
  • Works on any C version starting from C99.
  • Doesn't require any dependencies besides the standard library.

Introduction

To create a string, just use the str_new() function.

#include <smartstr.h>

int main(void){
    String str = str_new();

    //More code here...
}

Strings in SMARTSTR.H have only two members: A value, and a length. This is because a String is essentially a struct:

typedef struct String{
	char *value;
	size_t length;
} String;

Note: The length member always includes the null character (\0). So, if you do this:

#include <smartstr.h>

int main(void){
    String str1 = str_new();
    str_ccopy(&str1, "Hello World!");

    //More code here...
}

The member str1.length will have a value of 13 instead of 12, as str.value = Hello World!\0.

Whenever you're finished using a String, don't forget to str_free() it to prevent memory leaks!

str_free(&str1);

Reference

Please read SMARTSTR.H Reference.

Extra information

Thanks so much to all of our contributors.

All the code in this repository is licensed under the GNU Lesser General Public License version 3 or later. This library is meant to be distributed for non-commercial purposes, and neither this project's owner nor its contributors are responsible for the use anyone outside of it might give to the software provided and its assets.

About

Read-only; all PRs will be ignored!

Resources

License

Unknown, LGPL-3.0 licenses found

Licenses found

Unknown
LICENSE
LGPL-3.0
COPYING.LESSER

Stars

Watchers

Forks

Packages

No packages published

Languages