Git Product home page Git Product logo

ericyao2013 / vstring Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cade-vs/vstring

0.0 1.0 0.0 320 KB

VSTRING is C++ string library. It provides dynamic strings and char* compatibility and also Perl-like arrays and hashes. [VSTRING 是一个C++字符串库,提供动态字符串,兼容 char* ,Perl 类数组和散列,正则表达式对象。]

Home Page: http://cade.datamax.bg/away/vstring/

License: GNU General Public License v2.0

Makefile 1.06% C 82.79% C++ 16.16%

vstring's Introduction

NAME

VSTRING is C++ string manipulation and handling library.

SYNOPSIS

#include "vstring.h"
#include "vstrlib.h"

VString str = "Hello";
str += " World";    // str is `Hello World' now
str_reverse( str ); // str is `dlroW olleH' now
str_low( str );     // lower case

VArray va = str_split( " +", str ); // array has `dlroW', `olleH'
                                    // " +" is Regexp
str_reverse( va[0] );
str_reverse( va[1] );

str = str_join( va, " " );  // str is back to "Hello World"

VTrie tr = va;

// tr[ "Hello" ] contains "World"

DESCRIPTION

VSTRING provides dynamic strings and char* compatibility and also Perl-like arrays, hashes and regexp objects.

The dynamic string object can be freely exchanged with standard char* type, so there is no need to change function calls nor the implementation when you change from char* to String (and vice versa). The main difference from other similar libs is that the dynamic string class has no visible methods (except operators) so you will use it as a plain char* but it will expand/shrink as needed.

REFERENCE

vstring.h and vstrlib.h files can be used as reference. This file contains brief introduction and some notes but for further API documentation check the .h files.

BASE char* AND VString FUNCTIONS NOTES

All functions for char* handling may overflow! If you need safe strings, use the same functions but with VString instead of char*.

Functions common for char* and VString:

str_set( str, "hello" );
str_mul( str, 4 );
str_replace( str, "o", " " );
str_left( dest_str, str, 4 );
str_up( dest_str );

In the examples above, str, dest_str and source_str may be either char* or VString.

VString CLASS NOTES

VString str = "hello";
str += " world";
if( str == "hello world") { ... }
int len = str_len( str );
str[3] = 'z'; // safe! even outside string boundaries

VArray CLASS NOTES

VArray va;

// append array elements
va.push( "element 1" );
va.push( str ); // i.e. VString
va.push( other_varray ); 
va.push( trie ); // see VTrie below

// take out the last element
VString str = va.pop()

// push elements at the beginning 
va.unshift( "element 1" );
va.unshift( str ); // i.e. VString
va.unshift( other_varray ); 
va.unshift( trie ); // see VTrie below

// take out the first element
VString str = va.shift();

va.reverse(); // reverse elements order
va.undef(); // remove all elements

VTrie CLASS NOTES

VTrie tr;

tr[ "hello"  ] = "world";
tr[ "number" ] = "12345";

VArray va = tr; // array is: hello world number 12345
                // however only key+value order is preserved!

tr.reverse(); // reverse keys <-> values
                
tr.undef(); // remove all keys

VRegexp CLASS NOTES

VRegexp re( "a([0-9]+)" ); // compiling new regexp

if( re.m( "tralala85." ) ) // match against compiled regexp
  res1 = re[1]; // re[1] returns `85'

if( re.m( "tralala85.", "(la)+" ) ) // match against new regexp pattern
  {
  str_all_matched   = re[0]; // `lala'
  str_first_capture = re[1]; // `la'
  }

FEEDBACK

If you find bug or have comment on library API, code or documentation text, please, contact me.

AUTHOR

VSTRING Library

Vladi Belperchinov-Shabanski "Cade"

[email protected] [email protected] [email protected] [email protected] http://cade.datamax.bg/away/vstring/

Distributed under the GPL license, see end of this file for full text!

NOTE: vstring is distributed standalone as well as a part from vslib/vfu: http://cade.datamax.bg/vfu/

vstring's People

Watchers

Eric 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.