| 1 | package SPVM::Unicode; | ||
| 2 | |||
| 3 | 1 | our $VERSION = "0.058"; | |
| 4 | |||
| 5 | 1 | 1; | |
| 6 | |||
| 7 | =encoding utf8 | ||
| 8 | |||
| 9 | =head1 Name | ||
| 10 | |||
| 11 | SPVM::Unicode - Unicode Utilities | ||
| 12 | |||
| 13 | =head1 Description | ||
| 14 | |||
| 15 | Unicode class in L<SPVM> provides unicode utilities. | ||
| 16 | |||
| 17 | =head1 Usage | ||
| 18 | |||
| 19 | use Unicode; | ||
| 20 | |||
| 21 | my $string = "あいうえお"; | ||
| 22 | my $pos = 0; | ||
| 23 | while ((my $uchar = Unicode->uchar($string, \$pos)) >= 0); | ||
| 24 | # ... | ||
| 25 | } | ||
| 26 | |||
| 27 | =head1 Class Methods | ||
| 28 | |||
| 29 | =head2 ERROR_INVALID_UTF8 | ||
| 30 | |||
| 31 | C<static method INVALID_UTF8 : int ();> | ||
| 32 | |||
| 33 | Returns -2. | ||
| 34 | |||
| 35 | =head2 is_unicode_scalar_value | ||
| 36 | |||
| 37 | C<static method is_unicode_scalar_value : int ($code_point: int);> | ||
| 38 | |||
| 39 | If the code point $code_point is a Unicode scalar value, returns 1. Otherwise returns 0. | ||
| 40 | |||
| 41 | =head2 uchar | ||
| 42 | |||
| 43 | C<static method uchar : int ($string : string, $offset_ref : int*);> | ||
| 44 | |||
| 45 | Gets a Unicode codepoint by parsing UTF-8 string $string with the offset $$offset_ref and proceed the offset to the next parsing posision. | ||
| 46 | |||
| 47 | If $$offset_ref is over the string length, returns -1. | ||
| 48 | |||
| 49 | If an invalid UTF-8 character is found, returns the value of L</"ERROR_INVALID_UTF8">. | ||
| 50 | |||
| 51 | =head2 uchar_to_utf8 | ||
| 52 | |||
| 53 | C<static method uchar_to_utf8 : string ($unicode_code_point : int);> | ||
| 54 | |||
| 55 | Converts the Unicode codepoint $unicode_code_point to a UTF-8 character. | ||
| 56 | |||
| 57 | If the $unicode_code_point is invalid Unicode code point, returns undef. | ||
| 58 | |||
| 59 | =head2 utf8_to_utf16 | ||
| 60 | |||
| 61 | C<static method utf8_to_utf16 : short[] ($string : string);> | ||
| 62 | |||
| 63 | Converts the UTF-8 string $string to a UTF-16 string, and returns it. | ||
| 64 | |||
| 65 | =head2 utf16_to_utf8 | ||
| 66 | |||
| 67 | C<static method utf16_to_utf8 : string ($string : short[]);> | ||
| 68 | |||
| 69 | Converts the UTF-16 string $string to a UTF-8 string, and returns it. | ||
| 70 | |||
| 71 | =head2 utf32_to_utf16 | ||
| 72 | |||
| 73 | C<static method utf32_to_utf16 : short[] ($string : int[]);> | ||
| 74 | |||
| 75 | Converts the UTF-32 string $string to a UTF-16 string, and returns it. | ||
| 76 | |||
| 77 | =head2 utf16_to_utf32 | ||
| 78 | |||
| 79 | C<static method utf16_to_utf32 : int[] ($string : short[]);> | ||
| 80 | |||
| 81 | Converts the UTF-16 string $string to a UTF-32 string, and returns it. | ||
| 82 | |||
| 83 | =head1 Repository | ||
| 84 | |||
| 85 | L<SPVM::Unicode - Github|https://github.com/yuki-kimoto/SPVM-Unicode> | ||
| 86 | |||
| 87 | =head1 Copyright & License | ||
| 88 | |||
| 89 | Copyright (c) 2023 Yuki Kimoto | ||
| 90 | |||
| 91 | MIT License |