strings: rename Builder.write_b() to Builder.write_byte(), add deprecation (#13313)

pull/13315/head
Benjamin Stigsen 2022-01-28 19:34:44 +01:00 committed by GitHub
parent 7f22ed7935
commit ceb05b163a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 100 additions and 88 deletions

View File

@ -421,7 +421,7 @@ fn html_highlight(code string, tb &ast.Table) string {
break break
} }
} else { } else {
buf.write_b(code[i]) buf.write_byte(code[i])
i++ i++
} }
} }

View File

@ -266,7 +266,7 @@ fn color_highlight(code string, tb &ast.Table) string {
tok = next_tok tok = next_tok
next_tok = s.scan() next_tok = s.scan()
} else { } else {
buf.write_b(code[i]) buf.write_byte(code[i])
i++ i++
} }
} }

View File

@ -13,7 +13,7 @@ fn main() {
x := rand.read(blocksize) ? x := rand.read(blocksize) ?
for c in x { for c in x {
if c >= `0` && c <= `~` { if c >= `0` && c <= `~` {
sb.write_b(c) sb.write_byte(c)
} }
} }
if sb.len > size { if sb.len > size {

View File

@ -769,17 +769,17 @@ pub fn (a []string) str() string {
} }
sb_len += 2 // 1x[ + 1x] sb_len += 2 // 1x[ + 1x]
mut sb := strings.new_builder(sb_len) mut sb := strings.new_builder(sb_len)
sb.write_b(`[`) sb.write_byte(`[`)
for i in 0 .. a.len { for i in 0 .. a.len {
val := a[i] val := a[i]
sb.write_b(`'`) sb.write_byte(`'`)
sb.write_string(val) sb.write_string(val)
sb.write_b(`'`) sb.write_byte(`'`)
if i < a.len - 1 { if i < a.len - 1 {
sb.write_string(', ') sb.write_string(', ')
} }
} }
sb.write_b(`]`) sb.write_byte(`]`)
res := sb.str() res := sb.str()
unsafe { sb.free() } unsafe { sb.free() }
return res return res

View File

@ -268,7 +268,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
tmp.free() tmp.free()
} }
if write_minus { if write_minus {
sb.write_b(`-`) sb.write_byte(`-`)
bf.len0-- // compensate for the `-` above bf.len0-- // compensate for the `-` above
} }
if width == 0 { if width == 0 {

View File

@ -118,7 +118,7 @@ pub fn (mut parser Parser) split_parse(data string) {
else { 0 } else { 0 }
} }
if parser.lexical_attributes.open_code { // here will verify all needed to know if open_code finishes and string in code if parser.lexical_attributes.open_code { // here will verify all needed to know if open_code finishes and string in code
parser.lexical_attributes.lexeme_builder.write_b(chr) parser.lexical_attributes.lexeme_builder.write_byte(chr)
if parser.lexical_attributes.open_string > 0 if parser.lexical_attributes.open_string > 0
&& parser.lexical_attributes.open_string == string_code { && parser.lexical_attributes.open_string == string_code {
parser.lexical_attributes.open_string = 0 parser.lexical_attributes.open_string = 0
@ -141,12 +141,12 @@ pub fn (mut parser Parser) split_parse(data string) {
parser.lexical_attributes.open_comment = false parser.lexical_attributes.open_comment = false
parser.lexical_attributes.open_tag = false parser.lexical_attributes.open_tag = false
} else { } else {
parser.lexical_attributes.lexeme_builder.write_b(chr) parser.lexical_attributes.lexeme_builder.write_byte(chr)
} }
} else if parser.lexical_attributes.open_string > 0 { } else if parser.lexical_attributes.open_string > 0 {
if parser.lexical_attributes.open_string == string_code { if parser.lexical_attributes.open_string == string_code {
parser.lexical_attributes.open_string = 0 parser.lexical_attributes.open_string = 0
parser.lexical_attributes.lexeme_builder.write_b(chr) parser.lexical_attributes.lexeme_builder.write_byte(chr)
temp_lexeme := parser.builder_str() temp_lexeme := parser.builder_str()
if parser.lexical_attributes.current_tag.last_attribute != '' { if parser.lexical_attributes.current_tag.last_attribute != '' {
lattr := parser.lexical_attributes.current_tag.last_attribute lattr := parser.lexical_attributes.current_tag.last_attribute
@ -159,12 +159,12 @@ pub fn (mut parser Parser) split_parse(data string) {
} }
parser.lexical_attributes.lexeme_builder.go_back_to(0) parser.lexical_attributes.lexeme_builder.go_back_to(0)
} else { } else {
parser.lexical_attributes.lexeme_builder.write_b(chr) parser.lexical_attributes.lexeme_builder.write_byte(chr)
} }
} else if parser.lexical_attributes.open_tag { } else if parser.lexical_attributes.open_tag {
if parser.lexical_attributes.lexeme_builder.len == 0 && is_quote { if parser.lexical_attributes.lexeme_builder.len == 0 && is_quote {
parser.lexical_attributes.open_string = string_code parser.lexical_attributes.open_string = string_code
parser.lexical_attributes.lexeme_builder.write_b(chr) parser.lexical_attributes.lexeme_builder.write_byte(chr)
} else if chr == `>` { // close tag > } else if chr == `>` { // close tag >
complete_lexeme := parser.builder_str().to_lower() complete_lexeme := parser.builder_str().to_lower()
parser.lexical_attributes.current_tag.closed = (complete_lexeme.len > 0 parser.lexical_attributes.current_tag.closed = (complete_lexeme.len > 0
@ -190,7 +190,7 @@ pub fn (mut parser Parser) split_parse(data string) {
} }
// parser.print_debug(parser.lexical_attributes.current_tag.name) // parser.print_debug(parser.lexical_attributes.current_tag.name)
} else if chr !in [byte(9), ` `, `=`, `\n`] { // Tab, space, = and \n } else if chr !in [byte(9), ` `, `=`, `\n`] { // Tab, space, = and \n
parser.lexical_attributes.lexeme_builder.write_b(chr) parser.lexical_attributes.lexeme_builder.write_byte(chr)
} else if chr != 10 { } else if chr != 10 {
complete_lexeme := parser.builder_str().to_lower() complete_lexeme := parser.builder_str().to_lower()
if parser.lexical_attributes.current_tag.name == '' { if parser.lexical_attributes.current_tag.name == '' {
@ -226,7 +226,7 @@ pub fn (mut parser Parser) split_parse(data string) {
parser.generate_tag() parser.generate_tag()
parser.lexical_attributes.open_tag = true parser.lexical_attributes.open_tag = true
} else { } else {
parser.lexical_attributes.lexeme_builder.write_b(chr) parser.lexical_attributes.lexeme_builder.write_byte(chr)
} }
} }
} }

View File

@ -144,9 +144,9 @@ fn (mut c Client) send_auth() ? {
return return
} }
mut sb := strings.new_builder(100) mut sb := strings.new_builder(100)
sb.write_b(0) sb.write_byte(0)
sb.write_string(c.username) sb.write_string(c.username)
sb.write_b(0) sb.write_byte(0)
sb.write_string(c.password) sb.write_string(c.password)
a := sb.str() a := sb.str()
auth := 'AUTH PLAIN ${base64.encode_str(a)}\r\n' auth := 'AUTH PLAIN ${base64.encode_str(a)}\r\n'

View File

@ -748,9 +748,9 @@ fn test_long_query() {
base_string := rand.string(test_len) base_string := rand.string(test_len)
for c in base_string { for c in base_string {
buf.write_b(`(`) buf.write_byte(`(`)
buf.write_b(c) buf.write_byte(c)
buf.write_b(`)`) buf.write_byte(`)`)
} }
mut query := buf.str() mut query := buf.str()
@ -767,11 +767,11 @@ fn test_long_query() {
// test 2 // test 2
buf.clear() buf.clear()
for c in base_string { for c in base_string {
buf.write_b(`(`) buf.write_byte(`(`)
buf.write_b(c) buf.write_byte(c)
} }
for _ in 0..base_string.len { for _ in 0..base_string.len {
buf.write_b(`)`) buf.write_byte(`)`)
} }
query = buf.str() query = buf.str()
re = regex.regex_opt(query) or { panic(err) } re = regex.regex_opt(query) or { panic(err) }

View File

@ -103,13 +103,13 @@ pub fn format_str(s string, p BF_param) string {
} }
if p.allign == .right { if p.allign == .right {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
res.write_string(s) res.write_string(s)
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
return res.str() return res.str()

View File

@ -23,13 +23,13 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
if p.allign == .right { if p.allign == .right {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
sb.write_b(p.pad_ch) sb.write_byte(p.pad_ch)
} }
} }
sb.write_string(s) sb.write_string(s)
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
sb.write_b(p.pad_ch) sb.write_byte(p.pad_ch)
} }
} }
} }
@ -53,17 +53,17 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
if p.pad_ch == `0` { if p.pad_ch == `0` {
if p.positive { if p.positive {
if p.sign_flag { if p.sign_flag {
res.write_b(`+`) res.write_byte(`+`)
sign_written = true sign_written = true
} }
} else { } else {
res.write_b(`-`) res.write_byte(`-`)
sign_written = true sign_written = true
} }
} }
// write the pad chars // write the pad chars
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
@ -71,10 +71,10 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
// no pad char, write the sign before the number // no pad char, write the sign before the number
if p.positive { if p.positive {
if p.sign_flag { if p.sign_flag {
res.write_b(`+`) res.write_byte(`+`)
} }
} else { } else {
res.write_b(`-`) res.write_byte(`-`)
} }
} }
@ -123,13 +123,13 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
unsafe { res.write_ptr(&buf[i], n_char) } unsafe { res.write_ptr(&buf[i], n_char) }
} else { } else {
// we have a zero no need of more code! // we have a zero no need of more code!
res.write_b(`0`) res.write_byte(`0`)
} }
//=========================================== //===========================================
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
return return

