libfilezilla
Classes | Typedefs | Enumerations | Functions
fz Namespace Reference

The namespace used by libfilezilla. More...

Classes

class  async_task
 Handle for asynchronous tasks. More...
 
class  buffer
 The buffer class is a simple buffer where data can be appended at the end and consumed at the front. Think of it as a deque with contiguous storage. More...
 
class  condition
 Waitable condition variable. More...
 
class  datetime
 Represents a point of time in wallclock, tracking the timestamps accuracy/precision. More...
 
class  duration
 The duration class represents a time interval in milliseconds. More...
 
class  event_base
 Common base class for all events. More...
 
class  event_handler
 Simple handler for asynchronous event processing. More...
 
class  event_loop
 A threaded event loop that supports sending events and timers. More...
 
class  file
 Lean class for file access. More...
 
class  hash_accumulator
 Accumulator for hashing large amounts of data. More...
 
struct  less_insensitive_ascii
 Comparator to be used for std::map for case-insentitive keys. More...
 
class  local_filesys
 This class can be used to enumerate the contents of local directories and to query the metadata of files. More...
 
class  monotonic_clock
 A monotonic clock (aka steady clock) is independent from walltime. More...
 
class  mutex
 Lean replacement for std::(recursive_)mutex. More...
 
class  private_key
 Represents a X25519 private key with associated salt. More...
 
class  private_signing_key
 Represents a private key to sign message with using Ed25519. More...
 
class  process
 The process class manages an asynchronous process with redirected IO. More...
 
class  public_key
 Represents a X25519 public key with associated salt. More...
 
class  public_verification_key
 Represents a public key to verify messages signed using Ed25519. More...
 
class  query_string
 Class for parsing a URI's query string. More...
 
class  recursive_remove
 Recursively deletes directories. More...
 
class  scoped_lock
 A simple scoped lock. More...
 
class  shared_optional
 shared_optional is like std::shared_ptr but with relational operators acting like C++17's std::optional More...
 
class  simple_event
 This is the recommended event class. More...
 
class  sparse_optional
 Similar to C++17's std::optional, but stores the data in dynamic memory. More...
 
class  thread
 Spawns and represents a new thread of execution. More...
 
class  thread_pool
 A dumb thread-pool for asynchronous tasks. More...
 
class  uri
 The uri class is used to decompose URIs into their individual components. More...
 

Typedefs

typedef unsigned long long timer_id
 
typedef simple_event< timer_event_type, timer_id > timer_event
 All timer events have this type. More...
 
template<typename T >
using shared_value = shared_optional< T, true >
 like shared_optional but can never be empty More...
 
typedef std::wstring native_string
 A string in the system's native character type and encoding.
Note: This typedef changes depending on platform! More...
 

Enumerations

enum  base64_type { standard, url }
 Alphabet variations for base64. More...
 
enum  hash_algorithm { md5, sha1, sha256, sha512 }
 List of supported hashing algorithms.
 
enum  address_type { unknown, ipv4, ipv6 }
 
enum  { signature_size = 64 }
 

Functions

template<typename F , typename Tuple , typename Seq = typename std::make_index_sequence<std::tuple_size<typename std::remove_reference<Tuple>::type>::value>>
auto apply (F &&f, Tuple &&args) -> decltype(apply_(std::forward< F >(f), std::forward< Tuple >(args), Seq()))
 Apply tuple to ordinary functor. More...
 
template<typename Obj , typename F , typename Tuple , typename Seq = typename std::make_index_sequence<std::tuple_size<typename std::remove_reference<Tuple>::type>::value>>
auto apply (Obj &&obj, F &&f, Tuple &&args) -> decltype(apply_(std::forward< Obj >(obj), std::forward< F >(f), std::forward< Tuple >(args), Seq()))
 Apply tuple to pointer to member. More...
 
template<typename Char >
int hex_char_to_int (Char c)
 Converts a hex digit to decimal int. More...
 
template<typename String >
std::vector< uint8_t > hex_decode (String const &in)
 
template<typename Char = char, bool Lowercase = true>
Char int_to_hex_char (int d)
 Converts an integer to the corresponding lowercase hex digit. More...
 
template<typename String , typename InString , bool Lowercase = true>
String hex_encode (InString const &data)
 
