SPVM::StringBuffer(3)
π Name π
okay bestie, this is the SPVM::StringBuffer(3) page β User Contributed Perl Documentation, but make it cute π. The actual name is SPVM::StringBuffer β String Buffers β¨. That's the whole title, and we're obsessed.
πΈ Description πΈ
The StringBuffer class in SPVM has methods to manipulate string buffers. That's the vibe: it's a buffer, but for strings, and it's lowkey iconic π
.
β¨ Usage β¨
use StringBuffer;
# new
my $buffer = StringBuffer->new;
my $buffer = StringBuffer->new("abc");
# push string
$buffer->push("def");
# Convert to the string
my $string = $buffer->to_string;
π§ Details π§
π«Ά Internal Data Structure π«Ά
The "string" stored in a StringBuffer object always starts at index 0. Periodt.
The characters in the range that is greater than or equal to the "length" field and less than the "capacity" field are filled with "\0". That's the rule, no cap.
π Interfaces π
CloneableComparableEqualityCheckable
π Fields π
capacityβhas capacity : virtual ro int;β the capacity. This is the length of the internally reserved characters to extend the length of the string buffer.lengthβhas length : virtual ro int;β the length of the string buffer.stringβhas string : mutable string;β the internal string stored in theStringBufferobject.
π Class Methods π
new
static method new : StringBuffer ($string : string = undef, $capacity : int = -1);
Creates a new StringBuffer object using new_len. The passed $length to new_len is the length of $string. If the string is undef, it is 0. $string is copied to the value of the created string buffer. Cute.
new_len
static method new_len : StringBuffer ($length : int, $capacity : int = -1);
Creates a new StringBuffer object with $length and $capacity.
If $capacity is less than 0, $capacity is set to an appropriate value.
If $length is greater than $capacity, $capacity is set to $length.
Exceptions: $length must be greater than or equal to 0. Otherwise an exception is thrown. π
new_ref
static method new_ref : StringBuffer ($string : mutable string);
Creates a new StringBuffer object, sets the "string" field to the string $string, and returns the new object.
Exceptions: the array $array must be defined. Otherwise an exception is thrown. (Yes, it says $array β I'm just the messenger π)
π Instance Methods π
push
method push : void ($string : string, $offset : int = 0, $length : int = -1);
Adds a $string from $offset to the position proceeded by $length after the end of the string in the string buffer.
Exceptions:
$stringmust be defined. Otherwise an exception is thrown.$offsetmust be greater than or equal to0. Otherwise an exception is thrown.$offset + $lengthmust be less than or equal to the length of$string. Otherwise an exception is thrown.
push_char
method push_char : void ($char : int);
Adds Ascii $char after the end of the string in the string buffer.
reserve
method reserve : void ($new_capacity : int);
Reserves the characters that size is $new_capacity. If $new_capacity is greater than the capacity of the string buffer, the capacity of the string buffer is extended to $new_capacity.
Exceptions: $new_capacity must be greater than or equal to 0. Otherwise an exception is thrown.
to_string
method to_string : string ();
Creates a new string with the length of the buffer and copies all characters in the buffer into the new string, and returns it. Slay.
get_string
method get_string : string ();
Returns the internal "string".
set_length
method set_length : void ($length : int);
Sets "length" fields. If the length $length is greater than the "length" field, the characters of the exceeding part are filled with "\0".
set
method set : void ($string : string);
Sets the string $string.
compare_string
method compare_string : int ($string : string);
The return value is the same as the return value of the cmp operator given $self->to_string and $string.
equals_string
method equals_string : int ($string : string);
If the string contained in the StringBuffer instance is equal to the string $string, returns 1, otherwise returns 0.
clone
method clone ();
Clones this string buffer and returns it.
This method is a method implementation for the Cloneable interface.
cmp
method cmp : int ($a : StringBuffer, $b : StringBuffer);
Compares two StringBuffer and returns its result.
The return value is the same as the return value of the cmp operator given $a->to_string or undef (if $a is undef) and $b->to_string or undef (if $b is undef).
This method is a method implementation for the Comparable interface.
eq
method eq : int ($a : StringBuffer, $b : StringBuffer);
Checks if $a is equal to $b, and returns its result.
Implementation:
- If
$aand$bis defined, calls thecmpmethod. If the return value is0, returns1, otherwise0. - If only
$ais not defined, returns0. - If only
$bis not defined, returns0. - If both
$aand$bis not defined, returns1.
This method is a method implementation for the EqualityCheckable interface.
substr
method substr : string ($offset : int, $length : int = -1, $replacement : string = undef);
Calls the Fn#substr method given the value of the "string" field, $offset, $length, and returns its return value.
If the replacement string $replacement is specified, also calls the "replace" method.
Exceptions:
- The offset
$offset+ the length$lengthmust be less than or equal to the value of thelengthfield. Otherwise an exception is thrown. - Exceptions thrown by the
Fn#substrmethod could be thrown.
index
method index : int ($substring : string, $begin : int = 0, $end : int = -1);
Calls the Fn#index method given the "string" field, $substring, $bigen, $end, and returns its return value. (The page literally says $bigen there β iconic, we keep it π)
If $end is less than 0, it is set to the value of the "length" field.
Exceptions:
- The begin
$beginmust be between0and the length of the string field. Otherwise an exception is thrown. - The end
$endmust be less than or equal to the length of the string field. Otherwise an exception is thrown. - Exceptions thrown by the
Fn#indexmethod could be thrown.
contains
static method contains : int ($substring : string, $begin : int = 0, $end : int = -1);
Checks if the "string" field contains $substring.
Implementation:
The alias for the following code using the "index" method.
my $ret = $self->index($substring, $begin, $end) >= 0;
Exceptions: exceptions thrown by the "index" method could be thrown.
π Copyright & License π
Copyright (c) 2023 Yuki Kimoto
MIT License
and that's the whole page, bestie! π this was perl v5.42.2, dated 2026-02-03, and yes, the footer says SPVM::StringBuffer(3) β receipts included π«Άβ¨
π¦ where this page comes from
- alpine 3.24: spvm-doc 0.990125-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms