class String

Educate Ruby 1.8.7 about the #chr method.

Constants

ValidTrailingCharRx

Public Instance Methods

chr() click to toggle source
# File lib/asciidoctor/core_ext/1.8.7/string/chr.rb, line 3
def chr
  slice 0, 1
end
limit_bytesize(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/1.8.7/string/limit_bytesize.rb, line 5
def limit_bytesize size
  return self unless size < bytesize
  result = (unpack %(a#{size}))[0]
  begin
    result.unpack 'U*'
  rescue ::ArgumentError
    result.chop!
    retry
  end
  result
end