std::string base64_encode (std::string const &in, base64_type type=base64_type::standard, bool pad=true)
 Encodes raw input string to base64.
 
std::string base64_encode (std::vector< uint8_t > const &in, base64_type type=base64_type::standard, bool pad=true)
 
std::string base64_decode (std::string const &in)
 Decodes base64, ignores whitespace. Returns empty string on invalid input. More...
 
std::string percent_encode (std::string const &s, bool keep_slashes=false)
 Percent-enodes string. More...
 
std::string percent_encode (std::wstring const &s, bool keep_slashes=false)
 
std::wstring percent_encode_w (std::wstring const &s, bool keep_slashes=false)
 Percent-enodes wide-character. Non-ASCII characters are converted to UTF-8 befor they are encoded. More...
 
std::string percent_decode (std::string const &s)
 Percent-decodes string. More...
 
std::vector< uint8_t > encrypt (std::vector< uint8_t > const &plain, public_key const &pub, bool authenticated=true)
 Encrypt the plaintext to the given public key. More...
 
std::vector< uint8_t > encrypt (std::string const &plain, public_key const &pub, bool authenticated=true)
 
std::vector< uint8_t > encrypt (uint8_t const *plain, size_t size, public_key const &pub, bool authenticated=true)
 
std::vector< uint8_t > decrypt (std::vector< uint8_t > const &chiper, private_key const &priv, bool authenticated=true)
 Decrypt the ciphertext using the given private key. More...
 
std::vector< uint8_t > decrypt (std::string const &chiper, private_key const &priv, bool authenticated=true)
 
std::vector< uint8_t > decrypt (uint8_t const *cipher, size_t size, private_key const &priv, bool authenticated=true)
 
template<typename T >
bool same_type (event_base const &ev)
 
template<typename T , typename F >
bool dispatch (event_base const &ev, F &&f)
 Dispatch for simple_event<> based events to simple functors. More...
 
template<typename T , typename H , typename F >
bool dispatch (event_base const &ev, H *h, F &&f)
 Dispatch for simple_event<> based events to pointer to member. More...
 
template<typename T , typename ... Ts, typename H , typename F , typename ... Fs>
bool dispatch (event_base const &ev, H *h, F &&f, Fs &&... fs)
 Compound dispatch for simple_event<> based events. More...
 
bool remove_file (native_string const &name)
 remove the specified file. More...
 
template<typename String , typename... Args>
String sprintf (String const &fmt, Args &&... args)
 A simple type-safe sprintf replacement. More...
 
template<typename... Args>
std::string sprintf (char const *fmt, Args &&... args)
 
template<typename... Args>
std::wstring sprintf (wchar_t const *fmt, Args &&... args)
 
std::vector< uint8_t > md5 (std::string const &data)
 Standard MD5. More...
 
std::vector< uint8_t > md5 (std::vector< uint8_t > const &data)
 
std::vector< uint8_t > sha256 (std::string const &data)
 Standard SHA256.
 
std::vector< uint8_t > sha256 (std::vector< uint8_t > const &data)
 
std::vector< uint8_t > hmac_sha256 (std::string const &key, std::string const &data)
 Standard HMAC using SHA256.
 
std::vector< uint8_t > hmac_sha256 (std::vector< uint8_t > const &key, std::vector< uint8_t > const &data)
 
std::vector< uint8_t > hmac_sha256 (std::vector< uint8_t > const &key, std::string const &data)
 
std::vector< uint8_t > hmac_sha256 (std::string const &key, std::vector< uint8_t > const &data)
 
std::string get_ipv6_long_form (std::string const &short_address)
 Given a shortened IPv6 address, returns the full, unshortened address. More...
 
std::wstring get_ipv6_long_form (std::wstring const &short_address)
 
bool is_routable_address (std::string const &address)
 Tests whether the passed IP address is routable on the public Internet. More...
 
bool is_routable_address (std::wstring const &address)
 
address_type get_address_type (std::string const &address)
 Gets the type of the passed IP address.
 
address_type get_address_type (std::wstring const &address)
 
std::vector< uint8_t > sign (std::vector< uint8_t > const &message, private_signing_key const &priv)
 Returns the message with the signature appended, created using the passed private key.
 
std::vector< uint8_t > sign (std::string const &message, private_signing_key const &priv)
 
