diff --git a/lib/Sidef/Types/Glob/FileHandle.pm b/lib/Sidef/Types/Glob/FileHandle.pm index 9ee93782..dd669adc 100644 --- a/lib/Sidef/Types/Glob/FileHandle.pm +++ b/lib/Sidef/Types/Glob/FileHandle.pm @@ -222,11 +222,11 @@ package Sidef::Types::Glob::FileHandle { my $byte = CORE::ord(CORE::getc($self->{fh})); if (defined $var_ref) { - $$var_ref = Sidef::Types::Number::Number->new($byte // return Sidef::Types::Bool::Bool::FALSE); + $$var_ref = Sidef::Types::Number::Number::_set_int($byte // return Sidef::Types::Bool::Bool::FALSE); return Sidef::Types::Bool::Bool::TRUE; } - Sidef::Types::Number::Number->new($byte // return undef); + Sidef::Types::Number::Number::_set_int($byte // return undef); } *getb = \&read_byte; diff --git a/lib/Sidef/Types/String/String.pm b/lib/Sidef/Types/String/String.pm index 0b2e9eae..4d067c5f 100644 --- a/lib/Sidef/Types/String/String.pm +++ b/lib/Sidef/Types/String/String.pm @@ -225,18 +225,39 @@ package Sidef::Types::String::String { bless \(my $t = CORE::substr($$self, 0, defined($num) ? CORE::int($num) : 1)); } + *head = \&first; + sub last { my ($self, $num) = @_; bless \(my $t = CORE::substr($$self, defined($num) ? -(CORE::int($num) || return $self->new('')) : -1)); } + *tail = \&last; + sub char { my ($self, $pos) = @_; - bless \(my $t = CORE::substr($$self, CORE::int($pos), 1)); + bless \(my $t = CORE::substr($$self, CORE::int($pos), 1) // ''); } *char_at = \&char; + sub byte { + my ($self, $pos) = @_; + + require bytes; + + $pos = CORE::int($pos); + + if ($pos >= bytes::length($$self)) { + return undef; + } + + my $char = bytes::substr($$self, $pos, 1) // return undef; + Sidef::Types::Number::Number::_set_int(CORE::ord($char)); + } + + *byte_at = \&byte; + sub wordcase { my ($self) = @_; diff --git a/lib/Sidef/Types/String/String.pod b/lib/Sidef/Types/String/String.pod index e8f5c189..ae7830eb 100644 --- a/lib/Sidef/Types/String/String.pod +++ b/lib/Sidef/Types/String/String.pod @@ -339,6 +339,16 @@ Converts a binary string into its equivalent ASCII string representation. It tak =cut +=head2 byte + + self.byte(pos) + +Returns the + +Aliases: I + +=cut + =head2 bytes str.bytes @@ -698,18 +708,6 @@ Aliases: I =cut -=head2 first - - str.first(n) - -Returns the first C characters of the input string, where C is an integer. - -Parameters: - - n : An integer that represents the number of characters to be returned from the beginning of the input string. - -=cut - =head2 flip str.flip @@ -824,6 +822,18 @@ Aliases: I, I, I, I =cut +=head2 first + + str.first(n) + +Returns the first C characters of the input string, where C is an integer. + +Parameters: + + n : An integer that represents the number of characters to be returned from the beginning of the input string. + +=cut + =head2 hex self.hex