LLVM 22.0.0git
StringExtras.h File Reference

This file contains some functions that are useful when dealing with strings. More...

#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Compiler.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <string>
#include <utility>

Go to the source code of this file.

Classes

class  llvm::ListSeparator
 A helper class to return the specified delimiter string after the first invocation of operator StringRef(). Used to generate a comma-separated list from a loop like so: More...
class  llvm::SplittingIterator
 A forward iterator over partitions of string over a separator. More...

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
namespace  llvm::detail
 These are wrappers over isa* function that allow them to be used in generic algorithms such as llvm:all_of, llvm::none_of, etc.

Functions

char llvm::hexdigit (unsigned X, bool LowerCase=false)
 hexdigit - Return the hexadecimal character for the given number X (which should be less than 16).
std::vector< StringRefllvm::toStringRefArray (const char *const *Strings)
 Given an array of c-style strings terminated by a null pointer, construct a vector of StringRefs representing the same strings without the terminating null string.
StringRef llvm::toStringRef (bool B)
 Construct a string ref from a boolean.
StringRef llvm::toStringRef (ArrayRef< uint8_t > Input)
 Construct a string ref from an array ref of unsigned chars.
StringRef llvm::toStringRef (ArrayRef< char > Input)
template<class CharT = uint8_t>
ArrayRef< CharT > llvm::arrayRefFromStringRef (StringRef Input)
 Construct a string ref from an array ref of unsigned chars.
unsigned llvm::hexDigitValue (char C)
 Interpret the given character C as a hexadecimal digit and return its value.
bool llvm::isDigit (char C)
 Checks if character C is one of the 10 decimal digits.
bool llvm::isHexDigit (char C)
 Checks if character C is a hexadecimal numeric character.
bool llvm::isLower (char C)
 Checks if character C is a lowercase letter as classified by "C" locale.
bool llvm::isUpper (char C)
 Checks if character C is a uppercase letter as classified by "C" locale.
bool llvm::isAlpha (char C)
 Checks if character C is a valid letter as classified by "C" locale.
bool llvm::isAlnum (char C)
 Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classified by "C" locale.
bool llvm::isASCII (char C)
 Checks whether character C is valid ASCII (high bit is zero).
bool llvm::isASCII (llvm::StringRef S)
 Checks whether all characters in S are ASCII.
bool llvm::isPrint (char C)
 Checks whether character C is printable.
bool llvm::isPunct (char C)
 Checks whether character C is a punctuation character.
bool llvm::isSpace (char C)
 Checks whether character C is whitespace in the "C" locale.
char llvm::toLower (char x)
 Returns the corresponding lowercase character if x is uppercase.
char llvm::toUpper (char x)
 Returns the corresponding uppercase character if x is lowercase.
