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

strconv: deprecate v_sprintf in favor of string interpolation

This commit is contained in:
Alexander Medvednikov 2022-08-23 09:52:59 +03:00
parent a758b6686c
commit 2dde7ff5ba
6 changed files with 14 additions and 11 deletions

View File

@ -23,6 +23,7 @@ enum Char_parse_state {
}
// v_printf prints a sprintf-like formated `string` to the terminal.
[deprecated: 'use string interpolation instead']
pub fn v_printf(str string, pt ...voidptr) {
print(v_sprintf(str, ...pt))
}
@ -34,6 +35,7 @@ pub fn v_printf(str string, pt ...voidptr) {
// x := 3.141516
// assert strconv.v_sprintf('aaa %G', x) == 'aaa 3.141516'
// ```
[deprecated: 'use string interpolation instead']
[manualfree]
pub fn v_sprintf(str string, pt ...voidptr) string {
mut res := strings.new_builder(pt.len * 16)

View File

@ -750,7 +750,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
}
}
if !func.is_pub && func.language == .v && func.name.len > 0 && func.mod.len > 0
&& func.mod != c.mod {
&& func.mod != c.mod && !c.pref.is_test {
c.error('function `$func.name` is private', node.pos)
}
if !isnil(c.table.cur_fn) && !c.table.cur_fn.is_deprecated && func.is_deprecated {

View File

@ -1,5 +1,5 @@
vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv:3:31: error: expression cannot be passed as `voidptr`
1 | import strconv
2 |
3 | strconv.v_printf('%02.02f\n', 1.1)
| ~~~
vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv:5:23: error: expression cannot be passed as `voidptr`
3 | }
4 |
5 | myprintf('%02.02f\n', 1.1)
| ~~~

View File

@ -1,3 +1,5 @@
import strconv
fn myprintf(s string, x voidptr) {
strconv.v_printf('%02.02f\n', 1.1)
}
myprintf('%02.02f\n', 1.1)

View File

@ -3,7 +3,6 @@ module executable
import os
import time
import dl
import strconv
import v.live
pub const (
@ -84,7 +83,7 @@ fn compile_lib(mut r live.LiveReloadInfo) ?string {
}
fn current_shared_library_path(mut r live.LiveReloadInfo) (string, string) {
lib_path := strconv.v_sprintf(r.so_name_template.replace('\\', '\\\\'), r.reloads)
lib_path := r.so_name_template.replace('\\', '\\\\').replace('%d', r.reloads.str())
lib_path_with_extension := lib_path + r.so_extension
return lib_path, lib_path_with_extension
}

View File

@ -118,6 +118,7 @@ pub mut:
is_debug bool // turned on by -g or -cg, it tells v to pass -g to the C backend compiler.
is_vlines bool // turned on by -g (it slows down .tmp.c generation slightly).
is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run
show_timings bool // show how much time each compiler stage took
is_fmt bool
is_vet bool
is_vweb bool // skip _ var warning in templates
@ -201,7 +202,6 @@ pub mut:
check_only bool // same as only_check_syntax, but also runs the checker
experimental bool // enable experimental features
skip_unused bool // skip generating C code for functions, that are not used
show_timings bool // show how much time each compiler stage took
//
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
cleanup_files []string // list of temporary *.tmp.c and *.tmp.c.rsp files. Cleaned up on successfull builds.