View File

@ -17,7 +17,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
if p.allign == .right { if p.allign == .right {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
sb.write_b(p.pad_ch) sb.write_byte(p.pad_ch)
} }
} }
@ -25,7 +25,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
sb.write_b(p.pad_ch) sb.write_byte(p.pad_ch)
} }
} }
} }
@ -49,17 +49,17 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
if p.pad_ch == `0` { if p.pad_ch == `0` {
if p.positive { if p.positive {
if p.sign_flag { if p.sign_flag {
res.write_b(`+`) res.write_byte(`+`)
sign_written = true sign_written = true
} }
} else { } else {
res.write_b(`-`) res.write_byte(`-`)
sign_written = true sign_written = true
} }
} }
// write the pad chars // write the pad chars
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
@ -67,10 +67,10 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
// no pad char, write the sign before the number // no pad char, write the sign before the number
if p.positive { if p.positive {
if p.sign_flag { if p.sign_flag {
res.write_b(`+`) res.write_byte(`+`)
} }
} else { } else {
res.write_b(`-`) res.write_byte(`-`)
} }
} }
@ -88,7 +88,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
for _ in 0 .. n_char { for _ in 0 .. n_char {
i++ i++
res.write_b(buf[i]) res.write_byte(buf[i])
} }
i++ i++
@ -96,7 +96,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
return return

