bb/tool/quote/quote.go

42 lines
585 B
Go
Raw Permalink Normal View History

2020-06-07 22:51:39 +03:00
package quote
/* Quote quotes string if it contains white space character. */
import(
"os"
"io"
"fmt"
"unicode"
"bufio"
2024-05-15 21:07:35 +03:00
"surdeus.su/core/cli/mtool"
2020-06-07 22:51:39 +03:00
)
func HasWhiteSpace(s string) bool {
for _, r := range s {
if(unicode.IsSpace(r)){
return true
}
}
return false
}
2023-03-24 16:54:51 +03:00
func Run(flagSet *mtool.Flags) {
flagSet.Parse()
2020-06-07 22:51:39 +03:00
r := bufio.NewReader(os.Stdin)
for{
l, e := r.ReadString('\n')
if e==io.EOF {
break
}
last := len(l) - 1
if l[last] == '\n' {
l = l[:last]
}
if HasWhiteSpace(l) {
fmt.Printf("'%s'\n", l)
}else {
fmt.Println(l)
}
}
}