SPVM::Fn - SPVM Starndard Functions
use Fn; # Cut a newline LF my $line = (mutable string)copy "abc\n"; Fn->chomp($line); # Contains my $found = Fn->contains("pppabcde", "bcd"); # Split my $csv = "foo,bar,baz"; my $items = Fn->split(",", $string); # Join my $items = ["foo", "bar", "baz"]; my $csv = Fn->join(",", $items); # Constant values my $byte_max = Fn->BYTE_MAX(); my $short_max = Fn->SHORT_MAX(); my $int_max = Fn->INT_MAX(); my $long_max = Fn->LONG_MAX();
Fn module provides SPVM Starndard Functions. Fn contains number, string and array utilities.
Fn
Return -1. The return type is the int type.
-1
int
Return -2. The return type is the int type.
-2
static method BYTE_MAX : byte ()
The same as "INT8_MAX".
static method BYTE_MIN : byte ()
The same as "INT8_MIN".
static method DBL_MAX : double ()
Return the value of DBL_MAX macro defined in float.h header of C language.
DBL_MAX
float.h
C language
static method DBL_MIN : double ()
Return the value of DBL_MIN macro defined in float.h header of C language.
DBL_MIN
static method DOUBLE_MAX : double ()
The same as "DBL_MAX".
static method DOUBLE_MIN : double ()
The same as "DBL_MIN".
static method FLOAT_MAX : float ()
The same as "FLT_MAX".
static method FLOAT_MIN : float()
The same as "FLT_MIN".
static method FLT_MAX : float ()
Return the value of FLT_MAX macro defined in float.h header of C language.
FLT_MAX
static method FLT_MIN : float ()
Return the value of FLT_MIN macro defined in float.h header of C language.
FLT_MIN
static method INT16_MAX : short ()
Return 32767. The maximum value of the signed 16bit integer.
32767
static method INT16_MIN : short ()
Return -32768. The minimal value of the signed 16bit integer.
-32768
static method INT32_MAX : int ()
Return 2147483647. The maximum value of the signed 32bit integer.
2147483647
static method INT32_MIN : int ()
Return -2147483648. The minimal value of the signed 32bit integer.
-2147483648
static method INT64_MAX : long ()
Return 9223372036854775807. The maximum value of the signed 64bit integer.
9223372036854775807
static method INT64_MIN : long ()
Return -9223372036854775808. The minimal value of the signed 64bit integer.
-9223372036854775808
static method INT8_MAX : byte ()
Return 127. The maximum value of the signed 8bit integer.
127
static method INT8_MIN : byte ()
Return -128. The minimal value of the signed 8bit integer.
-128
static method INT_MAX : int ()
The same as "INT32_MAX".
static method INT_MIN : int ()
The same as "INT32_MIN".
static method LONG_MAX : long ()
The same as "INT64_MAX".
static method LONG_MIN : long ()
The same as "INT64_MIN".
static method RAND_MAX : int ()
Return 2147483647.
static method SHORT_MAX : short ()
The same as "INT16_MAX".
static method SHORT_MIN : short ()
The same as "INT16_MIN".
static method UBYTE_MAX : byte ()
The same as "UINT8_MAX".
static method UINT16_MAX : short ()
Return -1. This represents 0xFFFF in the unsigned 16bit integer in 2's complement.
0xFFFF
static method UINT32_MAX : int ()
Return -1. This represents 0xFFFFFFFF in the unsigned 32bit integer in 2's complement.
0xFFFFFFFF
static method UINT64_MAX : long ()
Return -1. This represents 0xFFFFFFFFFFFFFFFF in the unsigned 64bit integer in 2's complement.
0xFFFFFFFFFFFFFFFF
static method UINT8_MAX : byte ()
Return -1. This represents 0xFF in the unsigned 8bit integer in 2's complement.
0xFF
static method UINT_MAX : int ()
The same as "UINT32_MAX".
static method ULONG_MAX : long
The same as "UINT64_MAX".
static method USHORT_MAX : short ()
The same as "UINT16_MAX".
static method abs : int ($value : int)
Return the absolute value of the input value.
static method chomp : void ($string : mutable string)
Remove \n of the end of the string. Otherwise an exception will occur.
\n
The string must be defined
static method chompr : string ($string : string)
Copy the string and remove \n of the end of the copied string and return it.
The string must be defined. Otherwise an exception will occur.
static method chr : string ($code_point : int)
Convert the Unicode code point to the UTF-8 character and return it.
UTF-8
If the Unicode code point is not a Unicode scalar value, return undef.
undef
static method contains : int ($string : string, $substring : string, $offset = 0 : int, $length = -1 : int)
The alias for the following code using ""index".
my $ret = Fn->index($string, $substring, $offset, $length) >= 0;
static method copy_string : string ($string : string)
The alias for the following code using the copy operator
my $ret = copy $string;
static method crand : int ($seed : int*);
Create a random number from 0 to "RAND_MAX" using the seed and return it.
0
The seed is updated.
This method is thread safe.
Examples:
use Time; my $seed = (int)Time->time; my $crand0 = Fn->crand(\$seed); my $crand1 = Fn->crand(\$seed);
static method get_next_code_point : int ($string : string, $offset_ref : int*)
The same as "get_code_point".
This method is depracated. Use "get_code_point" instead.
static method get_code_point : int ($string : string, $offset_ref : int*)
Parse the UTF-8 character at the offset of the string and return its Unicode code point.
The offset is updated to the position of the next UTF-8 character.
If the offset is greater than the length of the string, return the value of "GET_CODE_POINT_ERROR_OVER_STRING_RANGE".
If the UTF-8 character is invalid, return the value of "GET_CODE_POINT_ERROR_INVALID_UTF8".
The offset must be greater than or equal to 0. Otherwise an exception will occur.
static method hex : int ($hex_string : string)
Convert the hex string to the int value and return it.
The hex string must be defined. Otherwise an exception will occur.
The length of the hex string must be 1 to 8. Otherwise an exception will occur.
1
8
The hex string must contain only hex characters 0-9a-zA-Z. Otherwise an exception will occur.
0-9a-zA-Z
static method index : int ($string : string, $substring : string, $offset = 0 : int, $length = -1 : int)
Search for the substring in the range of the string from the offset to the position proceeded by the length.
If the substring is found, return the found offset. Otherwise return -1.
If the length is less than 0, the length to the end of the string is calculated from the length of the string and the offset.
The substring must be defined. Otherwise an exception will occur.
The offset + the length specified by the argument must be less than or equal to the length of the string. Otherwise an exception will occur.
static method index_len : int ($string : string, $substring : string, $offset : int, $length : int)
The alias for the following code using "index".
my $ret = Fn->index($string, $substring, $offset, $length);
This method is deprecated and will be removed after 2022-09-03.
static method is_alnum : int ($code_point : int)
If the Unicode code point is an ASCII alphanumeric A-Za-z0-9, return 1. Otherwise return 0.
A-Za-z0-9
static method is_alpha : int ($code_point : int)
If the Unicode code point is an ASCII alphabetic A-Za-z, return 1. Otherwise return 0.
A-Za-z
static method is_array : int ($object : object)
If the object is defined and the type of the object is the array type, return 1. Otherwise return 0.
"is_array" in SPVM::Document::NativeAPI is used to check the type.
static method is_blank : int ($code_point : int)
If the Unicode code point is an ASCII blank 0x20(SP, ' '), 0x09(HT, '\t'), return 1. Otherwise return 0.
0x20(SP, ' ')
0x09(HT, '\t')
static method is_cntrl : int ($code_point : int)
If the Unicode code point is an ASCII control character 0x00-0x1F, 0x7F, return 1. Otherwise return 0.
0x00-0x1F
0x7F
static method is_digit : int ($code_point : int)
If the Unicode code point is an ASCII decimal digit 0-9, return 1. Otherwise return 0.
0-9
static method is_graph : int ($code_point : int)
If the character is an ASCII graphical character 0x21-0x7E, return 1. Otherwise return 0.
0x21-0x7E
static method is_hex_digit : int ($code_point : int)
If the character is a hexadecimal digit 0-9a-fA-F, return 1. Otherwise return 0.
0-9a-fA-F
static method is_lower : int ($code_point : int)
If the Unicode code point is an ASCII lowercase character a-z, return 1. Otherwise return 0.
a-z
static method is_mulnum_array : int ($object : object)
If the object is defined and the type of the object is the multi-numeric array type, return 1. Otherwise return 0.
"is_mulnum_array" in SPVM::Document::NativeAPI is used to check the type.
static method is_numeric_array : int ($object : object)
If the object is defined and the type of the object is the numeric array type, return 1. Otherwise return 0.
"is_numeric_array" in SPVM::Document::NativeAPI is used to check the type.
static method is_object_array : int ($object : object)
If the object is defined and the type of the object is an object array type, return 1. Otherwise return 0.
"is_object_array" in SPVM::Document::NativeAPI is used to check the type.
static method is_perl_space : int ($code_point : int)
If the Unicode code point is an Perl ASCII space character 0x09(HT, '\t'), 0x0A(LF, '\n'), 0x0C(FF, '\f'), 0x0D(CR, '\r'), 0x20(SP, ' '), return 1. Otherwise return 0.
0x0A(LF, '\n')
0x0C(FF, '\f')
0x0D(CR, '\r')
Note that prior to Perl v5.18, \s in ASCII mode did not match the vertical tab 0x0B(VT). is_perl_space is the same as this behavior.
\s
0x0B(VT)
is_perl_space
Current Perl \s in ASCII mode is the same as "is_space".
static method is_perl_word : int ($code_point : int)
If the Unicode code point is an Perl ASCII word character a-zA-Z0-9_, return 1. Otherwise return 0.
a-zA-Z0-9_
static method is_print : int ($code_point : int)
If the Unicode code point is an ASCII printable character 0x20-0x7E, return 1. Otherwise return 0.
0x20-0x7E
static method is_punct : int ($code_point : int)
If the Unicode code point is an ASCII a punctuation character 0x21-0x2F, 0x3A-0x40, 0x5B-0x60, 0x7B-0x7E, return 1. Otherwise return 0.
0x21-0x2F
0x3A-0x40
0x5B-0x60
0x7B-0x7E
static method is_space : int ($code_point : int)
If the Unicode code point is an ASCII a white-space 0x09(HT, '\t'), 0x0A(LF, '\n'), 0x0B(VT), 0x0C(FF, '\f'), 0x0D(CR, '\r'), 0x20(SP, ' ') return 1. Otherwise return 0.
static method is_upper : int ($code_point : int)
If the Unicode code point is an ASCII uppercase character A-Z, return 1. Otherwise return 0.
A-Z
static method is_xdigit : int ($code_point : int)
If the Unicode code point is an ASCII hexadecimal digit 0-9A-Fa-f, return 1. Otherwise return 0.
0-9A-Fa-f
static method join : string ($sep : string, $strings : string[])
Concatenate the strings with the separater and return it.
The strings must be defined. Otherwise an exception will occur.
The separator must be defined. Otherwise an exception will occur.
static method labs : long ($value : long)
static method lc : string ($string : string)
Convert the ASCII uppercase characters A-Z in the string to the corresponding ASCII lowercase characters a-z. And return it.
static method lcfirst : string ($string : string)
If the first character of the string is an ASCII uppercase character A-Z, it is converted to the corresponding ASCII lowercase characters a-z. And return the converted string.
static method look_next_code_point : int ($string : string, $offset_ref : int*)
The same as "look_code_point", but this method is depracated. Use "look_code_point" instead.
static method look_code_point : int ($string : string, $offset_ref : int*)
The same as "get_code_point", but the offset is not updated.
static method memcpy : void ($dest : object, $dest_offset : int, $source : object, $source_offset : int, $length : int);
Copy the range of the source to the the range of the destination.
The range of the destination is from the offset to the position proceeded by the length of the destination.
The range of the source is from the offset to the position proceeded by the length of the source.
The unit of the offset and the length is byte size.
byte
If the range of the source and the range of the destination overlap, the result is not guaranteed.
The destination must be defined. Otherwise an exception will occur.
The type of the destination must be the string type, the numeric arrya type, or the multi numeric array type. Otherwise an exception will occur.
The source must be defined. Otherwise an exception will occur.
The type of the source must be the string type, the numeric arrya type, or the multi numeric array type. Otherwise an exception will occur.
The destination must not be a read-only string. Otherwise an exception will occur.
The length must be greater than or equal to 0. Otherwise an exception will occur.
The offset of the destination + the length specified by the argument must be less than or equal to the length of the destination. Otherwise an exception will occur.
The offset of the source + the length specified by the argument must be less than or equal to the length of the source. Otherwise an exception will occur.
static method memmove : void ($dest : object, $dest_offset : int, $source : object, $source_offset : int, $length : int);
The same as "memcpy", but even if the range of the source and the range of the destination overlap, the result is guaranteed.
static method ord : int ($string : string);
The alias for the following code using "get_code_point".
my $offset = 0; my $code_point = Fn->get_code_point($string, \$offset);
static method powi : int ($base : int, $exponant : int)
Calculate the exponentiation from the base number and the exponant number.
The exponant number must be greater than or equal to 0. Otherwise an exception will occur.
If the base number is 0, the exponant number can't be 0. Otherwise an exception will occur.
static method powl : long ($base : long, $exponant : long)
static method rand : double ($seed : int*)
Get a 64bit floating point random number that is greater than or equal to 0 and less than 1 using the seed.
use Time; my $seed = (int)Time->time; my $rand0 = Fn->rand(\$seed); my $rand1 = Fn->rand(\$seed);
static method repeat : double ($string : string, $count : int)
Concatenate the string the number of times specified in the count and return it.
The repeat count must be greater than or equal to 0. Otherwise an exception will occur.
# "abcabcabc" my $repeat_string = Fn->repeat("abc", 3);
static method rindex : int ($string : string, $substring : string, $offset = 0 : int, $length = -1 : int)
Search for the substring in the range of the string from the offset to the position proceeded by the length in the direction from back to front.
static method rindex_len : int ($string : string, $substring : string, $offset : int, $length : int)
The alias for the following code using "rindex".
my $ret = Fn->rindex($string, $substring, $offset, $length);
static method shorten : void ($string : mutable string, $length : int32_t)
Shorten the string to the length specified by the argument using "shorten" in SPVM::Document::NativeAPI.
If the length specified by the argument is greater than or equal to the length of the string, nothing is performed.
static method split : string[] ($sep : string, $string : string, $limit = -1 : int)
If the limit is less than 0, split a string by the specific separator and convert them to an string array and return it.
If the limit is greater than than 0, the limit becomes the length of the maximam separated elements.
The limit can't be 0. Otherwise an exception will occur.
static method split_limit : string[] ($sep : string, $string : string, $limit : int)
The alias for the following code using "split".
my $ret = Fn->split($sep, $string, $limit);
static method substr : string ($string : string, $offset : int, $length = -1 : int)
Get the substring from the string. The extracting range of the string is from the offset to the position proceeded by the length.
static method to_double : double ($string : string);
Convert the string to the double value using strtod in C language.
double
strtod
The string must be the string that can be parsed as a double number. Otherwise an exception will occur.
The string must be a double number in the correct range. Otherwise an exception will occur.
my $string = "1.25"; my $num = Fn->to_double($string);
static method to_float : float ($string : string);
Convert the string to the double value using strtof in C language.
strtof
The string must be the string that can be parsed as a float number. Otherwise an exception will occur.
The string must be a float number in the correct range. Otherwise an exception will occur.
my $string = "1.25"; my $num = Fn->to_float($string);
static method to_int : int ($string : string, $digit : int);
The alias for the following code using "to_int_with_base".
my $ret = Fn->to_int_with_base($string, 10);
Convert the string to the int value using strtol in C language.
strtol
The string must be the string that can be parsed as an int number. Otherwise an exception will occur.
The string must be an int number in the correct range. Otherwise an exception will occur.
my $string = "-2147483648"; my $num = Fn->to_int_with_base($string, 10);
static method to_long : long ($string : string);
The alias for the following code using "to_long_with_base".
my $ret = Fn->to_long_with_base($string, 10);
static method to_long_with_base : long ($string : string, $digit : int);
Convert the string to the long value using strtoll in C language.
long
strtoll
The digit must be one of 2, 8, 10, or 16.
2
10
16
The string must be the string that can be parsed as a long number. Otherwise an exception will occur.
The string must be a long number in the correct range. Otherwise an exception will occur.
my $string = "-9223372036854775808"; my $num = Fn->to_long_with_base($string, 10);
static method to_lower : int ($code_point : int)
If the code point is the ASCII uppercase character A-Z, it is converted to the corresponding ASCII lowercase character a-z.
If the code point is not an ASCII uppercase character, return the code point specified by the argument.
static method to_upper : int ($code_point : int)
If the code point is the ASCII lowercase character a-z, it is converted to the corresponding ASCII uppercase character A-Z.
If the code point is not an ASCII lowercase character, return the code point specified by the argument.
static method trim_ascii_space : string ($string : string)
The same as "trim". This method is deprecated. Use "trim" instead.
static method trim : string ($string : string)
Remove the right and left spaces of the string and return it.
The removed spaces is the same as the spaces "is_space" method returns 1.
static method uc : string ($string : string)
Convert the ASCII lowercase characters a-z in the string to the corresponding ASCII uppercase characters A-Z. And return it.
static method ucfirst : string ($string : string)
If the first character of the string is an ASCII lowercase characters a-z, it is converted to the corresponding ASCII uppercase character A-Z. And return the converted string.
To install SPVM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPVM
CPAN shell
perl -MCPAN -e shell install SPVM
For more information on module installation, please visit the detailed CPAN module installation guide.