View File

@ -61,7 +61,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
ch := str[i] ch := str[i]
if ch != `%` && status == .norm_char { if ch != `%` && status == .norm_char {
res.write_b(ch) res.write_byte(ch)
i++ i++
continue continue
} }
@ -75,7 +75,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
if ch == `c` && status == .field_char { if ch == `c` && status == .field_char {
v_sprintf_panic(p_index, pt.len) v_sprintf_panic(p_index, pt.len)
d1 := unsafe { *(&byte(pt[p_index])) } d1 := unsafe { *(&byte(pt[p_index])) }
res.write_b(d1) res.write_byte(d1)
status = .reset_params status = .reset_params
p_index++ p_index++
i++ i++
@ -542,11 +542,11 @@ pub fn format_fl_old(f f64, p BF_param) string {
if p.pad_ch == `0` { if p.pad_ch == `0` {
if p.positive { if p.positive {
if p.sign_flag { if p.sign_flag {
res.write_b(`+`) res.write_byte(`+`)
sign_len_diff = -1 sign_len_diff = -1
} }
} else { } else {
res.write_b(`-`) res.write_byte(`-`)
sign_len_diff = -1 sign_len_diff = -1
} }
tmp := s tmp := s
@ -574,13 +574,13 @@ pub fn format_fl_old(f f64, p BF_param) string {
if p.allign == .right { if p.allign == .right {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
res.write_string(s) res.write_string(s)
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
@ -607,11 +607,11 @@ pub fn format_es_old(f f64, p BF_param) string {
if p.pad_ch == `0` { if p.pad_ch == `0` {
if p.positive { if p.positive {
if p.sign_flag { if p.sign_flag {
res.write_b(`+`) res.write_byte(`+`)
sign_len_diff = -1 sign_len_diff = -1
} }
} else { } else {
res.write_b(`-`) res.write_byte(`-`)
sign_len_diff = -1 sign_len_diff = -1
} }
tmp := s tmp := s
@ -638,13 +638,13 @@ pub fn format_es_old(f f64, p BF_param) string {
dif := p.len0 - s.len + sign_len_diff dif := p.len0 - s.len + sign_len_diff
if p.allign == .right { if p.allign == .right {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
res.write_string(s) res.write_string(s)
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
s.free() s.free()
@ -704,11 +704,11 @@ pub fn format_dec_old(d u64, p BF_param) string {
if p.pad_ch == `0` { if p.pad_ch == `0` {
if p.positive { if p.positive {
if p.sign_flag { if p.sign_flag {
res.write_b(`+`) res.write_byte(`+`)
sign_len_diff = -1 sign_len_diff = -1
} }
} else { } else {
res.write_b(`-`) res.write_byte(`-`)
sign_len_diff = -1 sign_len_diff = -1
} }
s = d.str() s = d.str()
@ -727,13 +727,13 @@ pub fn format_dec_old(d u64, p BF_param) string {
if p.allign == .right { if p.allign == .right {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
res.write_string(s) res.write_string(s)
if p.allign == .left { if p.allign == .left {
for i1 := 0; i1 < dif; i1++ { for i1 := 0; i1 < dif; i1++ {
res.write_b(p.pad_ch) res.write_byte(p.pad_ch)
} }
} }
return res.str() return res.str()

View File

@ -49,10 +49,17 @@ pub fn (mut b Builder) write_runes(runes []rune) {
} }
// write_b appends a single `data` byte to the accumulated buffer // write_b appends a single `data` byte to the accumulated buffer
[deprecated: 'Use write_byte() instead']
[deprecated_after: '2022-02-11']
pub fn (mut b Builder) write_b(data byte) { pub fn (mut b Builder) write_b(data byte) {
b << data b << data
} }
// write_byte appends a single `data` byte to the accumulated buffer
pub fn (mut b Builder) write_byte(data byte) {
b << data
}
// write implements the Writer interface // write implements the Writer interface
pub fn (mut b Builder) write(data []byte) ?int { pub fn (mut b Builder) write(data []byte) ?int {
if data.len == 0 { if data.len == 0 {

View File

@ -18,10 +18,15 @@ pub fn new_builder(initial_size int) Builder {
return []byte{cap: initial_size} return []byte{cap: initial_size}
} }
[deprecated: 'Use write_byte() instead']
pub fn (mut b Builder) write_b(data byte) { pub fn (mut b Builder) write_b(data byte) {
b << data b << data
} }
pub fn (mut b Builder) write_byte(data byte) {
b << data
}
pub fn (mut b Builder) write(data []byte) ?int { pub fn (mut b Builder) write(data []byte) ?int {
if data.len == 0 { if data.len == 0 {
return 0 return 0

View File

@ -65,7 +65,7 @@ fn test_byte_write() {
temp_str := 'byte testing' temp_str := 'byte testing'
mut count := 0 mut count := 0
for word in temp_str { for word in temp_str {
sb.write_b(word) sb.write_byte(word)
count++ count++
assert count == sb.len assert count == sb.len
} }

View File

@ -65,7 +65,7 @@ fn test_byte_write() {
temp_str := 'byte testing' temp_str := 'byte testing'
mut count := 0 mut count := 0
for word in temp_str { for word in temp_str {
sb.write_b(word) sb.write_byte(word)
count++ count++
assert count == sb.len assert count == sb.len
} }

View File

@ -37,9 +37,9 @@ pub fn (mut b Builder) rebuild_modules() {
chash := hash.sum64_string(ccontent, 7).hex_full() chash := hash.sum64_string(ccontent, 7).hex_full()
new_hashes[cpath] = chash new_hashes[cpath] = chash
sb_new_hashes.write_string(chash) sb_new_hashes.write_string(chash)
sb_new_hashes.write_b(` `) sb_new_hashes.write_byte(` `)
sb_new_hashes.write_string(cpath) sb_new_hashes.write_string(cpath)
sb_new_hashes.write_b(`\n`) sb_new_hashes.write_byte(`\n`)
} }
snew_hashes := sb_new_hashes.str() snew_hashes := sb_new_hashes.str()
// eprintln('new_hashes: $new_hashes') // eprintln('new_hashes: $new_hashes')

View File

@ -2538,7 +2538,7 @@ fn cescape_nonascii(original string) string {
write_octal_escape(mut b, c) write_octal_escape(mut b, c)
continue continue
} }
b.write_b(c) b.write_byte(c)
} }
res := b.str() res := b.str()
return res return res

View File

@ -76,7 +76,7 @@ fn is_html_open_tag(name string, s string) bool {
fn insert_template_code(fn_name string, tmpl_str_start string, line string) string { fn insert_template_code(fn_name string, tmpl_str_start string, line string) string {
// HTML, may include `@var` // HTML, may include `@var`
// escaped by cgen, unless it's a `vweb.RawHtml` string // escaped by cgen, unless it's a `vweb.RawHtml` string
trailing_bs := parser.tmpl_str_end + 'sb_${fn_name}.write_b(92)\n' + tmpl_str_start trailing_bs := parser.tmpl_str_end + 'sb_${fn_name}.write_byte(92)\n' + tmpl_str_start
round1 := ['\\', '\\\\', r"'", "\\'", r'@', r'$'] round1 := ['\\', '\\\\', r"'", "\\'", r'@', r'$']
round2 := [r'$$', r'\@', r'.$', r'.@'] round2 := [r'$$', r'\@', r'.$', r'.@']
mut rline := line.replace_each(round1).replace_each(round2) mut rline := line.replace_each(round1).replace_each(round2)

View File

@ -149,7 +149,7 @@ pub fn source_file_context(kind string, filepath string, pos token.Pos) []string
mut pointerline_builder := strings.new_builder(sline.len) mut pointerline_builder := strings.new_builder(sline.len)
for i := 0; i < start_column; { for i := 0; i < start_column; {
if sline[i].is_space() { if sline[i].is_space() {
pointerline_builder.write_b(sline[i]) pointerline_builder.write_byte(sline[i])
i++ i++
} else { } else {
char_len := utf8_char_len(sline[i]) char_len := utf8_char_len(sline[i])

View File

@ -65,8 +65,8 @@ pub fn smart_quote(str string, raw bool) string {
} }
if current == util.double_quote { if current == util.double_quote {
current = 0 current = 0
result.write_b(util.backslash) result.write_byte(util.backslash)
result.write_b(util.double_quote) result.write_byte(util.double_quote)
continue continue
} }
if current == util.backslash { if current == util.backslash {
@ -88,26 +88,26 @@ pub fn smart_quote(str string, raw bool) string {
} }
if next in util.invalid_escapes { if next in util.invalid_escapes {
skip_next = true skip_next = true
result.write_b(next) result.write_byte(next)
continue continue
} }
// keep all valid escape sequences // keep all valid escape sequences
skip_next = true skip_next = true
result.write_b(current) result.write_byte(current)
result.write_b(next) result.write_byte(next)
continue continue
} }
} }
if current == util.backslash_n { if current == util.backslash_n {
// keep newlines in string // keep newlines in string
current = 0 current = 0
result.write_b(util.backslash) result.write_byte(util.backslash)
result.write_b(`n`) result.write_byte(`n`)
continue continue
} }
if current == util.backslash_r && next == util.backslash_n { if current == util.backslash_r && next == util.backslash_n {
result.write_b(current) result.write_byte(current)
result.write_b(next) result.write_byte(next)
current = 0 current = 0
skip_next = true skip_next = true
continue continue
@ -115,20 +115,20 @@ pub fn smart_quote(str string, raw bool) string {
if !raw { if !raw {
if current == `$` { if current == `$` {
if last == util.backslash { if last == util.backslash {
result.write_b(last) result.write_byte(last)
result.write_b(current) result.write_byte(current)
continue continue
} }
} }
if current == util.backslash_r && next == util.backslash_n { if current == util.backslash_r && next == util.backslash_n {
// Windows style new line \r\n // Windows style new line \r\n
skip_next = true skip_next = true
result.write_b(util.backslash) result.write_byte(util.backslash)
result.write_b(`n`) result.write_byte(`n`)
continue continue
} }
} }
result.write_b(current) result.write_byte(current)
} }
return result.str() return result.str()
} }

View File

@ -15,21 +15,21 @@ fn write_value(v Any, i int, len int, mut wr strings.Builder) {
if i >= len - 1 { if i >= len - 1 {
return return
} }
wr.write_b(`,`) wr.write_byte(`,`)
} }
// str returns the string representation of the `map[string]Any`. // str returns the string representation of the `map[string]Any`.
[manualfree] [manualfree]
pub fn (flds map[string]Any) str() string { pub fn (flds map[string]Any) str() string {
mut wr := strings.new_builder(200) mut wr := strings.new_builder(200)
wr.write_b(`{`) wr.write_byte(`{`)
mut i := 0 mut i := 0
for k, v in flds { for k, v in flds {
wr.write_string('"$k":') wr.write_string('"$k":')
write_value(v, i, flds.len, mut wr) write_value(v, i, flds.len, mut wr)
i++ i++
} }
wr.write_b(`}`) wr.write_byte(`}`)
defer { defer {
unsafe { wr.free() } unsafe { wr.free() }
} }
@ -41,11 +41,11 @@ pub fn (flds map[string]Any) str() string {
[manualfree] [manualfree]
pub fn (flds []Any) str() string { pub fn (flds []Any) str() string {
mut wr := strings.new_builder(200) mut wr := strings.new_builder(200)
wr.write_b(`[`) wr.write_byte(`[`)
for i, v in flds { for i, v in flds {
write_value(v, i, flds.len, mut wr) write_value(v, i, flds.len, mut wr)
} }
wr.write_b(`]`) wr.write_byte(`]`)
defer { defer {
unsafe { wr.free() } unsafe { wr.free() }
} }
@ -157,7 +157,7 @@ fn json_string(s string) string {
hex_code := chr.hex() hex_code := chr.hex()
sb.write_string('\\u00$hex_code') sb.write_string('\\u00$hex_code')
} else { } else {
sb.write_b(chr) sb.write_byte(chr)
} }
} else { } else {
slice := s[i..i + char_len] slice := s[i..i + char_len]
@ -170,7 +170,7 @@ fn json_string(s string) string {
} else { } else {
// TODO: still figuring out what // TODO: still figuring out what
// to do with more than 4 chars // to do with more than 4 chars
sb.write_b(` `) sb.write_byte(` `)
} }
unsafe { unsafe {
slice.free() slice.free()

View File

@ -552,10 +552,10 @@ fn (mut tf TTF_File) get_unicode_string(length int) string {
c_len := ((0xe5000000 >> ((c >> 3) & 0x1e)) & 3) + 1 c_len := ((0xe5000000 >> ((c >> 3) & 0x1e)) & 3) + 1
real_len += c_len real_len += c_len
if c_len == 1 { if c_len == 1 {
tmp_txt.write_b(byte(c & 0xff)) tmp_txt.write_byte(byte(c & 0xff))
} else { } else {
tmp_txt.write_b(byte((c >> 8) & 0xff)) tmp_txt.write_byte(byte((c >> 8) & 0xff))
tmp_txt.write_b(byte(c & 0xff)) tmp_txt.write_byte(byte(c & 0xff))
} }
// dprintln("c: ${c:c}|${ byte(c &0xff) :c} c_len: ${c_len} str_len: ${real_len} in_len: ${length}") // dprintln("c: ${c:c}|${ byte(c &0xff) :c} c_len: ${c_len} str_len: ${real_len} in_len: ${length}")
} }