From 9d9f263c69cafdcf23fe3dc5dd6600d44565c54b Mon Sep 17 00:00:00 2001 From: Aire-One Date: Mon, 31 Oct 2022 15:04:44 +0100 Subject: [PATCH] fix(utils): use `stringx.strip` to trim string --- src/awesomewm.d.tl/utils.tl | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/awesomewm.d.tl/utils.tl b/src/awesomewm.d.tl/utils.tl index 0336f10..32cfe5e 100644 --- a/src/awesomewm.d.tl/utils.tl +++ b/src/awesomewm.d.tl/utils.tl @@ -1,3 +1,4 @@ +local stringx = require "pl.stringx" local web_sanitize = require "web_sanitize" local utils = {} @@ -34,25 +35,8 @@ function utils.map(list: { T }, iteratee: function(value: T, position: int return mapped end --- Extracted from teh Penlight Lua library. --- Sometime Lua string.gsub can't match unescaped strings. --- https://stackoverflow.com/a/72666170 -function utils.escape(s: string): string - return (s:gsub("[%-%.%+%[%]%(%)%$%^%%%?%*]", "%%%1")) -end - -function utils.replace(s: string, old: string, new: string, n: number): string - return (s:gsub(utils.escape(old), new:gsub("%%", "%%%%"), n)) -end - -function utils.trim(s: string): string - return s:match "^%s*(.-)%s*$" -end - function utils.sanitize_string(s: string): string - return utils.trim( - utils.replace(web_sanitize.extract_text(s), "^%s*(.-)%s*$", "%1") - ) + return (stringx.strip(web_sanitize.extract_text(s))) end -- At some point, we should probably write a wrapper to make penlight's function work with pcalls.