libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
z::core Namespace Reference

Section containing core functions and classes. More...

Classes

class  array
 A wrapper for std::vector. More...
 
interface  arrayLike
 An interface for all objects that can be both iterated over and directly indexed. More...
 
class  circularBuffer
 A circular buffer of fixed size. Appending can be done indefinitely, as the index will just loop back around to the beginning. More...
 
class  circularIterator
 A custom iterator for circular buffers. More...
 
class  generator
 An arbitrary generator for producing sequential results on-the-fly. More...
 
class  generatorIter
 Custom iterator for generators to allow for range-based for loops. More...
 
struct  hash32gen
 A compile-time CRC32 hash function. More...
 
struct  hash32gen< size, size, dummy >
 The stopping specialization for the hash32 template. More...
 
interface  indexable
 A base interface for all objects whose elements can be directly indexed. More...
 
interface  iterable
 A base interface for all objects that can be iterated over. More...
 
class  memoize< R(Args...)>
 A memoization class that caches the results of a function. More...
 
class  refArray
 An extension of the core::array class which assumes all elements to be pointers. More...
 
class  sentinel
 A sentinel that stops a numeric generator when the value reaches a certain point. More...
 
interface  sizable
 An interface for getting an object's size. More...
 
class  sortedArray
 An extension of the core::array class which attempts to keep all data sorted. More...
 
class  sortedRefArray
 An extension of the core::sortedArray class, specialized for pointers. More...
 
class  string
 A template class for character strings. More...
 
class  stringIterator
 A class for iterating over each character in a string. More...
 
class  timeout
 A class for easily managing timing. More...
 
class  timer
 A class for easily managing timers. More...
 
struct  yield
 The return value for generator functions. More...
 

Typedefs

template<typename T >
using deref_type = std::remove_const_t< std::remove_reference_t< decltype(*std::declval< decltype(std::declval< T >().begin())>())> >
 The type of the dereferenced value from an iterable. This is used to determine the type of value that the generator will yield.
 
template<typename T >
using iter_type = std::remove_const_t< decltype(std::declval< T >().begin())>
 The type of the iterator for an iterable. This is used to determine the type of iterator that the generator will use.
 

Functions

bool isUpperAlpha (uint32_t ch) noexcept
 Check if the given character is an uppercase alphabetic character.
 
bool isLowerAlpha (uint32_t ch) noexcept
 Check if the given character is a lowercase alphabetic character.
 
bool isUpper (uint32_t ch) noexcept
 Check if the given character is an uppercase character.
 
bool isLower (uint32_t ch) noexcept
 Check if the given character is a lowercase character.
 
uint32_t toUpper (uint32_t ch, bool camel=false) noexcept
 Convert the given character to uppercase.
 
uint32_t toLower (uint32_t ch, bool alternate=false) noexcept
 Convert the given character to lowercase.
 
bool isAlpha (uint32_t ch) noexcept
 Check if the given character is an alphabetic character.
 
int numeralValue (uint32_t ch) noexcept
 Convert the given character to its respective numeral value.
 
uint32_t numeral (int value) noexcept
 Convert the given value to its respective numeral character.
 
bool isNumeric (uint32_t ch, int base=10) noexcept
 Check if the given character is numeric under the given base.
 
bool isAlphaNumeric (uint32_t ch) noexcept
 Check if the given character is alphanumeric.
 
bool isWhiteSpace (uint32_t ch) noexcept
 Check if the given character is white space.
 
int toUTF8 (uint8_t *c, uint32_t chr) noexcept
 Convert a character to UTF-8 encoding.
 
int lenToUTF8 (uint32_t chr) noexcept
 Get the length of the UTF-8 encoding for a character.
 
uint32_t fromUTF8 (uint8_t *c) noexcept
 Convert a character from UTF-8 to UTF32 encoding.
 
int lenFromUTF8 (uint8_t *c) noexcept
 Get the character length of a UTF-8 sequence.
 
bool isUTF8 (uint8_t *c, int len) noexcept
 Get whether the characters are in valid UTF-8 format.
 
template<typename T >
generator< deref_type< T >, iter_type< T > > generatorFrom (const T &list)
 Create a generator from an arbitrary iterable.
 
template<typename T >
generator< deref_type< T >, std::pair< T, iter_type< T > > > generatorFrom (const T &&list)
 Create a generator from an arbitrary temporary iterable.
 
template<typename T >
generator< T, std::pair< array< T >, long > > generatorFrom (std::initializer_list< T > list)
 Create a generator from an initializer list.
 
template<typename K , typename V >
generator< std::pair< K, V >, typename std::map< K, V >::const_iterator > generatorFrom (const std::map< K, V > &map)
 Create a generator from a map.
 
