Coder Social home page Coder Social logo

vstr's Introduction

vstr/vstring - vector string

simple dynamic strings for c
The library can be used header-only by moving vstr.h to a directory in your program.

vstr contains just about all the functions you'll need.
In total there are 128 functions ranging from searching algorithms to advanced formatting
to number/float to string conversation.

what is the difference between vstr and vstring?

vstr and vstring are separated by different files, but can be used together in one project.
vstr is designed like c-strings and is compatible with them. It does not store the length of the string and must
go through the entire string to determine it's length.

+-------------------------------+------------------+
| String Data (built like vstr) | Null Termination |
+-------------------------------+------------------+

vstring is a string of known length. The length is stored in the 4 bytes (unsigned int) before
the pointer that is returned to the user.
Since the length of the string is always known, vstring is faster than vstr, but requires more memory.

+---------------+----------------------------------+------------------+
| String Length | String Data (designed like vstr) | Null Termination |
+---------------+----------------------------------+------------------+
                |
             pointer

how to decide between vstr and vstring

To decide between vstr and vstring some things have to be considered:

vstr vstring
requires less memory requires more memory than vstr
has to query the whole string
to obtain it's length
length is always known and can
be accessed very fast
fast implementation takes time to implement
made for small strings and few memory made for big applications with long strings

For fast implementation it's better to use vstr. For projects that work
with long strings, the speed of the application is better with vstring.

creating new string

str string = vstr_alloc("abc"); // new string from const char*
str string = vstr_alloc_len("abc", 3); // new string from const char* with length 3
str string = vstr_alloc_empty(); // new empty string

concatenating strings

str string1 = vstr_alloc("abc"); // new string with content "abc" and length 3
str string2 = vstr_alloc("def"); // new string with content "def" and length 3

vstr_cat(&string1, string2); // @string1 needs to be passed as reference here

printf("%s\n", string1); // prints: "abcdef"

utility functions

vstr_len(string) - returns the length of @string
vstr_equ(string1, string2) - returns true if @string1 and @string2 are identical
vstr_cont_s(string1, string2) - returns true if @string1 contains @string2

vstr_find_fs(string1, string2) - returns the index of the first occurence of @string2 in @string1
vstr_find_ls(string1, string2) - returns the index of the last occurence of @string2 in @string1

vstr_upper(string) - makes @string uppercase
vstr_lower(string) - makes @string lowercase

vstr's People

Contributors

cally72jhb avatar

Watchers

 avatar

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.