Cppcheck
Classes | Namespaces | Functions
utils.h File Reference
#include "config.h"
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <initializer_list>
#include <limits>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>

Go to the source code of this file.

Classes

struct  SelectMapKeys
 
struct  SelectMapValues
 
struct  OnExit
 
struct  EnumClassHash
 

Namespaces

 cppcheck
 

Functions

template<class Range , class T >
bool contains (const Range &r, const T &x)
 
template<class T >
bool contains (const std::initializer_list< T > &r, const T &x)
 
template<class T , class U >
bool contains (const std::initializer_list< T > &r, const U &x)
 
template<class T , class ... Ts>
std::array< T, sizeof...(Ts)+1 > makeArray (T x, Ts... xs)
 
bool startsWith (const std::string &str, const char start[], std::size_t startlen)
 
template<std::size_t N>
bool startsWith (const std::string &str, const char(&start)[N])
 
bool startsWith (const std::string &str, const std::string &start)
 
bool endsWith (const std::string &str, char c)
 
bool endsWith (const std::string &str, const char end[], std::size_t endlen)
 
template<std::size_t N>
bool endsWith (const std::string &str, const char(&end)[N])
 
static bool isPrefixStringCharLiteral (const std::string &str, char q, const std::string &p)
 
static bool isStringCharLiteral (const std::string &str, char q)
 
static bool isStringLiteral (const std::string &str)
 
static bool isCharLiteral (const std::string &str)
 
static std::string getStringCharLiteral (const std::string &str, char q)
 
static std::string getStringLiteral (const std::string &str)
 
static std::string getCharLiteral (const std::string &str)
 
static const char * getOrdinalText (int i)
 
CPPCHECKLIB int caseInsensitiveStringCompare (const std::string &lhs, const std::string &rhs)
 
CPPCHECKLIB bool isValidGlobPattern (const std::string &pattern)
 
CPPCHECKLIB bool matchglob (const std::string &pattern, const std::string &name)
 
CPPCHECKLIB bool matchglobs (const std::vector< std::string > &patterns, const std::string &name)
 
CPPCHECKLIB void strTolower (std::string &str)
 
template<typename T , typename std::enable_if< std::is_signed< T >::value, bool >::type = true>
bool strToInt (const std::string &str, T &num, std::string *err=nullptr)
 
template<typename T >
strToInt (const std::string &str)
 
template<typename T , int size>
std::size_t getArrayLength (const T(&)[size])
 Simple helper function: More...
 
static std::string id_string_i (std::uintptr_t l)
 get id string. More...
 
static std::string id_string (const void *p)
 
static const char * bool_to_string (bool b)
 
NORETURN void cppcheck::unreachable ()
 
template<typename T >
static T * empty_if_null (T *p)
 

Function Documentation

◆ bool_to_string()

static const char* bool_to_string ( bool  b)
inlinestatic

◆ caseInsensitiveStringCompare()

CPPCHECKLIB int caseInsensitiveStringCompare ( const std::string &  lhs,
const std::string &  rhs 
)

Definition at line 28 of file utils.cpp.

Referenced by cppcheck::stricmp::operator()(), and Path::sameFileName().

◆ contains() [1/3]

template<class Range , class T >
bool contains ( const Range &  r,
const T &  x 
)

◆ contains() [2/3]

template<class T >
bool contains ( const std::initializer_list< T > &  r,
const T &  x 
)

Definition at line 68 of file utils.h.

◆ contains() [3/3]

template<class T , class U >
bool contains ( const std::initializer_list< T > &  r,
const U &  x 
)

Definition at line 74 of file utils.h.

◆ empty_if_null()

template<typename T >
static T* empty_if_null ( T *  p)
inlinestatic

Definition at line 365 of file utils.h.

Referenced by CmdLineParser::parseFromArgs().

◆ endsWith() [1/3]

bool endsWith ( const std::string &  str,
char  c 
)
inline

◆ endsWith() [2/3]

bool endsWith ( const std::string &  str,
const char  end[],
std::size_t  endlen 
)
inline

