mirror of
https://github.com/vlang/v.git
synced 2025-09-15 23:42:28 +03:00
vlib: add an encoding.xml
module with parser, validation, entity encoding, unit tests (#19708)
This commit is contained in:
parent
01022e918e
commit
35558df96c
48 changed files with 2004 additions and 1 deletions
30
vlib/encoding/xml/reader_util.v
Normal file
30
vlib/encoding/xml/reader_util.v
Normal file
|
@ -0,0 +1,30 @@
|
|||
module xml
|
||||
|
||||
import io
|
||||
|
||||
fn next_char(mut reader io.Reader, mut buf []u8) !u8 {
|
||||
if reader.read(mut buf)! == 0 {
|
||||
return error('Unexpected End Of File.')
|
||||
}
|
||||
return buf[0]
|
||||
}
|
||||
|
||||
struct FullBufferReader {
|
||||
contents []u8
|
||||
mut:
|
||||
position int
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
fn (mut fbr FullBufferReader) read(mut buf []u8) !int {
|
||||
if fbr.position >= fbr.contents.len {
|
||||
return io.Eof{}
|
||||
}
|
||||
remaining := fbr.contents.len - fbr.position
|
||||
n := if buf.len < remaining { buf.len } else { remaining }
|
||||
unsafe {
|
||||
vmemcpy(&u8(buf.data), &u8(fbr.contents.data) + fbr.position, n)
|
||||
}
|
||||
fbr.position += n
|
||||
return n
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue