SPVM::Util - Variouse utilities
use SPVM::Util (chomp_lf, chomp_crlf); # Cut a newline LF { my $ret = chomp_lf("abc\n"); } # Cut a newline CR LF { my $ret = chomp_crlf("abc\r\n"); } # Create a new float complex array { my $re_values = [1.5f, 2.5f, 3.5f]; my $im_values = [5.5f, 6.5f, 7.5f]; my $farray = complex_farray($re_values, $im_values); } # Create a new double complex array { my $re_values = [1.5, 2.5, 3.5]; my $im_values = [5.5, 6.5, 7.5]; my $farray = complex_darray($re_values, $im_values); } # Create a new float complex value { my $z = complexf(1.5f, 2.5f); } # Create a new double complex value { my $z = complexd(1.5f, 2.5f); } # Copy a byte array { my $nums = [(byte)1, 2, 3]; my $nums_copy = copy_barray($nums); } # Copy a string { my $str = "abc"; my $str_copy = copy_str($str); } # Copy a short array { my $nums = [(short)1, 2, 3]; my $nums_copy = copy_sarray($nums); } # Copy a int array { my $nums = [1, 2, 3]; my $nums_copy = copy_iarray($nums); } # Copy a long array { my $nums = [(long)1, 2, 3]; my $nums_copy = copy_larray($nums); } # Copy a float array { my $nums = [1.5f, 2.5f, 3.5f]; my $nums_copy = copy_farray($nums); } # Copy a double array { my $nums = [1.5, 2.5, 3.5]; my $nums_copy = copy_darray($nums); } # Copy a string array { my $strs = ["abc", "def", "ghi"] my $strs_copy = copy_strarray($strs); } # Check if the two byte arrays equal { my $nums1 = [(byte)1, 2]; my $nums2 = [(byte)1, 2]; my $ret = equals_barray($nums1, $nums2); } # Check if the two short arrays equal { my $nums1 = [(short)1, 2]; my $nums2 = [(short)1, 2]; my $ret = equals_sarray($nums1, $nums2); } # Check if the two int arrays equal { my $nums1 = [(int)1, 2]; my $nums2 = [(int)1, 2]; my $ret = equals_iarray($nums1, $nums2); } # Check if the two long arrays equal { my $nums1 = [(long)1, 2]; my $nums2 = [(long)1, 2]; my $ret = equals_larray($nums1, $nums2); } # Check if the two float arrays equal { my $nums1 = [(float)1, 2]; my $nums2 = [(float)1, 2]; my $ret = equals_farray($nums1, $nums2); } # Check if the two double arrays equal { my $nums1 = [(double)1, 2]; my $nums2 = [(double)1, 2]; my $ret = equals_darray($nums1, $nums2); } # Check if the two string arrays equal { my $strs1 = ["abc", "def"]; my $strs2 = ["abc", "def"]; my $ret = equals_strarray($strs1, $strs2); } # Search substr { my $found_offset = index("pppabcde", "bcd", 2); } # Copy object array my $objects = [(object)SPVM::Int->new(1), SPVM::Int->new(2), SPVM::Int->new(3)]; my $objects_copy = copy_oarray($objects, sub : object ($self : self, $obj : object) { my $int_obj = (SPVM::Int)$obj; my $new_int_obj = SPVM::Int->new($int_obj->val); return $new_int_obj; }); # Stringify all object and join them by the specific separator my $objects = new Foo[3]; my $str = SPVM::Util->joino(",", $objects, sub : string ($self : self, $obj : object) { my $point = (SPVM::Point)$obj; my $x = $point->x; my $y = $point->y; my $str = "($x, $y)"; return $str; }); # split a string by the specific separator my $str = "foo,bar,baz"; my $splited_strs = split(",", $str);
Unix standard library.
sub copy_oarray : object[] ($objects : object[], $cloner : SPVM::Cloner)
Copy object array. You must specify a SPVM::Cloner object to copy each element.
sub sub equals_oarray : int ($objs1 : oarray, $objs2 : oarray, $equality_checker : SPVM::EqualityChecker)
Check equality of two objects. You must sepecify a SPVM::EqualityChecker object to check the equality of each element.
$objs1 and $objs2 and $equality_checker must be defined, otherwise a exception occur.
Return 1 if the length of $objs1 and $objs2 is same and all element is same, otherwise return 0.
sub joino : string ($sep : string, $objects : oarray, $stringer : SPVM::Stringer)
Stringify all objects and join them by specific separator. You must specify a SPVM::Stringer object to stringify each element.
If separater is undef, a exception occurs.
If object array is undef, a exception occurs.
sub split : string[] ($sep : string, $string : string)
Split a string by the specific separator.
sub chomp_lf : string ($string : string)
Copy the string and remove the newline "\n" from the end of string and return it.
sub chomp_crlf : string ($string : string)
Copy the string and remove the newline "\r\n" from the end of string and return it.
sub complex_farray : SPVM::Complex_2f[] ($re_values : float[], $im_values : float[])
Create a new array of SPVM::Complex_2f with real values and imaginary values.
sub complex_darray : SPVM::Complex_2d[] ($re_values : double[], $im_values : double[])
Create a new array of SPVM::Complex_2d with real values and imaginary values.
sub complexf : SPVM::Complex_2f ($re : float, $im : float)
Return a new value of SPVM::Complex_2f.
sub complexd : SPVM::Complex_2d ($re : double, $im : double)
Return a new value of SPVM::Complex_2d.
sub copy_barray : byte[] ($nums : byte[])
Copy a byte array.
If the array is undefined, a exception occurs.
sub copy_str : string ($string : string)
Copy a string.
sub copy_sarray : short[] ($nums : short[])
Copy a short array.
sub copy_iarray : int[] ($nums : int[])
Copy a int array.
sub copy_larray : long[] ($nums : long[])
Copy a long array.
sub copy_farray : float[] ($nums : float[])
Copy a float array.
sub copy_darray : double[] ($nums : double[])
Copy a double array.
sub copy_strarray : string[] ($strings : string[])
Copy a string array.
sub equals_barray : int ($nums1 : byte[], $nums2 : byte[])
Check if two byte arrays equal.
If at least one of the arrays is undefined, a excetpion occurs.
sub equals_sarray : int ($nums1 : short[], $nums2 : short[])
Check if two short arrays equal.
sub equals_iarray : int ($nums1 : int[], $nums2 : int[])
Check if two int arrays equal.
sub equals_larray : int ($nums1 : long[], $nums2 : long[])
Check if two long arrays equal.
sub equals_farray : int ($nums1 : float[], $nums2 : float[])
Check if two float arrays equal.
sub equals_darray : int ($nums1 : double[], $nums2 : double[])
Check if two double arrays equal.
sub equals_strarray : int ($strs1 : double[], $strs2 : double[])
Check if two string arrays equal.
sub E : double ()
Get a napier number.
sub get_type_name : string ($obj : object)
Get the type name of the object.
sub index : int ($str : string, $substr : string, $posision : int)
index function searches for one string within another. It returns the position of the first occurrence of $substr in $str at or after $position. If $position is omitted, starts searching from the beginning of the string. $position before the beginning of the string or after its end is treated as if it were the beginning or the end, respectively. $position and the return value are based at zero. If the substring is not found, "index" returns -1.
sub INT8_MIN : byte ()
Wapper of INT8_MIN of C99 cstdint library.
INT8_MAX : byte ()
Wapper of INT8_MAX of C99 cstdint library.
sub INT16_MIN : short ()
Wapper of INT16_MIN of C99 cstdint library.
sub INT16_MAX : short ()
Wapper of INT16_MAX of C99 cstdint library.
sub INT32_MIN : int ()
Wapper of INT32_MIN of C99 cstdint library.
sub INT32_MAX : int ()
Wapper of INT32_MAX of C99 cstdint library.
sub INT64_MIN : long ()
Wapper of INT64_MIN of C99 cstdint library.
sub INT64_MAX : long ()
Wapper of INT64_MAX of C99 cstdint library.
sub FLT_MIN : float ()
Wapper of FLT_MIN of C99 float library.
sub FLT_MAX : float ()
Wapper of FLT_MAX of C99 float library.
sub DBL_MIN : double ()
Wapper of DBL_MIN of C99 float library.
sub DBL_MAX : double ()
Wapper of DBL_MAX of C99 float library.
sub isalnum : int ($char : int)
If character is alphanumeric('A'-'Z', 'a'-'z', '0'-'9'), return 1. If not, return 0.
sub isalpha : int ($char : int)
If character is alphabetic('A'-'Z', 'a'-'z'), return 1. If not, return 0.
sub isblank : int ($char : int)
If character is blank(' ', '\t'), return 1. If not, return 0.
sub iscntrl : int ($char : int)
If character is a control character(0x00-0x1F, 0x7F), return 1. If not, return 0.
sub isdigit : int ($char : int)
If character is decimal digit ('0'~'9'), return 1. If not, return 0.
sub isgraph : int ($char : int)
If character has graphical representation(0x21-0x7E), return 1. If not, return 0.
sub islower : int ($char : int)
If character is lowercase letter('a'-'z'), return 1. If not, return 0.
sub isprint : int ($char : int)
If character is printable(0x20-0x7E), return 1. If not, return 0.
sub ispunct : int ($char : int)
If character is a punctuation character(0x21-0x2f, 0x3a-0x40, 0x5b-0x60, 0x7b-0x7e), return 1. If not, return 0.
sub isspace : int ($char : int)
If character is a white-space(' ', '\t', '\n', '\v', '\f', '\r'), return 1. If not, return 0.
sub isupper : int ($char : int)
If character is uppercase letter('A'-'Z'), return 1. If not, return 0.
sub isxdigit : int ($char : int)
If character is hexadecimal digit('0'-'9', 'A'-'F', 'a'-'f'), return 1. If not, return 0.
sub tolower : int ($char : int)
Convert uppercase letter('A'-'Z') to lowercase. If the character is not uppercase letter, return the character.
sub toupper : int ($char : int)
Convert lowercase letter('a'-'z') to lowercase. If the character is not uppercase letter, return the character.
sub is_perl_space : int ($char : int)
If character is Perl space character(' ', '\r', '\n', '\t', '\f'), return 1. If not, return 0.
sub is_perl_word : int ($char : int)
If character is Perl word character('a'-'z', 'A'-'Z', '_', '0'-'9'), return 1. If not, return 0.
sub joinb : string ($sep : string, $nums : byte[])
Join a byte array as string with separater and return it.
If byte array is undef, a exception occurs.
sub joins : string ($sep : string, $nums : short[])
Join a short array as string with separater and return it.
If short array is undef, a exception occurs.
sub joini : string ($sep : string, $nums : int[])
Join a int array as string with separater and return it.
If int array is undef, a exception occurs.
sub joinl : string ($sep : string, $nums : long[])
Join a long array as string with separater and return it.
If long array is undef, a exception occurs.
sub joinf : string ($sep : string, $nums : float[])
Join a float array as string with separater and return it.
If float array is undef, a exception occurs.
sub joind : string ($sep : string, $nums : double[])
Join a double array as string with separater and return it.
If double array is undef, a exception occurs.
sub join : string ($sep : string, $strings : string[])
Join a string array with separater and return it.
If string array is undef, a exception occurs.
sub lc : string($str : string)
Convert uppercase string to lowercase string.
sub lcfirst : string($str : string)
Convert first chracter of string from uppercase to lowercase.
sub memcpyb : void ($dest_data : byte[], $dest_offset : int, $src_data : byte[], $src_offset : int, $length : int)
Copy source byte array to destination byte array with the each offset and a length.
If source data range and destination data overlap, the result is not guaranteed.
If source byte array or destination array is undef, a exception occurs.
If length is nagative, a exception occurs.
If copy is not in the valid rainge, a exception occurs.
sub memcpys : void ($dest_data : short[], $dest_offset : int, $src_data : short[], $src_offset : int, $length : int)
Copy source short array to destination short array with the each offset and a length.
If source short array or destination array is undef, a exception occurs.
sub memcpyi : void ($dest_data : int[], $dest_offset : int, $src_data : int[], $src_offset : int, $length : int)
Copy source int array to destination int array with the each offset and a length.
If source int array or destination array is undef, a exception occurs.
sub memcpyl : void ($dest_data : long[], $dest_offset : int, $src_data : long[], $src_offset : int, $length : int)
Copy source long array to destination long array with the each offset and a length.
If source long array or destination array is undef, a exception occurs.
sub memcpyf : void ($dest_data : float[], $dest_offset : int, $src_data : float[], $src_offset : int, $length : int)
Copy source float array to destination float array with the each offset and a length.
If source float array or destination array is undef, a exception occurs.
sub memcpyd : void ($dest_data : double[], $dest_offset : int, $src_data : double[], $src_offset : int, $length : int)
Copy source double array to destination double array with the each offset and a length.
If source double array or destination array is undef, a exception occurs.
sub memmoveb : void ($dest_data : byte[], $dest_offset : int, $src_data : byte[], $src_offset : int, $length : int)
Even if source data range and destination data overlap, the result is guaranteed.
sub memmoves : void ($dest_data : short[], $dest_offset : int, $src_data : short[], $src_offset : int, $length : int)
sub memmovei : void ($dest_data : int[], $dest_offset : int, $src_data : int[], $src_offset : int, $length : int)
sub memmovel : void ($dest_data : long[], $dest_offset : int, $src_data : long[], $src_offset : int, $length : int)
sub memmovef : void ($dest_data : float[], $dest_offset : int, $src_data : float[], $src_offset : int, $length : int)
sub memmoved : void ($dest_data : double[], $dest_offset : int, $src_data : double[], $src_offset : int, $length : int)
sub new_object_array_proto : oarray ($proto_array : oarray, $length : int)
Create a new generic object array as the same type as the given array.
sub crand : int ();
Get random number(0 to SPVM::Util->RAND_MAX). This is same as rand function of C language.
The first seed is epoch time usually. Second seed is the return value.
use SPVM::Time; my $rand1 = crand(SPVM::Time->time); my $rand2 = crand($rand1);
sub rand : double ();
Get random number(0 <= random_number < 1). This is same as rand function of Perl language.
sub srand : void ($seed : long);
Sets random number seed for the "crand" static method.
sub replace : string ($str : string, $substr : string, $replace : string, $start_offset : int, $found_offset_ref : int&)
Replace the sub string in the string with a replace string and return the result string.
You can specify a byte offset of the string.
You can get the found byte offset by int reference.
my $str = "abcde"; my $substr = "bcd"; my $replace = "AB"; my $found_offset = 0; my $result_str = replace($str, $substr, $replace, 0, \$found_offset);
sub replace_all : string ($str : string, $substr : string, $replace : string)
Replace all the sub string in the string with a replace string and return the result string.
my $str = "foo bar foo bar foo"; my $substr = "bar"; my $replace = "AB"; my $result_str = replace_all($str, $substr, $replace);
sub strtoi : int ($string : string, $digit : int);
Convert the string to a int value with a digit(2, 8, 10, 16).
Format is [' ' or '\t' or '\n' or '\v' or '\f' or '\r'][+ or -][0][x][one more than 0-9]. Internal of [] is optional.
If convertion fails, a exception occuer.
my $string = "-2147483648"; my $num = strtoi($string, 10);
sub strtol : long ($string : string, $digit : int);
Convert the string to long value with digit(2, 8, 10, 16).
Format is [' ' or '\t' or '\n' or '\v' or '\f' or '\r'][+ or -][0][x][zero more than 0-9]. Internal of [] is optional.
If the convertion fails, a exception occuer.
my $string = "-9223372036854775808"; my $num = strtol($string, 10);
sub strtof : float ($string : string);
Convert the string to float value.
Format is [' ' or '\t' or '\n' or '\v' or '\f' or '\r'][+ or -][zero more than 0-9][.][zero more than 0-9][e or E[+ or -]zero more than 0-9]. Internal of [] is optional.
my $string = "1.25"; my $num = strtof($string);
sub strtod : double ($string : string);
my $string = "1.25"; my $num = strtod($string);
sub uc : string($str : string)
Convert a lowercase string to a uppercase string.
If the string is undef, a exception occur.
sub ucfirst : string($str : string)
Convert the first character of a string to a uppercase character.
sub rindex : int ($str : string, $substr : string, $offset : int)
Same as "index" function except that the search is the last of the string.
sub contains : int ($str : string, $substr : string)
If the string contains the sub string, return 1. If not, return 0.
sub abs : int ($x : int);
Get the abusolute value of a int value.
sub labs : long ($x : long);
Get the abusolute value for a long value.
native sub reverseb : void ($nums : byte[]);
Reverse the order of the elements of the byte array.
If the argument is undef, a exception occurs.
native sub reverses : void ($nums : short[]);
Reverse the order of the elements of the short array.
native sub reversei : void ($nums : int[]);
Reverse the order of the elements of the int array.
native sub reversel : void ($nums : long[]);
Reverse the order of the elements of the long array.
native sub reversef : void ($nums : float[]);
Reverse the order of the elements of the float array.
native sub reversed : void ($nums : double[]);
Reverse the order of the elements of the double array.
native sub reverseo : void ($objs : oarray);
Reverse the order of the elements of the object array.
sub warn : void ($string : string);
Print string with file name and line number to stderr. line break is added to end of string.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in '('0'~'9'),'. Assuming UTF-8
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.