pianod2
multisource multiuser scriptable networked music player
Typedefs | Functions
utility.h File Reference

Various helpful templates, classes and functions. More...

#include <config.h>
#include <cstdio>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <exception>
#include <stdexcept>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
Include dependency graph for utility.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef uint32_t lamerkey_t
 

Functions

int compare_title_order (const std::string &a, const std::string &b)
 Compare titles, ignoring 'a', 'an', or 'the'. More...
 
bool compare_titles (const std::string &astr, const std::string &bstr)
 Compare titles, ignoring 'a', 'an', or 'the'. More...
 
bool compare_person_or_title (const std::string &astr, const std::string &bstr)
 Compare an artist's name, which might be a person's name or a band. More...
 
lamerkey_t create_key_from_string (const char *source)
 Generate a key from a string. More...
 
lamerkey_t compute_crc (const char *data, lamerkey_t divisor, lamerkey_t remainder=0)
 Compute a key from a string using a CRC algorithm. More...
 
char * lamer_cipher (const char *keystr, const char *item)
 Encipher or decipher an item based on a key. More...
 
std::string lamer_cipher (const std::string &keystr, const std::string &item)
 
lamerkey_t create_key_from_string (const std::string &source)
 
int strcasecmp (const std::string &a, const char *b)
 
int strcasecmp (const char *a, const std::string &b)
 
int strcasecmp (const std::string &a, const std::string &b)
 
int strncasecmp (const std::string &a, const char *b, size_t n)
 
int strncasecmp (const char *a, const std::string &b, size_t n)
 
int strncasecmp (const std::string &a, const std::string &b, size_t n)
 
const char * strcasestr (const std::string &a, const char *b)
 
const char * strcasestr (const char *a, const std::string &b)
 
const char * strcasestr (const std::string &a, const std::string &b)
 
std::string strtolower (std::string str)
 
std::string & ltrim (std::string &s)
 Trim whitespace from beginning of a string. More...
 
std::string & rtrim (std::string &s)
 Trim whitespace from end of a string. More...
 
std::string & trim (std::string &s)
 Trim whitespace from both ends of a string. More...
 
std::string trim (const std::string &s)
 
std::string makeIdentity (std::string s)
 Remove whitespace and other desireable characters, and make all lowercase for use as an ID. More...
 
std::vector< std::string > split_string (const std::string &value)
 Split a string to words. More...
 
std::vector< std::string > split_string (const std::string &value, const std::string separator, bool include_empty_last=true)
 Split a string on a fixed pattern. More...
 
std::string join_strings (const std::vector< std::string > &list, const std::string joiner)
 Join strings together. More...
 
std::string join_strings (const std::vector< std::string > &list)
 Joing strings together using a space between concatenated values. More...
 

Detailed Description

Various helpful templates, classes and functions.

Typedef Documentation

◆ lamerkey_t

typedef uint32_t lamerkey_t

Function Documentation

◆ compare_person_or_title()

bool compare_person_or_title ( const std::string &  astr,
const std::string &  bstr 
)

Compare an artist's name, which might be a person's name or a band.

If it's a title, it may have 'a', 'an', or 'the', or maybe not. If it's a person, it may be /first last/ or /last, first/.

Parameters
astrFirst title.
bstrSecond title.
Returns
true if values are equivalent, false if not.
Warning
Because this function guesses type of name by looking at the parameters, int return would not be sort-consistent. Thus, return type bool.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_title_order()

int compare_title_order ( const std::string &  astr,
const std::string &  bstr 
)

Compare titles, ignoring 'a', 'an', or 'the'.

Parameters
astrFirst title.
bstrSecond title.
Returns
< 0 if astr < bstr; 0 if equal; >0 if astr > bstr.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_titles()

bool compare_titles ( const std::string &  astr,
const std::string &  bstr 
)
inline

Compare titles, ignoring 'a', 'an', or 'the'.

Parameters
astrFirst title.
bstrSecond title.
Returns
true if titles match, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_crc()

lamerkey_t compute_crc ( const char *  data,
lamerkey_t  divisor,
lamerkey_t  remainder 
)

Compute a key from a string using a CRC algorithm.

If VARIABLE_SIZE_DIVISORS is set, the CRC length is determined dynamically by the value in the divisor. Otherwise, it is determined by the length of the generator set in constants above.

Parameters
dataThe string to use to generate the key.
divisorThe generator/divisor for performing the CRC.
remainderFor unit testing; set to 0 for generating keys. For test purposes, reinvoke this function pass the function's result for remainder. The result should be 0; if not, it's broken.
Returns
The computed key.
Here is the caller graph for this function:

