Giter Club home page Giter Club logo

zstring's Introduction

About zString

zString is a C library providing slightly different functionality than the standard library string processing functions.

zString does not aim to replace standard library string functions, rather introduces new methods with different capabilities (such as zstrtok())

zString is developed by Fehmi Noyan ISI

Using zString

Just include zstring.h in your source file and make sure all the header files are in your include path. For instance, for clang ang gcc you can use -I option to add a directory into your include path.

Unit tests

In order to build unit tests, you need to checkout Unity test suite and have cmake installed on your system.

~ % git clone https://github.com/fnoyanisi/zString.git
~ % cd zString
~/zString % ls
CMakeLists.txt	LICENSE		README.adoc	src		test
~/zString % git clone https://github.com/ThrowTheSwitch/Unity.git unity
~/zString % ls
CMakeLists.txt	README.adoc	test
LICENSE		src		unity
~/zString % mkdir build
~/zString % cd build
~/zString/build % cmake -DBUILD_TESTS=yes ..
~/zString/build % cmake --build .
~/zString/build %

Version History

  • version 1.9 - (Dec 2019)

    • added Unity test suite for unit tests

    • using standard library functions

    • changed function and header file names

    • added doxygen documentation

    • removed zstrtok_q() function

  • version 1.8.3 - (Aug 2018)

    • minor changes to improve run time

    • zstrtrm() reimplemented by using zstrtrm_l() and zstrin_rtrim()

  • version 1.8.2 - (July 2018)

    • gitignore file added

    • several optimizations to reduce the run time

    • some style changes (based on style(9) of FreeBSD)

  • version 1.8.1 - (Jan 2017)

    • Fixed typos in comments and README file

    • LICENSE file added to the repo

    • License for zrmvchr.h has been updated as 2-Clause BSD License

    • Changes in version 1.8.1 submitted by GitHub user tbeu

  • version 1.8 - (Oct 2016)

    • trim family functions are isspace(3) compatible

    • added input validation checks for most of the functions

  • version 1.7 - (Oct 2016)

    • Used const char* instead of char* where possible

    • performed a lint(1) check and cleared discrepancies

  • version 1.6 - (Feb 2016)

    • Library is licensed with 2-Clause BSD License

    • zstrtrm() added

    • zstrtrm_l() added

    • zstrtrm_r() added

  • version 1.5 - (Feb 2016)

    • zstrtok_d() added

    • zrepchr() added

    • zrepstr() added

  • version 1.4 - (Jan 2016)

    • Updated zstrchr() to make the library compatible with llvm/clang

  • version 1.3

    • Bug fixes

  • version 1.2

    • Performance improvements for zrmvchr()

  • version 1.1

    • Additions

  • version 1.0 - (Nov 2012)

    • First version

Functions and Usage

It is enough to include zstring.h in your code. Alternatively, any header file can be included separately in order to use the function defined in it.

Refer the individual header file for the function to get more details on the function usage and arguments.

zstrchr(char *token, char s)

Searches for character s in string token.

zrmvchr(char *str,char *bad)

Removes characters contained in string bad, from string str. Each character in bad is searched separately.

zstrtok(char *str, const char *delim)

An alternative to standard library’s strtok() function that is also capable of handling successive delimiters.

zrepchr(char *str, char x, char y)

Replaces every occurrence of character x with character y within string str.

zrepstr(char *str, char *x, char *y)

Replaces every occurrence of string x with string y within string str.

zstrtrm(char *str)

Trims leading and trailing white-space characters from the character string str.

zstrtrm_l(char *str)

Trims leading white-space characters from the character string str.

zstrtrm_r(char *str)

Trims trailing white-space characters from the character string str.

License

zString can be distributed, modified and used under the terms of 2-clause BSD license.

zstring's People

Contributors

fnoyanisi avatar tbeu avatar

Stargazers

Fernando Basso avatar ayushtripathy avatar  avatar Amoh Gyebi Ampofo avatar Karuna Kiran Bhadra avatar  avatar Blake Pell avatar Daniel Luque avatar Hector Garcia avatar hyperbola avatar Cycatz avatar  avatar Carlos avatar shaco avatar Daniel Cascais avatar Halil Arslan avatar Cem Demirkartal avatar Gary Renes avatar SJ avatar Colin Luoma avatar krychu avatar Danilo Nery avatar Elliot Mason avatar Erkan Güzeler avatar DrDevinRX avatar Ashok Bakthavathsalam avatar Ionut Stoica avatar Anton Sysoev avatar Oz Tiram avatar Benjamin DeCamp avatar

Watchers

 avatar Hoa Thiên Vũ avatar

Forkers

mystuffs

zstring's Issues

Thread-safe strtok variants

Thread-safe variants of both strtok implementations (that do not rely on static variables) are interesting. See strtok_r (on POSIX) or strtok_s (the Win-specific one with three arguments) for maintaining the context between successive calls.

If the replacement string size is not equal to the needle size zrepstr overwrites other charecters

Hello,

If the replacement string size (y) is not equal to the needle size (x) zrepstr(...) function overwrites other characters.

For example,

#include <stdio.h>
#include <string.h>

#include "zrepstr.h"

int main()
{
    char str[50] = {0};

    snprintf(str, sizeof(str), "My simple text message");
    zrepstr(str, "text", "more than text");
    fprintf(stdout, "%s\n", str);
}

Where "more than text" overwrite the "message" string and it becomes something like this, "My simple more than te".

Add license file

  • Add a license file to the repo
  • zstring_remove_chr.h seems to have Original BSD 4-Clause license wheras all others are Simplified BSD 2-Clause.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.