# LogDoctor: StringOps Namespace Reference

Loading...
Searching...
No Matches
StringOps Namespace Reference

StringOps. More...

## Functions

size_t | count (std::string_view str, std::string_view flag) noexcept
| Counts the occurrences of the given sequence in the given string.
bool | isNumeric (QStringView str) noexcept
| Checks whether a string only contains numeric characters.
std::string | strip (const std::string &str, const char chr) noexcept
| Strips the given character from both the left and the right side of a string.
std::string | strip (const std::string &str, const char *chars=" \n\t\b\r\v") noexcept
| Strips the given characters from both the left and the right side of a string.
std::string | lstrip (const std::string &str, const char chr) noexcept
| Strips the given character from the left side of a string.
std::string | lstrip (const std::string &str, const char *chars=" \n\t\b\r\v") noexcept
| Strips the given characters from the left side of a string.
std::string | rstrip (const std::string &str, const char chr) noexcept
| Strips the given character from the right side of a string.
std::string | rstrip (const std::string &str, const char *chars=" \n\t\b\r\v") noexcept
| Strips the given characters from the right side of a string.
std::string | lstripUntil (const std::string &str, const char delim, const bool inclusive=true, const bool consecutives=true) noexcept
| Strips everything from a string starting from the left side untill the delimiter is found (a.k.a. cut)
void | split (std::vector< std::string > &list, const std::string &target_str, const char separator='\n') noexcept
| Splits a string using a separator.
void | split (std::vector< std::string > &list, const std::string &target_str, std::string_view separator) noexcept
| Splits a string using a separator.
void | splitrip (std::vector< std::string > &list, const std::string &target_str, const char separator='\n', const char *strips=" \n\t\b\r\v") noexcept
| Splits a string and strips all the splitted items.
void | splitrip (std::vector< std::string > &list, const std::string &target_str, const char *separator, const char *strips=" \n\t\b\r\v") noexcept
| Splits a string and strips all the splitted items.
std::string | replace (std::string_view str, std::string_view target, std::string_view replace) noexcept
| Replaces all the occurrences of a sequence with another.
std::string | toUpper (std::string_view str) noexcept
| Converts a string to upper case.
std::string | toLower (std::string_view str) noexcept
| Converts a string to lower case.
size_t | count (std::string_view str, const char flag) noexcept
| Counts the occurrences of the given sequence in the given string.
bool | isNumeric (std::string_view str) noexcept
| Checks whether a string only contains numeric characters.
bool | isAlphabetic (std::string_view str) noexcept
| Checks whether a string only contains alphabetic characters.
bool | isAlnum (std::string_view str) noexcept
| Checks whether a string only contains alpha-numeric characters.
bool | isIP (std::string_view str) noexcept
| Checks whether a string contains only IPv4/IPv6 chars.
bool | startsWith (std::string_view str, const char flag) noexcept
| Checks if a string starts with the given sequence.
bool | startsWith (std::string_view str, std::string_view flag) noexcept
| Checks if a string starts with the given sequence.
bool | endsWith (std::string_view str, const char flag) noexcept
| Checks if a string ends with the given sequence.
bool | endsWith (std::string_view str, std::string_view flag) noexcept
| Checks if a string ends with the given sequence.
bool | contains (std::string_view str, std::string_view flag) noexcept
| Checks if a string contains the given sequence.

## Detailed Description

StringOps.

Utilities for the strings

## Function Documentation

## contains()

bool StringOps::contains | ( | std::string_view | str,
|  | std::string_view | flag )

inlinenoexcept

Checks if a string contains the given sequence.

Parameters

  str | The target string
  flag | The sequence to search for

Returns
  The result of the check

## count() [1/2]

size_t StringOps::count | ( | std::string_view | str,
|  | const char | flag )

inlinenoexcept

Counts the occurrences of the given sequence in the given string.

Parameters

  str | The target string
  flag | The character to find

Returns
  The number of occurrences

## count() [2/2]

size_t StringOps::count | ( | std::string_view | str,
|  | std::string_view | flag )

noexcept

Counts the occurrences of the given sequence in the given string.

Parameters

  str | The target string
  flag | The string to find

Returns
  The number of occurrences

## endsWith() [1/2]

bool StringOps::endsWith | ( | std::string_view | str,
|  | const char | flag )

inlinenoexcept

Checks if a string ends with the given sequence.

Parameters

  str | The target string
  flag | The character to search for

Returns
  The result of the check

## endsWith() [2/2]

bool StringOps::endsWith | ( | std::string_view | str,
|  | std::string_view | flag )

inlinenoexcept

Checks if a string ends with the given sequence.

Passing an empty flag ends in a false positive

Parameters

  str | The target string
  flag | The sequence to search for

Returns
  The result of the check

## isAlnum()

bool StringOps::isAlnum | ( | std::string_view | str | ) |

inlinenoexcept

Checks whether a string only contains alpha-numeric characters.

Parameters

  str | The target string

Returns
  The result of the check

## isAlphabetic()

bool StringOps::isAlphabetic | ( | std::string_view | str | ) |

inlinenoexcept

Checks whether a string only contains alphabetic characters.

Parameters

  str | The target string

Returns
  The result of the check

## isIP()

bool StringOps::isIP | ( | std::string_view | str | ) |

inlinenoexcept

Checks whether a string contains only IPv4/IPv6 chars.

