bb/tool/quote/quote.go

42 lines
589 B
Go
Raw 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"
2023-11-11 12:51:15 +03:00
"github.com/omnipunk/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)
}
}
}