Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Library in C++ that implements strings operations

License

Notifications You must be signed in to change notification settings

eHonnef/string-operations-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String operations

Library in C++ that implements operations over the STL string.

Functions and files

[File]

The main file that contains all functions.

[Test file]

File that contains the test functions to check if everything is working.

Table of content

split


[Source]

Aux function for split

Templates:

  • Out, typename

Return type: void
Access: private

Arguments:

  • Type: std::string, Name: s
  • Type: char, Name: delim
  • Type: Out, Name: result

str_to_float


[Source]

Cast std::string val to float

Templates:

  • f, typename

Return type: f
Access: private

Arguments:

  • Type: std::string, Name: val

float_to_str


[Source]

Cast float val to std::string.

Templates:

  • f, typename

Return type: std::string
Access: private

Arguments:

  • Type: f, Name: val

isInt


[Source]

Checks if val is a integer.

Return type: bool
Access: public

Arguments:

  • Type: std::string, Name: val

isFloat


[Source]

Checks if val is any kind of float.

Return type: bool
Access: public

Arguments:

  • Type: std::string, Name: val

capitalize


[Source]

Capitalize the first char of str.

Return type: std::string
Access: public

Arguments:

  • Type: std::string, Name: str

check_regex_exp


[Source]

Creates a regex expression using the string exp and checks if there is a match in str. If it throws an exception (problably because your exp was wrong), put the function call in a try/catch and do something like: catch (std::exception &e) {print(e.what())}

Return type: bool
Access: public

Arguments:

  • Type: std::string, Name: str
  • Type: std::string, Name: exp

trim


[Source]

Returns the "trimmed" str (can be another char besides whitespace). E.g.: " trim me " -> "trim me".

Return type: std::string
Access: public

Arguments:

  • Type: std::string, Name: str
  • Type: std::string, Name: whitespace Default value: " "

split


[Source]

Returns a vector with the split string s spliting at delim char.

Return type: std::vectorstd::string
Access: public

Arguments:

  • Type: std::string, Name: s
  • Type: char, Name: delim Default value: ' '

find_full_words


[Source]

Checks if there is a full word in s.

Return type: bool
Access: public

Arguments:

  • Type: std::string, Name: s
  • Type: std::string, Name: word

find_replace_first


[Source]

Replace the first occurrence of string toReplace with replaceWith in a copy of s. Returns the replaced string, if not replaced it'll return the copy of s.

Return type: std::string
Access: public

Arguments:

  • Type: std::string, Name: s
  • Type: std::string, Name: toReplace
  • Type: std::string, Name: replaceWith

find_replace_all


[Source]

Replace all occurrence of string toReplace with replaceWith in a copy of s. Returns the replaced string, if not replaced it'll return the copy of s.

Return type: std::string
Access: public

Arguments:

  • Type: std::string, Name: s
  • Type: std::string, Name: toReplace
  • Type: std::string, Name: replaceWith

find_term


[Source]

Checks if the term is in s.

Return type: bool
Access: public

Arguments:

  • Type: std::string, Name: s
  • Type: std::string, Name: term

reduce


[Source]

Removes the whitespace (or another char) from str and fill the gap with fill. E.g.: " there is too much empty space" -> "there-is-too-much-empty-space" or "there is too much empty space".

Return type: std::string
Access: public

Arguments:

  • Type: std::string, Name: str
  • Type: std::string, Name: fill Default value: " "
  • Type: std::string, Name: whitespace Default value: " "

mismatch_string


[Source]

Removes the begin of a that matches b. Useful for handling paths. E.g.: "/this/is/a/path/to/something.txt" - "/this/is/a/path/" = "to/something.txt"

Return type: std::string
Access: public

Arguments:

  • Type: std::string, Name: a
  • Type: std::string, Name: b

vec_float_to_str


[Source]

Transforms a float (or double, or whatever float it is) vector float_v to a std::string vector.

Templates:

  • f, typename

Return type: std::vectorstd::string
Access: public

Arguments:

  • Type: std::vector, Name: float_v

vec_str_to_float


[Source]

Transforms a std::string vector str_v to a float (or double, or whatever float it is). You need to specify the return type, e.g.: vec_str_to_float<double>(string_vector)

Templates:

  • f, typename

Return type: std::vector
Access: public

Arguments:

  • Type: std::vectorstd::string, Name: str_v

indexOf


[Source]

Returns the index of first occurence of val inside of vec. If not found, returns -1.

Templates:

  • T, typename

Return type: int
Access: public

Arguments:

  • Type: std::vector, Name: vec
  • Type: T, Name: val

contains


[Source]

Uses indexOf to check if val is in vec.

Templates:

  • T, typename

Return type: bool
Access: public

Arguments:

  • Type: std::vector, Name: vec
  • Type: T, Name: val

print


[Source]

Python-like print.

Templates:

  • T, typename
  • TAIL, typename

Return type: void
Access: public

Arguments:

  • Type: T, Name: t
  • Type: TAIL..., Name: tail