common_util
Loading...
Searching...
No Matches
Typedefs | Functions
strutil.h File Reference

Common string utilities. More...

#include <string>
#include <vector>

Go to the source code of this file.

Typedefs

using cutl::strvec = std::vector<std::string>
 The type of vector strings used in this library.
 

Functions

std::string cutl::to_upper (const std::string &str)
 Convert a string to upper case.
 
std::string cutl::to_lower (const std::string &str)
 Convert a string to lower case.
 
std::string cutl::lstrip (const std::string &str)
 Remove leading whitespaces from a string.
 
std::string cutl::rstrip (const std::string &str)
 Remove trailing whitespaces from a string.
 
std::string cutl::strip (const std::string &str)
 Remove leading and trailing whitespaces from a string.
 
bool cutl::starts_with (const std::string &str, const std::string &start, bool ignoreCase=false)
 Check if a string starts with a given substring.
 
bool cutl::ends_with (const std::string &str, const std::string &end, bool ignoreCase=false)
 Check if a string ends with a given substring.
 
strvec cutl::split (const std::string &str, const std::string &separator)
 Split a string into a vector of substrings using a given separator.
 
std::string cutl::join (const strvec &strlist, const std::string &separator="")
 Join a vector of strings into a single string using a given separator.
 
std::string cutl::desensitizing (const std::string &str)
 Desensitizing a string by replacing some characters with '*'.
 

Detailed Description

Common string utilities.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations.

Author
spencer.luo
Date
2024-05-13

Function Documentation

◆ desensitizing()

std::string cutl::desensitizing ( const std::string & str)

Desensitizing a string by replacing some characters with '*'.

Parameters
strthe string to be desensitized.
Returns
std::string the desensitized string.

◆ ends_with()

bool cutl::ends_with ( const std::string & str,
const std::string & end,
bool ignoreCase = false )

Check if a string ends with a given substring.

Parameters
strthe string to be checked.
endthe substring to be checked.
ignoreCasewhether to ignore case when comparing, default is false.
Returns
true if the string ends with the substring, false otherwise.

◆ join()

std::string cutl::join ( const strvec & strlist,
const std::string & separator = "" )

Join a vector of strings into a single string using a given separator.

Parameters
strlistthe vector of strings to be joined.
separatorthe separator to join the strings.
Returns
std::string the joined string.

◆ lstrip()

std::string cutl::lstrip ( const std::string & str)

Remove leading whitespaces from a string.

Parameters
strthe string to be stripped.
Returns
std::string the stripped string.

◆ rstrip()

std::string cutl::rstrip ( const std::string & str)

Remove trailing whitespaces from a string.

Parameters
strthe string to be stripped.
Returns
std::string the stripped string.

◆ split()

strvec cutl::split ( const std::string & str,
const std::string & separator )

Split a string into a vector of substrings using a given separator.

Parameters
strthe string to be split.
separatorthe separator to split the string.
Returns
strvec the vector of substrings.

◆ starts_with()

bool cutl::starts_with ( const std::string & str,
const std::string & start,
bool ignoreCase = false )

Check if a string starts with a given substring.

Parameters
strthe string to be checked.
startthe substring to be checked.
ignoreCasewhether to ignore case when comparing, default is false.
Returns
true if the string starts with the substring, false otherwise.

◆ strip()

std::string cutl::strip ( const std::string & str)

Remove leading and trailing whitespaces from a string.

Parameters
strthe string to be stripped.
Returns
std::string the stripped string.

◆ to_lower()

std::string cutl::to_lower ( const std::string & str)

Convert a string to lower case.

Parameters
strthe string to be converted.
Returns
std::string the converted string.

◆ to_upper()

std::string cutl::to_upper ( const std::string & str)

Convert a string to upper case.

Parameters
strthe string to be converted.
Returns
std::string the converted string.