Sha256: f1f006a9b2d51c2478fd511dd80afbff32ef050e1a538a31ba3d13202e053ab9
Contents?: true
Size: 484 Bytes
Versions: 6
Compression:
Stored size: 484 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_bytesize 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_bytesize end
Version data entries
6 entries across 6 versions & 1 rubygems