about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-23 15:06:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-23 15:06:18 -0700
commit43dfa184d6e63e17efcd0c20a1090632eba88141 (patch)
treec8deaeee8814a2a6aeb7176c2e4a1f4beef5258e /text.lua
parentaeaa7d150cacb5f858f1b516ca3e2234c68b8e55 (diff)
downloadtext.love-43dfa184d6e63e17efcd0c20a1090632eba88141.tar.gz
helper: trimming whitespace from strings
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/text.lua b/text.lua
index 6f76442..61ead17 100644
--- a/text.lua
+++ b/text.lua
@@ -990,3 +990,15 @@ function Text.clear_screen_line_cache(State, line_index)
   State.line_cache[line_index].fragments = nil
   State.line_cache[line_index].screen_line_starting_pos = nil
 end
+
+function trim(s)
+  return s:gsub('^%s+', ''):gsub('%s+$', '')
+end
+
+function ltrim(s)
+  return s:gsub('^%s+', '')
+end
+
+function rtrim(s)
+  return s:gsub('%s+$', '')
+end