Escape non-ascii characters in prelude C comments
Non-ASCII code are often warned by localized compilers.
This commit is contained in:
parent
554b370b72
commit
5ec1fc52c1
Notes:
git
2023-08-24 13:01:48 +00:00
@ -43,7 +43,10 @@ class Prelude
|
|||||||
lineno = 0
|
lineno = 0
|
||||||
result = [@preludes.size, @vpath.strip(filename), lines, sub]
|
result = [@preludes.size, @vpath.strip(filename), lines, sub]
|
||||||
@vpath.foreach(filename) do |line|
|
@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!
|
line.rstrip!
|
||||||
lineno += 1
|
lineno += 1
|
||||||
@preludes[filename] ||= result
|
@preludes[filename] ||= result
|
||||||
@ -71,6 +74,7 @@ class Prelude
|
|||||||
orig
|
orig
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
comment.force_encoding(enc) if enc and comment
|
||||||
lines << [line, comment]
|
lines << [line, comment]
|
||||||
end
|
end
|
||||||
result << (start_line || 1)
|
result << (start_line || 1)
|
||||||
|
@ -17,7 +17,10 @@ module RubyVM::CEscape
|
|||||||
|
|
||||||
# generate comment, with escaps.
|
# generate comment, with escaps.
|
||||||
def commentify str
|
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
|
end
|
||||||
|
|
||||||
# Mimic gensym of CL.
|
# Mimic gensym of CL.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user