From b38283dcf1a238be77998075c7141146df4d7b7a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 30 Nov 2019 12:00:05 +0300 Subject: [PATCH] string: make left/right private --- vlib/builtin/string.v | 4 ++-- vlib/compiler/fn.v | 2 +- vlib/compiler/parser.v | 10 +++++----- vlib/time/time.v | 4 ++-- vlib/ui/{ui_mac.v => ui_darwin.v} | 0 5 files changed, 10 insertions(+), 10 deletions(-) rename vlib/ui/{ui_mac.v => ui_darwin.v} (100%) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 52acaf2658..963f9dc4c2 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -384,14 +384,14 @@ pub fn (s string) split_into_lines() []string { } // 'hello'.left(2) => 'he' -pub fn (s string) left(n int) string { +fn (s string) left(n int) string { if n >= s.len { return s } return s.substr(0, n) } // 'hello'.right(2) => 'llo' -pub fn (s string) right(n int) string { +fn (s string) right(n int) string { if n >= s.len { return '' } diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 41d168c4be..ac9d4955f2 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -214,7 +214,7 @@ fn (p mut Parser) fn_decl() { is_public: is_pub || p.is_vh // functions defined in .vh are always public is_unsafe: p.attr == 'unsafe_fn' is_deprecated: p.attr == 'deprecated' - comptime_define: if p.attr.starts_with('if ') { p.attr.right(3) } else { '' } + comptime_define: if p.attr.starts_with('if ') { p.attr[3..] } else { '' } } is_live := p.attr == 'live' && !p.pref.is_so && p.pref.is_live if p.attr == 'live' && p.first_pass() && !p.pref.is_live && !p.pref.is_so { diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 7457bc7fac..57c30b91e0 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -983,11 +983,11 @@ fn (p mut Parser) get_type() string { p.check(.amp) } // generic type check - ti := p.cur_fn.dispatch_of.inst - if p.lit in ti.keys() { + ti := p.cur_fn.dispatch_of.inst + if p.lit in ti.keys() { typ += ti[p.lit] - } else { - typ += p.lit + } else { + typ += p.lit } // C.Struct import if p.lit == 'C' && p.peek() == .dot { @@ -2093,7 +2093,7 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string { // } if is_indexer { l := p.cgen.cur_line.trim_space() - index_val := l.right(l.last_index(' ')).trim_space() + index_val := l[l.last_index(' ')..].trim_space() p.cgen.resetln(l[..fn_ph]) p.table.varg_access << VargAccess{ fn_name: p.cur_fn.name, diff --git a/vlib/time/time.v b/vlib/time/time.v index 270a1f6012..b4703ffb3b 100644 --- a/vlib/time/time.v +++ b/vlib/time/time.v @@ -421,7 +421,7 @@ pub fn (t Time) weekday_str() string { } pub struct C.timeval { - tv_sec u64 + tv_sec u64 tv_usec u64 } @@ -527,7 +527,7 @@ pub fn (t Time) get_fmt_date_str(fmt_dlmtr FormatDelimiter, fmt_date FormatDate) } month := '${t.smonth()}' - year := t.year.str().right(2) + year := t.year.str()[2..] return match fmt_date { .ddmmyy { '${t.day:02d}|${t.month:02d}|$year' } diff --git a/vlib/ui/ui_mac.v b/vlib/ui/ui_darwin.v similarity index 100% rename from vlib/ui/ui_mac.v rename to vlib/ui/ui_darwin.v