Sha256: bc0a62772b1cbbf30f0bce09f412351127ab3b1fd48c1c3dfb5d8f2fbf1ddca1
Contents?: true
Size: 466 Bytes
Versions: 1
Compression:
Stored size: 466 Bytes
Contents
class String # Safely truncate the string to the specified number of bytes. # If a multibyte char gets split, the dangling fragment is removed. 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 unless method_defined? :limit end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
asciidoctor-1.5.5 | lib/asciidoctor/core_ext/string/limit.rb |