mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
all: string interpolation code cleaning (#10204)
This commit is contained in:
parent
5e26273529
commit
2dd1d3fcbb
8 changed files with 17 additions and 491 deletions
|
@ -637,13 +637,11 @@ pub const (
|
|||
si_g64_code = '0xfe0f'
|
||||
)
|
||||
|
||||
// replace _STR("\'%.*s\\000\'", 2, in_str)
|
||||
[inline]
|
||||
pub fn str_intp_sq(in_str string) string {
|
||||
return 'str_intp(2, _MOV((StrIntpData[]){{_SLIT("\'"), $si_s_code, {.d_s = $in_str}},{_SLIT("\'"), 0, {.d_c = 0 }}}))'
|
||||
}
|
||||
|
||||
// replace _STR("\`%.*s\\000\`", 2, in_str)
|
||||
[inline]
|
||||
pub fn str_intp_rune(in_str string) string {
|
||||
return 'str_intp(2, _MOV((StrIntpData[]){{_SLIT("\`"), $si_s_code, {.d_s = $in_str}},{_SLIT("\`"), 0, {.d_c = 0 }}}))'
|
||||
|
@ -660,15 +658,25 @@ pub fn str_intp_g64(in_str string) string {
|
|||
}
|
||||
|
||||
// replace %% with the in_str
|
||||
[manualfree]
|
||||
pub fn str_intp_sub(base_str string, in_str string) string {
|
||||
index := base_str.index('%%') or {
|
||||
eprintln('No strin interpolation %% parameteres')
|
||||
exit(1)
|
||||
}
|
||||
// return base_str[..index] + in_str + base_str[index+2..]
|
||||
if index + 2 < base_str.len {
|
||||
return 'str_intp(2, _MOV((StrIntpData[]){{_SLIT("${base_str[..index]}"), $si_s_code, {.d_s = $in_str }},{_SLIT("${base_str[
|
||||
index + 2..]}"), 0, {.d_c = 0}}}))'
|
||||
|
||||
unsafe {
|
||||
st_str := base_str[..index]
|
||||
if index + 2 < base_str.len {
|
||||
en_str := base_str[index + 2..]
|
||||
res_str := 'str_intp(2, _MOV((StrIntpData[]){{_SLIT("$st_str"), $si_s_code, {.d_s = $in_str }},{_SLIT("$en_str"), 0, {.d_c = 0}}}))'
|
||||
st_str.free()
|
||||
en_str.free()
|
||||
return res_str
|
||||
}
|
||||
res2_str := 'str_intp(1, _MOV((StrIntpData[]){{_SLIT("$st_str"), $si_s_code, {.d_s = $in_str }}}))'
|
||||
st_str.free()
|
||||
return res2_str
|
||||
}
|
||||
return 'str_intp(1, _MOV((StrIntpData[]){{_SLIT("${base_str[..index]}"), $si_s_code, {.d_s = $in_str }}}))'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue