tags: don't allow tags with unbalanced parentheses.
Don't allow tags to have unbalanced parentheses, except for a few emoticon tags as special exceptions to the rule.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Danbooru
|
||||
module Extensions
|
||||
module String
|
||||
@@ -55,6 +57,22 @@ module Danbooru
|
||||
|
||||
text
|
||||
end
|
||||
|
||||
# @return [Boolean] True if the string contains only balanced parentheses; false if the string contains unbalanced parentheses.
|
||||
def has_balanced_parens?(open = "(", close = ")")
|
||||
parens = 0
|
||||
|
||||
chars.each do |char|
|
||||
if char == open
|
||||
parens += 1
|
||||
elsif char == close
|
||||
parens -= 1
|
||||
return false if parens < 0
|
||||
end
|
||||
end
|
||||
|
||||
parens == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user