1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: check (mut f Foo) syntax

This commit is contained in:
yuyi
2020-05-17 19:51:18 +08:00
committed by GitHub
parent b138cadbcb
commit 7f4cf08516
87 changed files with 492 additions and 480 deletions

View File

@ -13,7 +13,7 @@ mut:
text string
}
fn (s mut ChunkScanner) read_chunk_size() int {
fn (mut s ChunkScanner) read_chunk_size() int {
mut n := 0
for {
if s.pos >= s.text.len {
@ -43,11 +43,11 @@ fn unhex(c byte) byte {
return 0
}
fn (s mut ChunkScanner) skip_crlf() {
fn (mut s ChunkScanner) skip_crlf() {
s.pos += 2
}
fn (s mut ChunkScanner) read_chunk(chunksize int) string {
fn (mut s ChunkScanner) read_chunk(chunksize int) string {
startpos := s.pos
s.pos += chunksize
return s.text[startpos..s.pos]
@ -71,4 +71,3 @@ pub fn decode(text string) string {
cscanner.skip_crlf()
return sb.str()
}

View File

@ -651,7 +651,7 @@ fn parse_host(host string) ?string {
// - set_path('/foo%2fbar') will set path='/foo/bar' and raw_path='/foo%2fbar'
// set_path will return an error only if the provided path contains an invalid
// escaping.
pub fn (u mut URL) set_path(p string) ?bool {
pub fn (mut u URL) set_path(p string) ?bool {
path := unescape(p, .encode_path) or {
return error(err)
}

View File

@ -61,7 +61,7 @@ pub fn (v &Values) get_all(key string) []string {
// set sets the key to value. It replaces any existing
// values.
pub fn (v mut Values) set(key, value string) {
pub fn (mut v Values) set(key, value string) {
mut a := v.data[key]
a.data = [value]
v.data[key] = a
@ -70,7 +70,7 @@ pub fn (v mut Values) set(key, value string) {
// add adds the value to key. It appends to any existing
// values associated with key.
pub fn (v mut Values) add(key, value string) {
pub fn (mut v Values) add(key, value string) {
mut a := v.data[key]
if a.data.len == 0 {
a.data = []
@ -81,8 +81,7 @@ pub fn (v mut Values) add(key, value string) {
}
// del deletes the values associated with key.
pub fn (v mut Values) del(key string) {
pub fn (mut v Values) del(key string) {
v.data.delete(key)
v.size = v.data.size
}

View File

@ -1,6 +1,6 @@
module websocket
fn (ws mut Client) read_handshake(seckey string){
fn (mut ws Client) read_handshake(seckey string){
l.d("reading handshake...")
mut bytes_read := 0
max_buffer := 1024
@ -9,7 +9,7 @@ fn (ws mut Client) read_handshake(seckey string){
for bytes_read <= max_buffer {
res := ws.read_from_server(buffer + bytes_read, buffer_size)
if res == 0 || res == -1 {
if res == 0 || res == -1 {
l.f("read_handshake: Failed to read handshake.")
}
if buffer[bytes_read] == `\n` && buffer[bytes_read-1] == `\r` && buffer[bytes_read-2] == `\n` && buffer[bytes_read-3] == `\r` {
@ -21,10 +21,10 @@ fn (ws mut Client) read_handshake(seckey string){
ws.handshake_handler(string(byteptr(buffer)), seckey)
}
fn (ws mut Client) handshake_handler(handshake_response, seckey string){
fn (mut ws Client) handshake_handler(handshake_response, seckey string){
l.d("handshake_handler:\r\n${handshake_response}")
lines := handshake_response.split_into_lines()
header := lines[0]
if !header.starts_with("HTTP/1.1 101") && !header.starts_with("HTTP/1.0 101") {
l.f("handshake_handler: invalid HTTP status response code")

View File

@ -2,13 +2,13 @@ module websocket
fn C.write() int
fn (ws mut Client) write_to_server(buf voidptr, len int) int {
fn (mut ws Client) write_to_server(buf voidptr, len int) int {
mut bytes_written := 0
ws.write_lock.lock()
bytes_written = if ws.is_ssl {
C.SSL_write(ws.ssl, buf, len)
} else {
C.write(ws.socket.sockfd, buf, len)
C.write(ws.socket.sockfd, buf, len)
}
ws.write_lock.unlock()
return bytes_written

View File

@ -21,7 +21,7 @@ fn C.SSL_CTX_free()
fn C.SSL_write() int
fn C.SSL_read() int
fn (ws mut Client) connect_ssl(){
fn (mut ws Client) connect_ssl(){
l.i("Using secure SSL connection")
C.SSL_load_error_strings()
C.SSL_library_init()

View File

@ -23,7 +23,7 @@ pub fn utf8_validate(data byteptr, len int) bool {
return !state.failed && state.subindex <= 0
}
fn (s mut Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
fn (mut s Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
if s.subindex == 0 || (s.index > 1 && s.subindex == 1) || (s.index >= 6 && s.subindex == 2) {
if (s.subindex == 0 && r0) || (s.subindex == 1 && r1) || (s.subindex == 2 && is_tail) {
s.subindex++
@ -46,7 +46,7 @@ fn (s mut Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
return false
}
fn (s mut Utf8State) next_state (c byte) {
fn (mut s Utf8State) next_state (c byte) {
//sequence 1
if s.index == 0 {
if (c >= 0x00 + 1 && c <= 0x7F) || c == 0x00 {
@ -58,7 +58,7 @@ fn (s mut Utf8State) next_state (c byte) {
is_tail := c >= 0x80 && c <= 0xBF
//sequence 2
if s.index == 1 && s.seq(c >= 0xC2 && c <= 0xDF, false, is_tail) {return}
//sequence 3
if s.index == 2 && s.seq(c == 0xE0, c >= 0xA0 && c <= 0xBF, is_tail) {return}
if s.index == 3 && s.seq(c >= 0xE1 && c <= 0xEC, c >= 0x80 && c <= 0xBF, is_tail) {return}

View File

@ -115,7 +115,7 @@ fn (ws &Client) parse_uri() &Uri {
}
}
pub fn (ws mut Client) connect() int {
pub fn (mut ws Client) connect() int {
match ws.state {
.connected {
l.f("connect: websocket already connected")
@ -191,7 +191,7 @@ pub fn (ws mut Client) connect() int {
return 0
}
pub fn (ws mut Client) close(code int, message string){
pub fn (mut ws Client) close(code int, message string){
if ws.state != .closed && ws.socket.sockfd > 1 {
ws.lock.lock()
@ -248,7 +248,7 @@ pub fn (ws mut Client) close(code int, message string){
}
}
pub fn (ws mut Client) write(payload byteptr, payload_len int, code OPCode) int {
pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int {
if ws.state != .open {
ws.send_error_event("WebSocket closed. Cannot write.")
goto free_data
@ -319,7 +319,7 @@ pub fn (ws mut Client) write(payload byteptr, payload_len int, code OPCode) int
return bytes_written
}
pub fn (ws mut Client) listen() {
pub fn (mut ws Client) listen() {
l.i("Starting listener...")
for ws.state == .open {
ws.read()
@ -327,7 +327,7 @@ pub fn (ws mut Client) listen() {
l.i("Listener stopped as websocket was closed.")
}
pub fn (ws mut Client) read() int {
pub fn (mut ws Client) read() int {
mut bytes_read := u64(0)
initial_buffer := u64(256)
@ -601,7 +601,7 @@ pub fn (ws mut Client) read() int {
return -1
}
fn (ws mut Client) send_control_frame(code OPCode, frame_typ string, payload []byte) int {
fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []byte) int {
if ws.socket.sockfd <= 0 {
l.e("No socket opened.")
goto free_data