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

v2: string fixes, is_dir fix

This commit is contained in:
Alexander Medvednikov 2020-03-24 11:14:11 +01:00
parent 3d2fafa580
commit f101e9b9e2
6 changed files with 23 additions and 17 deletions

View File

@ -550,7 +550,7 @@ pub fn (s string) index_old(p string) int {
mut i := 0 mut i := 0
for i < s.len { for i < s.len {
mut j := 0 mut j := 0
for j < p.len && s[i + j] == p[j] { for j < p.len && s.str[i + j] == p.str[j] {
j++ j++
} }
if j == p.len { if j == p.len {
@ -568,7 +568,7 @@ pub fn (s string) index(p string) ?int {
mut i := 0 mut i := 0
for i < s.len { for i < s.len {
mut j := 0 mut j := 0
for j < p.len && s[i + j] == p[j] { for j < p.len && s.str[i + j] == p.str[j] {
j++ j++
} }
if j == p.len { if j == p.len {
@ -587,20 +587,20 @@ fn (s string) index_kmp(p string) int {
mut prefix := [0].repeat(p.len) mut prefix := [0].repeat(p.len)
mut j := 0 mut j := 0
for i := 1; i < p.len; i++ { for i := 1; i < p.len; i++ {
for p[j] != p[i] && j > 0 { for p.str[j] != p.str[i] && j > 0 {
j = prefix[j - 1] j = prefix[j - 1]
} }
if p[j] == p[i] { if p.str[j] == p.str[i] {
j++ j++
} }
prefix[i] = j prefix[i] = j
} }
j = 0 j = 0
for i in 0..s.len { for i in 0..s.len {
for p[j] != s[i] && j > 0 { for p.str[j] != s.str[i] && j > 0 {
j = prefix[j - 1] j = prefix[j - 1]
} }
if p[j] == s[i] { if p.str[j] == s.str[i] {
j++ j++
} }
if j == p.len { if j == p.len {
@ -627,7 +627,7 @@ pub fn (s string) last_index(p string) ?int {
mut i := s.len - p.len mut i := s.len - p.len
for i >= 0 { for i >= 0 {
mut j := 0 mut j := 0
for j < p.len && s[i + j] == p[j] { for j < p.len && s.str[i + j] == p.str[j] {
j++ j++
} }
if j == p.len { if j == p.len {
@ -653,7 +653,7 @@ pub fn (s string) index_after(p string, start int) int {
for i < s.len { for i < s.len {
mut j := 0 mut j := 0
mut ii := i mut ii := i
for j < p.len && s[ii] == p[j] { for j < p.len && s.str[ii] == p.str[j] {
j++ j++
ii++ ii++
} }
@ -667,7 +667,7 @@ pub fn (s string) index_after(p string, start int) int {
pub fn (s string) index_byte(c byte) int { pub fn (s string) index_byte(c byte) int {
for i in 0..s.len { for i in 0..s.len {
if s[i] == c { if s.str[i] == c {
return i return i
} }
} }
@ -676,7 +676,7 @@ pub fn (s string) index_byte(c byte) int {
pub fn (s string) last_index_byte(c byte) int { pub fn (s string) last_index_byte(c byte) int {
for i := s.len - 1; i >= 0; i-- { for i := s.len - 1; i >= 0; i-- {
if s[i] == c { if s.str[i] == c {
return i return i
} }
} }
@ -716,7 +716,7 @@ pub fn (s string) starts_with(p string) bool {
return false return false
} }
for i in 0..p.len { for i in 0..p.len {
if s[i] != p[i] { if s.str[i] != p.str[i] {
return false return false
} }
} }

View File

@ -565,7 +565,7 @@ fn (p mut Parser) cast(typ string) {
p.expected_type = typ p.expected_type = typ
expr_typ := p.bool_expression() expr_typ := p.bool_expression()
// Do not allow `int(my_int)` // Do not allow `int(my_int)`
if expr_typ == typ && typ != 'u64' { if expr_typ == typ {
p.warn('casting `$typ` to `$expr_typ` is not needed') p.warn('casting `$typ` to `$expr_typ` is not needed')
} }
// `face := FT_Face(cobj)` => `FT_Face face = *((FT_Face*)cobj);` // `face := FT_Face(cobj)` => `FT_Face face = *((FT_Face*)cobj);`

View File

@ -546,7 +546,7 @@ pub fn (v &V) v_files_from_dir(dir string) []string {
verror("$dir doesn't exist") verror("$dir doesn't exist")
} }
else if !os.is_dir(dir) { else if !os.is_dir(dir) {
verror("$dir isn't a directory") verror("$dir isn't a directory!")
} }
mut files := os.ls(dir)or{ mut files := os.ls(dir)or{
panic(err) panic(err)

View File

@ -170,10 +170,15 @@ fn (v mut V) set_module_lookup_paths() {
v.module_lookup_paths << os.base_dir(v.compiled_dir) // pdir of _test.v v.module_lookup_paths << os.base_dir(v.compiled_dir) // pdir of _test.v
} }
v.module_lookup_paths << v.compiled_dir v.module_lookup_paths << v.compiled_dir
x := os.join_path(v.compiled_dir, 'modules')
if v.pref.verbosity.is_higher_or_equal(.level_two) {
println('x: "$x"')
}
v.module_lookup_paths << os.join_path(v.compiled_dir, 'modules') v.module_lookup_paths << os.join_path(v.compiled_dir, 'modules')
v.module_lookup_paths << v.pref.lookup_path v.module_lookup_paths << v.pref.lookup_path
if v.pref.verbosity.is_higher_or_equal(.level_two) { if v.pref.verbosity.is_higher_or_equal(.level_two) {
v.log('v.module_lookup_paths: $v.module_lookup_paths') v.log('v.module_lookup_paths') //: $v.module_lookup_paths')
println(v.module_lookup_paths)
} }
} }

View File

@ -935,7 +935,8 @@ pub fn is_dir(path string) bool {
return false return false
} }
// ref: https://code.woboq.org/gcc/include/sys/stat.h.html // ref: https://code.woboq.org/gcc/include/sys/stat.h.html
return int(statbuf.st_mode) & S_IFMT == S_IFDIR val:= int(statbuf.st_mode) & S_IFMT
return val == S_IFDIR
} }
} }

View File

@ -132,7 +132,7 @@ pub fn (b &Builder) v_files_from_dir(dir string) []string {
verror("$dir doesn't exist") verror("$dir doesn't exist")
} }
else if !os.is_dir(dir) { else if !os.is_dir(dir) {
verror("$dir isn't a directory") verror("$dir isn't a directory!")
} }
mut files := os.ls(dir) or { mut files := os.ls(dir) or {
panic(err) panic(err)
@ -206,7 +206,7 @@ fn module_path(mod string) string {
pub fn (b &Builder) find_module_path(mod string) ?string { pub fn (b &Builder) find_module_path(mod string) ?string {
mod_path := module_path(mod) mod_path := module_path(mod)
for search_path in b.module_search_paths { for search_path in b.module_search_paths {
try_path := os.join_path(search_path, mod_path) try_path := os.join_path(search_path,mod_path)
if b.pref.verbosity.is_higher_or_equal(.level_three) { if b.pref.verbosity.is_higher_or_equal(.level_three) {
println(' >> trying to find $mod in $try_path ..') println(' >> trying to find $mod in $try_path ..')
} }