47 lines
988 B
V
47 lines
988 B
V
module shell
|
|
|
|
import strings.textscanner
|
|
|
|
const safe_chars = '%+,-./0123456789:=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'
|
|
|
|
// quote returns a shell-escaped version of string `s`.
|
|
pub fn quote(s string) string {
|
|
if s == '' {
|
|
return "''"
|
|
}
|
|
if s.is_pure_ascii() && s.contains_only(safe_chars) {
|
|
return s
|
|
}
|
|
return "'" + s.replace("'", '\'"\'"\'') + "'"
|
|
}
|
|
|
|
// join joins `s` array members into a shell-escaped string.
|
|
pub fn join(s []string) string {
|
|
mut quoted_args := []string{}
|
|
for arg in s {
|
|
quoted_args << quote(arg)
|
|
}
|
|
return quoted_args.join(' ')
|
|
}
|
|
|
|
// // join_all joins their arguments into a shell-escaped string.
|
|
// pub fn join_all(s ...string) string {
|
|
// return join(s)
|
|
// }
|
|
|
|
// split splits the string `s` into array using shell-like syntax.
|
|
pub fn split(s string) []string {
|
|
return []string{}
|
|
}
|
|
|
|
pub struct Lexer {
|
|
pub:
|
|
posix_mode bool = true
|
|
comment_chars string = '#'
|
|
pub mut:
|
|
tokens []string
|
|
}
|
|
|
|
pub fn (mut x Lexer) process(s string) {
|
|
}
|