template<typename K , typename V >
generator< std::pair< K, V >, std::pair< typename std::map< K, V >::const_iterator, std::map< K, V > > > generatorFrom (std::map< K, V > &&map)
 Create a generator from a temporary map.
 
hash32 crc32 (const char *str, int size) noexcept
 Computes the CRC32 hash of a string at runtime.
 
constexpr hash32 crc32 (const char *str) noexcept
 
template<typename T , encoding E>
string< Ejoin (const iterable< T > &list, const string< E > &delim) noexcept
 Concatenate elements in an array into a string, separated by a delimiter.
 
template<typename T >
zstring join (const iterable< T > &list, const zstring &delim) noexcept
 Concatenate elements in an array into a string, separated by a delimiter.
 
zstring join (const std::vector< std::string > &list, const zstring &delim) noexcept
 Concatenate elements in an array into a string, separated by a delimiter.
 
template<typename T , encoding E>
string< EjoinDeref (const iterable< T > &list, const string< E > &delim) noexcept
 Dereference elements in an array and concatenate them into a string, separated by a delimiter.
 
generator< long, longrange (long begin, long end, long step=1) noexcept
 Generate a sequence of integers in a specified range.
 
generator< long, longrange (long end) noexcept
 Generate a sequence of integers from 0 until the specified end point.
 
generator< long, longrange (long begin, const sentinel &check, long step=1) noexcept
 Generate a sequence of integers in a specified range.
 
template<typename T >
std::enable_if< std::is_base_of< z::core::sizable, T >::value >::type size (const T &object, size_t &bytes) noexcept
 Get the size of a sizable object.
 
template<typename T >
std::enable_if<!std::is_base_of< z::core::sizable, T >::value >::type size (const T &object, size_t &bytes) noexcept
 Get the size of a non-sizable object or datatype.
 
template<encoding E>
array< string< E > > split (const string< E > &input, const string< E > &delim="") noexcept
 Split a string into an array of strings according to a specified delimiter.
 

Variables

const sentinel infinity
 A sentinel that tells numeric generators to run forever.
 

Detailed Description

Section containing core functions and classes.

This section adds core functionality and is required as it is often referenced by other parts of the library. It can be used by itself, however, as it does not require any libraries besides STL.

Typedef Documentation

◆ deref_type

template<typename T >
using z::core::deref_type = typedef std::remove_const_t<std::remove_reference_t<decltype(*std::declval<decltype(std::declval<T>().begin())>())> >

The type of the dereferenced value from an iterable. This is used to determine the type of value that the generator will yield.

Template Parameters
T

◆ iter_type

template<typename T >
using z::core::iter_type = typedef std::remove_const_t<decltype(std::declval<T>().begin())>

The type of the iterator for an iterable. This is used to determine the type of iterator that the generator will use.

Template Parameters
T

Function Documentation

◆ crc32()

hash32 z::core::crc32 ( const char str,
int  size 
)
noexcept

Computes the CRC32 hash of a string at runtime.

This function is not constexpr and can be used for strings that are not known at compile time.

Parameters
strThe string to hash.
sizeThe size of the string.
Returns
The computed CRC32 hash.

◆ fromUTF8()

uint32_t z::core::fromUTF8 ( uint8_t c)
noexcept

Convert a character from UTF-8 to UTF32 encoding.

Parameters
cThe UTF-8 sequence. Assumed to be a 4-item array.
Returns
The character encoded as UTF32. '?' if input is not valid UTF-8.

◆ generatorFrom() [1/5]

template<typename K , typename V >
generator< std::pair< K, V >, typename std::map< K, V >::const_iterator > z::core::generatorFrom ( const std::map< K, V > &  map)

Create a generator from a map.

Template Parameters
KThe type of the key in the map.
VThe type of the value in the map.
Parameters
mapThe map to create a generator from.
Returns
A generator that will yield pairs of key-value from the map.

◆ generatorFrom() [2/5]

template<typename T >
generator< deref_type< T >, std::pair< T, iter_type< T > > > z::core::generatorFrom ( const T &&  list)

Create a generator from an arbitrary temporary iterable.

Template Parameters
TThe type of value that the iterable returns.
Parameters
listThe iterable to create a generator from.
Returns
A generator that will yield the items from the iterable.

◆ generatorFrom() [3/5]

template<typename T >
generator< deref_type< T >, iter_type< T > > z::core::generatorFrom ( const T list)

Create a generator from an arbitrary iterable.

Template Parameters
TThe type of value that the iterable returns.
Parameters
listThe iterable to create a generator from.
Returns
A generator that will yield the items from the iterable.
Examples
chainGenerators.cpp.

◆ generatorFrom() [4/5]

template<typename T >
generator< T, std::pair< array< T >, long > > z::core::generatorFrom ( std::initializer_list< T list)

Create a generator from an initializer list.

