class String

Educate Ruby 1.8.7 about the #chr method.

Public Instance Methods

chr() click to toggle source
# File lib/asciidoctor/core_ext/1.8.7/string/chr.rb, line 3
def chr
  self[0..0]
end
limit(size) click to toggle source

Safely truncate the string to the specified number of bytes. If a multibyte char gets split, the dangling fragment is removed.

# File lib/asciidoctor/core_ext/string/limit.rb, line 4
def limit size
  return self unless size < bytesize
  # NOTE JRuby 1.7 & Rubinius fail to detect invalid encoding unless encoding is forced; impact is marginal.
  size -= 1 until ((result = byteslice 0, size).force_encoding ::Encoding::UTF_8).valid_encoding?
  result
end