fun to_cmangle: String
do
if is_empty then return ""
- var res = new FlatBuffer
+ var res = new Buffer
var underscore = false
var start = 0
var c = chars[0]
# The exceptions are the common `\t` and `\n`.
fun escape_to_c: String
do
- var b = new FlatBuffer
+ var b = new Buffer
for i in [0..length[ do
var c = chars[i]
if c == '\n' then
# assert "ab|\{\}".escape_more_to_c("|\{\}") == "ab\\|\\\{\\\}"
fun escape_more_to_c(chars: String): String
do
- var b = new FlatBuffer
+ var b = new Buffer
for c in escape_to_c.chars do
if chars.chars.has(c) then
b.add('\\')
#
# assert "\n\"'\\\{\}0".escape_to_sh == "'\n\"'\\''\\\{\}0'"
fun escape_to_sh: String do
- var b = new FlatBuffer
+ var b = new Buffer
b.chars.add '\''
for i in [0..length[ do
var c = chars[i]
# These characters are `;`, `|`, `\`, and the non-printable ones.
# They will be rendered as `"?{hex}"`.
fun escape_to_mk: String do
- var b = new FlatBuffer
+ var b = new Buffer
for i in [0..length[ do
var c = chars[i]
if c == '$' then
# assert u.chars[0].ascii == 10 # (the ASCII value of the "new line" character)
fun unescape_nit: String
do
- var res = new FlatBuffer.with_capacity(self.length)
+ var res = new Buffer.with_cap(self.length)
var was_slash = false
for i in [0..length[ do
var c = chars[i]
# assert ".com/post?e=asdf&f=123".to_percent_encoding == ".com%2fpost%3fe%3dasdf%26f%3d123"
fun to_percent_encoding: String
do
- var buf = new FlatBuffer
+ var buf = new Buffer
for i in [0..length[ do
var c = chars[i]
# assert "invalid % usage".from_percent_encoding == "invalid ? usage"
fun from_percent_encoding: String
do
- var buf = new FlatBuffer
+ var buf = new Buffer
var i = 0
while i < length do
# SEE: <https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content>
fun html_escape: String
do
- var buf = new FlatBuffer
+ var buf = new Buffer
for i in [0..length[ do
var c = chars[i]
do
if self.is_lower then return self
- var new_str = new FlatBuffer.with_capacity(self.length)
+ var new_str = new Buffer.with_cap(self.length)
var prev_is_lower = false
var prev_is_upper = false
do
if self.is_upper then return self
- var new_str = new FlatBuffer
+ var new_str = new Buffer
var is_first_char = true
var follows_us = false
fun capitalized: SELFTYPE do
if length == 0 then return self
- var buf = new FlatBuffer.with_capacity(length)
+ var buf = new Buffer.with_cap(length)
var curr = chars[0].to_upper
var prev = curr
abstract class Buffer
super Text
+ # New `Buffer` factory, will return a concrete `Buffer` type with default capacity
+ new do return new FlatBuffer
+
+ # New `Buffer` factory, returns a concrete `Buffer` with a capacity of `i`
+ new with_cap(i: Int) do return new FlatBuffer.with_capacity(i)
+
redef type SELFTYPE: Buffer is fixed
# Specific implementations MUST set this to `true` in order to invalidate caches
# Clears the buffer
#
- # var b = new FlatBuffer
+ # var b = new Buffer
# b.append "hello"
# assert not b.is_empty
# b.clear
# Adds the content of text `s` at the end of self
#
- # var b = new FlatBuffer
+ # var b = new Buffer
# b.append "hello"
# b.append "world"
# assert b == "helloworld"
# `self` is appended in such a way that `self` is repeated `r` times
#
- # var b = new FlatBuffer
+ # var b = new Buffer
# b.append "hello"
# b.times 3
# assert b == "hellohellohello"
# Reverses itself in-place
#
- # var b = new FlatBuffer
+ # var b = new Buffer
# b.append("hello")
# b.reverse
# assert b == "olleh"
# Changes each lower-case char in `self` by its upper-case variant
#
- # var b = new FlatBuffer
+ # var b = new Buffer
# b.append("Hello World!")
# b.upper
# assert b == "HELLO WORLD!"
# Changes each upper-case char in `self` by its lower-case variant
#
- # var b = new FlatBuffer
+ # var b = new Buffer
# b.append("Hello World!")
# b.lower
# assert b == "hello world!"
length = 0
end
- redef fun empty do return new FlatBuffer
+ redef fun empty do return new Buffer
redef fun enlarge(cap)
do
var r = new FlatBuffer.with_infos(r_items, len, len)
return r
else
- return new FlatBuffer
+ return new Buffer
end
end
# assert 'x'.to_s == "x"
redef fun to_s
do
- var s = new FlatBuffer.with_capacity(1)
+ var s = new Buffer.with_cap(1)
s.chars[0] = self
return s.to_s
end
# Concatenate element without separators
fun plain_to_s: String
do
- var s = new FlatBuffer
+ var s = new Buffer
for e in self do if e != null then s.append(e.to_s)
return s.to_s
end
do
if is_empty then return ""
- var s = new FlatBuffer # Result
+ var s = new Buffer # Result
# Concat first item
var i = iterator
do
if is_empty then return ""
- var s = new FlatBuffer # Result
+ var s = new Buffer # Result
# Concat first item
var i = iterator