fmt_custom_encode [function]
fmt_custom_encode( string text, string class, string prefix, int format, int mindigits = 0, string postfix = "" )
encodes a custom format (selected character codes to numeric version)
Every character (byte) from text
that matches class
is converted to the following format:
prefix
- number according to
format
, at leastmindigits
long postfix
format
must be one of:
FMT_NUMBER_BINARY
- binary (base 2) numberFMT_NUMBER_OCTAL
- octal (base 8) numberFMT_NUMBER_DECIMAL
- decimal (base 10) numberFMT_NUMBER_HEX
,FMT_NUMBER_HEX_LC
- lowercase hexadecimal (base 16) numberFMT_NUMBER_HEX_UC
- uppercase hexadecimal (base 16) number
Use case example - encode a string for C/C++ source code output:
// character class: // - '^' - invert class (exclude the following characters/ranges) // - <space>, '!' - characters to exclude (first printable characters, before quote) // - '#-~' - character range to exclude (other printable characters, after quote) // the extra set of quotes around hex code prevent hyperactive parsers from thinking .. // .. that the following characters might be a part of the hex code fmt_custom_encode( 'some text', "^ !#-~", '""\\x', FMT_NUMBER_HEX, 2, '""' )