ASL
|
These utilities allow simple code like:
Measuring time and sleeping for some time:
Convert radians to degrees and limit to 0-360 deg interval:
Get random numbers in an interval:
Turn a file into a base64 representation:
Typedefs | |
typedef unsigned char | byte |
An unsigned byte. More... | |
Functions | |
float | infinity () |
Returns +infinity. | |
float | nan () |
Returns a NaN value. | |
template<class T > | |
T | sqr (T x) |
Returns x squared. | |
template<class T > | |
T | fract (T x) |
Returns the fractional part of x | |
template<class T > | |
T | round (T x, T k) |
Rounds a number to a multiple of k. | |
template<class T , class C > | |
T | clamp (T x, C a, C b) |
Clamps the value of x to make it lie inside the [a,b] interval. | |
template<class T > | |
T | deg2rad (T x) |
Returns x degrees converted to radians. | |
double | deg2rad (int x) |
Exceptionally treat ints as doubles so you can safely use deg2rad(45) | |
template<class T > | |
T | rad2deg (T x) |
Returns x radians converted to degrees. | |
String | encodeUrl (const String &s) |
Encodes a string with percent encoding for use in a URL. More... | |
String | decodeUrl (const String &s) |
Decodes a string with percent encoding. More... | |
double | now () |
Returns the current time as a real number in seconds since a fixed epoch (precision is platform-dependent, often around a microsecond). | |
void | sleep (double s) |
Makes the current thread sleep for the given time in seconds (can be fractional) | |
void | usleep (int us) |
Makes the current thread sleep for the given time in microseconds. | |
ByteArray | decodeBase64 (const String &s) |
Decodes a base64 encoded string into a byte array; the string can contain whitespace. | |
String | encodeBase64 (const ByteArray &s) |
Encodes a byte array as a string using base64 encoding. | |
String | encodeBase64 (const String &s) |
Encodes a string as a string using base64 encoding. | |
String | encodeHex (const ByteArray &src) |
Encodes a byte array as a string using hexadecimal. | |
ByteArray | decodeHex (const String &src) |
Decodes a hexadecimal encoded string into a byte array. | |
static String | encode (const String &s, bool component=false) |
Encodes a string with percent encoding for chars not allowed in URLs, by default more characters are left untouched (including '/', ':', like in JS encodeURI() ), if the component flag is set, then more characters are encoded (like JS encodeURIComponent() ) | |
static String | decode (const String &s) |
Decodes a string containing percent-encoded characters. | |
typedef unsigned char byte |
An unsigned byte.
This is also included in the global scope (using asl::byte;
) for compatibility with old code, unless ASL_NO_GLOBAL_BYTE
is defined.
asl::byte
Decodes a string with percent encoding.
Encodes a string with percent encoding for use in a URL.