std::string llvm::utohexstr (uint64_t X, bool LowerCase=false, unsigned Width=0)
void llvm::toHex (ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
 Convert buffer Input to its hexadecimal representation. The returned string is double the size of Input.
std::string llvm::toHex (ArrayRef< uint8_t > Input, bool LowerCase=false)
std::string llvm::toHex (StringRef Input, bool LowerCase=false)
bool llvm::tryGetHexFromNibbles (char MSB, char LSB, uint8_t &Hex)
 Store the binary representation of the two provided values, MSB and LSB, that make up the nibbles of a hexadecimal digit. If MSB or LSB do not correspond to proper nibbles of a hexadecimal digit, this method returns false. Otherwise, returns true.
uint8_t llvm::hexFromNibbles (char MSB, char LSB)
 Return the binary representation of the two provided values, MSB and LSB, that make up the nibbles of a hexadecimal digit.
bool llvm::tryGetFromHex (StringRef Input, std::string &Output)
 Convert hexadecimal string Input to its binary representation and store the result in Output. Returns true if the binary representation could be converted from the hexadecimal string. Returns false if Input contains non-hexadecimal digits. The output string is half the size of Input.
std::string llvm::fromHex (StringRef Input)
 Convert hexadecimal string Input to its binary representation. The return string is half the size of Input.
template<typename N>
bool llvm::to_integer (StringRef S, N &Num, unsigned Base=0)
 Convert the string S to an integer of the specified type using the radix Base. If Base is 0, auto-detects the radix. Returns true if the number was successfully converted, false otherwise.
template<typename N>
bool llvm::detail::to_float (const Twine &T, N &Num, N(*StrTo)(const char *, char **))
bool llvm::to_float (const Twine &T, float &Num)
bool llvm::to_float (const Twine &T, double &Num)
bool llvm::to_float (const Twine &T, long double &Num)
std::string llvm::utostr (uint64_t X, bool isNeg=false)
std::string llvm::itostr (int64_t X)
std::string llvm::toString (const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
std::string llvm::toString (const APSInt &I, unsigned Radix)
LLVM_ABI StringRef::size_type llvm::StrInStrNoCase (StringRef s1, StringRef s2)
 StrInStrNoCase - Portable version of strcasestr. Locates the first occurrence of string 's1' in string 's2', ignoring case. Returns the offset of s2 in s1 or npos if s2 cannot be found.
LLVM_ABI std::pair< StringRef, StringRefllvm::getToken (StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
 getToken - This function extracts one token from source, ignoring any leading characters that appear in the Delimiters string, and ending the token at any of the characters that appear in the Delimiters string. If there are no tokens in the source string, an empty string is returned. The function returns a pair containing the extracted token and the remaining tail string.
LLVM_ABI void llvm::SplitString (StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
 SplitString - Split up the specified string according to the specified delimiters, appending the result fragments to the output list.
StringRef llvm::getOrdinalSuffix (unsigned Val)
 Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
LLVM_ABI void llvm::printEscapedString (StringRef Name, raw_ostream &Out)
 Print each character of the specified string, escaping it if it is not printable or if it is an escape char.
LLVM_ABI void llvm::printHTMLEscaped (StringRef String, raw_ostream &Out)
 Print each character of the specified string, escaping HTML special characters.
LLVM_ABI void llvm::printLowerCase (StringRef String, raw_ostream &Out)
 printLowerCase - Print each character as lowercase if it is uppercase.
LLVM_ABI std::string llvm::convertToSnakeFromCamelCase (StringRef input)
 Converts a string from camel-case to snake-case by replacing all uppercase letters with '_' followed by the letter in lowercase, except if the uppercase letter is the first character of the string.
LLVM_ABI std::string llvm::convertToCamelFromSnakeCase (StringRef input, bool capitalizeFirst=false)
 Converts a string from snake-case to camel-case by replacing all occurrences of '_' followed by a lowercase letter with the letter in uppercase. Optionally allow capitalization of the first letter (if it is a lowercase letter)
template<typename IteratorT>
std::string llvm::detail::join_impl (IteratorT Begin, IteratorT End, StringRef Separator, std::input_iterator_tag)
template<typename IteratorT>
std::string llvm::detail::join_impl (IteratorT Begin, IteratorT End, StringRef Separator, std::forward_iterator_tag)
template<typename Sep>
void llvm::detail::join_items_impl (std::string &Result, Sep Separator)
template<typename Sep, typename Arg>
void llvm::detail::join_items_impl (std::string &Result, Sep Separator, const Arg &Item)
template<typename Sep, typename Arg1, typename... Args>
void llvm::detail::join_items_impl (std::string &Result, Sep Separator, const Arg1 &A1, Args &&... Items)
size_t llvm::detail::join_one_item_size (char)
size_t llvm::detail::join_one_item_size (const char *S)
template<typename T>
size_t llvm::detail::join_one_item_size (const T &Str)
template<typename... Args>
size_t llvm::detail::join_items_size (Args &&...Items)
template<typename IteratorT>
std::string llvm::join (IteratorT Begin, IteratorT End, StringRef Separator)
 Joins the strings in the range [Begin, End), adding Separator between the elements.
template<typename Range>
std::string llvm::join (Range &&R, StringRef Separator)
 Joins the strings in the range [R.begin(), R.end()), adding Separator between the elements.
template<typename Sep, typename... Args>
std::string llvm::join_items (Sep Separator, Args &&... Items)
 Joins the strings in the parameter pack Items, adding Separator between the elements. All arguments must be implicitly convertible to std::string, or there should be an overload of std::string::operator+=() that accepts the argument explicitly.
iterator_range< SplittingIteratorllvm::split (StringRef Str, StringRef Separator)
 Split the specified string over a separator and return a range-compatible iterable over its partitions. Used to permit conveniently iterating over separated strings like so:
iterator_range< SplittingIteratorllvm::split (StringRef Str, char Separator)

Detailed Description

This file contains some functions that are useful when dealing with strings.

Definition in file StringExtras.h.