From 291e9577ef97e78871ad4d3337eab6774971db2a Mon Sep 17 00:00:00 2001 From: Andrew Arrow Date: Tue, 8 Nov 2022 08:59:48 -0800 Subject: [PATCH] moving to new FindStylePositions as first call --- style_parser.go | 15 +++++++++++---- style_parser_test.go | 12 +++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/style_parser.go b/style_parser.go index 247b8d6..39fd81e 100644 --- a/style_parser.go +++ b/style_parser.go @@ -86,25 +86,32 @@ type StyleStringPosition struct { } func BreakByStyles(s string) []string { + return []string{} +} + +func FindStylePositions(s string) []int { fmt.Println(s) index := strings.Index(s, "](") if index == -1 { - return []string{s} + return []int{} } - buff := []string{} + buff := []int{} toProcess := s + offset := 0 for { - fmt.Println(index) + buff = append(buff, index+offset) toProcess = toProcess[index+1:] - fmt.Println(toProcess) + offset += index + 1 index = strings.Index(toProcess, "](") if index == -1 { break } } + return buff + // test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)! /* diff --git a/style_parser_test.go b/style_parser_test.go index 9be4b5e..94e5134 100644 --- a/style_parser_test.go +++ b/style_parser_test.go @@ -6,13 +6,15 @@ import ( "testing" ) +func TestFindStylePositions(t *testing.T) { + items := FindStylePositions("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!") + if len(items) != 3 { + t.Fatal("wrong length", len(items)) + } +} + func TestBreakByStylesComplex(t *testing.T) { items := BreakByStyles("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!") - // "test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!" - // 01234567890123456789012345678 - // 0- 4 normal - // 5-28 style - // 29- if len(items) != 10 { t.Fatal("wrong length", len(items)) }