Add replace_last and remove_last filters

This commit is contained in:
Anders Søgaard
2021-03-30 12:34:01 +02:00
parent 832516fb31
commit e575c1f131
+10
View File
@@ -268,6 +268,11 @@ module Liquid
input.to_s.sub(string.to_s, replacement.to_s)
end
# Replace the last occurrences of a string with another
def replace_last(input, string, replacement = '')
input.to_s.reserve.sub(string.to_s.reserve, replacement.to_s.reserve).reserve
end
# remove a substring
def remove(input, string)
input.to_s.gsub(string.to_s, '')
@@ -278,6 +283,11 @@ module Liquid
input.to_s.sub(string.to_s, '')
end
# remove the last occurences of a substring
def remove_last(input, string)
input.to_s.reverse.sub(string.to_s.reverse, '').reverse
end
# add one string to another
def append(input, string)
input.to_s + string.to_s