Sha256: c73d150aac3dfd8e77f05cc8ce76f0077e6b588cdb0a26e384751c0ba406f9f6

Contents?: true

Size: 877 Bytes

Versions: 48

Compression:

Stored size: 877 Bytes

Contents

# 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

Version data entries

48 entries across 48 versions & 3 rubygems

Version Path
rouge-4.5.1 lib/rouge/guessers/util.rb
rouge-4.5.0 lib/rouge/guessers/util.rb
rouge-4.4.0 lib/rouge/guessers/util.rb
rouge-4.3.0 lib/rouge/guessers/util.rb
rouge-4.2.1 lib/rouge/guessers/util.rb
rouge-4.2.0 lib/rouge/guessers/util.rb
rouge-4.1.3 lib/rouge/guessers/util.rb
rouge-4.1.2 lib/rouge/guessers/util.rb
rouge-4.1.1 lib/rouge/guessers/util.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/guessers/util.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/guessers/util.rb
rouge-4.1.0 lib/rouge/guessers/util.rb
rouge-4.0.1 lib/rouge/guessers/util.rb
rouge-4.0.0 lib/rouge/guessers/util.rb
rouge-3.30.0 lib/rouge/guessers/util.rb
rouge-3.29.0 lib/rouge/guessers/util.rb
rouge-3.28.0 lib/rouge/guessers/util.rb
rouge-3.27.0 lib/rouge/guessers/util.rb
rouge-3.26.1 lib/rouge/guessers/util.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/guessers/util.rb