diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-08-23 15:06:18 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-08-23 15:06:18 -0700 |
commit | 43dfa184d6e63e17efcd0c20a1090632eba88141 (patch) | |
tree | c8deaeee8814a2a6aeb7176c2e4a1f4beef5258e | |
parent | aeaa7d150cacb5f858f1b516ca3e2234c68b8e55 (diff) | |
download | text.love-43dfa184d6e63e17efcd0c20a1090632eba88141.tar.gz |
helper: trimming whitespace from strings
-rw-r--r-- | text.lua | 12 |
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 |