Browse Source

Merge remote-tracking branch 'upstream/master'

master
Luna 1 year ago
parent
commit
e7290dee33
9 changed files with 96 additions and 64 deletions
  1. +0
    -1
      Makefile
  2. +22
    -6
      compiler/main.v
  3. +2
    -2
      compiler/msvc.v
  4. +2
    -2
      compiler/query.v
  5. +2
    -2
      compiler/tests/msvc_test.v
  6. +2
    -1
      make_msvc.bat
  7. +25
    -17
      vlib/builtin/string.v
  8. +6
    -0
      vlib/builtin/string_test.v
  9. +35
    -33
      vlib/net/urllib/urllib.v

+ 0
- 1
Makefile View File

@@ -1,5 +1,4 @@
CC ?= cc
PREFIX ?= /usr/local

all: stage1



+ 22
- 6
compiler/main.v View File

@@ -118,6 +118,10 @@ fn main() {
println('vpm has been disabled due to an exploit')
return
}
if 'symlink' in args {
create_symlink()
return
}
if args.join(' ').contains(' test v') {
test_v()
return
@@ -585,7 +589,11 @@ fn (v mut V) add_v_files_to_compile() {
}

fn get_arg(joined_args, arg, def string) string {
key := '-$arg '
return get_all_after(joined_args, '-$arg', def)
}

fn get_all_after(joined_args, arg, def string) string {
key := '$arg '
mut pos := joined_args.index(key)
if pos == -1 {
return def
@@ -617,17 +625,18 @@ fn (v &V) log(s string) {
}

fn new_v(args[]string) *V {
joined_args := args.join(' ')
target_os := get_arg(joined_args, 'os', '')
mut out_name := get_arg(joined_args, 'o', 'a.out')
mut dir := args.last()
if args.contains('run') {
dir = args[2]
dir = get_all_after(joined_args, 'run', '')
}
// println('new compiler "$dir"')
if args.len < 2 {
dir = ''
}
joined_args := args.join(' ')
target_os := get_arg(joined_args, 'os', '')
mut out_name := get_arg(joined_args, 'o', 'a.out')
// println('new compiler "$dir"')
// build mode
mut build_mode := BuildMode.default_mode
mut mod := ''
@@ -906,3 +915,10 @@ fn test_v() {
os.rm( tmpcfilepath )
}
}

fn create_symlink() {
vexe := os.executable()
link_path := '/usr/local/bin/v'
os.system('ln -sf $vexe $link_path')
println('symlink "$link_path" has been created')
}

+ 2
- 2
compiler/msvc.v View File

@@ -325,8 +325,8 @@ pub fn (v mut V) cc_msvc() {
}
}
arg := if lowest != -1 {
rest = base.right(lowest).trim_space().trim(`,`)
base.left(lowest).trim_space().trim(`,`)
rest = base.right(lowest).trim_space().trim(',')
base.left(lowest).trim_space().trim(',')
} else {
rest = ''
base.trim_space()


+ 2
- 2
compiler/query.v View File

@@ -9,12 +9,12 @@ import strings
fn sql_params2params_gen(sql_params []string, sql_types []string, qprefix string) string {
mut params_gen := ''
for i, mparam in sql_params {
param := mparam.trim(` `)
param := mparam.trim_space()
paramtype := sql_types[ i ]
if param[0].is_digit() {
params_gen += '${qprefix}params[$i] = int_str($param).str;\n'
}else if param[0] == `\'` {
sparam := param.trim(`\'`)
sparam := param.trim('\'')
params_gen += '${qprefix}params[$i] = "$sparam";\n'
} else {
// A variable like q.nr_orders


+ 2
- 2
compiler/tests/msvc_test.v View File

@@ -28,8 +28,8 @@ fn test_flag_parsing() {
}
}
arg := if lowest != -1 {
rest = base.right(lowest).trim_space().trim(`,`)
base.left(lowest).trim_space().trim(`,`)
rest = base.right(lowest).trim_space().trim(',')
base.left(lowest).trim_space().trim(',')
} else {
rest = ''
base.trim_space()


+ 2
- 1
make_msvc.bat View File

@@ -28,11 +28,12 @@ if %ERRORLEVEL% GEQ 1 (

echo rebuild from source
v2.exe -os msvc -o v.exe compiler

if %ERRORLEVEL% GEQ 1 (
goto :compileerror
)

dir v_win.c v2.exe v.exe

del .v_win.c.obj
del v_win.c
del v2.exe


+ 25
- 17
vlib/builtin/string.v View File

@@ -590,30 +590,38 @@ pub fn (s string) trim_space() string {
return res
}

pub fn (s string) trim(c byte) string {
if s == '' {
return ''
}
mut i := 0
for i < s.len && c == s[i] {
i++
pub fn (s string) trim(cutset string) string {
if s.len == 0 || cutset.len == 0 {
return s
}
mut res := s.right(i)
mut end := res.len - 1
for end >= 0 && c == res[end] {
end--
cs_arr := cutset.bytes()
mut pos_left := 0
mut pos_right := s.len - 1
mut cs_match := true
for pos_left <= s.len && pos_right >= -1 && cs_match {
cs_match = false
if s[pos_left] in cs_arr {
pos_left++
cs_match = true
}
if s[pos_right] in cs_arr {
pos_right--
cs_match = true
}
if pos_left > pos_right {
return ''
}
}
res = res.left(end + 1)
return res
return s.substr(pos_left, pos_right+1)
}

pub fn (s string) trim_left(cutset string) string {
if s.len == 0 || cutset.len == 0 {
return s
}
mut pos := 0
cs_arr := cutset.bytes()
for s[pos] in cs_arr {
mut pos := 0
for pos <= s.len && s[pos] in cs_arr {
pos++
}
return s.right(pos)
@@ -623,9 +631,9 @@ pub fn (s string) trim_right(cutset string) string {
if s.len == 0 || cutset.len == 0 {
return s
}
mut pos := s.len - 1
cs_arr := cutset.bytes()
for s[pos] in cs_arr {
mut pos := s.len - 1
for pos >= -1 && s[pos] in cs_arr {
pos--
}
return s.left(pos+1)


+ 6
- 0
vlib/builtin/string_test.v View File

@@ -302,6 +302,12 @@ fn test_hash() {
assert s5.hash() % ((1 << 20) -1) == 592861
}

fn test_trim() {
assert 'banana'.trim('bna') == ''
assert 'abc'.trim('ac') == 'b'
assert 'aaabccc'.trim('ac') == 'b'
}

fn test_trim_left() {
mut s := 'module main'
assert s.trim_left(' ') == 'module main'


+ 35
- 33
vlib/net/urllib/urllib.v View File

@@ -8,7 +8,7 @@
// it deviates for compatibility reasons.

// Based off: https://github.com/golang/go/blob/master/src/net/url/url.go
// Last commit: https://github.com/golang/go/commit/a326bc6df27309815e4a2ae005adef233cfb9ea9
// Last commit: https://github.com/golang/go/commit/61bb56ad63992a3199acc55b2537c8355ef887b6
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -596,13 +596,13 @@ fn parse_host(host string) ?string {
if host.starts_with('[') {
// parse an IP-Literal in RFC 3986 and RFC 6874.
// E.g., '[fe80::1]', '[fe80::1%25en0]', '[fe80::1]:80'.
i := host.last_index(']')
mut i := host.last_index(']')
if i < 0 {
return error(error_msg('missing \']\' in host', ''))
}
colonport := host.right(i+1)
if !valid_optional_port(colonport) {
return error(error_msg('invalid port $colonport after host ', ''))
mut colon_port := host.right(i+1)
if !valid_optional_port(colon_port) {
return error(error_msg('invalid port $colon_port after host ', ''))
}

// RFC 6874 defines that %25 (%-encoded percent) introduces
@@ -623,6 +623,14 @@ fn parse_host(host string) ?string {
return err
}
return host1 + host2 + host3
} else {
i = host.last_index(':')
if i != -1 {
colon_port = host.right(i)
if !valid_optional_port(colon_port) {
return error(error_msg('invalid port $colon_port after host ', ''))
}
}
}
}

@@ -1007,46 +1015,40 @@ pub fn (u &URL) request_uri() string {
return result
}

// hostname returns u.host, without any port number.
// hostname returns u.host, stripping any valid port number if present.
//
// If host is an IPv6 literal with a port number, hostname returns the
// IPv6 literal without the square brackets. IPv6 literals may include
// a zone identifier.
// If the result is enclosed in square brackets, as literal IPv6 addresses are,
// the square brackets are removed from the result.
pub fn (u &URL) hostname() string {
return strip_port(u.host)
host_port := split_host_port(u.host)
return host_port[0]
}

// port returns the port part of u.host, without the leading colon.
// If u.host doesn't contain a port, port returns an empty string.
pub fn (u &URL) port() string {
return port_only(u.host)
host_port := split_host_port(u.host)
return host_port[1]
}

pub fn strip_port(hostport string) string {
colon := hostport.index(':')
if colon == -1 {
return hostport
// split_host_port separates host and port. If the port is not valid, it returns
// the entire input as host, and it doesn't check the validity of the host.
// Per RFC 3986, it requires ports to be numeric.
fn split_host_port(hostport string) []string {
mut host := hostport
mut port := ''
colon := host.last_index(':')
if colon != -1 && valid_optional_port(host.right(colon)) {
port = host.right(colon+1)
host = host.left(colon)
}
i := hostport.index(']')
if i != -1 {
return hostport.left(i).trim_left('[')
}
return hostport.left(colon)
}

pub fn port_only(hostport string) string {
colon := hostport.index(':')
if colon == -1 {
return ''
}
i := hostport.index(']:')
if i != -1 {
return hostport.right(i+(']:'.len))
if host.starts_with('[') && host.ends_with(']') {
host = host.substr(1, host.len-1)
}
if hostport.contains(']') {
return ''
}
return hostport.right(colon+(':'.len))

return [host, port]
}

// valid_userinfo reports whether s is a valid userinfo string per RFC 3986


Loading…
Cancel
Save