Module: Solargraph::Source::EncodingFixes

Included in:
Solargraph::Source, Change
Defined in:
lib/solargraph/source/encoding_fixes.rb

Class Method Summary collapse

Class Method Details

.normalize(string) ⇒ String

Convert strings to normalized UTF-8.


10
11
12
13
14
15
16
17
18
# File 'lib/solargraph/source/encoding_fixes.rb', line 10

def normalize string
  begin
    string.dup.force_encoding('UTF-8')
  rescue ::Encoding::CompatibilityError, ::Encoding::UndefinedConversionError, ::Encoding::InvalidByteSequenceError => e
    # @todo Improve error handling

    Solargraph::Logging.logger.warn "Normalize error: #{e.message}"
    string
  end
end