gloox::util Namespace Reference

## Classes

class | AtomicRefCount
class | Mutex
class | MutexGuard

## Functions

int | internalLog2 (unsigned int n)
unsigned | _lookup (const std::string &str, const char *values[], unsigned size, int def)
const std::string | _lookup (unsigned code, const char *values[], unsigned size, const std::string &def)
unsigned | _lookup2 (const std::string &str, const char *values[], unsigned size, int def)
const std::string | _lookup2 (unsigned code, const char *values[], unsigned size, const std::string &def)
std::string | hex (const std::string &input)
const std::string | escape (std::string what)
void | appendEscaped (std::string &target, const std::string &data)
bool | checkValidXMLChars (const std::string &data)
void | replaceAll (std::string &target, const std::string &find, const std::string &replace)
template<typename T, typename F>
void | ForEach (T &t, F f)
template<typename T, typename F, typename D>
void | ForEach (T &t, F f, D &d)
template<typename T, typename F, typename D1, typename D2>
void | ForEach (T &t, F f, D1 &d1, D2 &d2)
template<typename T, typename F, typename D1, typename D2, typename D3>
void | ForEach (T &t, F f, D1 &d1, D2 &d2, D3 &d3)
template<typename T>
void | clearList (std::list< T * > &L)
template<typename Key, typename T>
void | clearMap (std::map< Key, T * > &M)
template<typename Key, typename T>
void | clearMap (std::map< const Key, T * > &M)

## Detailed Description

A namespace holding a couple utility functions.

## Function Documentation

## _lookup() [1/2]

GLOOX_API unsigned _lookup | ( | const std::string & | str,
|  | const char * | values[],
|  | unsigned | size,
|  | int | def = -1 )

Finds the enumerated value associated with a string value.

Parameters

  str | String to search for.
  values | Array of String/Code pairs to look into.
  size | The array's size.
  def | Default value returned in case the lookup failed.

Returns
  The associated enum code.

Definition at line 35 of file util.cpp.

## _lookup() [2/2]

GLOOX_API const std::string _lookup | ( | unsigned | code,
|  | const char * | values[],
|  | unsigned | size,
|  | const std::string & | def = EmptyString )

Finds the string associated with an enumerated type.

Parameters

  code | Code of the string to search for.
  values | Array of String/Code pairs to look into.
  size | The array's size.
  def | Default value returned in case the lookup failed.

