All Projects → mahdavipanah → Stringplus

mahdavipanah / Stringplus

Licence: mit
Funny and minimal string library for C++ inspired by underscore.string

Programming Languages

cplusplus
227 projects

Projects that are alternatives of or similar to Stringplus

Str
A fast, solid and strong typed string manipulation library with multibyte support
Stars: ✭ 199 (+2742.86%)
Mutual labels:  library, string, string-manipulation
Validatetor
Android library for fast and simple string validation
Stars: ✭ 136 (+1842.86%)
Mutual labels:  library, string
Tinystr
A small ASCII-only bounded length string representation.
Stars: ✭ 48 (+585.71%)
Mutual labels:  library, string
node-red-contrib-string
Provides a string manipulation node with a chainable UI based on the concise and lightweight stringjs.com.
Stars: ✭ 15 (+114.29%)
Mutual labels:  string, string-manipulation
Util
A collection of useful utility functions
Stars: ✭ 201 (+2771.43%)
Mutual labels:  string, string-manipulation
Superstring.py
A fast and memory-optimized string library for heavy-text manipulation in Python
Stars: ✭ 231 (+3200%)
Mutual labels:  string, string-manipulation
vbml
Way to check, match and resist.
Stars: ✭ 27 (+285.71%)
Mutual labels:  string, string-manipulation
Strman Java
A Java 8 string manipulation library.
Stars: ✭ 1,362 (+19357.14%)
Mutual labels:  string, string-manipulation
normalize-text
📝 Provides a simple API to normalize texts, whitespaces, paragraphs & diacritics.
Stars: ✭ 54 (+671.43%)
Mutual labels:  string, string-manipulation
stringext
Extra string functions for OCaml
Stars: ✭ 20 (+185.71%)
Mutual labels:  string, string-manipulation
safe-string-interpolation
A type driven approach to string interpolation, aiming at consistent, secure, and only-human-readable logs and console outputs !
Stars: ✭ 14 (+100%)
Mutual labels:  string, string-manipulation
Voca rs
Voca_rs is the ultimate Rust string library inspired by Voca.js, string.py and Inflector, implemented as independent functions and on Foreign Types (String and str).
Stars: ✭ 167 (+2285.71%)
Mutual labels:  string, string-manipulation
Androidlibrary
Android library to reveal or obfuscate strings and assets at runtime
Stars: ✭ 162 (+2214.29%)
Mutual labels:  string, string-manipulation
Php Confusable Homoglyphs
A PHP port of https://github.com/vhf/confusable_homoglyphs
Stars: ✭ 27 (+285.71%)
Mutual labels:  library, string
Strtk
C++ String Toolkit Library
Stars: ✭ 113 (+1514.29%)
Mutual labels:  string, string-manipulation
Ustring
The Hoa\Ustring library.
Stars: ✭ 403 (+5657.14%)
Mutual labels:  library, string
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (+400%)
Mutual labels:  string, string-manipulation
Litestringbuilder
Alternative to the System.Text.StringBuilder C# class.
Stars: ✭ 48 (+585.71%)
Mutual labels:  string, string-manipulation
split-on-first
Split a string on the first occurrence of a given separator
Stars: ✭ 68 (+871.43%)
Mutual labels:  string, string-manipulation
Tiny Utf8
Unicode (UTF-8) capable std::string
Stars: ✭ 322 (+4500%)
Mutual labels:  string, string-manipulation

stringplus

The aim of this project is not to make a very complicated library. We are trying to make it as simple as possible. Simple but powerful. While underscore.string is a very awesome and professional javascript library for working with strings, we are trying to do things similar. With stringplus you can do a lot things to strings! and meanwhile we want the code to be very clean so everyone can read and contribute to it.

Usage

To use stringplus you have to include stringplus.h wherever you need it

#include "stringplus.h"

and then all the functionalities are available in the stringplus namespace.
If you don't want to use the namespace every time:

using namespace stringplus;

Then you have to compile stringplus.cc with your program. For example:

g++ -std=c++11 main.cc stringplus.cc

API

Individual functions

to_upper(string) => string

Replaces lower case alphabetical chars with upper case.

stringplus::to_upper("foo bar");
// => "FOO BAR"

to_lower(string) => string

Replaces upper case alphabetical chars with lower case.

stringplus::to_lower("FOO BAR");
// => "foo bar"

is_alpha(string) => bool

Returns true if all chars in the string are alphabetical.

