+ # Packs the content of a string in packs of `ln` chars.
+ # This variant ensures that only the last element might be smaller than `ln`
+ #
+ # ~~~nit
+ # var s = "abcdefghijklmnopqrstuvwxyz"
+ # assert s.pack_l(4) == ["abcd","efgh","ijkl","mnop","qrst","uvwx","yz"]
+ # ~~~
+ fun pack_l(ln: Int): Array[Text] do
+ var st = 0
+ var retarr = new Array[Text].with_capacity(length / ln + length % ln)
+ while st < length do
+ retarr.add(substring(st, ln))
+ st += ln
+ end
+ return retarr
+ end
+
+ # Packs the content of a string in packs of `ln` chars.
+ # This variant ensures that only the first element might be smaller than `ln`
+ #
+ # ~~~nit
+ # var s = "abcdefghijklmnopqrstuvwxyz"
+ # assert s.pack_r(4) == ["ab","cdef","ghij","klmn","opqr","stuv","wxyz"]
+ # ~~~
+ fun pack_r(ln: Int): Array[Text] do
+ var st = length
+ var retarr = new Array[Text].with_capacity(length / ln + length % ln)
+ while st >= 0 do
+ retarr.add(substring(st - ln, ln))
+ st -= ln
+ end
+ return retarr.reversed
+ end
+
+ # Concatenates self `i` times
+ #
+ #~~~nit
+ # assert "abc" * 4 == "abcabcabcabc"
+ # assert "abc" * 1 == "abc"
+ # assert "abc" * 0 == ""
+ # var b = new Buffer
+ # b.append("天地")
+ # b = b * 4
+ # assert b == "天地天地天地天地"
+ #~~~
+ fun *(i: Int): SELFTYPE is abstract
+
+ # Insert `s` at `pos`.
+ #
+ #~~~nit
+ # assert "helloworld".insert_at(" ", 5) == "hello world"
+ # var b = new Buffer
+ # b.append("Hello世界")
+ # b = b.insert_at(" beautiful ", 5)
+ # assert b == "Hello beautiful 世界"
+ #~~~
+ fun insert_at(s: String, pos: Int): SELFTYPE is abstract
+
+ # Returns a reversed version of self
+ #
+ # assert "hello".reversed == "olleh"
+ # assert "bob".reversed == "bob"
+ # assert "".reversed == ""
+ fun reversed: SELFTYPE is abstract
+
+ # A upper case version of `self`
+ #
+ # assert "Hello World!".to_upper == "HELLO WORLD!"
+ fun to_upper: SELFTYPE is abstract
+
+ # A lower case version of `self`
+ #
+ # assert "Hello World!".to_lower == "hello world!"
+ fun to_lower : SELFTYPE is abstract
+
+ # Takes a camel case `self` and converts it to snake case
+ #
+ # assert "randomMethodId".to_snake_case == "random_method_id"
+ #
+ # The rules are the following:
+ #
+ # An uppercase is always converted to a lowercase
+ #
+ # assert "HELLO_WORLD".to_snake_case == "hello_world"
+ #
+ # An uppercase that follows a lowercase is prefixed with an underscore
+ #
+ # assert "HelloTheWORLD".to_snake_case == "hello_the_world"
+ #
+ # An uppercase that follows an uppercase and is followed by a lowercase, is prefixed with an underscore
+ #
+ # assert "HelloTHEWorld".to_snake_case == "hello_the_world"
+ #
+ # All other characters are kept as is; `self` does not need to be a proper CamelCased string.
+ #
+ # assert "=-_H3ll0Th3W0rld_-=".to_snake_case == "=-_h3ll0th3w0rld_-="
+ fun to_snake_case: SELFTYPE is abstract
+
+ # Takes a snake case `self` and converts it to camel case
+ #
+ # assert "random_method_id".to_camel_case == "randomMethodId"
+ #
+ # If the identifier is prefixed by an underscore, the underscore is ignored
+ #
+ # assert "_private_field".to_camel_case == "_privateField"
+ #
+ # If `self` is upper, it is returned unchanged
+ #
+ # assert "RANDOM_ID".to_camel_case == "RANDOM_ID"
+ #
+ # If there are several consecutive underscores, they are considered as a single one
+ #
+ # assert "random__method_id".to_camel_case == "randomMethodId"
+ fun to_camel_case: SELFTYPE is abstract
+
+ # Returns a capitalized `self`
+ #
+ # Letters that follow a letter are lowercased
+ # Letters that follow a non-letter are upcased.
+ #
+ # If `keep_upper = true`, already uppercase letters are not lowercased.
+ #
+ # SEE : `Char::is_letter` for the definition of letter.
+ #
+ # assert "jAVASCRIPT".capitalized == "Javascript"
+ # assert "i am root".capitalized == "I Am Root"
+ # assert "ab_c -ab0c ab\nc".capitalized == "Ab_C -Ab0C Ab\nC"
+ # assert "preserve my ACRONYMS".capitalized(keep_upper=true) == "Preserve My ACRONYMS"
+ fun capitalized(keep_upper: nullable Bool): SELFTYPE do
+ if length == 0 then return self
+
+ var buf = new Buffer.with_cap(length)
+ buf.capitalize(keep_upper=keep_upper, src=self)
+ return buf.to_s
+ end