Returns
  The associated string (empty in case there's no match).

Definition at line 43 of file util.cpp.

## _lookup2() [1/2]

GLOOX_API unsigned _lookup2 | ( | const std::string & | str,
|  | const char * | values[],
|  | unsigned | size,
|  | int | def = -1 )

Finds the ORable enumerated value associated with a string value.

Parameters

  str | String to search for.
  values | Array of String/Code pairs to look into.
  size | The array's size.
  def | The default value to return if the lookup failed.

Returns
  The associated enum code.

Definition at line 48 of file util.cpp.

## _lookup2() [2/2]

GLOOX_API const std::string _lookup2 | ( | unsigned | code,
|  | const char * | values[],
|  | unsigned | size,
|  | const std::string & | def = EmptyString )

Finds the string associated with an ORable enumerated type.

Parameters

  code | Code of the string to search for.
  values | Array of String/Code pairs to look into.
  size | The array's size.
  def | The default value to return if the lookup failed.

Returns
  The associated string (empty in case there's no match).

Definition at line 54 of file util.cpp.

## appendEscaped()

GLOOX_API void appendEscaped | ( | std::string & | target,
|  | const std::string & | data )

Append the data to the target, doing any necessary escaping along the way (& --> &amp;, etc). This method is faster than calling "escape" and appending the return value, especially for source strings that don't need any escaping.

Parameters

  target | The string to append the data to.
  data | The string to append that might need escaping.

Definition at line 95 of file util.cpp.

## checkValidXMLChars()

GLOOX_API bool checkValidXMLChars | ( | const std::string & | data | ) |

Checks whether the given input is valid UTF-8.

Parameters

  data | The data to check for validity.

Returns
  @b True if the input is valid UTF-8, false otherwise.

Definition at line 141 of file util.cpp.

## clearList()

template<typename T>

void clearList | ( | std::list< T * > & | L | ) |

inline

Delete all elements from a list of pointers.

Parameters

  L | List of pointers to delete.

Definition at line 152 of file util.h.

## clearMap() [1/2]

template<typename Key, typename T>

void clearMap | ( | std::map< const Key, T * > & | M | ) |

inline

Delete all associated values from a map (not the key elements). Const key type version.

Parameters

  M | Map of pointer values to delete.

Definition at line 187 of file util.h.

## clearMap() [2/2]

template<typename Key, typename T>

void clearMap | ( | std::map< Key, T * > & | M | ) |

inline

Delete all associated values from a map (not the key elements).

Parameters

  M | Map of pointer values to delete.

Definition at line 169 of file util.h.

## escape()

GLOOX_API const std::string escape | ( | std::string | what | ) |

Does some fancy escaping. (& --> &amp;, etc).

Note
  If you intend to append the result of escape to another string, use the faster appendEscaped.

Parameters

  what | A string to escape.

Returns
  The escaped string.

Definition at line 77 of file util.cpp.

## ForEach() [1/4]

template<typename T, typename F>

void ForEach | ( | T & | t,
|  | F | f )

inline

A convenience function that executes the given function on each object in a given list.

Parameters

  t | The object to execute the function on.
  f | The function to execute.

Definition at line 96 of file util.h.

## ForEach() [2/4]

template<typename T, typename F, typename D>

void ForEach | ( | T & | t,
|  | F | f,
|  | D & | d )

inline

A convenience function that executes the given function on each object in a given list, passing the given argument.

Parameters

  t | The object to execute the function on.
  f | The function to execute.
  d | An argument to pass to the function.

Definition at line 110 of file util.h.

## ForEach() [3/4]

template<typename T, typename F, typename D1, typename D2>

void ForEach | ( | T & | t,
|  | F | f,
|  | D1 & | d1,
|  | D2 & | d2 )

inline

A convenience function that executes the given function on each object in a given list, passing the given arguments.

Parameters

  t | The object to execute the function on.
  f | The function to execute.
  d1 | An argument to pass to the function.
  d2 | An argument to pass to the function.

Definition at line 125 of file util.h.

## ForEach() [4/4]

template<typename T, typename F, typename D1, typename D2, typename D3>

void ForEach | ( | T & | t,
|  | F | f,
|  | D1 & | d1,
|  | D2 & | d2,
|  | D3 & | d3 )

inline

A convenience function that executes the given function on each object in a given list, passing the given arguments.

Parameters

  t | The object to execute the function on.
  f | The function to execute.
  d1 | An argument to pass to the function.
  d2 | An argument to pass to the function.
  d3 | An argument to pass to the function.

Definition at line 141 of file util.h.

## hex()

std::string hex | ( | const std::string & | input | ) |

Returns the input string in hex notation.

Parameters

  input | The (binary) input string.

Returns
  The input string in hex notation.

Definition at line 60 of file util.cpp.

## internalLog2()

GLOOX_API int internalLog2 | ( | unsigned int | n | ) |

Custom log2() implementation.

Parameters

  n | Figure to take the logarithm from.

Returns
  The logarithm to the basis of 2.

Definition at line 24 of file util.cpp.

## replaceAll()

GLOOX_API void replaceAll | ( | std::string & | target,
|  | const std::string & | find,
|  | const std::string & | replace )

Replace all instances of one substring of arbitrary length with another substring of arbitrary length. Replacement happens in place (so make a copy first if you don't want the original modified).

Parameters

  target | The string to process. Changes are made "in place".
  find | The sub-string to find within the target string
  replace | The sub-string to substitute for the find string.

Todo
  Look into merging with util::escape() and Parser::decode().

Definition at line 177 of file util.cpp.