example.nim 601 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import gapbuffer
  2. import strutils
  3. var buf = "Hello, world!".toGapBuffer()
  4. proc dumpInfo =
  5. echo buf.head.join(), "|", buf.tail.join()
  6. echo buf
  7. echo()
  8. dumpInfo()
  9. buf.move(6)
  10. dumpInfo()
  11. buf.delete()
  12. dumpInfo()
  13. buf.insert('!')
  14. dumpInfo()
  15. buf[buf.pos] = ','
  16. dumpInfo()
  17. buf.moveTo(0)
  18. dumpInfo()
  19. buf[buf.pos] = 'h'
  20. dumpInfo()
  21. buf.moveTo(buf.len - 1)
  22. dumpInfo()
  23. buf.insert("abc\ndef\cghi\ljkl\c\lmno")
  24. var i = 0
  25. for line in buf.splitLines():
  26. echo(i, ": ", line.join())
  27. inc i
  28. echo()
  29. buf.insert("\n")
  30. buf.moveTo(10)
  31. i = 0
  32. for line in buf.splitLines():
  33. echo(i, ": ", line.join())
  34. inc i
  35. echo()