Ejemplo n.º 1
0
func (f *Fragment) Pretty(textLimit int, left *utf8string.String) string {
	length := min(textLimit-3, f.Length)
	cleaner := strings.NewReplacer("\n", " ")
	text := cleaner.Replace(left.Slice(f.Left, f.Left+length))
	if length < f.Length {
		text = text + "..."
	}
	return fmt.Sprintf("Left: %8d\tRight: %8d\tLength: %8d\tText: %s\n", f.Left, f.Right, f.Length, text)
}
Ejemplo n.º 2
0
func newFragment(text *utf8string.String, left, right, length int) (*Fragment, *Theme) {
	match := text.Slice(left, left+length)
	if trimLeft := strings.IndexFunc(match, notWhitespace); trimLeft != -1 {
		unicodeTrim := utf8.RuneCountInString(match[:trimLeft])
		match = match[trimLeft:]
		left += unicodeTrim
		right += unicodeTrim
		length -= unicodeTrim
	}
	if trimmedLength := strings.LastIndexFunc(match, notWhitespace) + 1; trimmedLength != 0 {
		unicodeTrim := utf8.RuneCountInString(match[trimmedLength:])
		match = match[:trimmedLength]
		length -= unicodeTrim
	}
	theme := newTheme(match)
	return &Fragment{
		Left:   left,
		Right:  right,
		Length: length,
		Id:     theme.Id,
	}, theme
}
Ejemplo n.º 3
0
func (f *Fragment) Strings(left, right *utf8string.String) (string, string) {
	return left.Slice(f.Left, f.Left+f.Length), right.Slice(f.Right, f.Right+f.Length)
}