mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: add strings.Builder.write_string and use write_string instead of write (#8892)
This commit is contained in:
@ -4,12 +4,12 @@ import strings
|
||||
|
||||
fn generate_temp_html() string {
|
||||
mut temp_html := strings.new_builder(200)
|
||||
temp_html.write('<!doctype html><html><head><title>Giant String</title></head><body>')
|
||||
temp_html.write_string('<!doctype html><html><head><title>Giant String</title></head><body>')
|
||||
for counter := 0; counter < 4; counter++ {
|
||||
temp_html.write("<div id='name_$counter' ")
|
||||
temp_html.write("class='several-$counter'>Look at $counter</div>")
|
||||
temp_html.write_string("<div id='name_$counter' ")
|
||||
temp_html.write_string("class='several-$counter'>Look at $counter</div>")
|
||||
}
|
||||
temp_html.write('</body></html>')
|
||||
temp_html.write_string('</body></html>')
|
||||
return temp_html.str()
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,11 @@ fn test_split_parse() {
|
||||
fn test_giant_string() {
|
||||
mut temp_html := strings.new_builder(200)
|
||||
mut parser := Parser{}
|
||||
temp_html.write('<!doctype html><html><head><title>Giant String</title></head><body>')
|
||||
temp_html.write_string('<!doctype html><html><head><title>Giant String</title></head><body>')
|
||||
for counter := 0; counter < 2000; counter++ {
|
||||
temp_html.write("<div id='name_$counter' class='several-$counter'>Look at $counter</div>")
|
||||
temp_html.write_string("<div id='name_$counter' class='several-$counter'>Look at $counter</div>")
|
||||
}
|
||||
temp_html.write('</body></html>')
|
||||
temp_html.write_string('</body></html>')
|
||||
parser.parse_html(temp_html.str())
|
||||
assert parser.tags.len == 4009
|
||||
}
|
||||
|
@ -38,35 +38,35 @@ pub fn (tag Tag) text() string {
|
||||
return '\n'
|
||||
}
|
||||
mut text_str := strings.new_builder(200)
|
||||
text_str.write(tag.content.replace('\n', ''))
|
||||
text_str.write_string(tag.content.replace('\n', ''))
|
||||
for child in tag.children {
|
||||
text_str.write(child.text())
|
||||
text_str.write_string(child.text())
|
||||
}
|
||||
return text_str.str()
|
||||
}
|
||||
|
||||
pub fn (tag &Tag) str() string {
|
||||
mut html_str := strings.new_builder(200)
|
||||
html_str.write('<$tag.name')
|
||||
html_str.write_string('<$tag.name')
|
||||
for key, value in tag.attributes {
|
||||
html_str.write(' $key')
|
||||
html_str.write_string(' $key')
|
||||
if value.len > 0 {
|
||||
html_str.write('="$value"')
|
||||
html_str.write_string('="$value"')
|
||||
}
|
||||
}
|
||||
html_str.write(if tag.closed && tag.close_type == .in_name {
|
||||
html_str.write_string(if tag.closed && tag.close_type == .in_name {
|
||||
'/>'
|
||||
} else {
|
||||
'>'
|
||||
})
|
||||
html_str.write(tag.content)
|
||||
html_str.write_string(tag.content)
|
||||
if tag.children.len > 0 {
|
||||
for child in tag.children {
|
||||
html_str.write(child.str())
|
||||
html_str.write_string(child.str())
|
||||
}
|
||||
}
|
||||
if !tag.closed || tag.close_type == .new_tag {
|
||||
html_str.write('</$tag.name>')
|
||||
html_str.write_string('</$tag.name>')
|
||||
}
|
||||
return html_str.str()
|
||||
}
|
||||
|
Reference in New Issue
Block a user