Definition at line 115 of file utils.h.

◆ endsWith() [3/3]

template<std::size_t N>
bool endsWith ( const std::string &  str,
const char(&)  end[N] 
)

Definition at line 121 of file utils.h.

References endsWith().

◆ getArrayLength()

template<typename T , int size>
std::size_t getArrayLength ( const   T(&)[size])

Simple helper function:

Returns
size of array

Definition at line 296 of file utils.h.

◆ getCharLiteral()

static std::string getCharLiteral ( const std::string &  str)
inlinestatic

Definition at line 182 of file utils.h.

References getStringCharLiteral(), and isCharLiteral().

Referenced by CheckString::incorrectStringBooleanError().

◆ getOrdinalText()

static const char* getOrdinalText ( int  i)
inlinestatic

◆ getStringCharLiteral()

static std::string getStringCharLiteral ( const std::string &  str,
char  q 
)
inlinestatic

Definition at line 169 of file utils.h.

Referenced by getCharLiteral(), and getStringLiteral().

◆ getStringLiteral()

static std::string getStringLiteral ( const std::string &  str)
inlinestatic

◆ id_string()

static std::string id_string ( const void *  p)
inlinestatic

◆ id_string_i()

static std::string id_string_i ( std::uintptr_t  l)
inlinestatic

get id string.

i.e. for dump files it will be a hexadecimal output.

Definition at line 305 of file utils.h.

Referenced by id_string().

◆ isCharLiteral()

static bool isCharLiteral ( const std::string &  str)
inlinestatic

◆ isPrefixStringCharLiteral()

static bool isPrefixStringCharLiteral ( const std::string &  str,
char  q,
const std::string &  p 
)
inlinestatic

◆ isStringCharLiteral()

static bool isStringCharLiteral ( const std::string &  str,
char  q 
)
inlinestatic

Definition at line 147 of file utils.h.

References endsWith().

Referenced by isCharLiteral(), and isStringLiteral().

◆ isStringLiteral()

static bool isStringLiteral ( const std::string &  str)
inlinestatic

◆ isValidGlobPattern()

CPPCHECKLIB bool isValidGlobPattern ( const std::string &  pattern)

Definition at line 41 of file utils.cpp.

Referenced by SuppressionList::addSuppression(), and ImportProject::ignorePaths().

◆ makeArray()

template<class T , class ... Ts>
std::array<T, sizeof...(Ts) + 1> makeArray ( x,
Ts...  xs 
)
inline

Definition at line 80 of file utils.h.

Referenced by valueFlowImpossibleValues().

◆ matchglob()

CPPCHECKLIB bool matchglob ( const std::string &  pattern,
const std::string &  name 
)

◆ matchglobs()

CPPCHECKLIB bool matchglobs ( const std::vector< std::string > &  patterns,
const std::string &  name 
)

Definition at line 118 of file utils.cpp.

References matchglob().

Referenced by CmdLineParser::fillSettingsFromArgs(), and ImportProject::importVcxproj().

◆ startsWith() [1/3]

bool startsWith ( const std::string &  str,
const char  start[],
std::size_t  startlen 
)
inline

◆ startsWith() [2/3]

template<std::size_t N>
bool startsWith ( const std::string &  str,
const char(&)  start[N] 
)

Definition at line 100 of file utils.h.

References startsWith().

◆ startsWith() [3/3]

bool startsWith ( const std::string &  str,
const std::string &  start 
)
inline

Definition at line 105 of file utils.h.

References startsWith().

◆ strToInt() [1/2]

template<typename T >
T strToInt ( const std::string &  str)

Definition at line 281 of file utils.h.

References strToInt().

◆ strToInt() [2/2]

template<typename T , typename std::enable_if< std::is_signed< T >::value, bool >::type = true>
bool strToInt ( const std::string &  str,
T &  num,
std::string *  err = nullptr 
)

◆ strTolower()

CPPCHECKLIB void strTolower ( std::string &  str)