This topic describes the syntax, description, parameters, return values, and examples of Miscellaneous functions.

base64_enc

This function is described as follows:
  • Syntax: base64_enc(s [, no_padding])
  • Description

    You can call this function to convert a string to a Base64-encoded string.

  • Parameters
    • s: the string to be encoded.
    • no_padding: specifies whether to pad the string. Valid values: true for not padding and false for padding. Default value: false.
  • Return values

    This function returns a Base64-encoded string.

  • Examples
    if $http_data {
       decdata = base64_dec($http_data)
       say(concat('base64_decdata=', decdata))
       say(concat('base64_encdata=', base64_enc('hello, dsl'))) 
    }
    
    Request header: "data: aGVsbG8sIGRzbA=="
    Response: base64_decdata=hello, dsl
    base64_encdata=aGVsbG8sIGRzbA==

base64_dec

This function is described as follows:
  • Syntax: base64_dec(s)
  • Description

    You can call this function to decode a Base64-encoded string.

  • Parameters

    s: the string to be decoded.

  • Return values

    This function returns the decoded raw string.

  • Examples
    if $http_data {
       decdata = base64_dec($http_data)
       say(concat('base64_decdata=', decdata))
       say(concat('base64_encdata=', base64_enc('hello, dsl'))) 
    }
    
    Request header: "data: aGVsbG8sIGRzbA=="
    Response: base64_decdata=hello, dsl
    base64_encdata=aGVsbG8sIGRzbA==

url_escape

This function is described as follows:
  • Syntax: url_escape(s)
  • Description

    You can call this function to URL encode a string.

  • Parameters

    s: the string to be encoded.

  • Return values

    This function returns a URL-encoded string.

  • Examples
    raw = '/abc/123/ dd/file.m3u8'
    esdata = url_escape(raw)
    dsdata = url_unescape(esdata)
    if eq(raw, dsdata) {
        say(concat('raw=', raw))
        say(concat('dsdata=', dsdata))
    }
    Output: raw=/abc/123/ dd/file.m3u8
    esdata=%2Fabc%2F123%2F%20dd%2Ffile.m3u8
    dsdata=/abc/123/ dd/file.m3u8

url_unescape

This function is described as follows:
  • Syntax: url_unescape(s)
  • Description

    You can call this function to decode a URL-encoded string.

  • Parameters

    s: the URL-encoded string to be decoded.

  • Return values

    This function returns the URL-decoded string.

  • Examples
    raw = '/abc/123/ dd/file.m3u8'
    esdata = url_escape(raw)
    dsdata = url_unescape(esdata)
    if eq(raw, dsdata) {
        say(concat('raw=', raw))
        say(concat('dsdata=', dsdata))
    }
    Output: raw=/abc/123/ dd/file.m3u8
    esdata=%2Fabc%2F123%2F%20dd%2Ffile.m3u8
    dsdata=/abc/123/ dd/file.m3u8

rand

This function is described as follows:
  • Syntax: rand(n1, n2)
  • Description

    You can call this function to generate and return a random number. Value range for the returned random number: n1 <= return value <= n2. The n1 parameter specifies the minimum value of the random number. The n2 parameter specifies the maximum value of the random number.

  • Examples
    r = rand(1,100)

rand_hit

This function is described as follows:
  • Syntax: rand_hit(ratio)
  • Description

    You can call this function to return true or false depending on the specified ratio. The ratio parameter specifies the percentage of being true. The value range for the ratio parameter is from 0 to 100. If the ratio is 100, this function returns true. If the ratio is 0, this function returns false.

rand_bytes

This function is described as follows:
  • Syntax: rand_bytes(len)
  • Description

    You can call this function to generate and return a random numeric string. The len parameter specifies the length of the random numeric string.

crc

This function is described as follows:
  • Syntax: crc(s)
  • Description

    You can call this function to return the CRC digest of a string. The s parameter specifies the string to process and produce the digest for.

tonumber

This function is described as follows:
  • Syntax: tonumber(s [, base])
  • Description

    You can call this function to convert a string to a number. The s parameter specifies the string to be converted. The base parameter specifies the format of the returned number. Valid values of the base parameter: 10 (default) for the decimal format and 16 for the hexadecimal format.

  • Examples
    n = tonumber('100')
    say(concat('tonumber()=', n))
    
    Output: tonumber()=100