Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ruby2cext/str_to_c_strlit.rb
Constant Summary collapse
- C_STRLIT_MAP =
(0..255).map { |b| b.chr.inspect[1..-2] }.freeze
Instance Method Summary collapse
Instance Method Details
#to_c_strlit ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/ruby2cext/str_to_c_strlit.rb', line 4 def to_c_strlit # this might be a bit slow, but #inspect escapes ruby specific stuff, # that generates warnings in C (e.g. '#$' => "\#$") map = C_STRLIT_MAP res = "" each_byte { |b| res << map[b] } "\"#{res}\"" end |