зеркало из https://github.com/github/ruby.git
Escape non-ascii characters in prelude C comments
Non-ASCII code are often warned by localized compilers.
This commit is contained in:
Родитель
554b370b72
Коммит
5ec1fc52c1
|
@ -43,7 +43,10 @@ class Prelude
|
|||
lineno = 0
|
||||
result = [@preludes.size, @vpath.strip(filename), lines, sub]
|
||||
@vpath.foreach(filename) do |line|
|
||||
line.force_encoding("ASCII-8BIT") if line.respond_to?(:force_encoding)
|
||||
if line.respond_to?(:force_encoding)
|
||||
enc = line.encoding
|
||||
line.force_encoding("ASCII-8BIT")
|
||||
end
|
||||
line.rstrip!
|
||||
lineno += 1
|
||||
@preludes[filename] ||= result
|
||||
|
@ -71,6 +74,7 @@ class Prelude
|
|||
orig
|
||||
end
|
||||
end
|
||||
comment.force_encoding(enc) if enc and comment
|
||||
lines << [line, comment]
|
||||
end
|
||||
result << (start_line || 1)
|
||||
|
|
|
@ -17,7 +17,10 @@ module RubyVM::CEscape
|
|||
|
||||
# generate comment, with escaps.
|
||||
def commentify str
|
||||
return "/* #{str.b.gsub('*/', '*\\/').gsub('/*', '/\\*')} */"
|
||||
unless str = str.dump[/\A"\K.*(?="\z)/]
|
||||
raise Encoding::CompatibilityError, "must be ASCII-compatible (#{str.encoding})"
|
||||
end
|
||||
return "/* #{str.gsub('*/', '*\\/').gsub('/*', '/\\*')} */"
|
||||
end
|
||||
|
||||
# Mimic gensym of CL.
|
||||
|
|
Загрузка…
Ссылка в новой задаче