Files
news.gitea.happylizard.me/bin/gems/rouge-4.5.1/lib/rouge/guessers/util.rb
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

35 lines
877 B
Ruby

# frozen_string_literal: true
module Rouge
module Guessers
module Util
module SourceNormalizer
UTF8_BOM = "\xEF\xBB\xBF"
UTF8_BOM_RE = /\A#{UTF8_BOM}/
# @param [String,nil] source
# @return [String,nil]
def self.normalize(source)
source.sub(UTF8_BOM_RE, '').gsub(/\r\n/, "\n")
end
end
def test_glob(pattern, path)
File.fnmatch?(pattern, path, File::FNM_DOTMATCH | File::FNM_CASEFOLD)
end
# @param [String,IO] source
# @return [String]
def get_source(source)
if source.respond_to?(:to_str)
SourceNormalizer.normalize(source.to_str)
elsif source.respond_to?(:read)
SourceNormalizer.normalize(source.read)
else
raise ArgumentError, "Invalid source: #{source.inspect}"
end
end
end
end
end