◆ create_key_from_string() [1/2]

lamerkey_t create_key_from_string ( const char *  source)

Generate a key from a string.

Parameters
sourceThe string.
Returns
The key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_key_from_string() [2/2]

lamerkey_t create_key_from_string ( const std::string &  source)
inline
Here is the call graph for this function:

◆ join_strings() [1/2]

std::string join_strings ( const std::vector< std::string > &  list)
inline

Joing strings together using a space between concatenated values.

Here is the call graph for this function:

◆ join_strings() [2/2]

std::string join_strings ( const std::vector< std::string > &  list,
const std::string  joiner 
)

Join strings together.

Parameters
listThe strings to join.
joinerThe string to insert between list strings.
Returns
The assembled string.
Here is the caller graph for this function:

◆ lamer_cipher() [1/2]

char* lamer_cipher ( const char *  keystr,
const char *  item 
)

Encipher or decipher an item based on a key.

Parameters
keystrThe string to use to generate a key.
itemThe string to encipher or decipher.
Returns
The enciphered/deciphered string, freshly malloced; or NULL on error. Original strings are unmodified.
Warning
Allocates space on the heap for the returned string. Caller must free() this when done with the string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lamer_cipher() [2/2]

std::string lamer_cipher ( const std::string &  keystr,
const std::string &  item 
)
Here is the call graph for this function:

◆ ltrim()

std::string& ltrim ( std::string &  s)
inline

Trim whitespace from beginning of a string.

Author
Evan Teran
See also
http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
Here is the caller graph for this function:

◆ makeIdentity()

std::string makeIdentity ( std::string  s)

Remove whitespace and other desireable characters, and make all lowercase for use as an ID.

◆ rtrim()

std::string& rtrim ( std::string &  s)
inline

Trim whitespace from end of a string.

Author
Evan Teran
See also
http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
Here is the caller graph for this function:

◆ split_string() [1/2]

std::vector<std::string> split_string ( const std::string &  value)

Split a string to words.

Mid-word punctuation is retained.

  • "Don't stop thinking" -> "Don't", "stop", "thinking"
  • "'Lyin' Eyes" -> "Lyin", "eyes"
    Parameters
    valueThe string to split.
    Returns
    Words.
Here is the caller graph for this function:

◆ split_string() [2/2]

std::vector<std::string> split_string ( const std::string &  value,
const std::string  separator,
const bool  include_empty_last 
)

Split a string on a fixed pattern.

Parameters
valueThe string to split.
separatorThe pattern for splitting the string. It is removed from the result strings.
include_empty_lastIf false, then if the separator occurs at end of string, then the null space following it is omitted from the results.
Returns
1 or more strings.

◆ strcasecmp() [1/3]

int strcasecmp ( const char *  a,
const std::string &  b 
)
inline
Here is the call graph for this function:

◆ strcasecmp() [2/3]

int strcasecmp ( const std::string &  a,
const char *  b 
)
inline
Here is the caller graph for this function:

◆ strcasecmp() [3/3]

int strcasecmp ( const std::string &  a,
const std::string &  b 
)
inline
Here is the call graph for this function:

◆ strcasestr() [1/3]

const char* strcasestr ( const char *  a,
const std::string &  b 
)
inline
Here is the call graph for this function:

◆ strcasestr() [2/3]

const char* strcasestr ( const std::string &  a,
const char *  b 
)
inline
Here is the caller graph for this function:

◆ strcasestr() [3/3]

const char* strcasestr ( const std::string &  a,
const std::string &  b 
)
inline
Here is the call graph for this function:

◆ strncasecmp() [1/3]

int strncasecmp ( const char *  a,
const std::string &  b,
size_t  n 
)
inline
Here is the call graph for this function:

◆ strncasecmp() [2/3]

int strncasecmp ( const std::string &  a,
const char *  b,
size_t  n 
)
inline
Here is the caller graph for this function:

◆ strncasecmp() [3/3]

int strncasecmp ( const std::string &  a,
const std::string &  b,
size_t  n 
)
inline
Here is the call graph for this function:

◆ strtolower()

std::string strtolower ( std::string  str)
inline
Here is the caller graph for this function:

◆ trim() [1/2]

std::string trim ( const std::string &  s)
inline
Here is the call graph for this function:

◆ trim() [2/2]

std::string& trim ( std::string &  s)
inline

Trim whitespace from both ends of a string.

Author
Evan Teran
See also
http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
Here is the call graph for this function:
Here is the caller graph for this function: