Method: Sprockets::EncodingUtils#scan_css_charset
- Defined in:
- lib/sprockets/encoding_utils.rb
#scan_css_charset(str) ⇒ Object
Internal: Scan binary CSS string for @charset encoding name.
str - ASCII-8BIT encoded String
Returns encoding String name or nil.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/sprockets/encoding_utils.rb', line 207 def scan_css_charset(str) buf = [] i = 0 str.each_byte.each do |byte| # Halt on line breaks break if byte == 0x0A || byte == 0x0D # Only ascii bytes next unless 0x0 < byte && byte <= 0xFF if i < CHARSET_SIZE elsif i == CHARSET_SIZE if buf == CHARSET_START buf = [] else break end elsif byte == 0x22 return buf.pack('C*') end buf << byte i += 1 end nil end |