mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-03-01 03:51:59 +01:00
32 lines
524 B
Go
32 lines
524 B
Go
// Copyright 2025, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package trimquotes
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
func TrimQuotes(s string) (string, bool) {
|
|
if len(s) > 2 && s[0] == '"' {
|
|
trimmed, err := strconv.Unquote(s)
|
|
if err != nil {
|
|
return s, false
|
|
}
|
|
return trimmed, true
|
|
}
|
|
return s, false
|
|
}
|
|
|
|
func TryTrimQuotes(s string) string {
|
|
trimmed, _ := TrimQuotes(s)
|
|
return trimmed
|
|
}
|
|
|
|
func ReplaceQuotes(s string, shouldReplace bool) string {
|
|
if shouldReplace {
|
|
return strconv.Quote(s)
|
|
}
|
|
return s
|
|
}
|