Template Parameters
TThe type of value that the iterable returns.
Parameters
listThe initializer list to create a generator from.
Returns
A generator that will yield the items from the initializer list.

◆ generatorFrom() [5/5]

template<typename K , typename V >
generator< std::pair< K, V >, std::pair< typename std::map< K, V >::const_iterator, std::map< K, V > > > z::core::generatorFrom ( std::map< K, V > &&  map)

Create a generator from a temporary map.

Template Parameters
KThe type of the key in the map.
VThe type of the value in the map.
Parameters
mapThe map to create a generator from.
Returns
A generator that will yield pairs of key-value from the map.

◆ isAlpha()

bool z::core::isAlpha ( uint32_t  ch)
noexcept

Check if the given character is an alphabetic character.

Parameters
chthe character to check.
Returns
True if the character is an alphabetic character. False otherwise.

◆ isAlphaNumeric()

bool z::core::isAlphaNumeric ( uint32_t  ch)
noexcept

Check if the given character is alphanumeric.

Parameters
chThe character to check.
Returns
True if the character is alphanumeric. False otherwise.

◆ isLower()

bool z::core::isLower ( uint32_t  ch)
noexcept

Check if the given character is a lowercase character.

Parameters
chthe character to check.
Returns
True if the character is lowercase. False otherwise.

◆ isLowerAlpha()

bool z::core::isLowerAlpha ( uint32_t  ch)
noexcept

Check if the given character is a lowercase alphabetic character.

This function differs from isLower() in that it only returns true for characters a-z.

Parameters
chthe character to check.
Returns
True if the character is lowercase. False otherwise.

◆ isNumeric()

bool z::core::isNumeric ( uint32_t  ch,
int  base = 10 
)
noexcept

Check if the given character is numeric under the given base.

Parameters
chThe character to check.
baseThe base for this character.
Returns
True if the character is numeric under the given base. False otherwise.

◆ isUpper()

bool z::core::isUpper ( uint32_t  ch)
noexcept

Check if the given character is an uppercase character.

Parameters
chthe character to check.
Returns
True if the character is uppercase. False otherwise.

◆ isUpperAlpha()

bool z::core::isUpperAlpha ( uint32_t  ch)
noexcept

Check if the given character is an uppercase alphabetic character.

This function differs from isUpper() in that it only returns true for characters A-Z.

Parameters
chthe character to check.
Returns
True if the character is uppercase. False otherwise.

◆ isUTF8()

bool z::core::isUTF8 ( uint8_t c,
int  len 
)
noexcept

Get whether the characters are in valid UTF-8 format.

Parameters
cThe character sequence. Assumed to have len characters.
lenThe characters in the sequence. Characters after the 4th will be ignored.
Returns
True if the sequence is valid UTF-8 format, false otherwise.

◆ isWhiteSpace()

bool z::core::isWhiteSpace ( uint32_t  ch)
noexcept

Check if the given character is white space.

Parameters
chThe character to check.
Returns
True if the character is a white space character. False otherwise.

◆ join() [1/3]

template<typename T , encoding E>
string< E > z::core::join ( const iterable< T > &  list,
const string< E > &  delim 
)
noexcept

Concatenate elements in an array into a string, separated by a delimiter.

Parameters
listAn iterable whose elements can implicitly convert to strings.
delimThe delimiter to go between items.
Returns
A string containing all elements in order, separated by the delimiter.
Re-Entry: This function is thread-safe. Simultaneous calls will not cause data races.
Examples
array.cpp, chainGenerators.cpp, generator.cpp, and range.cpp.

◆ join() [2/3]

template<typename T >
zstring z::core::join ( const iterable< T > &  list,
const zstring delim 
)
noexcept

Concatenate elements in an array into a string, separated by a delimiter.

Parameters
listAn iterable whose elements can implicitly convert to strings.
delimThe delimiter to go between items.
Returns
A string containing all elements in order, separated by the delimiter.
Re-Entry: This function is thread-safe. Simultaneous calls will not cause data races.

◆ join() [3/3]

zstring z::core::join ( const std::vector< std::string > &  list,
const zstring delim 
)
noexcept

Concatenate elements in an array into a string, separated by a delimiter.

This is a specialization for joining a std::vector of std::strings into a single zstring.

Parameters
listA std::vector of std::string items.
delimThe delimiter to go between items.
Returns
A string containing all elements in order, separated by the delimiter.
Re-Entry: This function is thread-safe. Simultaneous calls will not cause data races.

◆ joinDeref()

template<typename T , encoding E>
string< E > z::core::joinDeref ( const iterable< T > &  list,
const string< E > &  delim 
)
noexcept

Dereference elements in an array and concatenate them into a string, separated by a delimiter.

Parameters
listAn iterable of pointers whose objects can implicitly convert to strings.
delimThe delimiter to go between items.
Returns
A string containing all elements in order, separated by the delimiter.
Re-Entry: This function is thread-safe. Simultaneous calls will not cause data races.