std::vector< uint8_t > sign (uint8_t const &message, size_t const size, private_signing_key const &priv)
 
bool verify (std::vector< uint8_t > const &message, public_verification_key const &pub)
 Verify the message. Returns true iff it has been signed by the private key corresponding to the passed public key.
 
bool verify (std::string const &message, public_verification_key const &pub)
 
bool verify (uint8_t const *message, size_t const size, public_verification_key const &pub)
 
native_string to_native (std::string const &in)
 Converts std::string to native_string. More...
 
native_string to_native (std::wstring const &in)
 Convert std::wstring to native_string. More...
 
int stricmp (std::string const &a, std::string const &b)
 Locale-sensitive stricmp. More...
 
int stricmp (std::wstring const &a, std::wstring const &b)
 
template<typename Char >
Char tolower_ascii (Char c)
 Converts ASCII uppercase characters to lowercase as if C-locale is used. More...
 
template<>
std::wstring::value_type tolower_ascii (std::wstring::value_type c)
 
template<typename Char >
Char toupper_ascii (Char c)
 Converts ASCII lowercase characters to uppercase as if C-locale is used.
 
template<>
std::wstring::value_type toupper_ascii (std::wstring::value_type c)
 
template<typename String >
String str_tolower_ascii (String const &s)
 tr_tolower_ascii does for strings what tolower_ascii does for individual characters
 
template<typename String >
String str_toupper_ascii (String const &s)
 
template<typename String >
bool equal_insensitive_ascii (String const &a, String const &b)
 Locale-insensitive stricmp. More...
 
std::wstring to_wstring (std::string const &in)
 Converts from std::string in system encoding into std::wstring. More...
 
std::wstring to_wstring (std::wstring const &in)
 Returns identity, that way to_wstring can be called with native_string.
 
template<typename Arg >
std::enable_if< std::is_arithmetic< std::decay_t< Arg > >::value, std::wstring >::type to_wstring (Arg &&arg)
 Converts from arithmetic type to std::wstring.
 
std::wstring to_wstring_from_utf8 (std::string const &in)
 Converts from std::string in UTF-8 into std::wstring. More...
 
std::wstring to_wstring_from_utf8 (char const *s, size_t len)
 
std::string to_string (std::wstring const &in)
 Converts from std::wstring into std::string in system encoding. More...
 
std::string to_string (std::string const &in)
 Returns identity, that way to_string can be called with native_string.
 
template<typename Arg >
std::enable_if< std::is_arithmetic< std::decay_t< Arg > >::value, std::string >::type to_string (Arg &&arg)
 Converts from arithmetic type to std::string.
 
template<typename Char >
size_t strlen (Char const *str)
 Returns length of 0-terminated character sequence. Works with both narrow and wide-characters.
 
std::string to_utf8 (std::string const &in)
 Converts from std::string in native encoding into std::string in UTF-8. More...
 
std::string to_utf8 (std::wstring const &in)
 Converts from std::wstring in native encoding into std::string in UTF-8. More...
 
template<typename String , typename Arg >
auto toString (Arg &&arg) -> typename std::enable_if< std::is_same< String, std::string >::value, decltype(to_string(std::forward< Arg >(arg)))>::type
 Calls either fz::to_string or fz::to_wstring depending on the passed template argument.
 
template<typename Char >
Char const * choose_string (char const *c, wchar_t const *w)
 Returns the function argument of the type matching the template argument. More...
 
template<>
char const * choose_string (char const *c, wchar_t const *)
 Returns the function argument of the type matching the template argument. More...
 
template<>
wchar_t const * choose_string (char const *, wchar_t const *w)
 Returns the function argument of the type matching the template argument. More...
 
std::string replaced_substrings (std::string const &in, std::string const &find, std::string const &replacement)
 Returns in with all occurrences of find in the input string replaced with replacement.
 
std::wstring replaced_substrings (std::wstring const &in, std::wstring const &find, std::wstring const &replacement)
 
bool replace_substrings (std::string &in, std::string const &find, std::string const &replacement)
 Modifies in, replacing all occurrences of find with replacement.
 
bool replace_substrings (std::wstring &in, std::wstring const &find, std::wstring const &replacement)
 
