mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: byte => u8
This commit is contained in:
@ -49,14 +49,14 @@ pub fn (mut b Builder) write_runes(runes []rune) {
|
||||
}
|
||||
|
||||
// write_b appends a single `data` byte to the accumulated buffer
|
||||
[deprecated: 'Use write_byte() instead']
|
||||
[deprecated: 'Use write_u8() instead']
|
||||
[deprecated_after: '2022-02-11']
|
||||
pub fn (mut b Builder) write_b(data byte) {
|
||||
b << data
|
||||
}
|
||||
|
||||
// write_byte appends a single `data` byte to the accumulated buffer
|
||||
pub fn (mut b Builder) write_byte(data byte) {
|
||||
pub fn (mut b Builder) write_u8(data byte) {
|
||||
b << data
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ pub fn (mut b Builder) drain_builder(mut other Builder, other_new_cap int) {
|
||||
// Note: it can panic, if there are not enough bytes in the strings builder yet.
|
||||
[inline]
|
||||
pub fn (b &Builder) byte_at(n int) byte {
|
||||
return unsafe { (&[]byte(b))[n] }
|
||||
return unsafe { (&[]u8(b))[n] }
|
||||
}
|
||||
|
||||
// write appends the string `s` to the buffer
|
||||
@ -95,7 +95,7 @@ pub fn (mut b Builder) write_string(s string) {
|
||||
// for c in s {
|
||||
// b.buf << c
|
||||
// }
|
||||
// b.buf << []byte(s) // TODO
|
||||
// b.buf << []u8(s) // TODO
|
||||
}
|
||||
|
||||
// go_back discards the last `n` bytes from the buffer
|
||||
@ -146,8 +146,8 @@ pub fn (mut b Builder) writeln(s string) {
|
||||
if s.len > 0 {
|
||||
unsafe { b.push_many(s.str, s.len) }
|
||||
}
|
||||
// b.buf << []byte(s) // TODO
|
||||
b << byte(`\n`)
|
||||
// b.buf << []u8(s) // TODO
|
||||
b << u8(`\n`)
|
||||
}
|
||||
|
||||
// last_n(5) returns 'world'
|
||||
@ -176,8 +176,8 @@ pub fn (b &Builder) after(n int) string {
|
||||
// accumulated data that was in the string builder, before the
|
||||
// .str() call.
|
||||
pub fn (mut b Builder) str() string {
|
||||
b << byte(0)
|
||||
bcopy := unsafe { &byte(memdup_noscan(b.data, b.len)) }
|
||||
b << u8(0)
|
||||
bcopy := unsafe { &u8(memdup_noscan(b.data, b.len)) }
|
||||
s := unsafe { bcopy.vstring_with_len(b.len - 1) }
|
||||
b.trim(0)
|
||||
return s
|
||||
|
@ -18,12 +18,12 @@ pub fn new_builder(initial_size int) Builder {
|
||||
return []u8{cap: initial_size}
|
||||
}
|
||||
|
||||
[deprecated: 'Use write_byte() instead']
|
||||
[deprecated: 'Use write_u8() instead']
|
||||
pub fn (mut b Builder) write_b(data u8) {
|
||||
b << data
|
||||
}
|
||||
|
||||
pub fn (mut b Builder) write_byte(data u8) {
|
||||
pub fn (mut b Builder) write_u8(data u8) {
|
||||
b << data
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ fn test_byte_write() {
|
||||
temp_str := 'byte testing'
|
||||
mut count := 0
|
||||
for word in temp_str {
|
||||
sb.write_byte(word)
|
||||
sb.write_u8(word)
|
||||
count++
|
||||
assert count == sb.len
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ fn test_byte_write() {
|
||||
temp_str := 'byte testing'
|
||||
mut count := 0
|
||||
for word in temp_str {
|
||||
sb.write_byte(word)
|
||||
sb.write_u8(word)
|
||||
count++
|
||||
assert count == sb.len
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ pub fn random(n int) string {
|
||||
// amount of `end` marks in the `input`. An empty string is returned otherwise.
|
||||
// Using two identical marks as `start` and `end` results in undefined output behavior.
|
||||
// find_between_pair_byte is the fastest in the find_between_pair_* family of functions.
|
||||
// Example: assert strings.find_between_pair_byte('(V) (NOT V)',`(`,`)`) == 'V'
|
||||
// Example: assert strings.find_between_pair_byte('s {X{Y}} s',`{`,`}`) == 'X{Y}'
|
||||
pub fn find_between_pair_byte(input string, start byte, end byte) string {
|
||||
// Example: assert strings.find_between_pair_u8('(V) (NOT V)',`(`,`)`) == 'V'
|
||||
// Example: assert strings.find_between_pair_u8('s {X{Y}} s',`{`,`}`) == 'X{Y}'
|
||||
pub fn find_between_pair_u8(input string, start byte, end byte) string {
|
||||
mut marks := 0
|
||||
mut start_index := -1
|
||||
for i, b in input {
|
||||
|
@ -71,9 +71,9 @@ const expected_string_outputs = [
|
||||
|
||||
fn test_find_between_pair_family() {
|
||||
assert strings.find_between_pair_rune('xx♡ok❦yy', `♡`, `❦`) == 'ok'
|
||||
assert strings.find_between_pair_byte('xx{ok}yy', `{`, `}`) == 'ok'
|
||||
assert strings.find_between_pair_u8('xx{ok}yy', `{`, `}`) == 'ok'
|
||||
assert strings.find_between_pair_string('xx/*ok*/yy', '/*', '*/') == 'ok'
|
||||
assert strings.find_between_pair_byte('xx{ok}yy', `{`, `}`) == 'ok'
|
||||
assert strings.find_between_pair_u8('xx{ok}yy', `{`, `}`) == 'ok'
|
||||
assert strings.find_between_pair_string('xxxxokyyyy', 'xxx', 'yyy') == 'xok'
|
||||
|
||||
for i, tstr in test_rune_and_byte {
|
||||
@ -83,7 +83,7 @@ fn test_find_between_pair_family() {
|
||||
}
|
||||
|
||||
for i, tstr in test_rune_and_byte {
|
||||
e1 := strings.find_between_pair_byte(tstr, `[`, `]`)
|
||||
e1 := strings.find_between_pair_u8(tstr, `[`, `]`)
|
||||
e2 := expected_rune_and_byte_outputs[i]
|
||||
assert '$e1' == '$e2'
|
||||
}
|
||||
|
Reference in New Issue
Block a user