Documentation ¶
Overview ¶
Example (NoTrailingNewline) ¶
ld := NewLineDelimiter(os.Stdout, "|") defer ld.Flush() fmt.Fprint(ld, " Hello \n World ")
Output: | Hello | | World |
Example (TrailingNewline) ¶
ld := NewLineDelimiter(os.Stdout, "|") defer ld.Flush() fmt.Fprint(ld, " Hello \n World \n")
Output: | Hello | | World | ||
Index ¶
- func BytesToString(b []byte) string
- func CamelString(s string) string
- func CodePointToUTF8(str string, base int) string
- func EscapeQualifiedName(in string) string
- func HTMLEntityToUTF8(str string, base int) string
- func Indent(text, prefix string) string
- func JoinQualifiedName(namespace, name string) string
- func LintCamelString(name string) string
- func ShortenString(str string, n int) string
- func SnakeString(s string) string
- func SpaceInOne(s string) string
- func SplitQualifiedName(str string) (string, string)
- func StringMarshalJSON(s string, escapeHTML bool) []byte
- func StringToBytes(s string) []byte
- func UnescapeQualifiedName(in string) string
- type LineDelimiter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToString ¶
BytesToString convert []byte type to string type.
func CamelString ¶
CamelString converts the accepted string to a camel string (xx_yy to XxYy)
func CodePointToUTF8 ¶
CodePointToUTF8 converts Unicode Code Point to UTF-8. e.g.: CodePointToUTF8(`{"info":[["color","\u5496\u5561\u8272\u7c\u7eff\u8272"]]}`, 16) => `{"info":[["color","咖啡色|绿色"]]}`
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 HTMLEntityToUTF8 ¶
HTMLEntityToUTF8 converts HTML Unicode to UTF-8. e.g.: HTMLEntityToUTF8(`{"info":[["color","ᕸᖹ⁐c;eff;⁐"]]}`, 16) => `{"info":[["color","咖啡色|绿色"]]}`
func JoinQualifiedName ¶
JoinQualifiedName joins 'namespace' and 'name' and returns a fully qualified name Assumes that the input is valid.
func LintCamelString ¶
LintCamelString converts the accepted string to a camel string (xx_id to XxID) NOTE:
support common initialisms
func ShortenString ¶
ShortenString returns the first N slice of a string.
func SnakeString ¶
SnakeString converts the accepted string to a snake string (XxYy to xx_yy)
func SpaceInOne ¶
SpaceInOne combines multiple consecutive space characters into one.
func SplitQualifiedName ¶
SplitQualifiedName Splits a fully qualified name and returns its namespace and name. Assumes that the input 'str' has been validated.
func StringMarshalJSON ¶
StringMarshalJSON converts the string to JSON byte stream.
Example ¶
s := `<>&{}""` fmt.Printf("%s\n", StringMarshalJSON(s, true)) fmt.Printf("%s\n", StringMarshalJSON(s, false))
Output: "\u003c\u003e\u0026{}\"\"" "<>&{}\"\""
func StringToBytes ¶
StringToBytes convert string type to []byte type. NOTE: panic if modify the member value of the []byte.
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.