mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 01:10:41 -07:00
Add replace_last and remove_last filters
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user