Module: Ibex::Frontend::SourceEncoding

Defined in:
lib/ibex/frontend/source_span.rb,
sig/ibex/frontend/source_span.rbs

Overview

Normalizes grammar source without changing its bytes.

Class Method Summary collapse

Class Method Details

.validated_utf8(source, file) ⇒ String

RBS:

  • (String source, String file) -> String

Parameters:

  • source (String)
  • file (String)

Returns:

  • (String)


8
9
10
11
12
13
# File 'lib/ibex/frontend/source_span.rb', line 8

def self.validated_utf8(source, file)
  validated = source.dup.force_encoding(Encoding::UTF_8)
  raise Ibex::Error, "#{file}: input must be valid UTF-8" unless validated.valid_encoding?

  validated.freeze
end