template<typename String , typename Delim , typename Container = std::vector<String>>
Container strtok (String const &s, Delim const &delims)
 Tokenizes string. Returns all non-empty substrings.
 
template<typename T , typename String >
to_integral (String const &s, T const errorval=T())
 
template<typename String >
bool str_is_ascii (String const &s)
 Returns true iff the string only has characters in the 7-bit ASCII range.
 
template<typename String >
String trimmed (String const &s, String const &chars=fz::choose_string< typename String::value_type >(" \\, L" \\\"), bool fromLeft=true, bool fromRight=true)
 Return passed string with all leading and trailing whitespace removed.
 
template<typename String >
String ltrimmed (String const &s, String const &chars=fz::choose_string< typename String::value_type >(" \\, L" \\\"))
 
template<typename String >
String rtrimmed (String const &s, String const &chars=fz::choose_string< typename String::value_type >(" \\, L" \\\"))
 
template<typename String >
void trim (String &s, String const &chars=fz::choose_string< typename String::value_type >(" \\, L" \\\"))
 Remove all leading and trailing whitespace from string.
 
template<typename String >
void ltrim (String &s, String const &chars=fz::choose_string< typename String::value_type >(" \\, L" \\\"))
 
template<typename String >
void rtrim (String &s, String const &chars=fz::choose_string< typename String::value_type >(" \\, L" \\\"))
 
template<bool insensitive_ascii = false, typename String >
bool starts_with (String const &s, String const &beginning)
 Tests whether the first string starts with the second string. More...
 
template<bool insensitive_ascii = false, typename String >
bool ends_with (String const &s, String const &ending)
 Tests whether the first string ends with the second string. More...
 
duration operator- (duration const &a, duration const &b)
 
duration operator- (datetime const &a, datetime const &b)
 Gets the difference between two timestamps as duration. More...
 
duration operator- (monotonic_clock const &a, monotonic_clock const &b)
 
void sleep (duration const &d)
 Sleep current thread for the specified duration. More...
 
int64_t random_number (int64_t min, int64_t max)
 Get a secure random integer uniformly distributed in the closed interval [min, max].
 
std::vector< uint8_t > random_bytes (size_t size)
 Get random uniformly distributed bytes.
 
std::string get_version_string ()
 Get version string of libfilezilla.
 
std::tuple< int, int, int, int, std::string > get_version ()
 Get version of libfilezilla broken down into components major, minor, micro, nano and suffix.
 

Detailed Description

The namespace used by libfilezilla.

All declarations in any libfilezilla header are in this namespace.

Typedef Documentation

◆ native_string

typedef std::string native_string

A string in the system's native character type and encoding.
Note: This typedef changes depending on platform!

On Windows, the system's native encoding is UTF-16, so native_string is typedef'ed to std::wstring.

On all other platform, native_string is a typedef for std::string.

Always using native_string has the benefit that no conversion needs to be performed which is especially useful if dealing with filenames.

◆ shared_value

using shared_value = shared_optional<T, true>

like shared_optional but can never be empty

All operations that would result in an empty shared_optional instead result in a default-constructed value.

As such, operator* and operator-> are always well-defined.

◆ timer_event

typedef simple_event<timer_event_type, timer_id> timer_event

All timer events have this type.

All timer events have one arguments of type timer_id which is the id of the timer that triggered.

Enumeration Type Documentation

◆ base64_type

enum base64_type
strong

Alphabet variations for base64.

  • standard: Alphabet with / and + as chars 62 and 63
  • url: - and _

Function Documentation

◆ apply() [1/2]

auto fz::apply ( F &&  f,
Tuple &&  args 
) -> decltype(apply_(std::forward<F>(f), std::forward<Tuple>(args), Seq()))

Apply tuple to ordinary functor.

Example:

int f(int value, std::string const& str) { return value + str.size(); }
auto t = std::make_tuple(5, std::string("Hello!"));
int v = fz::apply(&f, t);
// v is now 11

◆ apply() [2/2]

auto fz::apply ( Obj &&  obj,
F &&  f,
Tuple &&  args 
) -> decltype(apply_(std::forward<Obj>(obj), std::forward<F>(f), std::forward<Tuple>(args), Seq()))

Apply tuple to pointer to member.

Example:

struct object {
int f(int value, std::string const& str) const { return value + str.size(); }
};
object o;
auto t = std::make_tuple(5, std::string("Hello!"));
int v = fz::apply(&o, &object::f, t);
// v is now 11

◆ base64_decode()

std::string fz::base64_decode ( std::string const &  in)

Decodes base64, ignores whitespace. Returns empty string on invalid input.

Padding is optional, alphabet is auto-detected.

◆ choose_string() [1/3]

Char const* fz::choose_string ( char const *  c,
wchar_t const *  w 
)
inline

Returns the function argument of the type matching the template argument.

See also
fzS

◆ choose_string() [2/3]

char const* fz::choose_string ( char const *  c,
wchar_t const *  w 
)
inline

Returns the function argument of the type matching the template argument.

See also
fzS

◆ choose_string() [3/3]

wchar_t const* fz::choose_string ( char const *  c,
wchar_t const *  w 
)
inline

Returns the function argument of the type matching the template argument.

See also
fzS

◆ decrypt()

std::vector<uint8_t> fz::decrypt ( std::vector< uint8_t > const &  chiper,
private_key const &  priv,
bool  authenticated = true 
)

Decrypt the ciphertext using the given private key.

Parameters
privThe private matching the public key that was originally used to encrypt the data
authenticatedif true, authenticated encryption is used.
Returns
plaintext on success, empty container on failure
Decryption algorithm:

Let M_priv be the key portion and S_m be the salt portion of the priv parameter and C the ciphertext.

  • First C is split into E_pub, S_e, C' and T such that
    C: = E_pub || S_e || C1 || T
  • M_pub is calculated from M_priv
  • Using ECDH on Curve25519 (X25519), the shared secret R is recovered:
    R := X25519(M_priv, E_pub)
  • From R, a symmetric AES256 key K and a nonce IV are derived:
    • K := SHA256(S_e || 0 || S || E_pub || M_pub || S_m)
    • IV := SHA256(S_e || 2 || S || E_pub || M_pub || S_m) if authenticated,
      IV := SHA256(S_e || 1 || S || E_pub || M_pub || S_m) otherwise
  • The ciphertext is decrypted into the plaintext P using
    P, T' := AES256-GCM(K, IV, C') if authenticated,
    P := AES256-CTR(K, IV, C'), T:='' otherwise
  • If the calculated T' matches T, then P is returned, otherwise decryption has failed and nothing is returned.

◆ dispatch() [1/3]

bool fz::dispatch ( event_base const &  ev,
F &&  f 
)

Dispatch for simple_event<> based events to simple functors.

Template Parameters
Tthe event type, a simple_event<> instantiation
Parameters
evthe received event
ffunctor that should be called if the event matches the passed type.

If the passed event is of the type passed as template argument, the passed function is called with the contents of the event unpacked as arguments.

Returns
true iff event matches passed type.
See also
event_handler for complete usage example.

◆ dispatch() [2/3]

bool fz::dispatch ( event_base const &  ev,
H *  h,
F &&  f 
)

Dispatch for simple_event<> based events to pointer to member.

Template Parameters
Tthe event type, a simple_event<> instantiation
Parameters
evthe received event.
hobject whose member gets called if the event matches the passed type.
fpointer to member of h that should be called if the event matches the passed type.

If the passed event is of the type passed as template argument, the passed function is called with the contents of the event unpacked as arguments.

Returns
true iff event matches passed type.
See also
event_handler for complete usage example.

◆ dispatch() [3/3]

bool fz::dispatch ( event_base const &  ev,
H *  h,
F &&  f,
Fs &&...  fs 
)

Compound dispatch for simple_event<> based events.

Calls the simple dispatch for each passed type and tries the next one if it didn't match.

Order the passed types in decreasing usage frequency for maximum performance.

Template Parameters
Tthe event type, a simple_event<> instantiation
Tsadditional event types
Parameters
evthe received event.
hobject whose member gets called if the event matches the passed type.
fpointer to member of h that should be called if the event matches the passed type.
fsadditional pairs of objects and pointers to members.
Returns
true iff event matched a passed type.
See also
event_handler for complete usage example.

◆ encrypt()

std::vector<uint8_t> fz::encrypt ( std::vector< uint8_t > const &  plain,
public_key const &  pub,
bool  authenticated = true 
)

Encrypt the plaintext to the given public key.

Parameters
authenticatedif true, authenticated encryption is used.
Encryption algorithm:

Let M_pub be the key portion, S_e be the salt portion of the pub parameter and P be the plaintext.

  • First an ephemeral private key E_priv with corresponding public key E_pub and S_e is randomly generated
  • Using ECDH on Curve25519 (X25519), a shared secret R is derived:
    R := X25519(E_priv, M_pub)
  • From R, a symmetric AES256 key K and a nonce IV are derived:
    • K := SHA256(S_e || 0 || S || E_pub || M_pub || S_m)
    • IV := SHA256(S_e || 2 || S || E_pub || M_pub || S_m) if authenticated,
      IV := SHA256(S_e || 1 || S || E_pub || M_pub || S_m) otherwise
  • The plaintext is encrypted into the ciphertext C' and authentication tag T using
    C', T := AES256-GCM(K, IV, P) if authenticated,
    C' := AES256-CTR(K, IV, P) T:='' otherwise
  • The ciphertext C is returned, containing E_pub, S_e and T:
    C := E_pub || S_e || C' || T

◆ ends_with()

bool fz::ends_with ( String const &  s,
String const &  ending 
)

Tests whether the first string ends with the second string.

Parameters
insensitive_asciiIf true, comparison is case-insensitive

◆ equal_insensitive_ascii()

bool fz::equal_insensitive_ascii ( String const &  a,
String const &  b 
)

Locale-insensitive stricmp.

Equivalent to str_tolower_ascii(a).compare(str_tolower_ascii(b));

◆ get_ipv6_long_form()

std::string fz::get_ipv6_long_form ( std::string const &  short_address)

Given a shortened IPv6 address, returns the full, unshortened address.

If passed address is encloded in square brackes, they are stripped.

Returns an empty string if the passed string isn't a valid IPv6 address.

◆ hex_char_to_int()

int fz::hex_char_to_int ( Char  c)

Converts a hex digit to decimal int.

Example: '9' becomes 9, 'b' becomes 11, 'D' becomes 13

Returns -1 if input is not a valid hex digit.

◆ int_to_hex_char()

Char fz::int_to_hex_char ( int  d)

Converts an integer to the corresponding lowercase hex digit.

Example: 9 becomes '9', 11 becomes 'b'

Undefined output if input is less than 0 or larger than 15

◆ is_routable_address()

bool fz::is_routable_address ( std::string const &  address)

Tests whether the passed IP address is routable on the public Internet.

Unroutable addresss are:

  • Invalid addresses
  • ::/128 (the unspecified address)
  • ::1/128 (localhost)
  • fe80::/10 (link-local)
  • fc00::/7 (unique local)
  • 127.0.0.0/8 (localhost)
  • 10.0.0.0/8 (private)
  • 172.16.0.0/12 (private)
  • 192.168.0.0/16 (private)
  • 169.254.0.0/16 (link-local)

All other addresses are assumed routable.

◆ md5()

std::vector<uint8_t> fz::md5 ( std::string const &  data)

Standard MD5.

Insecure, avoid using this

◆ operator-() [1/2]

duration operator- ( datetime const &  a,
datetime const &  b 
)

Gets the difference between two timestamps as duration.

This function ignores accuracy, it treats both timestamps as if they had millisecond-accuracy.

◆ operator-() [2/2]

duration operator- ( monotonic_clock const &  a,
monotonic_clock const &  b 
)
inline

Gets the difference between two clocks as duration

◆ percent_decode()

std::string fz::percent_decode ( std::string const &  s)

Percent-decodes string.

If the string cannot be decoded, an empty string is returned.

◆ percent_encode()

std::string fz::percent_encode ( std::string const &  s,
bool  keep_slashes = false 
)

Percent-enodes string.

The characters A-Z, a-z, 0-9, hyphen, underscore, period, tilde are not percent-encoded, optionally slashes arne't encoded either. Every other character is encoded.

Parameters
keep_slashesIf set, slashes are not encoded.

◆ percent_encode_w()

std::wstring fz::percent_encode_w ( std::wstring const &  s,
bool  keep_slashes = false 
)

Percent-enodes wide-character. Non-ASCII characters are converted to UTF-8 befor they are encoded.

See also
fz::percent-encode

◆ remove_file()

bool fz::remove_file ( native_string const &  name)

remove the specified file.

Returns
true iff the file has been removed or did not exist to begin with.

◆ same_type()

bool fz::same_type ( event_base const &  ev)

Used as lightweight RTTI alternative during dispatch

Returns
true iff T& t = ...; t.derived_type() == ev.derived_type()

◆ sleep()

void fz::sleep ( duration const &  d)

Sleep current thread for the specified duration.

Alternative to std::this_thread::sleep_for which unfortunately isn't implemented on MinGW.

Note
May wake up early, e.g. due to a signal. You can use monotonic_clock to check elapsed time and sleep again if needed.

◆ sprintf()

String fz::sprintf ( String const &  fmt,
Args &&...  args 
)

A simple type-safe sprintf replacement.

Only partially implements the format specifiers for the printf family of C functions:

  • Positional arguments
  • Supported flags: 0, ' ', -, +
  • Field widths are supported as decimal integers not exceeding 10k, longer widths are truncated
  • precision is ignored
  • Supported types: d, i, u, s, x, X, p

For string arguments, mixing char*, wchar_t*, std::string and std::wstring is allowed.

Asserts if unsupported types are passed or if the types don't match the arguments. Fails gracefully with NDEBUG.

Example:

std::string s = fz::printf("%2$s %1$s", "foo", std::wstring("bar");
assert(s == "bar foo"); // This is true

◆ starts_with()

bool fz::starts_with ( String const &  s,
String const &  beginning 
)

Tests whether the first string starts with the second string.

Parameters
insensitive_asciiIf true, comparison is case-insensitive

◆ stricmp()

int fz::stricmp ( std::string const &  a,
std::string const &  b 
)

Locale-sensitive stricmp.

Like std::string::compare but case-insensitive, respecting locale.

Note
does not handle embedded null

◆ to_native() [1/2]

native_string fz::to_native ( std::string const &  in)

Converts std::string to native_string.

Returns
the converted string on success. On failure an empty string is returned.
Examples:
list.cpp, and process.cpp.

◆ to_native() [2/2]

native_string fz::to_native ( std::wstring const &  in)

Convert std::wstring to native_string.

Returns
the converted string on success. On failure an empty string is returned.

◆ to_string()

std::string fz::to_string ( std::wstring const &  in)

Converts from std::wstring into std::string in system encoding.

Returns
the converted string on success. On failure an empty string is returned.
Note
Does not handle embedded nulls
Examples:
list.cpp.

◆ to_utf8() [1/2]

std::string fz::to_utf8 ( std::string const &  in)

Converts from std::string in native encoding into std::string in UTF-8.

Returns
the converted string on success. On failure an empty string is returned.
Note
Does not handle embedded nulls

◆ to_utf8() [2/2]

std::string fz::to_utf8 ( std::wstring const &  in)

Converts from std::wstring in native encoding into std::string in UTF-8.

Returns
the converted string on success. On failure an empty string is returned.
Note
Does not handle embedded nulls

◆ to_wstring()

std::wstring fz::to_wstring ( std::string const &  in)

Converts from std::string in system encoding into std::wstring.

Returns
the converted string on success. On failure an empty string is returned.
Note
Does not handle embedded nulls

◆ to_wstring_from_utf8()

std::wstring fz::to_wstring_from_utf8 ( std::string const &  in)

Converts from std::string in UTF-8 into std::wstring.

Returns
the converted string on success. On failure an empty string is returned.

◆ tolower_ascii()

Char fz::tolower_ascii ( Char  c)

Converts ASCII uppercase characters to lowercase as if C-locale is used.

Under some locales there is a different case-relationship between the letters a-z and A-Z as one expects from ASCII under the C locale. In Turkish for example there are different variations of the letter i, namely dotted and dotless. What we see as 'i' is the lowercase dotted i and 'I' is the uppercase dotless i. Since std::tolower is locale-aware, I would become the dotless lowercase i.

This is not always what we want. FTP commands for example are case-insensitive ASCII strings, LIST and list are the same.

tolower_ascii instead converts all types of 'i's to the ASCII i as well.

Returns
A-Z becomes a-z.
In addition dotless lowercase i and dotted uppercase i also become the standard i.