ASL
Global functions

Detailed Description

These utilities allow simple code like:

Measuring time and sleeping for some time:

double t1 = now();
sleep(0.5); // sleep for 500 ms
double t2 = now();
double elapsed = t2 - t1; // -> around 0.5
double now()
Returns the current time as a real number in seconds since a fixed epoch (precision is platform-depen...

Convert radians to degrees and limit to 0-360 deg interval:

double degrees = clamp(rad2deg(angle), 0, 360);
T clamp(T x, C a, C b)
Clamps the value of x to make it lie inside the [a,b] interval.
Definition: defs.h:205
T rad2deg(T x)
Returns x radians converted to degrees.
Definition: defs.h:216

Get random numbers in an interval:

double x = random(-1.0, 1.0);
String item = names[ random( names.length() ) ]; // pick random array item

Turn a file into a base64 representation:

TextFile("image.jpg.b64").put( encodeBase64(File("image.jpg").content()) );

Typedefs

typedef unsigned char byte
 An unsigned byte. More...
 

Functions

float infinity ()
 Returns +infinity.
 
float nan ()
 Returns a NaN value.
 
template<class T >
sqr (T x)
 Returns x squared.
 
template<class T >
fract (T x)
 Returns the fractional part of x
 
template<class T >
round (T x, T k)
 Rounds a number to a multiple of k.
 
template<class T , class C >
clamp (T x, C a, C b)
 Clamps the value of x to make it lie inside the [a,b] interval.
 
template<class 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 >
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 Documentation

◆ byte

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.

Deprecated:
This type will not be added to the global scope anymore; code should use asl::byte

Function Documentation

◆ decodeUrl()

String asl::decodeUrl ( const String s)
inline

Decodes a string with percent encoding.

Deprecated:
Use Url::decode()

◆ encodeUrl()

String asl::encodeUrl ( const String s)
inline

Encodes a string with percent encoding for use in a URL.

Deprecated:
Use Url::encode()