◆ lenFromUTF8()

int z::core::lenFromUTF8 ( uint8_t c)
noexcept

Get the character length of a UTF-8 sequence.

Parameters
cThe UTF-8 sequence. Assumed to be a 4-item array.
Returns
The number of characters in the UTF-8 sequence. Assumed to be valid UTF-8.

◆ lenToUTF8()

int z::core::lenToUTF8 ( uint32_t  chr)
noexcept

Get the length of the UTF-8 encoding for a character.

Parameters
chrThe character to convert to UTF-8.
Returns
The number of characters in the UTF-8 sequence.

◆ numeral()

uint32_t z::core::numeral ( int  value)
noexcept

Convert the given value to its respective numeral character.

0-9 give '0'-'9'. 10-36 give 'A'-'Z'.

Parameters
valuethe value to convert.
Returns
The character numeral for the value. If it is not a numeral value, returns '0'.

◆ numeralValue()

int z::core::numeralValue ( uint32_t  ch)
noexcept

Convert the given character to its respective numeral value.

'0'-'9' give 0-9. from 'A'-'Z' give 10-36. Case insensitive.

Parameters
chthe character to check.
Returns
The numeral value of the character. If it is not a numeric character, returns -1.

◆ range() [1/3]

generator< long, long > z::core::range ( long  begin,
const sentinel check,
long  step = 1 
)
noexcept

Generate a sequence of integers in a specified range.

Parameters
beginThe beginning of the range (inclusive).
checkThe sentinel value that indicates when the end of the range has been reached.
stepThe step size.
Returns
A generator that outputs a regular sequence of integers in the range.

◆ range() [2/3]

generator< long, long > z::core::range ( long  begin,
long  end,
long  step = 1 
)
noexcept

Generate a sequence of integers in a specified range.

Parameters
beginThe beginning of the range (inclusive).
endThe end of the range (exclusive).
stepThe step size.
Returns
A generator that outputs a regular sequence of integers in the range.
Examples
chainGenerators.cpp, generator.cpp, and range.cpp.

◆ range() [3/3]

generator< long, long > z::core::range ( long  end)
noexcept

Generate a sequence of integers from 0 until the specified end point.

Parameters
endThe end of the range (exclusive).
Returns
A generator that outputs a regular sequence of integers in the range.

◆ size() [1/2]

template<typename T >
std::enable_if< std::is_base_of< z::core::sizable, T >::value >::type z::core::size ( const T object,
size_t bytes 
)
inlinenoexcept

Get the size of a sizable object.

Calls the object's size() method.

Returns
The number of bytes in memory this object currently consumes.

◆ size() [2/2]

template<typename T >
std::enable_if<!std::is_base_of< z::core::sizable, T >::value >::type z::core::size ( const T object,
size_t bytes 
)
inlinenoexcept

Get the size of a non-sizable object or datatype.

Returns
The number of bytes in memory this object currently consumes.

◆ split()

template<encoding E>
array< string< E > > z::core::split ( const string< E > &  input,
const string< E > &  delim = "" 
)
noexcept

Split a string into an array of strings according to a specified delimiter.

Parameters
inputThe string to split into an array.
delimThe delimiter that separates items.
Returns
A null array if the input string has 0 characters. Otherwise, an array containing all substrings between any occurring delimiters.
Re-Entry: This function is thread-safe. Simultaneous calls will not cause data races.

◆ toLower()

uint32_t z::core::toLower ( uint32_t  ch,
bool  alternate = false 
)
noexcept

Convert the given character to lowercase.

Parameters
chthe character to convert.
alternateIf true, use whatever alternate lowercase version a character has, if any (e.g. Σς instead of Σσ).
Returns
The character, converted to lowercase if applicable.
Examples
dictionary.cpp.

◆ toUpper()

uint32_t z::core::toUpper ( uint32_t  ch,
bool  camel = false 
)
noexcept

Convert the given character to uppercase.

Parameters
chthe character to convert.
camelIf true, convert characters with a camelCase version (e.g. NJ vs Nj vs nj). If false, convert only to uppercase.
Returns
The character, converted to uppercase if applicable.

◆ toUTF8()

int z::core::toUTF8 ( uint8_t c,
uint32_t  chr 
)
noexcept

Convert a character to UTF-8 encoding.

Parameters
cThe UTF-8 sequence, returned by pointer. Assumed to be a 4-item array.
chrThe character to convert to UTF-8.
Returns
The number of characters in the UTF-8 sequence.

Variable Documentation

◆ infinity

const sentinel z::core::infinity
extern

A sentinel that tells numeric generators to run forever.

Warning
Calling generator functions that consume all values (e.g. count()) will cause an infinite loop.
Examples
range.cpp.