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

all: s.contains(s2) instead of in

This commit is contained in:
Alexander Medvednikov 2021-03-23 11:38:56 +03:00
parent b5c286256c
commit 0c055a1ce9
7 changed files with 13 additions and 14 deletions

View File

@ -882,7 +882,7 @@ pub fn (s string) contains(substr string) bool {
// contains_any returns `true` if the string contains any chars in `chars`.
pub fn (s string) contains_any(chars string) bool {
for c in chars {
if c.ascii_str() in s {
if s.contains(c.ascii_str()) {
return true
}
}

View File

@ -780,6 +780,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
infix_expr.left_type = map_info.key_type
}
.string {
c.warn('use `str.contains(substr)` instead of `substr in str`', left_right_pos)
c.check_expected(left_type, right_type) or {
c.error('left operand to `$infix_expr.op` does not match: $err.msg',
left_right_pos)
@ -4509,7 +4510,8 @@ pub fn (mut c Checker) ident(mut ident ast.Ident) table.Type {
}
if typ == table.error_type && c.expected_type == table.string_type
&& !c.using_new_err_struct && !c.inside_selector_expr
&& !c.inside_println_arg && 'v.' !in c.file.mod.name && !c.is_builtin_mod {
&& !c.inside_println_arg && !c.file.mod.name.contains('v.')
&& !c.is_builtin_mod {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <- TODO: remove; this prevents a failure in the `performance-regressions` CI job
c.warn('string errors are deprecated; use `err.msg` instead',
ident.pos)

View File

@ -162,7 +162,7 @@ pub fn gen(files []ast.File, table &table.Table, pref &pref.Preferences) string
mut module_built := ''
if pref.build_mode == .build_module {
for file in files {
if pref.path in file.path
if file.path.contains(pref.path)
&& file.mod.short_name == pref.path.all_after_last(os.path_separator).trim_right(os.path_separator) {
module_built = file.mod.name
break

View File

@ -634,22 +634,19 @@ pub fn cc_from_string(cc_str string) CompilerType {
normalized_cc_array := normalized_cc.split('/')
last_elem := normalized_cc_array.last()
cc := last_elem.all_before('.')
if '++' in cc {
if cc.contains('++') {
return .cplusplus
}
if 'tcc' in cc {
if cc.contains('tcc') || cc.contains('tinyc') {
return .tinyc
}
if 'tinyc' in cc {
return .tinyc
}
if 'clang' in cc {
if cc.contains('clang') {
return .clang
}
if 'mingw' in cc {
if cc.contains('mingw') {
return .mingw
}
if 'msvc' in cc {
if cc.contains('msvc') {
return .msvc
}
return .gcc

View File

@ -972,7 +972,7 @@ pub fn (t &TypeSymbol) embed_name() string {
mut embed_name := t.name.split('.').last()
// remove generic part from name
// Abc<int> => Abc
if '<' in embed_name {
if embed_name.contains('<') {
embed_name = embed_name.split('<')[0]
}
return embed_name

View File

@ -61,7 +61,7 @@ pub fn mod_path_to_full_name(mod string, path string) ?string {
vmod_folders := ['vlib', '.vmodules', 'modules']
mut in_vmod_path := false
for vmod_folder in vmod_folders {
if vmod_folder + os.path_separator in path {
if path.contains(vmod_folder + os.path_separator) {
in_vmod_path = true
break
}

View File

@ -66,7 +66,7 @@ fn parse_request_line(s string) ?(http.Method, urllib.URL, http.Version) {
}
fn parse_header(s string) ?(string, string) {
if ':' !in s {
if !s.contains(':') {
return error('missing colon in header')
}
words := s.split_nth(':', 2)