stringplus::is_alpha("abcd");
// => true

stringplus::is_alpha("Abn4");
// => false

is_digit(string) => bool

Returns true if all chars in the string are digits.

stringplus::is_digit("1234");
// => true

stringplus::is_digit("34n4");
// => false

is_alpha_digit(string) => bool

Returns true if all chars in the string are digits or an uppercase or lowercase letter.

stringplus::is_alpha_digit("1234");
// => true

stringplus::is_alpha_digit("34n4");
// => true

stringplus::is_alpha_digit("34n[");
// => false

is_lower(string) => bool

Returns true if all alpha chars in the string are lowercases.

stringplus::is_lower("1234");
// => true

stringplus::is_lower("34n4");
// => true

stringplus::is_lower("34M");
// => false

is_upper(string) => bool

Returns true if all alpha chars in the string are uppercases.

stringplus::is_upper("1234");
// => true

stringplus::is_upper("34N4");
// => true

stringplus::is_upper("34n");
// => false

capitalize(string, [bool = false]) => string

Converts first letter of the string to uppercase. If true is passed as second argument the rest of the string will be converted to lower case.

stringplus::capitalize("abcd");
// => "Abcd"

stringplus::capitalize("aBCD");
// => "ABCD"

stringplus::capitalize("aBCD", true);
// => "Abcd"

decapitalize(string) => string

Converts first letter of the string to lowercase.

stringplus::decapitalize("ABCd");
// => "aBCD"

chop(string, int step) => std::vector<string>

Chops the string to a vector with the given step.

stringplus::chop("whitespace", 3);
// => ["whi", "tes", "pac", "e"]

clean(string) => string

Trim and replace multiple spaces with a single space.

stringplus::clean(" foo    bar   ");
// => "foo bar"

swap_case(string) => string

Returns a copy of the string in which all the case-based characters have had their case swapped.

stringplus::swap_case("hELLO");
// => "Hello"

reverse(string) => string

Return reversed string:

stringplus::reverse("Hello");
// => "olleH"

stringplus::reverse("12345");
// => "54321"

truncate(string, int, [string = "..."]) => string

Truncates the strings with the length greater than the given length with the given string.

stringplus::truncate("Hello world", 5);
// => "Hello..."

stringplus::truncate("Hello", 10);
// => "Hello"

stringplus::truncate("Hello world", 5, " read more");
// => "Hello read more"

surround(string, string) => string

Surrounds a string with another string.

stringplus::surround("foo", "bar");
// => "barfoobar"

repeat(string, int, [string = ""]) => string

Repeats a string count times, seperated by given string.

stringplus::repeat("foo", 3, "bar");
// => "foobarfoobarfoo"

####pad(string, int, [char = ' ', string = "left"]) => string pads the string with character until the total string length is equal to the passed length parameter. By default, pads on the left with the space char (" ").

stringplus::pad("1", 8);
// => "       1"

stringplus::pad("1", 8, "0");
// => "00000001"

stringplus::pad("1", 8, "0", "right");
// => "10000000"

stringplus::pad("1", 8, "0", "both");
// => "00001000"

lpad(string, int, [char]) => string

left-pad a string. Alias for pad(string, int, char, "left")

stringplus::lpad("1", 8, "0");
// => "00000001"

rpad(string, int, [char]) => string

right-pad a string. Alias for pad(string, int, char, "right")

stringplus::rpad("1", 8, "0");
// => "10000000"

lrpad(string, int, [char]) => string

left/right-pad a string. Alias for pad(string, int, char, "both")

stringplus::lrpad("1", 8, "0");
// => "00001000"

starts_with(string, string, [int = 0]) => bool

Checks whether the string begins with starts at position.

stringplus::starts_with("image.gif", "image");
// => true

stringplus::starts_with(".vimrc", "vim");
// => false

stringplus::starts_with(".vimrc", "vim", 1);
// => true

ends_with(string str, string, [int = -1]) => bool

Checks whether the string ends with ends at position (default: str.length()).

stringplus::ends_with("image.gif", "gif");
// => true

stringplus::ends_with("image.old.gif", "old");
// => false

stringplus::ends_with("image.old.gif", "old", 9);
// => true

join(string, vector<string>) => string

Joins strings together with given separator.

stringplus::join(" ", {"foo", "bar"});
// => "foo bar"

count(string, string) => int

Returns number of occurrences of substring in a string.

stringplus::count("Hello world", "l");
// => 3
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].