From 0c055a1ce9130d9e2bd5eb8ce719c611a97e9251 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 23 Mar 2021 11:38:56 +0300 Subject: [PATCH] all: s.contains(s2) instead of `in` --- vlib/builtin/string.v | 2 +- vlib/v/checker/checker.v | 4 +++- vlib/v/gen/c/cgen.v | 2 +- vlib/v/pref/pref.v | 13 +++++-------- vlib/v/table/types.v | 2 +- vlib/v/util/module.v | 2 +- vlib/vweb/request.v | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index c6dceaa835..4016939c83 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -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 } } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index f84929c62e..af7de08ced 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index e93007a118..45c771ea4d 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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 diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 5fbb362c82..bb3831078d 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -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 diff --git a/vlib/v/table/types.v b/vlib/v/table/types.v index ba322b9dd8..d7c555b895 100644 --- a/vlib/v/table/types.v +++ b/vlib/v/table/types.v @@ -972,7 +972,7 @@ pub fn (t &TypeSymbol) embed_name() string { mut embed_name := t.name.split('.').last() // remove generic part from name // Abc => Abc - if '<' in embed_name { + if embed_name.contains('<') { embed_name = embed_name.split('<')[0] } return embed_name diff --git a/vlib/v/util/module.v b/vlib/v/util/module.v index 37ab820266..430851b1df 100644 --- a/vlib/v/util/module.v +++ b/vlib/v/util/module.v @@ -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 } diff --git a/vlib/vweb/request.v b/vlib/vweb/request.v index f0e20d824f..a1ff88a13a 100644 --- a/vlib/vweb/request.v +++ b/vlib/vweb/request.v @@ -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)