mirror of
https://github.com/gizak/termui.git
synced 2025-04-24 13:48:50 +08:00
TestFindStyleBlocks is working
This commit is contained in:
parent
ea81b84555
commit
33fef6cb94
@ -84,8 +84,36 @@ type StyleBlock struct {
|
||||
End int
|
||||
}
|
||||
|
||||
func findStartEndOfStyle(pos int, runes []rune) StyleBlock {
|
||||
current := pos
|
||||
sb := StyleBlock{0, 0}
|
||||
for {
|
||||
current--
|
||||
if runes[current] == tokenBeginStyledText {
|
||||
sb.Start = current
|
||||
break
|
||||
}
|
||||
}
|
||||
current = pos
|
||||
for {
|
||||
current++
|
||||
if runes[current] == tokenEndStyle {
|
||||
sb.End = current
|
||||
break
|
||||
}
|
||||
}
|
||||
return sb
|
||||
}
|
||||
|
||||
func FindStyleBlocks(s string) []StyleBlock {
|
||||
items := []StyleBlock{}
|
||||
runes := []rune(s)
|
||||
|
||||
positions := FindStylePositions(s)
|
||||
for _, pos := range positions {
|
||||
sb := findStartEndOfStyle(pos, runes)
|
||||
items = append(items, sb)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user