2 Commits 51c30df78a ... 011ba877cc

Author SHA1 Message Date
  Samadi van Koten 011ba877cc Add insert method for strings as well as chars 7 years ago
  Samadi van Koten 200e2c67a7 Add GapBuffer to string benchmark 7 years ago
2 changed files with 8 additions and 0 deletions
  1. 3 0
      benchmark.nim
  2. 5 0
      gapbuffer.nim

+ 3 - 0
benchmark.nim

@@ -24,6 +24,9 @@ benchmark "from 16 character string":
   discard "abcdefghijklmnop".toGapBuffer()
 
 var buf = "abcdefghijklmnop".toGapBuffer()
+benchmark "to 16 character string":
+  discard $buf
+
 benchmark "get position":
   discard buf.pos()
 

+ 5 - 0
gapbuffer.nim

@@ -88,6 +88,11 @@ proc insert*(buf: var GapBuffer, ch: char) =
   ## Insert a character before the gap
   buf.head.add(ch)
 
+proc insert*(buf: var GapBuffer, str: string) =
+  ## Insert a string before the gap
+  for ch in str.items():
+    buf.insert(ch)
+
 proc delete*(buf: var GapBuffer) =
   ## Remove the character before the gap
   buf.head.setLen(buf.head.len - 1)