Method: Sprockets::EncodingUtils#detect

Defined in:
lib/sprockets/encoding_utils.rb

#detect(str) ⇒ Object

Public: Basic string detecter.

Attempts to parse any Unicode BOM otherwise falls back to the environment’s external encoding.

str - ASCII-8BIT encoded String

Returns encoded String.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/sprockets/encoding_utils.rb', line 99

def detect(str)
  str = detect_unicode_bom(str)

  # Attempt Charlock detection
  if str.encoding == Encoding::BINARY
    charlock_detect(str)
  end

  # Fallback to environment's external encoding
  if str.encoding == Encoding::BINARY
    str.force_encoding(Encoding.default_external)
  end

  str
end