This method doesn't check if the IP could be actually valid, since this is beyond its purpose

Parameters

  str | The target string

Returns
  The result of the check

## isNumeric() [1/2]

bool StringOps::isNumeric | ( | QStringView | str | ) |

noexcept

Checks whether a string only contains numeric characters.

Parameters

  str | The target string

Returns
  The result of the check

## isNumeric() [2/2]

bool StringOps::isNumeric | ( | std::string_view | str | ) |

inlinenoexcept

Checks whether a string only contains numeric characters.

Parameters

  str | The target string

Returns
  The result of the check

## lstrip() [1/2]

std::string StringOps::lstrip | ( | const std::string & | str,
|  | const char * | chars = " \n\t\b\r\v" )

noexcept

Strips the given characters from the left side of a string.

Parameters

  str | The target string
  chars | The characters to strip away

Returns
  The result string

## lstrip() [2/2]

std::string StringOps::lstrip | ( | const std::string & | str,
|  | const char | chr )

noexcept

Strips the given character from the left side of a string.

Parameters

  str | The target string
  chr | The character to strip away

Returns
  The result string

## lstripUntil()

std::string StringOps::lstripUntil | ( | const std::string & | str,
|  | const char | delim,
|  | const bool | inclusive = true,
|  | const bool | consecutives = true )

noexcept

Strips everything from a string starting from the left side untill the delimiter is found (a.k.a. cut)

Parameters

  str | The target string
  delim | The delimiter
  inclusive | Whether to also strip the delimiter or not
  consecutives | Whether to strip all the occurrences of the delimiter if they're consecutive, only applies if inclusive

Returns
  The result string

## replace()

std::string StringOps::replace | ( | std::string_view | str,
|  | std::string_view | target,
|  | std::string_view | replace )

noexcept

Replaces all the occurrences of a sequence with another.

Parameters

  str | The target string
  target | The sequence which will be replaced
  replace | The sequence to be used to replace the target

Returns
  The result string

## rstrip() [1/2]

std::string StringOps::rstrip | ( | const std::string & | str,
|  | const char * | chars = " \n\t\b\r\v" )

noexcept

Strips the given characters from the right side of a string.

Parameters

  str | The target string
  chars | The characters to strip away

Returns
  The result string

## rstrip() [2/2]

std::string StringOps::rstrip | ( | const std::string & | str,
|  | const char | chr )

noexcept

Strips the given character from the right side of a string.

Parameters

  str | The target string
  chr | The character to strip away

Returns
  The result string

## split() [1/2]

void StringOps::split | ( | std::vector< std::string > & | list,
|  | const std::string & | target_str,
|  | const char | separator = '\n' )

noexcept

Splits a string using a separator.

Parameters

  list | Will hold the splitted content
  target_str | The target string
  separator | The character to use as separator

## split() [2/2]

void StringOps::split | ( | std::vector< std::string > & | list,
|  | const std::string & | target_str,
|  | std::string_view | separator )

noexcept

Splits a string using a separator.

Parameters

  list | Will hold the splitted content
  target_str | The target string
  separator | The sequence to use as separator

## splitrip() [1/2]

void StringOps::splitrip | ( | std::vector< std::string > & | list,
|  | const std::string & | target_str,
|  | const char * | separator,
|  | const char * | strips = " \n\t\b\r\v" )

noexcept

Splits a string and strips all the splitted items.

Parameters

  list | Will hold the splitted content
  target_str | The target string
  separator | The sequence to use as separator
  strip | The characters to strip away

## splitrip() [2/2]

void StringOps::splitrip | ( | std::vector< std::string > & | list,
|  | const std::string & | target_str,
|  | const char | separator = '\n',
|  | const char * | strips = " \n\t\b\r\v" )

noexcept

Splits a string and strips all the splitted items.

Parameters

  list | Will hold the splitted content
  target_str | The target string
  separator | The sequence to use as separator
  strip | The characters to strip away

## startsWith() [1/2]

bool StringOps::startsWith | ( | std::string_view | str,
|  | const char | flag )

inlinenoexcept

Checks if a string starts with the given sequence.

Parameters

  str | The target string
  flag | The character to search for

Returns
  The result of the check

## startsWith() [2/2]

bool StringOps::startsWith | ( | std::string_view | str,
|  | std::string_view | flag )

inlinenoexcept

Checks if a string starts with the given sequence.

Passing an empty flag ends in a false positive

Parameters

  str | The target string
  flag | The sequence to search for

Returns
  The result of the check

## strip() [1/2]

std::string StringOps::strip | ( | const std::string & | str,
|  | const char * | chars = " \n\t\b\r\v" )

noexcept

Strips the given characters from both the left and the right side of a string.

Parameters

  str | The target string
  chars | The characters to strip away

Returns
  The result string

## strip() [2/2]

std::string StringOps::strip | ( | const std::string & | str,
|  | const char | chr )

noexcept

Strips the given character from both the left and the right side of a string.

Parameters

  str | The target string
  chr | The character to strip away

Returns
  The result string

## toLower()

std::string StringOps::toLower | ( | std::string_view | str | ) |

noexcept

Converts a string to lower case.

Parameters

  str | The target string

Returns
  The result string

## toUpper()

std::string StringOps::toUpper | ( | std::string_view | str | ) |

noexcept

Converts a string to upper case.

Parameters

  str | The target string

Returns
  The result string