Skip to content

Commit

Permalink
Style: Remove redundant regex escapes
Browse files Browse the repository at this point in the history
 #ignore
  • Loading branch information
sanssecours committed Sep 11, 2022
1 parent c4b41af commit 8425ade
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Support/bin/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class String
# >> '${NAME/-/o/}'.replace_name('- - -')
# => 'o\\ o\\ o'
def replace_name(name, regex_escape_name = true)
gsub(%r{\${NAME(?:\/([^\/]+)\/([^\/]+)\/)?}}).each do |_match|
gsub(%r{\${NAME(?:/([^/]+)/([^/]+)/)?}}).each do |_match|
pattern = Regexp.last_match(1)
replacement = Regexp.last_match(2)
name = name.gsub(pattern, replacement) if pattern && replacement
Expand Down
2 changes: 1 addition & 1 deletion Support/lib/Ruby/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def locate_included_item(input)
option = '(?>\[.*?\])?'
file = '(?>\{(.*?)\})'
match = input.scan(/#{environment}#{comment}#{option}#{comment}#{file}/m)
match.empty? ? '' : match.pop.pop.gsub(/(^\")?(\"$)?/, '')
match.empty? ? '' : match.pop.pop.gsub(/(^")?("$)?/, '')
end

# Get the currently selected text in TextMate
Expand Down
16 changes: 8 additions & 8 deletions Support/lib/Ruby/latex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def parse_bibfile(filepath)
def bib_entries(filepath)
raise "Could not locate file: #{filepath}" unless file?(filepath)

entries = File.read(filepath).scan(/^\s*@[^\{]*\{.*?(?=\n[ \t]*@|\z)/m)
entries = File.read(filepath).scan(/^\s*@[^{]*\{.*?(?=\n[ \t]*@|\z)/m)
entries.map { |entry| entry.strip.gsub(/(?:^\s*%.*|\n)+$/m, '') }
end

Expand Down Expand Up @@ -626,7 +626,7 @@ def bib_citation(bib_entry, bib_variables)
def bibentry_type_key_rest(bib_entry)
scanner = StringScanner.new(bib_entry)
scanner.scan(/\s*@/)
bibtype = scanner.scan(/[^\s\{]+/)
bibtype = scanner.scan(/[^\s{]+/)
scanner.scan(/\s*\{\s*/)
citekey = scanner.scan(/[^\s,]+(?=\s*,)/)
scanner.scan(/\s*,\s*/)
Expand Down Expand Up @@ -734,7 +734,7 @@ def consume_value_brackets(scanner)
end

def consume_value_variable(scanner, first_char, variables)
scanned = scanner.scan(/[\w]*/)
scanned = scanner.scan(/\w*/)
scanned.nil? ? nil : variables[first_char + scanned].to_s
end

Expand Down Expand Up @@ -883,8 +883,8 @@ def self.label_scan(root)
label_list << Label.new(:file => filename, :line => line,
:label => groups[0], :contents => text)
end
scanner.extractors[/.*?\[.*label=(.*?)\,.*\]/] = label_extractor
scanner.extractors[/^[^%]*\\label\{([^\}]*)\}/] = label_extractor
scanner.extractors[/.*?\[.*label=(.*?),.*\]/] = label_extractor
scanner.extractors[/^[^%]*\\label\{([^}]*)\}/] = label_extractor
scanner.recursive_scan
label_list
end
Expand Down Expand Up @@ -929,7 +929,7 @@ class << self
private

def add_bibitem_scan(scanner)
bibitem_regexp = /^[^%]*\\bibitem(?:\[[^\]]*\])?\{([^\}]*)\}(.*)/
bibitem_regexp = /^[^%]*\\bibitem(?:\[[^\]]*\])?\{([^}]*)\}(.*)/
scanner.extractors[bibitem_regexp] = proc do |_, _, groups, _|
scanner.cites << Citation.new('citekey' => groups[0],
'cite_data' => groups[1])
Expand All @@ -941,8 +941,8 @@ def add_bibliography_scan(scanner)
# We ignore bibliography files located on Windows drives by not
# +matching+ any path which starts with a single letter followed by a
# “:” e.g.: “c:”
regexes = [/^[^%]*\\bibliography\s*\{(?![a-zA-Z]:)([^\}]*)\}/,
/^[^%]*\\addbibresource\s*\{(?![a-zA-Z]:)([^\}]*)\}/]
regexes = [/^[^%]*\\bibliography\s*\{(?![a-zA-Z]:)([^}]*)\}/,
/^[^%]*\\addbibresource\s*\{(?![a-zA-Z]:)([^}]*)\}/]
extractor = proc do |_, _, groups, _|
(groups[0].split(',') << ENV['TM_LATEX_BIB']).compact.each do |bib|
file = LaTeX.find_file(bib.strip, 'bib', File.dirname(scanner.root))
Expand Down

0 comments on commit 8425ade

Please sign in to comment.