minimum maxlen=6, pass -1 for no max length
(val string, forceQuote bool, maxLen int)
| 120 | |
| 121 | // minimum maxlen=6, pass -1 for no max length |
| 122 | func ShellQuote(val string, forceQuote bool, maxLen int) string { |
| 123 | if maxLen != -1 && maxLen < 6 { |
| 124 | maxLen = 6 |
| 125 | } |
| 126 | rtn := val |
| 127 | if needsQuoteRe.MatchString(val) { |
| 128 | rtn = "'" + strings.ReplaceAll(val, "'", `'"'"'`) + "'" |
| 129 | } else if forceQuote { |
| 130 | rtn = "\"" + rtn + "\"" |
| 131 | } |
| 132 | if maxLen == -1 || len(rtn) <= maxLen { |
| 133 | return rtn |
| 134 | } |
| 135 | if strings.HasPrefix(rtn, "\"") || strings.HasPrefix(rtn, "'") { |
| 136 | return rtn[0:maxLen-4] + "..." + rtn[len(rtn)-1:] |
| 137 | } |
| 138 | return rtn[0:maxLen-3] + "..." |
| 139 | } |
| 140 | |
| 141 | func EllipsisStr(s string, maxLen int) string { |
| 142 | if maxLen < 4 { |
no outgoing calls
no test coverage detected