| 1 | package SPVM::Fn; | ||
| 2 | |||
| 3 | 1; | ||
| 4 | |||
| 5 | =encoding utf8 | ||
| 6 | |||
| 7 | =head1 Name | ||
| 8 | |||
| 9 | SPVM::Fn - SPVM Starndard Functions | ||
| 10 | |||
| 11 | =head1 Description | ||
| 12 | |||
| 13 | The Fn class of L<SPVM> has methods for numbers, strings, general utilities. | ||
| 14 | |||
| 15 | =head1 Usage | ||
| 16 | |||
| 17 | use Fn; | ||
| 18 | |||
| 19 | # Cut a newline LF | ||
| 20 | my $line = (mutable string)copy "abc\n"; | ||
| 21 | Fn->chomp($line); | ||
| 22 | |||
| 23 | # Contains | ||
| 24 | my $found = Fn->contains("pppabcde", "bcd"); | ||
| 25 | |||
| 26 | # Split | ||
| 27 | my $csv = "foo,bar,baz"; | ||
| 28 | my $args_width = Fn->split(",", $string); | ||
| 29 | |||
| 30 | # Join | ||
| 31 | my $args_width = ["foo", "bar", "baz"]; | ||
| 32 | my $csv = Fn->join(",", $args_width); | ||
| 33 | |||
| 34 | # Constant values | ||
| 35 | my $byte_max = Fn->BYTE_MAX(); | ||
| 36 | my $short_max = Fn->SHORT_MAX(); | ||
| 37 | my $int_max = Fn->INT_MAX(); | ||
| 38 | my $long_max = Fn->LONG_MAX(); | ||
| 39 | |||
| 40 | =head1 Class Methods | ||
| 41 | |||
| 42 | =head2 BYTE_MAX | ||
| 43 | |||
| 44 | C<static method BYTE_MAX : byte ();> | ||
| 45 | |||
| 46 | The same as L</"INT8_MAX">. | ||
| 47 | |||
| 48 | =head2 BYTE_MIN | ||
| 49 | |||
| 50 | C<static method BYTE_MIN : byte ();> | ||
| 51 | |||
| 52 | The same as L</"INT8_MIN">. | ||
| 53 | |||
| 54 | =head2 DBL_MAX | ||
| 55 | |||
| 56 | C<static method DBL_MAX : double ();> | ||
| 57 | |||
| 58 | Returns the value of C<DBL_MAX> macro defined in C<float.h> header of the C language. | ||
| 59 | |||
| 60 | =head2 DBL_MIN | ||
| 61 | |||
| 62 | C<static method DBL_MIN : double ();> | ||
| 63 | |||
| 64 | Returns the value of C<DBL_MIN> macro defined in C<float.h> header of the C language. | ||
| 65 | |||
| 66 | =head2 DOUBLE_MAX | ||
| 67 | |||
| 68 | C<static method DOUBLE_MAX : double ();> | ||
| 69 | |||
| 70 | The same as L</"DBL_MAX">. | ||
| 71 | |||
| 72 | =head2 DOUBLE_MIN | ||
| 73 | |||
| 74 | C<static method DOUBLE_MIN : double ();> | ||
| 75 | |||
| 76 | The same as L</"DBL_MIN">. | ||
| 77 | |||
| 78 | =head2 FLOAT_MAX | ||
| 79 | |||
| 80 | C<static method FLOAT_MAX : float ();> | ||
| 81 | |||
| 82 | The same as L</"FLT_MAX">. | ||
| 83 | |||
| 84 | =head2 FLOAT_MIN | ||
| 85 | |||
| 86 | C<static method FLOAT_MIN : float();> | ||
| 87 | |||
| 88 | The same as L</"FLT_MIN">. | ||
| 89 | |||
| 90 | =head2 FLT_MAX | ||
| 91 | |||
| 92 | C<static method FLT_MAX : float ();> | ||
| 93 | |||
| 94 | Returns the value of C<FLT_MAX> macro defined in C<float.h> header of the C language. | ||
| 95 | |||
| 96 | =head2 FLT_MIN | ||
| 97 | |||
| 98 | C<static method FLT_MIN : float ();> | ||
| 99 | |||
| 100 | Returns the value of C<FLT_MIN> macro defined in C<float.h> header of the C language. | ||
| 101 | |||
| 102 | =head2 INT16_MAX | ||
| 103 | |||
| 104 | C<static method INT16_MAX : short ();> | ||
| 105 | |||
| 106 | Returns 32767. The maximum value of the signed 16bit integer. | ||
| 107 | |||
| 108 | =head2 INT16_MIN | ||
| 109 | |||
| 110 | C<static method INT16_MIN : short ();> | ||
| 111 | |||
| 112 | Returns -32768. The minimal value of the signed 16bit integer. | ||
| 113 | |||
| 114 | =head2 INT32_MAX | ||
| 115 | |||
| 116 | C<static method INT32_MAX : int ();> | ||
| 117 | |||
| 118 | Returns 2147483647. The maximum value of the signed 32bit integer. | ||
| 119 | |||
| 120 | =head2 INT32_MIN | ||
| 121 | |||
| 122 | C<static method INT32_MIN : int ();> | ||
| 123 | |||
| 124 | Returns -2147483648. The minimal value of the signed 32bit integer. | ||
| 125 | |||
| 126 | =head2 INT64_MAX | ||
| 127 | |||
| 128 | C<static method INT64_MAX : long ();> | ||
| 129 | |||
| 130 | Returns 9223372036854775807. The maximum value of the signed 64bit integer. | ||
| 131 | |||
| 132 | =head2 INT64_MIN | ||
| 133 | |||
| 134 | C<static method INT64_MIN : long ();> | ||
| 135 | |||
| 136 | Returns -9223372036854775808. The minimal value of the signed 64bit integer. | ||
| 137 | |||
| 138 | =head2 INT8_MAX | ||
| 139 | |||
| 140 | C<static method INT8_MAX : byte ();> | ||
| 141 | |||
| 142 | Returns 127. The maximum value of the signed 8bit integer. | ||
| 143 | |||
| 144 | =head2 INT8_MIN | ||
| 145 | |||
| 146 | C<static method INT8_MIN : byte ();> | ||
| 147 | |||
| 148 | Returns -128. The minimal value of the signed 8bit integer. | ||
| 149 | |||
| 150 | =head2 INT_MAX | ||
| 151 | |||
| 152 | C<static method INT_MAX : int ();> | ||
| 153 | |||
| 154 | The same as L</"INT32_MAX">. | ||
| 155 | |||
| 156 | =head2 INT_MIN | ||
| 157 | |||
| 158 | C<static method INT_MIN : int ();> | ||
| 159 | |||
| 160 | The same as L</"INT32_MIN">. | ||
| 161 | |||
| 162 | =head2 LONG_MAX | ||
| 163 | |||
| 164 | C<static method LONG_MAX : long ();> | ||
| 165 | |||
| 166 | The same as L</"INT64_MAX">. | ||
| 167 | |||
| 168 | =head2 LONG_MIN | ||
| 169 | |||
| 170 | C<static method LONG_MIN : long ();> | ||
| 171 | |||
| 172 | The same as L</"INT64_MIN">. | ||
| 173 | |||
| 174 | =head2 RAND_MAX | ||
| 175 | |||
| 176 | C<static method RAND_MAX : int ();> | ||
| 177 | |||
| 178 | Returns 2147483647. | ||
| 179 | |||
| 180 | =head2 SHORT_MAX | ||
| 181 | |||
| 182 | C<static method SHORT_MAX : short ();> | ||
| 183 | |||
| 184 | The same as L</"INT16_MAX">. | ||
| 185 | |||
| 186 | =head2 SHORT_MIN | ||
| 187 | |||
| 188 | C<static method SHORT_MIN : short ();> | ||
| 189 | |||
| 190 | The same as L</"INT16_MIN">. | ||
| 191 | |||
| 192 | =head2 UBYTE_MAX | ||
| 193 | |||
| 194 | C<static method UBYTE_MAX : byte ();> | ||
| 195 | |||
| 196 | The same as L</"UINT8_MAX">. | ||
| 197 | |||
| 198 | =head2 UINT16_MAX | ||
| 199 | |||
| 200 | C<static method UINT16_MAX : short ();> | ||
| 201 | |||
| 202 | Returns -1. This represents C<0xFFFF> in the unsigned 16bit integer in 2's complement. | ||
| 203 | |||
| 204 | =head2 UINT32_MAX | ||
| 205 | |||
| 206 | C<static method UINT32_MAX : int ();> | ||
| 207 | |||
| 208 | Returns -1. This represents C<0xFFFFFFFF> in the unsigned 32bit integer in 2's complement. | ||
| 209 | |||
| 210 | =head2 UINT64_MAX | ||
| 211 | |||
| 212 | C<static method UINT64_MAX : long ();> | ||
| 213 | |||
| 214 | Returns -1. This represents C<0xFFFFFFFFFFFFFFFF> in the unsigned 64bit integer in 2's complement. | ||
| 215 | |||
| 216 | =head2 UINT8_MAX | ||
| 217 | |||
| 218 | C<static method UINT8_MAX : byte ();> | ||
| 219 | |||
| 220 | Returns -1. This represents C<0xFF> in the unsigned 8bit integer in 2's complement. | ||
| 221 | |||
| 222 | =head2 UINT_MAX | ||
| 223 | |||
| 224 | C<static method UINT_MAX : int ();> | ||
| 225 | |||
| 226 | The same as L</"UINT32_MAX">. | ||
| 227 | |||
| 228 | =head2 ULONG_MAX | ||
| 229 | |||
| 230 | C<static method ULONG_MAX : long> | ||
| 231 | |||
| 232 | The same as L</"UINT64_MAX">. | ||
| 233 | |||
| 234 | =head2 USHORT_MAX | ||
| 235 | |||
| 236 | C<static method USHORT_MAX : short ();> | ||
| 237 | |||
| 238 | The same as L</"UINT16_MAX">. | ||
| 239 | |||
| 240 | =head2 abs | ||
| 241 | |||
| 242 | C<static method abs : int ($value : int);> | ||
| 243 | |||
| 244 | Returns the absolute value of $value. | ||
| 245 | |||
| 246 | =head2 chomp | ||
| 247 | |||
| 248 | C<static method chomp : int ($string : mutable string);> | ||
| 249 | |||
| 250 | Removes C<\r\n> or C<\n> at the end of $string, and returns the removed length. | ||
| 251 | |||
| 252 | Exceptions: | ||
| 253 | |||
| 254 | $string must be defined. Otherwise an exception is thrown. | ||
| 255 | |||
| 256 | =head2 chompr | ||
| 257 | |||
| 258 | C<static method chompr : string ($string : string);> | ||
| 259 | |||
| 260 | Copies $string and removes C<\r\n> or C<\n> at the end of the copied string and returns it. | ||
| 261 | |||
| 262 | Exceptions: | ||
| 263 | |||
| 264 | $string must be defined. Otherwise an exception is thrown. | ||
| 265 | |||
| 266 | =head2 chr | ||
| 267 | |||
| 268 | C<static method chr : string ($code_point : int);> | ||
| 269 | |||
| 270 | Converts $code_point to the UTF-8 character and return it. | ||
| 271 | |||
| 272 | If $code_point is not a Unicode scalar value, return undef. | ||
| 273 | |||
| 274 | =head2 contains | ||
| 275 | |||
| 276 | C<static method contains : int ($string : string, $substring : string, $begin : int = 0, $end : int = -1);> | ||
| 277 | |||
| 278 | Checks if $string contains $substring. | ||
| 279 | |||
| 280 | Implementation: | ||
| 281 | |||
| 282 | The alias for the following code using L</"index"> method. | ||
| 283 | |||
| 284 | my $ret = Fn->index($string, $substring, $begin, $end) >= 0; | ||
| 285 | |||
| 286 | =head2 copy_string | ||
| 287 | |||
| 288 | C<static method copy_string : string ($string : string);> | ||
| 289 | |||
| 290 | The alias for the following code using L<copy operator|SPVM::Document::Language::Operators/"copy Operator"> | ||
| 291 | |||
| 292 | my $ret = copy $string; | ||
| 293 | |||
| 294 | =head2 crand | ||
| 295 | |||
| 296 | C<static method crand : int ($seed_ref : int*);> | ||
| 297 | |||
| 298 | Create a random number from 0 to L</"RAND_MAX"> using $$seed_ref and return it. | ||
| 299 | |||
| 300 | $$seed_ref is updated. | ||
| 301 | |||
| 302 | This method is thread safe. | ||
| 303 | |||
| 304 | Examples: | ||
| 305 | |||
| 306 | use Sys::Time; | ||
| 307 | my $seed = (int)Sys::Time->time; | ||
| 308 | my $crand0 = Fn->crand(\$seed); | ||
| 309 | my $crand1 = Fn->crand(\$seed); | ||
| 310 | |||
| 311 | =head2 equals_string_range | ||
| 312 | |||
| 313 | C<static method equals_string_range : int ($string1 : string, $string1_offset : int, $string2 : string, $string2_offset : int, $length : int);> | ||
| 314 | |||
| 315 | Compares $string1 + $string1_offset with $string2 + $string2_offset by $length. If they are euqal, returns 1, otherwise returns 0. | ||
| 316 | |||
| 317 | If $length is 0, returns 1. | ||
| 318 | |||
| 319 | Exceptions: | ||
| 320 | |||
| 321 | $string1 must be defined. Otherwise an exception is thrown. | ||
| 322 | |||
| 323 | $string2 must be defined. Otherwise an exception is thrown. | ||
| 324 | |||
| 325 | $string1_offset must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 326 | |||
| 327 | $string2_offset must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 328 | |||
| 329 | =head2 get_code_point | ||
| 330 | |||
| 331 | C<static method get_code_point : int ($string : string, $offset_ref : int*);> | ||
| 332 | |||
| 333 | Parses the UTF-8 character at the value reffered by $offset_ref of $string and return its Unicode code point. | ||
| 334 | |||
| 335 | The offset is updated to the position of the next UTF-8 character. | ||
| 336 | |||
| 337 | Exceptions: | ||
| 338 | |||
| 339 | $string must be defined. Otherwise an exception is thrown. | ||
| 340 | |||
| 341 | $offset must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 342 | |||
| 343 | The value of $offset must be less than the length of $string. Otherwise an exception is thrown. | ||
| 344 | |||
| 345 | If an invalid UTF-8 is gotten, an exception is thrown set C<eval_error_id> to the basic type ID of L<Error::Unicode::InvalidUTF8|SPVM::Error::Unicode::InvalidUTF8> class. | ||
| 346 | |||
| 347 | =head2 hex | ||
| 348 | |||
| 349 | C<static method hex : int ($hex_string : string);> | ||
| 350 | |||
| 351 | Converts $hex_string to the C<int> value and return it. | ||
| 352 | |||
| 353 | Exceptions: | ||
| 354 | |||
| 355 | $hex string must be defined. Otherwise an exception is thrown. | ||
| 356 | |||
| 357 | The length of $hex string must be 1 to 8. Otherwise an exception is thrown. | ||
| 358 | |||
| 359 | $hex string must contain only hex characters C<0-9a-zA-Z>. Otherwise an exception is thrown. | ||
| 360 | |||
| 361 | =head2 index | ||
| 362 | |||
| 363 | C<static method index : int ($string : string, $substring : string, $begin : int = 0, $end : int = -1);> | ||
| 364 | |||
| 365 | Searches for $substring in the range of $string from $begin to $end. | ||
| 366 | |||
| 367 | The search is performed from the beginning of the range of $string. | ||
| 368 | |||
| 369 | If $substring is found, returns the found offset. Otherwise, returns -1. | ||
| 370 | |||
| 371 | If $end is less than 0, $end is set to the length of $string minus 1. | ||
| 372 | |||
| 373 | Exceptions: | ||
| 374 | |||
| 375 | $string must be defined. Otherwise an exception is thrown. | ||
| 376 | |||
| 377 | $substring must be defined. Otherwise an exception is thrown. | ||
| 378 | |||
| 379 | $begin must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 380 | |||
| 381 | $end must be less than the length of $string. | ||
| 382 | |||
| 383 | =head2 init_string | ||
| 384 | |||
| 385 | C<static method init_string : void ($string : mutable string, $ascii_code : int = 0, $offset = 0 int, $length = -1);> | ||
| 386 | |||
| 387 | Sets the characters in $string from $offset to the position proceeded by $length to $ascii_code. | ||
| 388 | |||
| 389 | If $length is less than 0, $length is set to the length of $string - $offset. | ||
| 390 | |||
| 391 | Exceptions: | ||
| 392 | |||
| 393 | $string must be defined. Otherwise an exception is thrown. | ||
| 394 | |||
| 395 | $offset + $length must be less than or equal to the length of $string. | ||
| 396 | |||
| 397 | =head2 is_alnum | ||
| 398 | |||
| 399 | C<static method is_alnum : int ($code_point : int);> | ||
| 400 | |||
| 401 | If the Unicode $code_point is an ASCII alphanumeric C<A-Za-z0-9>, returns 1, otherwise returns 0. | ||
| 402 | |||
| 403 | =head2 is_alpha | ||
| 404 | |||
| 405 | C<static method is_alpha : int ($code_point : int);> | ||
| 406 | |||
| 407 | If the Unicode $code_point is an ASCII alphabetic C<A-Za-z>, returns 1, otherwise returns 0. | ||
| 408 | |||
| 409 | =head2 is_array | ||
| 410 | |||
| 411 | C<static method is_array : int ($object : object);> | ||
| 412 | |||
| 413 | If $object is defined and the type of $object is array type, returns 1, otherwise returns 0. | ||
| 414 | |||
| 415 | L<SPVM::Document::NativeAPI/"is_array"> is used to check the type. | ||
| 416 | |||
| 417 | =head2 is_blank | ||
| 418 | |||
| 419 | C<static method is_blank : int ($code_point : int);> | ||
| 420 | |||
| 421 | If the Unicode $code_point is an ASCII blank C<0x20(SP, ' ')>, C<0x09(HT, '\t')>, returns 1, otherwise returns 0. | ||
| 422 | |||
| 423 | =head2 is_class | ||
| 424 | |||
| 425 | C<static method is_class : int ($object : object);> | ||
| 426 | |||
| 427 | If $object is defined and the type of $object is a class type, returns 1, otherwise returns 0. | ||
| 428 | |||
| 429 | L<SPVM::Document::NativeAPI/"is_class"> is used to check the type. | ||
| 430 | |||
| 431 | =head2 is_cntrl | ||
| 432 | |||
| 433 | C<static method is_cntrl : int ($code_point : int);> | ||
| 434 | |||
| 435 | If the Unicode $code_point is an ASCII control character C<0x00-0x1F>, C<0x7F>, returns 1, otherwise returns 0. | ||
| 436 | |||
| 437 | =head2 is_digit | ||
| 438 | |||
| 439 | C<static method is_digit : int ($code_point : int);> | ||
| 440 | |||
| 441 | If the Unicode $code_point is an ASCII decimal digit 0-9, returns 1, otherwise returns 0. | ||
| 442 | |||
| 443 | =head2 is_graph | ||
| 444 | |||
| 445 | C<static method is_graph : int ($code_point : int);> | ||
| 446 | |||
| 447 | If $character is an ASCII graphical character C<0x21-0x7E>, returns 1, otherwise returns 0. | ||
| 448 | |||
| 449 | =head2 is_hex_digit | ||
| 450 | |||
| 451 | C<static method is_hex_digit : int ($code_point : int);> | ||
| 452 | |||
| 453 | If $character is a hexadecimal digit C<0-9a-fA-F>, returns 1, otherwise returns 0. | ||
| 454 | |||
| 455 | =head2 is_lower | ||
| 456 | |||
| 457 | C<static method is_lower : int ($code_point : int);> | ||
| 458 | |||
| 459 | If the Unicode $code_point is an ASCII lowercase character C<a-z>, returns 1, otherwise returns 0. | ||
| 460 | |||
| 461 | =head2 is_mulnum_array | ||
| 462 | |||
| 463 | C<static method is_mulnum_array : int ($object : object);> | ||
| 464 | |||
| 465 | If $object is defined and the type of $object is a multi-numeric array type, returns 1, otherwise returns 0. | ||
| 466 | |||
| 467 | L<SPVM::Document::NativeAPI/"is_mulnum_array"> is used to check the type. | ||
| 468 | |||
| 469 | =head2 is_numeric_array | ||
| 470 | |||
| 471 | C<static method is_numeric_array : int ($object : object);> | ||
| 472 | |||
| 473 | If $object is defined and the type of $object is a numeric array type, returns 1, otherwise returns 0. | ||
| 474 | |||
| 475 | L<SPVM::Document::NativeAPI/"is_numeric_array"> is used to check the type. | ||
| 476 | |||
| 477 | =head2 is_object_array | ||
| 478 | |||
| 479 | C<static method is_object_array : int ($object : object);> | ||
| 480 | |||
| 481 | If $object is defined and the type of $object is an object array type, returns 1, otherwise returns 0. | ||
| 482 | |||
| 483 | L<SPVM::Document::NativeAPI/"is_object_array"> is used to check the type. | ||
| 484 | |||
| 485 | =head2 is_perl_space | ||
| 486 | |||
| 487 | C<static method is_perl_space : int ($code_point : int);> | ||
| 488 | |||
| 489 | If the Unicode $code_point is an Perl ASCII space character C<0x09(HT, '\t')>, C<0x0A(LF, '\n')>, C<0x0C(FF, '\f')>, C<0x0D(CR, '\r')>, C<0x20(SP, ' ')>, returns 1, otherwise returns 0. | ||
| 490 | |||
| 491 | Note that prior to Perl v5.18, C<\s> in ASCII mode did not match the vertical tab C<0x0B(VT)>. C<is_perl_space> is the same as this behavior. | ||
| 492 | |||
| 493 | Current Perl C<\s> in ASCII mode is the same as L</"is_space">. | ||
| 494 | |||
| 495 | =head2 is_perl_word | ||
| 496 | |||
| 497 | C<static method is_perl_word : int ($code_point : int);> | ||
| 498 | |||
| 499 | If the Unicode $code_point is an Perl ASCII word character C<a-zA-Z0-9_>, returns 1, otherwise returns 0. | ||
| 500 | |||
| 501 | =head2 is_pointer_class | ||
| 502 | |||
| 503 | C<static method is_pointer_class : int ($object : object);> | ||
| 504 | |||
| 505 | If $object is defined and $object is a L<pointer class|SPVM::Document::Language::Class/"Pointer Class">, returns 1, otherwise returns 0. | ||
| 506 | |||
| 507 | L<SPVM::Document::NativeAPI/"is_pointer_class"> is used to check the type. | ||
| 508 | |||
| 509 | =head2 is_print | ||
| 510 | |||
| 511 | C<static method is_print : int ($code_point : int);> | ||
| 512 | |||
| 513 | If the Unicode C<$$code_point> is an ASCII printable character C<0x20-0x7E>, returns 1, otherwise returns 0. | ||
| 514 | |||
| 515 | =head2 is_punct | ||
| 516 | |||
| 517 | C<static method is_punct : int ($code_point : int);> | ||
| 518 | |||
| 519 | If the Unicode $code_point is an ASCII a punctuation character C<0x21-0x2F>, C<0x3A-0x40>, C<0x5B-0x60>, C<0x7B-0x7E>, returns 1, otherwise returns 0. | ||
| 520 | |||
| 521 | =head2 is_space | ||
| 522 | |||
| 523 | C<static method is_space : int ($code_point : int);> | ||
| 524 | |||
| 525 | If the Unicode $code_point is an ASCII a white-space C<0x09(HT, '\t')>, C<0x0A(LF, '\n')>, C<0x0B(VT)>, C<0x0C(FF, '\f')>, C<0x0D(CR, '\r')>, C<0x20(SP, ' ')> returns 1, otherwise returns 0. | ||
| 526 | |||
| 527 | =head2 is_upper | ||
| 528 | |||
| 529 | C<static method is_upper : int ($code_point : int);> | ||
| 530 | |||
| 531 | If $code_point is an ASCII uppercase character C<A-Z>, returns 1, otherwise returns 0. | ||
| 532 | |||
| 533 | =head2 is_xdigit | ||
| 534 | |||
| 535 | C<static method is_xdigit : int ($code_point : int);> | ||
| 536 | |||
| 537 | If $code_point is an ASCII hexadecimal digit C<0-9A-Fa-f>, returns 1, otherwise returns 0. | ||
| 538 | |||
| 539 | =head2 join | ||
| 540 | |||
| 541 | C<static method join : string ($separator : string, $strings : string[]);> | ||
| 542 | |||
| 543 | Concatenates $strings with $separater and return it. | ||
| 544 | |||
| 545 | Exceptions: | ||
| 546 | |||
| 547 | $strings must be defined. Otherwise an exception is thrown. | ||
| 548 | |||
| 549 | $separator must be defined. Otherwise an exception is thrown. | ||
| 550 | |||
| 551 | =head2 labs | ||
| 552 | |||
| 553 | C<static method labs : long ($value : long);> | ||
| 554 | |||
| 555 | Returns the absolute value of $value. | ||
| 556 | |||
| 557 | =head2 lc | ||
| 558 | |||
| 559 | C<static method lc : string ($string : string);> | ||
| 560 | |||
| 561 | Converts the ASCII uppercase characters C<A-Z> in $string to the corresponding ASCII lowercase characters C<a-z>. And return it. | ||
| 562 | |||
| 563 | Exceptions: | ||
| 564 | |||
| 565 | $string must be defined. Otherwise an exception is thrown. | ||
| 566 | |||
| 567 | =head2 lcfirst | ||
| 568 | |||
| 569 | C<static method lcfirst : string ($string : string);> | ||
| 570 | |||
| 571 | If the first character of $string is an ASCII uppercase character C<A-Z>, it is converted to the corresponding ASCII lowercase characters C<a-z>. And return the converted string. | ||
| 572 | |||
| 573 | Exceptions: | ||
| 574 | |||
| 575 | $string must be defined. Otherwise an exception is thrown. | ||
| 576 | |||
| 577 | =head2 look_code_point | ||
| 578 | |||
| 579 | C<static method look_code_point : int ($string : string, $offset_ref : int*);> | ||
| 580 | |||
| 581 | The same as L</"get_code_point">, but the offset is not updated. | ||
| 582 | |||
| 583 | =head2 memcpy | ||
| 584 | |||
| 585 | C<static method memcpy : void ($dest : object, $dest_offset : int, $source : object, $source_offset : int, $length : int);> | ||
| 586 | |||
| 587 | Copies the range of $source to the range of $dest. | ||
| 588 | |||
| 589 | The range of $dest is from $offset to the position proceeded by $length of the destination. | ||
| 590 | |||
| 591 | The range of $source is from $offset to the position proceeded by $length of the source. | ||
| 592 | |||
| 593 | The unit of $offset and $length is C<byte> size. | ||
| 594 | |||
| 595 | If the range of $source and the range of $dest overlap, the result is B<not> guaranteed. | ||
| 596 | |||
| 597 | Exceptions: | ||
| 598 | |||
| 599 | $dest must be defined. Otherwise an exception is thrown. | ||
| 600 | |||
| 601 | The type of $dest must be the C<string> type, the numeric array type, or the multi-numeric array type. Otherwise an exception is thrown. | ||
| 602 | |||
| 603 | $source must be defined. Otherwise an exception is thrown. | ||
| 604 | |||
| 605 | The type of $source must be the C<string> type, the numeric array type, or the multi-numeric array type. Otherwise an exception is thrown. | ||
| 606 | |||
| 607 | $dest must not be a read-only string. Otherwise an exception is thrown. | ||
| 608 | |||
| 609 | $length must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 610 | |||
| 611 | $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown. | ||
| 612 | |||
| 613 | $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown. | ||
| 614 | |||
| 615 | =head2 memmove | ||
| 616 | |||
| 617 | C<static method memmove : void ($dest : object, $dest_offset : int, $source : object, $source_offset : int, $length : int);> | ||
| 618 | |||
| 619 | The same as L</"memcpy">, but even if the range of $source and the range of $dest overlap, the result is guaranteed. | ||
| 620 | |||
| 621 | =head2 ord | ||
| 622 | |||
| 623 | C<static method ord : int ($string : string);> | ||
| 624 | |||
| 625 | The alias for the following code using L</"get_code_point">. | ||
| 626 | |||
| 627 | my $offset = 0; | ||
| 628 | my $code_point = Fn->get_code_point($string, \$offset); | ||
| 629 | |||
| 630 | =head2 powi | ||
| 631 | |||
| 632 | C<static method powi : int ($base : int, $exponant : int);> | ||
| 633 | |||
| 634 | Calculates the exponentiation from $base number and $exponant number. | ||
| 635 | |||
| 636 | Exceptions: | ||
| 637 | |||
| 638 | $exponant number must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 639 | |||
| 640 | If $base number is 0, $exponant number cannnot be 0. | ||
| 641 | |||
| 642 | =head2 powl | ||
| 643 | |||
| 644 | C<static method powl : long ($base : long, $exponant : long);> | ||
| 645 | |||
| 646 | Calculates the exponentiation from $base number and $exponant number. | ||
| 647 | |||
| 648 | Exceptions: | ||
| 649 | |||
| 650 | $exponant number must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 651 | |||
| 652 | If $base number is 0, $exponant number cannnot be 0. | ||
| 653 | |||
| 654 | =head2 rand | ||
| 655 | |||
| 656 | C<static method rand : double ($seed : int*, $max : int = 1);> | ||
| 657 | |||
| 658 | Gets a 64bit floating point random number that is greater than or equal to 0 and less than $max using $seed. | ||
| 659 | |||
| 660 | If $max is specified, $max is multiplied to the return value. | ||
| 661 | |||
| 662 | The seed is updated. | ||
| 663 | |||
| 664 | This method is thread safe. | ||
| 665 | |||
| 666 | Examples: | ||
| 667 | |||
| 668 | use Sys::Time; | ||
| 669 | my $seed = (int)Sys::Time->time; | ||
| 670 | my $rand0 = Fn->rand(\$seed); | ||
| 671 | my $rand1 = Fn->rand(\$seed); | ||
| 672 | |||
| 673 | Exceptions: | ||
| 674 | |||
| 675 | The max number \$max must be greater than 0. Otherwise an exception is thrown. | ||
| 676 | |||
| 677 | See Also: | ||
| 678 | |||
| 679 | If you want to omit $seed, you can use L<Sys#rand|SPVM::Sys/"rand"> method. | ||
| 680 | |||
| 681 | =head2 repeat | ||
| 682 | |||
| 683 | C<static method repeat : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|string|object ($string_or_array : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|string|object, $count : int);> | ||
| 684 | |||
| 685 | If $string_or_array is a string, concatenates $string the number of times specified in $count and return it. | ||
| 686 | |||
| 687 | Otherwise, retruns a new array that repeats the array $array $count times. | ||
| 688 | |||
| 689 | Exceptions: | ||
| 690 | |||
| 691 | The $string_or_array must be defined. Otherwise an exception is thrown. | ||
| 692 | |||
| 693 | The count $count count be a non-negative integer. Otherwise an exception is thrown. | ||
| 694 | |||
| 695 | Examples: | ||
| 696 | |||
| 697 | # "abcabcabc" | ||
| 698 | my $repeat_string = Fn->repeat("abc", 3); | ||
| 699 | |||
| 700 | # [1, 2, 3, 1, 2, 3, 1, 2, 3] | ||
| 701 | my $repeat_int_array = Fn->repeat([1, 2, 3], 3); | ||
| 702 | |||
| 703 | =head2 repeat_string | ||
| 704 | |||
| 705 | C<static method repeat_string : string ($string : string, $count : int);> | ||
| 706 | |||
| 707 | Concatenates $string the number of times specified in $count and return it. | ||
| 708 | |||
| 709 | Exceptions: | ||
| 710 | |||
| 711 | The $string must be defined. Otherwise an exception is thrown. | ||
| 712 | |||
| 713 | The repeat_string count $count count be a non-negative integer. Otherwise an exception is thrown. | ||
| 714 | |||
| 715 | Examples: | ||
| 716 | |||
| 717 | # "abcabcabc" | ||
| 718 | my $repeat_string_string = Fn->repeat_string("abc", 3); | ||
| 719 | |||
| 720 | See Also: | ||
| 721 | |||
| 722 | See L<Array#repeat|SPVM::Array/"repeat"> method about repeat_stringing an array. | ||
| 723 | |||
| 724 | =head2 replace_chars | ||
| 725 | |||
| 726 | C<static method replace_chars : void ($string : mutable string, $from_ch : int, $to_ch : int);> | ||
| 727 | |||
| 728 | Replaces all characters specified by the second argument in $string with the characters specified by the third argument. | ||
| 729 | |||
| 730 | Exceptions: | ||
| 731 | |||
| 732 | $string must be defined. Otherwise an exception is thrown. | ||
| 733 | |||
| 734 | =head2 rindex | ||
| 735 | |||
| 736 | C<static method rindex : int ($string : string, $substring : string, $end : int = -1, $begin : int = 0);> | ||
| 737 | |||
| 738 | Searches for $substring in the range of $string from $begin to $end. | ||
| 739 | |||
| 740 | The search is performed from the end of the range of $string. | ||
| 741 | |||
| 742 | If $substring is found, returns the found offset. Otherwise, returns -1. | ||
| 743 | |||
| 744 | If $end is less than 0, $end is set to the length of $string minus 1. | ||
| 745 | |||
| 746 | Exceptions: | ||
| 747 | |||
| 748 | $string must be defined. Otherwise an exception is thrown. | ||
| 749 | |||
| 750 | $substring must be defined. Otherwise an exception is thrown. | ||
| 751 | |||
| 752 | $begin must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 753 | |||
| 754 | $end must be less than the length of $string. | ||
| 755 | |||
| 756 | =head2 sizeof_native_int | ||
| 757 | |||
| 758 | C<static method sizeof_native_int : int ();> | ||
| 759 | |||
| 760 | Returns the native C<int> size. This is the same value as C<sizeof(int)> in the C language. | ||
| 761 | |||
| 762 | =head2 sizeof_native_pointer | ||
| 763 | |||
| 764 | C<static method sizeof_native_pointer : int ();> | ||
| 765 | |||
| 766 | Returns the native pointer size. This is the same value as C<sizeof(void*)> in the C language. | ||
| 767 | |||
| 768 | =head2 shorten | ||
| 769 | |||
| 770 | C<static method shorten : void ($string : mutable string, $length : int32_t);> | ||
| 771 | |||
| 772 | Shortens $string to $length specified by the argument using L<SPVM::Document::NativeAPI/"shorten">. | ||
| 773 | |||
| 774 | If the length specified by the argument is greater than or equal to the length of the string, nothing is performed. | ||
| 775 | |||
| 776 | Exceptions: | ||
| 777 | |||
| 778 | $string must be defined. | ||
| 779 | |||
| 780 | $length must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 781 | |||
| 782 | =head2 shorten_null_char | ||
| 783 | |||
| 784 | C<static method shorten_null_char : void ($string : mutable string);> | ||
| 785 | |||
| 786 | Shortens $string just before the first null character C<\0>. | ||
| 787 | |||
| 788 | If null characters is not found, do nothing. | ||
| 789 | |||
| 790 | Exceptions: | ||
| 791 | |||
| 792 | $string must be defined. Otherwise an exception is thrown. | ||
| 793 | |||
| 794 | B<Example:> | ||
| 795 | |||
| 796 | my $message = (mutable string)copy "foo\0bar"; | ||
| 797 | |||
| 798 | # "foo" | ||
| 799 | my $message_shoten = Fn->shorten_null_char($message); | ||
| 800 | |||
| 801 | =head2 split | ||
| 802 | |||
| 803 | C<static method split : string[] ($separator : string, $string : string, $limit : int = -1);> | ||
| 804 | |||
| 805 | If $limit is less than 0, split $string by the specific $separator and convert them to an string array and return it. | ||
| 806 | |||
| 807 | If $limit is greater than than 0, the limit becomes the length of the maximam separated elements. | ||
| 808 | |||
| 809 | Exceptions: | ||
| 810 | |||
| 811 | $separator must be defined. Otherwise an exception is thrown. | ||
| 812 | |||
| 813 | $string must be defined. Otherwise an exception is thrown. | ||
| 814 | |||
| 815 | $limit cannnot be 0. Otherwise an exception is thrown. | ||
| 816 | |||
| 817 | =head2 substr | ||
| 818 | |||
| 819 | C<static method substr : string ($string : string, $offset : int, $length : int = -1, $replacement : string = undef);> | ||
| 820 | |||
| 821 | Cuts a substring of $length from $offset of a string $string, and returns it. | ||
| 822 | |||
| 823 | If $length is ommited or $offset plus $length is less than or equal to the length of $string, $length is set to the length of $string minus $offset. | ||
| 824 | |||
| 825 | If the length is less than 0, the length to the end of the string is calculated from the length of $string and $offset. | ||
| 826 | |||
| 827 | Replacement: | ||
| 828 | |||
| 829 | If $replacement is given, $string is set to a string that is the replacement string $replacement of $string from $offset to $length. | ||
| 830 | |||
| 831 | Exceptions: | ||
| 832 | |||
| 833 | $string must be defined. Otherwise an exception is thrown. | ||
| 834 | |||
| 835 | $string must be a string. Otherwise an exception is thrown. | ||
| 836 | |||
| 837 | $offset must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 838 | |||
| 839 | The offset $offset must be less than or equal to the length of the string $string. Otherwise an exception is thrown. | ||
| 840 | |||
| 841 | =head2 to_code_points | ||
| 842 | |||
| 843 | C<static method to_code_points : int[] ($string : string)> | ||
| 844 | |||
| 845 | Converts $string to the Unicode code points, and returns it. | ||
| 846 | |||
| 847 | Exceptions: | ||
| 848 | |||
| 849 | $string must be defined. Otherwise an exception is thrown. | ||
| 850 | |||
| 851 | $string contains an invalid Unicode code point. Otherwise an exception is thrown. | ||
| 852 | |||
| 853 | =head2 to_double | ||
| 854 | |||
| 855 | C<static method to_double : double ($string : string);> | ||
| 856 | |||
| 857 | Converts $string to the C<double> value using C<strtod> in the C language. | ||
| 858 | |||
| 859 | Exceptions: | ||
| 860 | |||
| 861 | $string must be defined. Otherwise an exception is thrown. | ||
| 862 | |||
| 863 | $string must be the string that can be parsed as a double number. Otherwise an exception is thrown. | ||
| 864 | |||
| 865 | $string must be a double number in $correct range. Otherwise an exception is thrown. | ||
| 866 | |||
| 867 | Examples: | ||
| 868 | |||
| 869 | my $string = "1.25"; | ||
| 870 | my $num = Fn->to_double($string); | ||
| 871 | |||
| 872 | =head2 to_float | ||
| 873 | |||
| 874 | C<static method to_float : float ($string : string);> | ||
| 875 | |||
| 876 | Converts $string to the C<double> value using C<strtof> in the C language. | ||
| 877 | |||
| 878 | Exceptions: | ||
| 879 | |||
| 880 | $string must be defined. Otherwise an exception is thrown. | ||
| 881 | |||
| 882 | $string must be the string that can be parsed as a float number. Otherwise an exception is thrown. | ||
| 883 | |||
| 884 | $string must be a float number in $correct range. Otherwise an exception is thrown. | ||
| 885 | |||
| 886 | Examples: | ||
| 887 | |||
| 888 | my $string = "1.25"; | ||
| 889 | my $num = Fn->to_float($string); | ||
| 890 | |||
| 891 | =head2 to_int | ||
| 892 | |||
| 893 | C<static method to_int : int ($string : string, $unsigned : int = 0);> | ||
| 894 | |||
| 895 | The alias for the following code using L</"to_int_with_base">. | ||
| 896 | |||
| 897 | my $ret = Fn->to_int_with_base($string, 10, $unsigned); | ||
| 898 | |||
| 899 | =head2 to_int_with_base | ||
| 900 | |||
| 901 | C<static method to_int_with_base : int ($string : string, $digit : int, $unsigned : int = 0);> | ||
| 902 | |||
| 903 | Converts $string to the C<int> value with $digit. | ||
| 904 | |||
| 905 | If $unsigned is a true value, the conversion is performed using C<strtoull> in the C language, and the range is checked as a 32-bit unsigned integer. | ||
| 906 | |||
| 907 | If $unsigned is a false value, the conversion is performed using C<strtol> in the C language, and the range is checked as a 32-bit signed integer. | ||
| 908 | |||
| 909 | Exceptions: | ||
| 910 | |||
| 911 | $string must be defined. Otherwise an exception is thrown. | ||
| 912 | |||
| 913 | $digit must be one of 2, 8, 10, or 16. Otherwise an exception is thrown. | ||
| 914 | |||
| 915 | $string must be the string that can be parsed as a 32-bit integer. Otherwise an exception is thrown. | ||
| 916 | |||
| 917 | $string must be an integer in the correct range. Otherwise an exception is thrown. | ||
| 918 | |||
| 919 | Examples: | ||
| 920 | |||
| 921 | my $string = "4294967295"; | ||
| 922 | my $num = Fn->to_int_with_base($string, 10, 1); | ||
| 923 | |||
| 924 | =head2 to_long | ||
| 925 | |||
| 926 | C<static method to_long : long ($string : string, $unsigned : int = 0);> | ||
| 927 | |||
| 928 | The alias for the following code using L</"to_long_with_base">. | ||
| 929 | |||
| 930 | my $ret = Fn->to_long_with_base($string, 10, $unsigned); | ||
| 931 | |||
| 932 | =head2 to_long_with_base | ||
| 933 | |||
| 934 | C<static method to_long_with_base : long ($string : string, $digit : int, $unsigned : int = 0);> | ||
| 935 | |||
| 936 | Converts $string to the C<long> value with $digit. | ||
| 937 | |||
| 938 | If $unsigned is a true value, the conversion is performed using C<strtoull> in the C language, and the range is checked as a 64-bit unsigned integer. | ||
| 939 | |||
| 940 | If $unsigned is a false value, the conversion is performed using C<strtoll> in the C language, and the range is checked as a 64-bit signed integer. | ||
| 941 | |||
| 942 | Exceptions: | ||
| 943 | |||
| 944 | $string must be defined. Otherwise an exception is thrown. | ||
| 945 | |||
| 946 | $digit must be one of 2, 8, 10, or 16. Otherwise an exception is thrown. | ||
| 947 | |||
| 948 | $string must be the string that can be parsed as a 64-bit integer. Otherwise an exception is thrown. | ||
| 949 | |||
| 950 | $string must be a 64-bit integer in the correct range. Otherwise an exception is thrown. | ||
| 951 | |||
| 952 | Examples: | ||
| 953 | |||
| 954 | my $string = "18446744073709551615"; | ||
| 955 | my $num = Fn->to_long_with_base($string, 10, 1); | ||
| 956 | |||
| 957 | =head2 to_lower | ||
| 958 | |||
| 959 | C<static method to_lower : int ($code_point : int);> | ||
| 960 | |||
| 961 | If $code_point is the ASCII uppercase character C<A-Z>, it is converted to the corresponding ASCII lowercase character C<a-z>. | ||
| 962 | |||
| 963 | If $code_point is not an ASCII uppercase character, return itself. | ||
| 964 | |||
| 965 | =head2 to_upper | ||
| 966 | |||
| 967 | C<static method to_upper : int ($code_point : int);> | ||
| 968 | |||
| 969 | If $code_point is the ASCII lowercase character C<a-z>, it is converted to the corresponding ASCII uppercase character C<A-Z>. | ||
| 970 | |||
| 971 | If $code_point is not an ASCII lowercase character, return itself. | ||
| 972 | |||
| 973 | =head2 to_utf8_chars | ||
| 974 | |||
| 975 | C<static method to_utf8_chars : string[] ($string : string);> | ||
| 976 | |||
| 977 | Converts $string to UTF-8 characters, and returns it. | ||
| 978 | |||
| 979 | Exceptions: | ||
| 980 | |||
| 981 | $string must be defined. Otherwise an exception is thrown. | ||
| 982 | |||
| 983 | $string contains an invalid Unicode code point. Otherwise an exception is thrown. | ||
| 984 | |||
| 985 | Examples: | ||
| 986 | |||
| 987 | my $string = "あいうa"; | ||
| 988 | |||
| 989 | # ["あ", "い", "う", "a"] | ||
| 990 | my $utf8_chars = Fn->to_utf8_chars($string); | ||
| 991 | |||
| 992 | =head2 tr | ||
| 993 | |||
| 994 | C<static method tr : string ($string : string, $pattern : string, $replace : string)> | ||
| 995 | |||
| 996 | Replaced the range of $pattern with the range of $replace in a $string and returns a replaced string. | ||
| 997 | |||
| 998 | The range must be the format C<a-z> or C<a>. If the format is C<a>, it is converted to C<a-a>. | ||
| 999 | |||
| 1000 | # The range format examples | ||
| 1001 | "a-z" | ||
| 1002 | "0-9" | ||
| 1003 | "a" | ||
| 1004 | "5" | ||
| 1005 | "0-9" | ||
| 1006 | "あ-ん" | ||
| 1007 | |||
| 1008 | Exceptions: | ||
| 1009 | |||
| 1010 | $string must be defined. Otherwise an exception is thrown. | ||
| 1011 | |||
| 1012 | $pattern must be defined. Otherwise an exception is thrown. | ||
| 1013 | |||
| 1014 | $replace must be defined. Otherwise an exception is thrown. | ||
| 1015 | |||
| 1016 | If $string contains an invalid Unicode code point, an exception is thrown. | ||
| 1017 | |||
| 1018 | The range format of the (pattern|replace) cannnot be contain an invalid Unicode code point. If so, an exception is thrown. If so, an exception is thrown. | ||
| 1019 | |||
| 1020 | The second character ot the range format of the (pattern|replace) must be \"-\". Otherwise an exception is thrown. | ||
| 1021 | |||
| 1022 | The range format of the (pattern|replace) must be 1 or 3 characters. Otherwise an exception is thrown. | ||
| 1023 | |||
| 1024 | The exceptions of the L<"/get_code_point"> method can be thrown. | ||
| 1025 | |||
| 1026 | C<Examples:> | ||
| 1027 | |||
| 1028 | { | ||
| 1029 | my $string = "0123456789"; | ||
| 1030 | my $pattern = "0-9"; | ||
| 1031 | my $replace = "0-9"; | ||
| 1032 | |||
| 1033 | # "0123456789" | ||
| 1034 | my $ret = Fn->tr($string, $pattern, $replace); | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | { | ||
| 1038 | my $string = "abcd"; | ||
| 1039 | my $pattern = "a-c"; | ||
| 1040 | my $replace = "x-z"; | ||
| 1041 | |||
| 1042 | # "xyzd" | ||
| 1043 | my $ret = Fn->tr($string, $pattern, $replace); | ||
| 1044 | } | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | =head2 trim | ||
| 1048 | |||
| 1049 | C<static method trim : string ($string : string);> | ||
| 1050 | |||
| 1051 | Removes the right and left spaces of $string and return it. | ||
| 1052 | |||
| 1053 | The removed spaces is the same as the spaces L</"is_space"> method returns 1. | ||
| 1054 | |||
| 1055 | Exceptions: | ||
| 1056 | |||
| 1057 | $string must be defined. Otherwise an exception is thrown. | ||
| 1058 | |||
| 1059 | =head2 uc | ||
| 1060 | |||
| 1061 | C<static method uc : string ($string : string);> | ||
| 1062 | |||
| 1063 | Converts the ASCII lowercase characters C<a-z> in $string to the corresponding ASCII uppercase characters C<A-Z>. And return it. | ||
| 1064 | |||
| 1065 | Exceptions: | ||
| 1066 | |||
| 1067 | $string must be defined. Otherwise an exception is thrown. | ||
| 1068 | |||
| 1069 | =head2 ucfirst | ||
| 1070 | |||
| 1071 | C<static method ucfirst : string ($string : string);> | ||
| 1072 | |||
| 1073 | If the first character of $string is an ASCII lowercase characters C<a-z>, it is converted to the corresponding ASCII uppercase character C<A-Z>. And return the converted string. | ||
| 1074 | |||
| 1075 | Exceptions: | ||
| 1076 | |||
| 1077 | $string must be defined. Otherwise an exception is thrown. | ||
| 1078 | |||
| 1079 | =head2 utf8_length | ||
| 1080 | |||
| 1081 | C<static method utf8_length : int ($string : string)> | ||
| 1082 | |||
| 1083 | Gets the length as a UTF-8 string from $string, and returns it. | ||
| 1084 | |||
| 1085 | Exceptions: | ||
| 1086 | |||
| 1087 | $string must be defined. Otherwise an exception is thrown. | ||
| 1088 | |||
| 1089 | If $string contains an invalid Unicode code point, an exception is thrown. | ||
| 1090 | |||
| 1091 | Examples: | ||
| 1092 | |||
| 1093 | # 3 | ||
| 1094 | my $utf8_length = Fn->utf8_length("あいう"); | ||
| 1095 | |||
| 1096 | =head2 utf8_substr | ||
| 1097 | |||
| 1098 | C<static method utf8_substr : string ($string : string, $utf8_offset : int, $utf8_length : int = -1);> | ||
| 1099 | |||
| 1100 | Gets the substring from $string. The extracting range of the string is from $utf8_offset to the position proceeded by $utf8_length, and returns it. | ||
| 1101 | |||
| 1102 | If the length is less than 0, the length to the end of the string is calculated from the length of $string and $utf8_offset. | ||
| 1103 | |||
| 1104 | Exceptions: | ||
| 1105 | |||
| 1106 | $string must be defined. Otherwise an exception is thrown. | ||
| 1107 | |||
| 1108 | If $string contains an invalid Unicode code point, an exception is thrown. | ||
| 1109 | |||
| 1110 | $utf8_offset + $utf8_length must be less than or equal to the UTF-8 length of $string. Otherwise an exception is thrown. | ||
| 1111 | |||
| 1112 | Examples: | ||
| 1113 | |||
| 1114 | # "いえ" | ||
| 1115 | my $utf8_substr = Fn->utf8_substr("あいうえ", 1, 2); | ||
| 1116 | |||
| 1117 | =head2 merge_options | ||
| 1118 | |||
| 1119 | C<static method merge_options : object[] ($options1 : object[], $options2 : object[]);> | ||
| 1120 | |||
| 1121 | Creates a new any object array merging $options1 and $options2, and returns it. | ||
| 1122 | |||
| 1123 | If $options1 is not defined, $options1 is set to an empty any object array. | ||
| 1124 | |||
| 1125 | If $options2 is not defined, $options2 is set to an empty any object array. | ||
| 1126 | |||
| 1127 | Exceptions: | ||
| 1128 | |||
| 1129 | The length of $options1 must be an even number. Otherwise an exception is thrown. | ||
| 1130 | |||
| 1131 | The length of $options2 must be an even number. Otherwise an exception is thrown. | ||
| 1132 | |||
| 1133 | Exceptions thrown by the L<merge_object|SPVM::Array/"merge_object"> in the Array class could be thrown. | ||
| 1134 | |||
| 1135 | Examples: | ||
| 1136 | |||
| 1137 | my $merged_options = Fn->merge_options({foo => 1, bar => 2}, {baz => 5}); | ||
| 1138 | |||
| 1139 | =head2 object_to_int | ||
| 1140 | |||
| 1141 | C<static method object_to_int : int ($object : object);> | ||
| 1142 | |||
| 1143 | Converts the address of $object to a value of int type, and returns it. | ||
| 1144 | |||
| 1145 | =head2 get_spvm_version_string | ||
| 1146 | |||
| 1147 | C<static method get_spvm_version_string : string ();> | ||
| 1148 | |||
| 1149 | Returns the L<version string|SPVM::Document::Language::Class/"Version String"> of the SPVM language. | ||
| 1150 | |||
| 1151 | =head2 get_spvm_version_number | ||
| 1152 | |||
| 1153 | C<static method get_spvm_version_number : double ();> | ||
| 1154 | |||
| 1155 | Returns the L<version number|SPVM::Document::Language::Class/"Version Number"> of the SPVM language. | ||
| 1156 | |||
| 1157 | =head2 get_version_string | ||
| 1158 | |||
| 1159 | C<static method get_version_string : string ($basic_type_name : string);> | ||
| 1160 | |||
| 1161 | Returns the L<version string|SPVM::Document::Language::Class/"Version String"> of the class $basic_type_name. | ||
| 1162 | |||
| 1163 | =head2 get_version_number | ||
| 1164 | |||
| 1165 | C<static method get_version_number : double ($basic_type_name : string);> | ||
| 1166 | |||
| 1167 | Returns the L<version number|SPVM::Document::Language::Class/"Version Number"> of the class $basic_type_name. | ||
| 1168 | |||
| 1169 | Exceptions: | ||
| 1170 | |||
| 1171 | $basic_type_name must be defined. Otherwise an exception is thrown. | ||
| 1172 | |||
| 1173 | The class specified by $basic_type_name must be loaded. Otherwise an exception is thrown. | ||
| 1174 | |||
| 1175 | =head2 defer | ||
| 1176 | |||
| 1177 | C<static method defer : L<Scope::Guard|SPVM::Scope::Guard> ($callback : L<Callback|SPVM::Callback>);> | ||
| 1178 | |||
| 1179 | Calls L<Scope::Guard#new|Scope::Guard/"new"> and return its return value. | ||
| 1180 | |||
| 1181 | =head2 get_memory_blocks_count | ||
| 1182 | |||
| 1183 | C<static method get_memory_blocks_count : int ();> | ||
| 1184 | |||
| 1185 | Gets the count of the memory blocks allocated by the L<new_memory_block|SPVM::Document::NativeAPI/"new_memory_block"> native API. | ||
| 1186 | |||
| 1187 | =head2 to_address | ||
| 1188 | |||
| 1189 | C<static method to_address : string ($object : object);> | ||
| 1190 | |||
| 1191 | Gets the address of an object $object as a string. | ||
| 1192 | |||
| 1193 | =head2 check_option_names | ||
| 1194 | |||
| 1195 | C<static method check_option_names : void ($options : object[], $available_option_names : string[]);> | ||
| 1196 | |||
| 1197 | Checks if the options $options that contain name-value pairs has the available option names $available_option_names. | ||
| 1198 | |||
| 1199 | If $options is undef, nothing is done. | ||
| 1200 | |||
| 1201 | If the check is ok, nothing is done. Otherwise the following exception is thrown. | ||
| 1202 | |||
| 1203 | The "%s" option is not available. | ||
| 1204 | |||
| 1205 | %s is an option name. | ||
| 1206 | |||
| 1207 | Examples: | ||
| 1208 | |||
| 1209 | my $options = {foo => 1, bar => 2}; | ||
| 1210 | |||
| 1211 | my $available_option_names = ["foo", "bar", "baz"]; | ||
| 1212 | |||
| 1213 | Fn->check_option_names($options, $available_option_names); | ||
| 1214 | |||
| 1215 | =head2 get_basic_type_id | ||
| 1216 | |||
| 1217 | static method get_basic_type_id : int ($basic_type_name : string); | ||
| 1218 | |||
| 1219 | Gets the basic type ID of the basic type $basic_type_name. | ||
| 1220 | |||
| 1221 | Exceptions: | ||
| 1222 | |||
| 1223 | $basic_type_name must be defined. Otherwise an exception is thrwon. | ||
| 1224 | |||
| 1225 | If the basic type is not found, an exception is thrwon. | ||
| 1226 | |||
| 1227 | =head2 memset_char | ||
| 1228 | |||
| 1229 | C<static method memset_char : void ($string : mutable string, $char : int, $offset : int = 0, $length : int = -1);> | ||
| 1230 | |||
| 1231 | Set the range of the characters of the string $string to the character $char. | ||
| 1232 | |||
| 1233 | $char is an ASCII code. | ||
| 1234 | |||
| 1235 | The range of the characters of $string is from the offset $offset to the position proceeded by the length $length. | ||
| 1236 | |||
| 1237 | If $length is less than 0, the length to the end of the string is calculated from the length of $string and $offset. | ||
| 1238 | |||
| 1239 | Exceptions: | ||
| 1240 | |||
| 1241 | $string must be defined. | ||
| 1242 | |||
| 1243 | $offset must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 1244 | |||
| 1245 | $offset + $length must be less than or equal to the length of $string. Otherwise an exception is thrown. | ||
| 1246 | |||
| 1247 | =head2 or | ||
| 1248 | |||
| 1249 | C<static method or : object ($left : object, $right : object);> | ||
| 1250 | |||
| 1251 | If $left is a true value, returns $left. Otherwise, returns $right; | ||
| 1252 | |||
| 1253 | =head2 if | ||
| 1254 | |||
| 1255 | C<static method if : object ($condition : int, $left : object, $right : object);> | ||
| 1256 | |||
| 1257 | If $condition is a true value, returns $left. Otherwise, returns $right; | ||
| 1258 | |||
| 1259 | =head2 grep | ||
| 1260 | |||
| 1261 | C<static method grep : object[] ($callback : L<Callback::Grep|SPVM::Callback::Grep>, $array : object[]);> | ||
| 1262 | |||
| 1263 | Returns a new array containing only the elements of the array $array for which the callback $callback returned a true value. | ||
| 1264 | |||
| 1265 | Exceptions: | ||
| 1266 | |||
| 1267 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1268 | |||
| 1269 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1270 | |||
| 1271 | =head2 grep_byte | ||
| 1272 | |||
| 1273 | C<static method grep_byte : byte[] ($callback : L<Callback::Grep::Byte|SPVM::Callback::Grep::Byte>, $array : byte[]);> | ||
| 1274 | |||
| 1275 | Returns a new array containing only the elements of the array $array for which the callback $callback returned a true value. | ||
| 1276 | |||
| 1277 | Exceptions: | ||
| 1278 | |||
| 1279 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1280 | |||
| 1281 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1282 | |||
| 1283 | =head2 grep_short | ||
| 1284 | |||
| 1285 | C<static method grep_short : short[] ($callback : L<Callback::Grep::Short|SPVM::Callback::Grep::Short>, $array : short[]);> | ||
| 1286 | |||
| 1287 | Returns a new array containing only the elements of the array $array for which the callback $callback returned a true value. | ||
| 1288 | |||
| 1289 | Exceptions: | ||
| 1290 | |||
| 1291 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1292 | |||
| 1293 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1294 | |||
| 1295 | =head2 grep_int | ||
| 1296 | |||
| 1297 | C<static method grep_int : int[] ($callback : L<Callback::Grep::Int|SPVM::Callback::Grep::Int>, $array : int[]);> | ||
| 1298 | |||
| 1299 | Returns a new array containing only the elements of the array $array for which the callback $callback returned a true value. | ||
| 1300 | |||
| 1301 | Exceptions: | ||
| 1302 | |||
| 1303 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1304 | |||
| 1305 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1306 | |||
| 1307 | =head2 grep_long | ||
| 1308 | |||
| 1309 | C<static method grep : long[] ($callback : L<Callback::Grep::Long|SPVM::Callback::Grep::Long>, $array : long[]);> | ||
| 1310 | |||
| 1311 | Returns a new array containing only the elements of the array $array for which the callback $callback returned a true value. | ||
| 1312 | |||
| 1313 | Exceptions: | ||
| 1314 | |||
| 1315 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1316 | |||
| 1317 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1318 | |||
| 1319 | =head2 grep_float | ||
| 1320 | |||
| 1321 | C<static method grep_float : float[] ($callback : L<Callback::Grep::Float|SPVM::Callback::Grep::Float>, $array : float[]);> | ||
| 1322 | |||
| 1323 | Returns a new array containing only the elements of the array $array for which the callback $callback returned a true value. | ||
| 1324 | |||
| 1325 | Exceptions: | ||
| 1326 | |||
| 1327 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1328 | |||
| 1329 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1330 | |||
| 1331 | =head2 grep_double | ||
| 1332 | |||
| 1333 | C<static method grep_double : double[] ($callback : L<Callback::Grep::Double|SPVM::Callback::Grep::Double>, $array : double[]);> | ||
| 1334 | |||
| 1335 | Returns a new array containing only the elements of the array $array for which the callback $callback returned a true value. | ||
| 1336 | |||
| 1337 | Exceptions: | ||
| 1338 | |||
| 1339 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1340 | |||
| 1341 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1342 | |||
| 1343 | =head2 map | ||
| 1344 | |||
| 1345 | C<static method map : object[] ($callback : L<Callback::Map|SPVM::Callback::Map>, $array : object[]);> | ||
| 1346 | |||
| 1347 | Returns a new array with each element of the array $array processed in the callback $callback. | ||
| 1348 | |||
| 1349 | Exceptions: | ||
| 1350 | |||
| 1351 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1352 | |||
| 1353 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1354 | |||
| 1355 | =head2 map_expand | ||
| 1356 | |||
| 1357 | C<static method map_expand : object[] ($callback : L<Callback::MapExpand|SPVM::Callback::MapExpand>, $array : object[]);> | ||
| 1358 | |||
| 1359 | Returns a new array with each element of the array $array processed in the callback $callback which returns multiple values. | ||
| 1360 | |||
| 1361 | Exceptions: | ||
| 1362 | |||
| 1363 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1364 | |||
| 1365 | The callback $callback must be defined. Otherwise, an exception is thrown. | ||
| 1366 | |||
| 1367 | =head2 get_compile_type_name | ||
| 1368 | |||
| 1369 | C<static method get_compile_type_name : string ($basic_type_name : string, $type_dimension : int, $type_flag : int);> | ||
| 1370 | |||
| 1371 | Create a compile-time type name given the basic type name $basic_type_name, the type dimension $type_dimension, the type flag $type_flag, and returns it. | ||
| 1372 | |||
| 1373 | If C<$type_flag & 1> is true, the type is a reference type. | ||
| 1374 | |||
| 1375 | If C<$type_flag & 2> is true, the type is one that have a mutable qualifier. | ||
| 1376 | |||
| 1377 | Examples: | ||
| 1378 | |||
| 1379 | # int[][] | ||
| 1380 | my $compile_type_name = Fn->get_compile_type_name("int", 2, 0); | ||
| 1381 | |||
| 1382 | # int* | ||
| 1383 | my $compile_type_name = Fn->get_compile_type_name("int", 0, 1); | ||
| 1384 | |||
| 1385 | Exceptions: | ||
| 1386 | |||
| 1387 | The basic type name $basic_type_name must be defined. Otherwise, an exception is thrown. | ||
| 1388 | |||
| 1389 | The type dimension $type_dimension must be grether than or equal to 0 and less than or equal to 255. Otherwise, an exception is thrown. | ||
| 1390 | |||
| 1391 | =head2 is_any_numeric_array | ||
| 1392 | |||
| 1393 | C<static method is_any_numeric_array : int ($object : object);> | ||
| 1394 | |||
| 1395 | If the object $object is defined and the type of $object is a numeric array type or a multi-numeric array type, returns 1, otherwise returns 0. | ||
| 1396 | |||
| 1397 | An any numeric array means an array of a numeric array type or a multi-numeric array type. | ||
| 1398 | |||
| 1399 | =head2 array_length | ||
| 1400 | |||
| 1401 | C<static method array_length : int ($array : object);> | ||
| 1402 | |||
| 1403 | Returns the array length of the array $array. | ||
| 1404 | |||
| 1405 | Exceptions: | ||
| 1406 | |||
| 1407 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1408 | |||
| 1409 | The type of the array $array must be an array type. Otherwise, an exception is thrown. | ||
| 1410 | |||
| 1411 | =head2 get_elem_size | ||
| 1412 | |||
| 1413 | C<static method get_elem_size : int ($array : object);> | ||
| 1414 | |||
| 1415 | Returns the element byte size of the array $array. | ||
| 1416 | |||
| 1417 | Exceptions: | ||
| 1418 | |||
| 1419 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1420 | |||
| 1421 | The type of the array $array must be an array type. Otherwise, an exception is thrown. | ||
| 1422 | |||
| 1423 | =head2 get_elem_type_name | ||
| 1424 | |||
| 1425 | C<static method get_elem_type_name : string ($array : object);> | ||
| 1426 | |||
| 1427 | Returns the element type name of the array $array. | ||
| 1428 | |||
| 1429 | Implementation: | ||
| 1430 | |||
| 1431 | my $type_name = type_name $array; | ||
| 1432 | my $ret = Fn->substr($type_name, 0, length $type_name - 2); | ||
| 1433 | |||
| 1434 | Note that this is not the real element type name of each element. It is merely the type name of the array, but without the trailing C<[]>. | ||
| 1435 | |||
| 1436 | Exceptions: | ||
| 1437 | |||
| 1438 | The array $array must be defined. Otherwise, an exception is thrown. | ||
| 1439 | |||
| 1440 | The type of the array $array must be an array type. Otherwise, an exception is thrown. | ||
| 1441 | |||
| 1442 | =head2 print_stderr | ||
| 1443 | |||
| 1444 | C<static method print_stderr : void ($string : string);> | ||
| 1445 | |||
| 1446 | Prints the string $string to L<SPVM's standard error|SPVM::Document::Language::System/"Standard Streams">. | ||
| 1447 | |||
| 1448 | If $string is undef, this method produces no output. | ||
| 1449 | |||
| 1450 | =head2 say_stderr | ||
| 1451 | |||
| 1452 | C<static method say_stderr : void ($string : string);> | ||
| 1453 | |||
| 1454 | Prints the string $string with a new line C<\n> to L<SPVM's standard error|SPVM::Document::Language::System/"Standard Streams">. | ||
| 1455 | |||
| 1456 | If $string is undef, this method prints C<\n>. | ||
| 1457 | |||
| 1458 | =head2 memcmp | ||
| 1459 | |||
| 1460 | C<static method memcmp : void ($data1 : object, $data1_offset : int, $data2 : object, $data2_offset : int, $length : int);> | ||
| 1461 | |||
| 1462 | Compares the data $data1 from index $dest_offset with the data $data2 from index $data2_offset to the length $length using C<memcmp> C function, and returns the result. | ||
| 1463 | |||
| 1464 | Unit of $data1_offset, $data2_offset, and $length is bytes. | ||
| 1465 | |||
| 1466 | Exceptions: | ||
| 1467 | |||
| 1468 | $data1 must be defined. Otherwise an exception is thrown. | ||
| 1469 | |||
| 1470 | The type of $data1 must be the C<string> type, the numeric array type, or the multi-numeric array type. Otherwise an exception is thrown. | ||
| 1471 | |||
| 1472 | $data2 must be defined. Otherwise an exception is thrown. | ||
| 1473 | |||
| 1474 | The type of $data2 must be the C<string> type, the numeric array type, or the multi-numeric array type. Otherwise an exception is thrown. | ||
| 1475 | |||
| 1476 | $data1 must not be a read-only string. Otherwise an exception is thrown. | ||
| 1477 | |||
| 1478 | $length must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 1479 | |||
| 1480 | $data1_offset + $length must be less than or equal to the length of $data1. Otherwise an exception is thrown. | ||
| 1481 | |||
| 1482 | $data2_offset + $length must be less than or equal to the length of $data2. Otherwise an exception is thrown. | ||
| 1483 | |||
| 1484 | =head2 reverse_inplace | ||
| 1485 | |||
| 1486 | C<static method reverse_inplace : void ($array_or_string : object);> | ||
| 1487 | |||
| 1488 | Reverses the elements in the array $array_or_string or the characters in the string $array_or_string in-place. | ||
| 1489 | |||
| 1490 | Exceptions: | ||
| 1491 | |||
| 1492 | $array_or_string must be defined. Otherwise an exception is thrown. | ||
| 1493 | |||
| 1494 | The type of $array_or_string must be an array type or string type. Otherwise an exception is thrown. | ||
| 1495 | |||
| 1496 | The string $array_or_string must not be read-only. Otherwise an exception is thrown. | ||
| 1497 | |||
| 1498 | =head2 is_string_array | ||
| 1499 | |||
| 1500 | C<static method is_string_array : int ($object : object)> | ||
| 1501 | |||
| 1502 | If $object is defined and the type of $object is string array type C<string[]>, returns 1, otherwise returns 0. | ||
| 1503 | |||
| 1504 | =head2 length | ||
| 1505 | |||
| 1506 | C<static method length : int ($array_or_string : object);> | ||
| 1507 | |||
| 1508 | Returns the array length of $array_or_string if the type of $array_or_sring is an array type. | ||
| 1509 | |||
| 1510 | Returns the string length of $array_or_string if the type of $array_or_sring is string type. | ||
| 1511 | |||
| 1512 | Exceptions: | ||
| 1513 | |||
| 1514 | $array_or_string must be defined. Otherwise an exception is thrown. | ||
| 1515 | |||
| 1516 | The type of $array_or_string must be an array type or string type. Otherwise an exception is thrown. | ||
| 1517 | |||
| 1518 | =head2 get_elem_or_char_size | ||
| 1519 | |||
| 1520 | C<static method get_elem_or_char_size : int ($array_or_string : object);> | ||
| 1521 | |||
| 1522 | Returns the element byte size of the array $array if the type of $array_or_sring is an array type. | ||
| 1523 | |||
| 1524 | Returns 1, the byte size of C<byte> type if the type of $array_or_sring is string type. | ||
| 1525 | |||
| 1526 | Exceptions: | ||
| 1527 | |||
| 1528 | The array $array_or_string must be defined. Otherwise, an exception is thrown. | ||
| 1529 | |||
| 1530 | The type of the array $array_or_string must be an array type. Otherwise, an exception is thrown. | ||
| 1531 | |||
| 1532 | =head2 copy | ||
| 1533 | |||
| 1534 | C<static method copy : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|string|object ($array_or_string : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|string|object, $shallow : int = 0);> | ||
| 1535 | |||
| 1536 | Copies $array_or_string and returns it. | ||
| 1537 | |||
| 1538 | Implementation: | ||
| 1539 | |||
| 1540 | If $array_or_string is undef, returns undef. | ||
| 1541 | |||
| 1542 | If the type of $array_or_string is an string array type and $shallow is a false value, the copy is performed by L<Array#copy_string|SPVM::Array/"copy_string"> method. | ||
| 1543 | |||
| 1544 | If the type of $array_or_string is an string array type and $shallow is a true value, the copy is performed by L<Array#copy_string_address|SPVM::Array/"copy_string_address"> method. | ||
| 1545 | |||
| 1546 | If the type of $array_or_string is an object array type and $shallow is a false value, the copy is performed by L<Array#copy_object|SPVM::Array/"copy_object"> method given L<Cloner#default_cloner|SPVM::Cloner/"default_cloner"> method. | ||
| 1547 | |||
| 1548 | If the type of $array_or_string is an object array type and $shallow is a true value, the copy is performed by L<Array#copy_object_address|SPVM::Array/"copy_object_address"> method. | ||
| 1549 | |||
| 1550 | If the type of $array_or_string is a numeric array type or a multi-numeric array type, the copy is performed by L<Array#copy_any_numeric|SPVM::Array/"copy_any_numeric"> method. | ||
| 1551 | |||
| 1552 | If the type of $array_or_string is string type, the copy is performed by C<copy> operator. | ||
| 1553 | |||
| 1554 | Exceptions: | ||
| 1555 | |||
| 1556 | The type of $array_or_string must be an array type or string type. | ||
| 1557 | |||
| 1558 | =head2 reverse | ||
| 1559 | |||
| 1560 | C<static method reverse : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|string|object ($array_or_string : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|string|object);> | ||
| 1561 | |||
| 1562 | Reterns a new array that reverses the elements in the array $array_or_string or the characters in the string $array_or_string. | ||
| 1563 | |||
| 1564 | This method calls L</"copy"> method and L</"reverse_inplace"> method to create a new array and reverses elements. | ||
| 1565 | |||
| 1566 | Exceptions: | ||
| 1567 | |||
| 1568 | Exceptions thrown by L</"copy"> method and L</"reverse_inplace"> method could be thrown. | ||
| 1569 | |||
| 1570 | =head2 slice | ||
| 1571 | |||
| 1572 | C<static method slice : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|object ($array : byte[]|short[]|int[]|long[]|float[]|double[]|string[]|object, $offset : int, $length :int);> | ||
| 1573 | |||
| 1574 | Slices the array $array from the offset $offset to the length $length, and returns it. | ||
| 1575 | |||
| 1576 | The type of $array must be an object array type, a numeric array type, or a multi-numeric array type. | ||
| 1577 | |||
| 1578 | This method calls L<Array#memcpy_object|SPVM::Array/"memcpy_object"> method or L</"memcpy"> method to slice $array. | ||
| 1579 | |||
| 1580 | Exceptions: | ||
| 1581 | |||
| 1582 | The array $array must be defined. Otherwise an exception is thrown. | ||
| 1583 | |||
| 1584 | The type of the array $array must be an object array type, a numeric array type or a multi-numeric array type. Otherwise an exception is thrown. | ||
| 1585 | |||
| 1586 | Exceptions thrown by L<Array#memcpy_object|SPVM::Array/"memcpy_object"> method or L</"memcpy"> method could be thrown. | ||
| 1587 | |||
| 1588 | =head2 system_is_little_endian | ||
| 1589 | |||
| 1590 | C<static method system_is_little_endian ();> | ||
| 1591 | |||
| 1592 | If the system is little-endian, returns 1, otherwise returns 0. | ||
| 1593 | |||
| 1594 | =head2 sprintf | ||
| 1595 | |||
| 1596 | C<static method sprintf : string ($format : string, $args : object...);> | ||
| 1597 | |||
| 1598 | Calls L<Format#sprintf|SPVM::Format/"sprintf"> method and returns its return value. | ||
| 1599 | |||
| 1600 | Exceptions: | ||
| 1601 | |||
| 1602 | Exceptions thrown by thrown L<Format#sprintf|SPVM::Format/"sprintf"> method could be thrown. | ||
| 1603 | |||
| 1604 | Examples: | ||
| 1605 | |||
| 1606 | my $ret = Fn->sprintf("%s %d", "abc", 2); | ||
| 1607 | |||
| 1608 | =head2 sort_asc | ||
| 1609 | |||
| 1610 | C<static method sort_asc : byte[]|short[]|int[]|long[]|float[]|double[]|string[] ($array : byte[]|short[]|int[]|long[]|float[]|double[]|string[]);> | ||
| 1611 | |||
| 1612 | Copies the array $array using L</"copy"> method, sorts the copied array by ascendant order, and returns it. | ||
| 1613 | |||
| 1614 | The type of $array must be a numeric array type. | ||
| 1615 | |||
| 1616 | Thie method calls a corresponding method in L<Sort|SPVM::Sort> class. | ||
| 1617 | |||
| 1618 | Exceptions: | ||
| 1619 | |||
| 1620 | The array $array must be defined. Otherwise an exception is thrown. | ||
| 1621 | |||
| 1622 | The type of the array $array must be a numeric array type. Otherwise an exception is thrown. | ||
| 1623 | |||
| 1624 | =head2 sort_desc | ||
| 1625 | |||
| 1626 | C<static method sort_desc : byte[]|short[]|int[]|long[]|float[]|double[]|string[] ($array : byte[]|short[]|int[]|long[]|float[]|double[]|string[]);> | ||
| 1627 | |||
| 1628 | Copies the array $array using L</"copy"> method, sorts the copied array by descendant order, and returns it. | ||
| 1629 | |||
| 1630 | The type of $array must be a numeric array type. | ||
| 1631 | |||
| 1632 | Thie method calls a corresponding method in L<Sort|SPVM::Sort> class. | ||
| 1633 | |||
| 1634 | Exceptions: | ||
| 1635 | |||
| 1636 | The array $array must be defined. Otherwise an exception is thrown. | ||
| 1637 | |||
| 1638 | The type of the array $array must be a numeric array type. Otherwise an exception is thrown. | ||
| 1639 | |||
| 1640 | =head2 sort | ||
| 1641 | |||
| 1642 | C<static method sort : object[] ($array : object[], $comparator : Comparator);> | ||
| 1643 | |||
| 1644 | Copies the array $array using L</"copy"> method, sorts the copied array by the order specified by the comparator $comparator, and returns it. | ||
| 1645 | |||
| 1646 | This method calls L<Sort#sort_object|SPVM::Sort/"sort_object"> method to sort the copied array. | ||
| 1647 | |||
| 1648 | Exceptions: | ||
| 1649 | |||
| 1650 | Exceptions thrown by thrown L<Sort#sort_object|SPVM::Sort/"sort_object"> method could be thrown. | ||
| 1651 | |||
| 1652 | =head2 change_endian | ||
| 1653 | |||
| 1654 | C<static method change_endian : void ($binary : mutable string, $size : int, $offset : int = 0);> | ||
| 1655 | |||
| 1656 | The byte order of the first $size bytes of the binary data $binary at the offset $offset are reversed in-plcae. | ||
| 1657 | |||
| 1658 | Exceptions: | ||
| 1659 | |||
| 1660 | The binary data $binary must be defined. Otherwise an exception is thrown. | ||
| 1661 | |||
| 1662 | The byte size $size must be greater than 0. Otherwise an exception is thrown. | ||
| 1663 | |||
| 1664 | The offset $offset must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 1665 | |||
| 1666 | The byte size $size must be less than or equal to the offset $offset plus the length of the binary data $binary. | ||
| 1667 | |||
| 1668 | =head2 big_endian_to_system_endian | ||
| 1669 | |||
| 1670 | C<static method big_endian_to_system_endian : void ($binary : mutable string, $size : int, $offset : int = 0);> | ||
| 1671 | |||
| 1672 | The byte order of the first $size bytes of the binary data $binary at the offset $offset are changed from big endian to system endian. | ||
| 1673 | |||
| 1674 | This method calls L</"change_endian"> method to change endian. | ||
| 1675 | |||
| 1676 | Exceptions: | ||
| 1677 | |||
| 1678 | Exceptions thrown by L</"change_endian"> method could be thrown. | ||
| 1679 | |||
| 1680 | =head2 system_endian_to_big_endian | ||
| 1681 | |||
| 1682 | C<static method system_endian_to_big_endian : void ($binary : mutable string, $size : int, $offset : int = 0);> | ||
| 1683 | |||
| 1684 | The byte order of the first $size bytes of the binary data $binary at the offset $offset are changed from system endian to big endian. | ||
| 1685 | |||
| 1686 | This method calls L</"change_endian"> method to change endian. | ||
| 1687 | |||
| 1688 | Exceptions: | ||
| 1689 | |||
| 1690 | Exceptions thrown by L</"change_endian"> method could be thrown. | ||
| 1691 | |||
| 1692 | =head2 little_endian_to_system_endian | ||
| 1693 | |||
| 1694 | C<static method little_endian_to_system_endian : void ($binary : mutable string, $size : int, $offset : int = 0);> | ||
| 1695 | |||
| 1696 | The byte order of the first $size bytes of the binary data $binary at the offset $offset are changed from little endian to system endian. | ||
| 1697 | |||
| 1698 | This method calls L</"change_endian"> method to change endian. | ||
| 1699 | |||
| 1700 | Exceptions: | ||
| 1701 | |||
| 1702 | Exceptions thrown by L</"change_endian"> method could be thrown. | ||
| 1703 | |||
| 1704 | =head2 system_endian_to_little_endian | ||
| 1705 | |||
| 1706 | C<static method system_endian_to_little_endian : void ($binary : mutable string, $size : int, $offset : int = 0);> | ||
| 1707 | |||
| 1708 | The byte order of the first $size bytes of the binary data $binary at the offset $offset are changed from system endian to little endian. | ||
| 1709 | |||
| 1710 | This method calls L</"change_endian"> method to change endian. | ||
| 1711 | |||
| 1712 | Exceptions: | ||
| 1713 | |||
| 1714 | Exceptions thrown by L</"change_endian"> method could be thrown. | ||
| 1715 | |||
| 1716 | =head2 pack | ||
| 1717 | |||
| 1718 | C<static method pack : string ($template : string, $objects : object...);> | ||
| 1719 | |||
| 1720 | Converts the objects $objects to a binary data according to the template $template, and returns it. | ||
| 1721 | |||
| 1722 | This method just creates a L<Packer|SPVM::Packer> object, calls L<Packer#pack|SPVM::Packer/"pack"> method, and returns its return value. | ||
| 1723 | |||
| 1724 | Examples: | ||
| 1725 | |||
| 1726 | my $binary = Fn->pack("l", 3); | ||
| 1727 | |||
| 1728 | =head2 unpack | ||
| 1729 | |||
| 1730 | C<static method unpack : object[] ($template : string, $binary : string);> | ||
| 1731 | |||
| 1732 | Converts the binary data $binary to the objects $objects according to the template $template, and returns it. | ||
| 1733 | |||
| 1734 | This method just creates a L<Packer|SPVM::Packer> object, calls L<Packer#unpack|SPVM::Packer/"unpack"> method, and returns its return value. | ||
| 1735 | |||
| 1736 | =head2 no_close | ||
| 1737 | |||
| 1738 | C<static method no_close : int ($object : object);> | ||
| 1739 | |||
| 1740 | Calls L<no_close|SPVM::Document::NativeAPI/"no_close"> native API given $object, and retunrs its return value. | ||
| 1741 | |||
| 1742 | Excetpions: | ||
| 1743 | |||
| 1744 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1745 | |||
| 1746 | =head2 set_no_close | ||
| 1747 | |||
| 1748 | C<static method set_no_close : void ($object : object, $no_close : int);> | ||
| 1749 | |||
| 1750 | Calls L<set_no_close|SPVM::Document::NativeAPI/"set_no_close"> native API given $object, $no_close. | ||
| 1751 | |||
| 1752 | Excetpions: | ||
| 1753 | |||
| 1754 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1755 | |||
| 1756 | =head2 no_close | ||
| 1757 | |||
| 1758 | C<static method no_close : int ($object : object);> | ||
| 1759 | |||
| 1760 | Calls L<no_close|SPVM::Document::NativeAPI/"no_close"> native API given $object, and retunrs its return value. | ||
| 1761 | |||
| 1762 | Excetpions: | ||
| 1763 | |||
| 1764 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1765 | |||
| 1766 | =head2 set_no_close | ||
| 1767 | |||
| 1768 | C<static method set_no_close : void ($object : object, $no_close : int);> | ||
| 1769 | |||
| 1770 | Calls L<set_no_close|SPVM::Document::NativeAPI/"set_no_close"> native API given $object, $no_close. | ||
| 1771 | |||
| 1772 | Excetpions: | ||
| 1773 | |||
| 1774 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1775 | |||
| 1776 | =head2 get_pointer | ||
| 1777 | |||
| 1778 | C<static method get_pointer : L<Address|SPVM::Address> ($object : object);> | ||
| 1779 | |||
| 1780 | Creates a new L<Address|SPVM::Address> object, sets its L<pointer value|SPVM::Document::NativeClass/"Pointer Value"> to the pointer value of the object $object, and returns the new object. | ||
| 1781 | |||
| 1782 | Exceptions: | ||
| 1783 | |||
| 1784 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1785 | |||
| 1786 | =head2 set_pointer | ||
| 1787 | |||
| 1788 | C<static method set_pointer : void ($object : object, $address : L<Address|SPVM::Address>);> | ||
| 1789 | |||
| 1790 | Sets the L<pointer value|SPVM::Document::NativeClass/"Pointer Value"> of the object $object to the pointer value of the address $address. | ||
| 1791 | |||
| 1792 | Exceptions: | ||
| 1793 | |||
| 1794 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1795 | |||
| 1796 | The address $address must be defined. Otherwise an exception is thrown. | ||
| 1797 | |||
| 1798 | =head2 has_null_pointer | ||
| 1799 | |||
| 1800 | C<static method has_null_pointer : int ($object : object);> | ||
| 1801 | |||
| 1802 | If the L<pointer value|SPVM::Document::NativeClass/"Pointer Value"> of the object $object is NULL, returns 1, otherwise returns 0. | ||
| 1803 | |||
| 1804 | Exceptions: | ||
| 1805 | |||
| 1806 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1807 | |||
| 1808 | =head2 eq_pointer | ||
| 1809 | |||
| 1810 | C<static method eq_pointer : int ($object1 : object, $object2 : object);> | ||
| 1811 | |||
| 1812 | If the L<pointer value|SPVM::Document::NativeClass/"Pointer Value"> of the object $object1 is equal to the pointer value of the object $object2, returns 1, otherwise returns 0. | ||
| 1813 | |||
| 1814 | Exceptions: | ||
| 1815 | |||
| 1816 | The object $object1 must be defined. Otherwise an exception is thrown. | ||
| 1817 | |||
| 1818 | The object $object2 must be defined. Otherwise an exception is thrown. | ||
| 1819 | |||
| 1820 | =head2 pointer_to_string | ||
| 1821 | |||
| 1822 | C<static method pointer_to_string : string ($object : object);> | ||
| 1823 | |||
| 1824 | Creates a new string that contains the hex address of the L<pointer value|SPVM::Document::NativeClass/"Pointer Value"> of the object $object, and returns the new string. | ||
| 1825 | |||
| 1826 | Exceptions: | ||
| 1827 | |||
| 1828 | The object $object must be defined. Otherwise an exception is thrown. | ||
| 1829 | |||
| 1830 | =head2 dump_object_internal | ||
| 1831 | |||
| 1832 | C<static method dump_object_internal : string ($object : object);> | ||
| 1833 | |||
| 1834 | Calls L<dump_object_internal|SPVM::Document::NativeAPI/"dump_object_internal"> native API, and returns its return value. | ||
| 1835 | |||
| 1836 | =head2 get_seed | ||
| 1837 | |||
| 1838 | C<static method get_seed : int ();> | ||
| 1839 | |||
| 1840 | Calls L<get_seed|SPVM::Document::NativeAPI/"get_seed"> native API, and retunrs its return value. | ||
| 1841 | |||
| 1842 | =head2 set_seed | ||
| 1843 | |||
| 1844 | C<static method set_seed : void ($seed : int);> | ||
| 1845 | |||
| 1846 | Calls L<get_seed|SPVM::Document::NativeAPI/"set_seed"> native API given $seed. | ||
| 1847 | |||
| 1848 | =head2 seed_initialized | ||
| 1849 | |||
| 1850 | C<static method seed_initialized : int ();> | ||
| 1851 | |||
| 1852 | Calls L<seed_initialized|SPVM::Document::NativeAPI/"seed_initialized"> native API, and retunrs its return value. | ||
| 1853 | |||
| 1854 | =head2 get_basic_type_name_in_version_from | ||
| 1855 | |||
| 1856 | C<static method get_basic_type_name_in_version_from : basic_type_name ($basic_type_name : basic_type_name);> | ||
| 1857 | |||
| 1858 | Returns the basic_type_name specified by L<version_from Statement|SPVM::Document::Language::Class/"version_from Statement"> of the class $basic_type_name. If it is not specified, returns undef. | ||
| 1859 | |||
| 1860 | =head2 destroy_cache_class_vars | ||
| 1861 | |||
| 1862 | C<static method destroy_cache_class_vars : void ();> | ||
| 1863 | |||
| 1864 | Sets all class variables of all classes that is a object type and C<cache> class variable attribute is specified to undef. | ||
| 1865 | |||
| 1866 | =head2 destroy_runtime_permanent_vars | ||
| 1867 | |||
| 1868 | C<method destroy_runtime_permanent_vars : void ();> | ||
| 1869 | |||
| 1870 | Sets all runtime permanent variables to undef. | ||
| 1871 | |||
| 1872 | Currently thie method calls L</"destroy_cache_class_vars> method and sets C<$@> to undef. | ||
| 1873 | |||
| 1874 | =head2 range | ||
| 1875 | |||
| 1876 | C<static method range : int[] ($begin : int, $end : int);> | ||
| 1877 | |||
| 1878 | Returns a new array of values counting (up by ones) from $begin to $end. | ||
| 1879 | |||
| 1880 | Exceptions: | ||
| 1881 | |||
| 1882 | $end must be greater than or equal to $begin. | ||
| 1883 | |||
| 1884 | =head2 to_hash | ||
| 1885 | |||
| 1886 | C<static method to_hash : Hash ($options : L<Hash|SPVM::Hash>|object[]);> | ||
| 1887 | |||
| 1888 | Converts the options $options to a L<Hash|SPVM::Hash> object, and returns it. | ||
| 1889 | |||
| 1890 | If $options is C<undef>, returns an empty L<Hash|SPVM::Hash> object. | ||
| 1891 | |||
| 1892 | If $options is a Hash object, returns it. | ||
| 1893 | |||
| 1894 | If $options is an C<object[]> object, it is converted to a L<Hash|SPVM::Hash> object, and returns it. | ||
| 1895 | |||
| 1896 | Exceptions: | ||
| 1897 | |||
| 1898 | If the type of the options \$options must be Hash or object[], an exception is thrown. | ||
| 1899 | |||
| 1900 | =head2 get_basic_type_name_by_id | ||
| 1901 | |||
| 1902 | C<static method get_basic_type_name_by_id : string ($basic_type_id : int);> | ||
| 1903 | |||
| 1904 | Gets the basic type name of the basic type ID $basic_type_id. | ||
| 1905 | |||
| 1906 | Exceptions: | ||
| 1907 | |||
| 1908 | If the basic type specified by $basic_type_id is not found, an exception is thrown. | ||
| 1909 | |||
| 1910 | =head2 get_current_basic_type_name | ||
| 1911 | |||
| 1912 | C<static method get_current_basic_type_name : string ($level : int = 0);> | ||
| 1913 | |||
| 1914 | Returns the basic type name at the specified caller stack level C<$level>. | ||
| 1915 | |||
| 1916 | The level 0 represents the currently executing method's basic type. The level 1 represents its caller's basic type, and so on. | ||
| 1917 | |||
| 1918 | Exceptions: | ||
| 1919 | |||
| 1920 | If the specified C<$level> is out of range of the caller stack, an exception is thrown. | ||
| 1921 | |||
| 1922 | =head2 get_current_basic_type_name | ||
| 1923 | |||
| 1924 | C<static method get_current_basic_type_name : string ();> | ||
| 1925 | |||
| 1926 | Returns the name of the basic type (class) that owns the method currently being executed. | ||
| 1927 | |||
| 1928 | This method calls the L<get_current_method|SPVM::Document::NativeAPI/"get_current_method"> native API. | ||
| 1929 | |||
| 1930 | Exceptions: | ||
| 1931 | |||
| 1932 | If the caller stack is empty, an exception is thrown. | ||
| 1933 | |||
| 1934 | =head2 get_current_method_abs_name | ||
| 1935 | |||
| 1936 | C<static method get_current_method_abs_name : string ($level : int = 0);> | ||
| 1937 | |||
| 1938 | Returns the absolute name of the method at the specified caller stack level C<$level>. | ||
| 1939 | |||
| 1940 | The absolute name is the basic type name and the method name joined with C<#>. | ||
| 1941 | |||
| 1942 | The level 0 represents the currently executing method. The level 1 represents its caller, and so on. | ||
| 1943 | |||
| 1944 | Exceptions: | ||
| 1945 | |||
| 1946 | If the specified C<$level> is out of range of the caller stack, an exception is thrown. | ||
| 1947 | |||
| 1948 | =head2 longmess | ||
| 1949 | |||
| 1950 | C<static method longmess : string ($message : string, $start_call_depth : int = 0);> | ||
| 1951 | |||
| 1952 | Reconstructs a full message, including a stack trace, using the metadata stored in the runtime stack and the specified message string. | ||
| 1953 | |||
| 1954 | This method calls the L<longmess|SPVM::Document::NativeAPI/"longmess"> native API. | ||
| 1955 | |||
| 1956 | Returns the newly created string object. | ||
| 1957 | |||
| 1958 | =head2 build_exception_message | ||
| 1959 | |||
| 1960 | C<static method build_exception_message : string ($start_call_depth : int = 0);> | ||
| 1961 | |||
| 1962 | Reconstructs the full exception message, including a stack trace, by calling L</"longmess"> with the current exception object stored in the runtime stack. | ||
| 1963 | |||
| 1964 | The I<start_call_depth> argument specifies the starting depth of the stack trace relative to the current call. For example, 0 starts from the caller of this method. | ||
| 1965 | |||
| 1966 | This method calls the L<build_exception_message|SPVM::Document::NativeAPI/"build_exception_message"> native API. | ||
| 1967 | |||
| 1968 | Returns the newly created string object. | ||
| 1969 | |||
| 1970 | Examples: | ||
| 1971 | |||
| 1972 | eval { | ||
| 1973 | MyModule->do_something; | ||
| 1974 | }; | ||
| 1975 | |||
| 1976 | if ($@) { | ||
| 1977 | # Reconstruct the message with a stack trace | ||
| 1978 | my $message_with_caller_stack_lines = Fn->build_exception_message; | ||
| 1979 | Fn->say_stderr($message_with_caller_stack_lines); | ||
| 1980 | } | ||
| 1981 | |||
| 1982 | =head2 get_call_depth | ||
| 1983 | |||
| 1984 | C<static method get_call_depth : int ();> | ||
| 1985 | |||
| 1986 | Returns the current call stack depth. | ||
| 1987 | |||
| 1988 | The base depth is -1. When the first method is called, the depth becomes 0. | ||
| 1989 | |||
| 1990 | =head2 is_utf8 | ||
| 1991 | |||
| 1992 | C<static method is_utf8 : int ($string : string);> | ||
| 1993 | |||
| 1994 | Checks if the given string I<$string> is a valid UTF-8 sequence. | ||
| 1995 | |||
| 1996 | If the string is a valid UTF-8 sequence, returns 1, otherwise returns 0. | ||
| 1997 | |||
| 1998 | Notes: | ||
| 1999 | |||
| 2000 | This method calls the L<is_utf8|SPVM::Document::NativeAPI/"is_utf8"> native API. | ||
| 2001 | |||
| 2002 | Exceptions: | ||
| 2003 | |||
| 2004 | The string I<$string> must be defined. Otherwise an exception is thrown. | ||
| 2005 | |||
| 2006 | =head2 to_byte_object_unsigned | ||
| 2007 | |||
| 2008 | C<static method to_byte_object_unsigned : Byte ($string : string);> | ||
| 2009 | |||
| 2010 | Converts $string to a L<Byte|SPVM::Byte> object that is treated as an unsigned 8-bit integer. | ||
| 2011 | |||
| 2012 | The conversion is performed using L</"to_int"> with the C<$unsigned> argument set to 1. | ||
| 2013 | |||
| 2014 | The L<new_unsigned|SPVM::Byte/"new_unsigned"> method of the L<Byte|SPVM::Byte> class is used to create the object. | ||
| 2015 | |||
| 2016 | Exceptions: | ||
| 2017 | |||
| 2018 | Exceptions thrown by L</"to_int"> are thrown. | ||
| 2019 | |||
| 2020 | Examples: | ||
| 2021 | |||
| 2022 | my $string = "255"; | ||
| 2023 | my $obj = Fn->to_byte_object_unsigned($string); | ||
| 2024 | |||
| 2025 | =head2 to_short_object_unsigned | ||
| 2026 | |||
| 2027 | C<static method to_short_object_unsigned : Short ($string : string);> | ||
| 2028 | |||
| 2029 | Converts $string to a L<Short|SPVM::Short> object that is treated as an unsigned 16-bit integer. | ||
| 2030 | |||
| 2031 | The conversion is performed using L</"to_int"> with the C<$unsigned> argument set to 1. | ||
| 2032 | |||
| 2033 | The L<new_unsigned|SPVM::Short/"new_unsigned"> method of the L<Short|SPVM::Short> class is used to create the object. | ||
| 2034 | |||
| 2035 | Exceptions: | ||
| 2036 | |||
| 2037 | Exceptions thrown by L</"to_int"> are thrown. | ||
| 2038 | |||
| 2039 | Examples: | ||
| 2040 | |||
| 2041 | my $string = "65535"; | ||
| 2042 | my $obj = Fn->to_short_object_unsigned($string); | ||
| 2043 | |||
| 2044 | =head2 to_int_object_unsigned | ||
| 2045 | |||
| 2046 | C<static method to_int_object_unsigned : Int ($string : string);> | ||
| 2047 | |||
| 2048 | Converts $string to an L<Int|SPVM::Int> object that is treated as an unsigned 32-bit integer. | ||
| 2049 | |||
| 2050 | The conversion is performed using L</"to_int"> with the C<$unsigned> argument set to 1. | ||
| 2051 | |||
| 2052 | The L<new_unsigned|SPVM::Int/"new_unsigned"> method of the L<Int|SPVM::Int> class is used to create the object. | ||
| 2053 | |||
| 2054 | Exceptions: | ||
| 2055 | |||
| 2056 | Exceptions thrown by L</"to_int"> are thrown. | ||
| 2057 | |||
| 2058 | Examples: | ||
| 2059 | |||
| 2060 | my $string = "4294967295"; | ||
| 2061 | my $obj = Fn->to_int_object_unsigned($string); | ||
| 2062 | |||
| 2063 | =head2 to_long_object_unsigned | ||
| 2064 | |||
| 2065 | C<static method to_long_object_unsigned : Long ($string : string);> | ||
| 2066 | |||
| 2067 | Converts $string to a L<Long|SPVM::Long> object that is treated as an unsigned 64-bit integer. | ||
| 2068 | |||
| 2069 | The conversion is performed using L</"to_long"> with the C<$unsigned> argument set to 1. | ||
| 2070 | |||
| 2071 | The L<new_unsigned|SPVM::Long/"new_unsigned"> method of the L<Long|SPVM::Long> class is used to create the object. | ||
| 2072 | |||
| 2073 | Exceptions: | ||
| 2074 | |||
| 2075 | Exceptions thrown by L</"to_long"> are thrown. | ||
| 2076 | |||
| 2077 | Examples: | ||
| 2078 | |||
| 2079 | my $string = "18446744073709551615"; | ||
| 2080 | my $obj = Fn->to_long_object_unsigned($string); | ||
| 2081 | |||
| 2082 | =head2 getrandom | ||
| 2083 | |||
| 2084 | C<static method getrandom : string ($size : int);> | ||
| 2085 | |||
| 2086 | Gets OS-specific secure random bytes with the given size I<$size>. | ||
| 2087 | |||
| 2088 | The following APIs are used depending on the operating system: | ||
| 2089 | |||
| 2090 | =over 2 | ||
| 2091 | |||
| 2092 | =item * Windows: L<BCryptGenRandom|https://learn.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom> | ||
| 2093 | |||
| 2094 | =item * macOS, iOS, BSD: L<arc4random_buf|https://man.freebsd.org/cgi/man.cgi?query=arc4random_buf> | ||
| 2095 | |||
| 2096 | =item * Linux, Android: L<getrandom|https://man7.org/linux/man-pages/man2/getrandom.2.html> | ||
| 2097 | |||
| 2098 | =back | ||
| 2099 | |||
| 2100 | Returns a newly created string object filled with the random bytes. | ||
| 2101 | |||
| 2102 | Exceptions: | ||
| 2103 | |||
| 2104 | The size I<$size> must be non-negative. Otherwise an exception is thrown. | ||
| 2105 | |||
| 2106 | If the random bytes could not be retrieved from the OS, an exception is thrown. | ||
| 2107 | |||
| 2108 | Examples: | ||
| 2109 | |||
| 2110 | # Get a 32-byte secure random key | ||
| 2111 | my $key = Fn->getrandom(32); | ||
| 2112 | |||
| 2113 | # Get a 16-byte nonce for AES-GCM | ||
| 2114 | my $nonce = Fn->getrandom(12); | ||
| 2115 | |||
| 2116 | =head2 env | ||
| 2117 | |||
| 2118 | C<native static method env : string ($name : string);> | ||
| 2119 | |||
| 2120 | Gets the value of the environment variable specified by its name $name. | ||
| 2121 | |||
| 2122 | The value is retrieved using the C<getenv> function of the C standard library. | ||
| 2123 | |||
| 2124 | If the environment variable is not found, C<undef> is returned. | ||
| 2125 | |||
| 2126 | Exceptions: | ||
| 2127 | |||
| 2128 | The name $name must be defined. Otherwise an exception is thrown. | ||
| 2129 | |||
| 2130 | Examples: | ||
| 2131 | |||
| 2132 | # Get the value of the PATH environment variable | ||
| 2133 | my $path = Fn->env("PATH"); | ||
| 2134 | |||
| 2135 | # Get the value of the HOME environment variable | ||
| 2136 | my $home = Fn->env("HOME"); | ||
| 2137 | |||
| 2138 | =head2 enable_record_object | ||
| 2139 | |||
| 2140 | C<static method enable_record_object : void ();> | ||
| 2141 | |||
| 2142 | Enables object recording for memory leak tracking. | ||
| 2143 | |||
| 2144 | =head2 disable_record_object | ||
| 2145 | |||
| 2146 | C<static method disable_record_object : void ();> | ||
| 2147 | |||
| 2148 | Disables object recording for memory leak tracking. | ||
| 2149 | |||
| 2150 | =head2 dump_recorded_objects | ||
| 2151 | |||
| 2152 | C<static method dump_recorded_objects : string ();> | ||
| 2153 | |||
| 2154 | Dumps all recorded objects currently tracked for memory leak detection along with their allocation stack traces. | ||
| 2155 | |||
| 2156 | Returns the newly created string object containing the dump. | ||
| 2157 | |||
| 2158 | =head1 See Also | ||
| 2159 | |||
| 2160 | =over 2 | ||
| 2161 | |||
| 2162 | =item * L<Types|SPVM::Document::Language::Types> | ||
| 2163 | |||
| 2164 | =item * L<Class Definition|SPVM::Document::Language::Class> | ||
| 2165 | |||
| 2166 | =item * L<Operators|SPVM::Document::Language::Operators> | ||
| 2167 | |||
| 2168 | =back | ||
| 2169 | |||
| 2170 | =head1 Copyright & License | ||
| 2171 | |||
| 2172 | Copyright (c) 2023 Yuki Kimoto | ||
| 2173 | |||
| 2174 | MIT License |