Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttributeAtRange ¶
type AttributeMapping ¶
type AttributeMapping map[Attribute]Attributes
type AttributedString ¶
type AttributedString struct { Str string Attrs []*AttributeAtRange }
func NewAttributedString ¶
func NewAttributedString(Str string) *AttributedString
func (*AttributedString) AddAttribute ¶
func (a *AttributedString) AddAttribute(index, length int, attribute Attribute)
func (*AttributedString) SliceOfStringsWithAtributes ¶
func (a *AttributedString) SliceOfStringsWithAtributes() SliceOfStringsWithAtributes
func (*AttributedString) String ¶
func (a *AttributedString) String() string
type Attributes ¶
type Attributes []Attribute
func Multi ¶
func Multi(a Attribute, b ...Attribute) Attributes
func (Attributes) Flatten ¶
func (m Attributes) Flatten() Attributes
func (Attributes) String ¶
func (a Attributes) String() string
type Attributor ¶
type Attributor interface { Attribute(*AttributedString) *AttributedString AttributeString(string) *AttributedString }
func NewAttributeMappingAttributor ¶
func NewAttributeMappingAttributor(m map[Attribute]Attributes) Attributor
func NewAttributor ¶
func NewAttributor(fn AttributorFn) Attributor
func NewMultiAttributor ¶
func NewMultiAttributor(m ...Attributor) Attributor
func NewRegexAttributor ¶
func NewRegexAttributor(r ...*regexp.Regexp) Attributor
Example ¶
str := "Hello World,\n\"string\" is a string and 123 is a number." exp := regexp.MustCompile(`(?P<STR>"(?:[^"]|\\")*")|(?P<NUM>\d+)`) attributor := attributedtext.NewRegexAttributor(exp) attrstr := attributor.AttributeString(str) for i, swa := range attrstr.SliceOfStringsWithAtributes() { fmt.Printf("%d. %-20s %#v\n", i+1, "String:", swa.Str) for k, attr := range swa.Attrs { fmt.Printf(" %-20s %T %+v\n", fmt.Sprintf("Attribute(%d):", k+1), attr, attr) } }
Output: 1. String: "Hello World,\n" 2. String: "\"string\"" Attribute(1): string STR 3. String: " is a string and " 4. String: "123" Attribute(1): string NUM 5. String: " is a number."
type AttributorFn ¶
type AttributorFn func(*AttributedString) *AttributedString
type MultiAttribute ¶
type MultiAttribute interface {
Flatten() Attributes
}
type SliceOfStringsWithAtributes ¶
type SliceOfStringsWithAtributes []*StringWithAttributes
Example ¶
attrstr := attributedtext.NewAttributedString("Some Message") attrstr.AddAttribute(0, 4, "A") attrstr.AddAttribute(5, 7, 1234) for i, swa := range attrstr.SliceOfStringsWithAtributes() { fmt.Printf("%d. %-20s %#v\n", i+1, "String:", swa.Str) for k, attr := range swa.Attrs { fmt.Printf(" %-20s %T %+v\n", fmt.Sprintf("Attribute(%d):", k+1), attr, attr) } }
Output: 1. String: "Some" Attribute(1): string A 2. String: " " 3. String: "Message" Attribute(1): int 1234
type StringWithAttributes ¶
type StringWithAttributes struct { Str string Attrs Attributes }
Click to show internal directories.
Click to hide internal directories.