This commit is contained in:
Daylin Morgan 2025-01-23 18:30:52 -06:00
parent 50d0ee5a3b
commit 4c63636c24
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 15 additions and 1 deletions

View file

@ -347,6 +347,12 @@ func add*(x: var Bbstring, y :Bbstring) =
for span in y.spans:
x.spans.add shift(span, i)
# TODO: squash "like" spans for efficiency?
func add*(x: var Bbstring, y: string) =
let i = x.plain.len
x.plain.add y
x.spans.add BbSpan(styles: @[], slice:[i, i + y.len - 1 ])
func bbEscape*(s: string): string {.inline.} =
s.replace("[", "[[").replace("\\", "\\\\")

View file

@ -92,5 +92,13 @@ suite "strutils":
check (bb"[red]red").align(10) == bb" [red]red"
check (bb"[red]red").alignLeft(10) == bb"[red]red[/] "
test "add":
var x = bb("[red]red")
x.add bb("[yellow]yellow")
check bb"[red]red[/][yellow]yellow[/]" == x
var y = bb("[red]red")
y.add "yellow"
check bb"[red]red[/]yellow" == y