package strings
import "k8s.io/utils/strings"
Example (NoTrailingNewline)¶
Code:
{
ld := NewLineDelimiter(os.Stdout, "|")
defer ld.Flush()
fmt.Fprint(ld, " Hello \n World ")
// Output:
// | Hello |
// | World |
}
Output:
| Hello | | World |
Example (TrailingNewline)¶
Code:
{
ld := NewLineDelimiter(os.Stdout, "|")
defer ld.Flush()
fmt.Fprint(ld, " Hello \n World \n")
// Output:
// | Hello |
// | World |
// ||
}
Output:
| Hello | | World | ||
Index ¶
- func EscapeQualifiedName(in string) string
- func JoinQualifiedName(namespace, name string) string
- func ShortenString(str string, n int) string
- func SplitQualifiedName(str string) (string, string)
- func UnescapeQualifiedName(in string) string
- type LineDelimiter
Examples ¶
Functions ¶
func EscapeQualifiedName ¶
EscapeQualifiedName converts a plugin name, which might contain a / into a string that is safe to use on-disk. This assumes that the input has already been validates as a qualified name. we use "~" rather than ":" here in case we ever use a filesystem that doesn't allow ":".
func JoinQualifiedName ¶
JoinQualifiedName joins 'namespace' and 'name' and returns a fully qualified name Assumes that the input is valid.
func ShortenString ¶
ShortenString returns the first N slice of a string.
func SplitQualifiedName ¶
SplitQualifiedName Splits a fully qualified name and returns its namespace and name. Assumes that the input 'str' has been validated.
func UnescapeQualifiedName ¶
UnescapeQualifiedName converts an escaped plugin name (as per EscapeQualifiedName) back to its normal form. This assumes that the input has already been validates as a qualified name.
Types ¶
type LineDelimiter ¶
type LineDelimiter struct {
// contains filtered or unexported fields
}
LineDelimiter is a filter that will split input on lines and bracket each line with the delimiter string.
func NewLineDelimiter ¶
func NewLineDelimiter(output io.Writer, delimiter string) *LineDelimiter
NewLineDelimiter allocates a new io.Writer that will split input on lines and bracket each line with the delimiter string. This can be useful in output tests where it is difficult to see and test trailing whitespace.
func (*LineDelimiter) Flush ¶
func (ld *LineDelimiter) Flush() (err error)
Flush all lines up until now. This will assume insert a linebreak at the current point of the stream.
func (*LineDelimiter) Write ¶
func (ld *LineDelimiter) Write(buf []byte) (n int, err error)
Write writes buf to the LineDelimiter ld. The only errors returned are ones encountered while writing to the underlying output stream.
Source Files ¶
escape.go line_delimiter.go strings.go
Directories ¶
Path | Synopsis |
---|---|
strings/slices | Package slices defines various functions useful with slices of string type. |
- Version
- v0.0.0-20250321185631-1f6e0b77f77e (latest)
- Published
- Mar 21, 2025
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 1 month ago –
Tools for package owners.