This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Unicode
|
||||
class DisplayWidth
|
||||
VERSION = "2.6.0"
|
||||
UNICODE_VERSION = "16.0.0"
|
||||
DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + "/../../../data/")
|
||||
INDEX_FILENAME = DATA_DIRECTORY + "/display_width.marshal.gz"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "zlib"
|
||||
require_relative "constants"
|
||||
|
||||
module Unicode
|
||||
class DisplayWidth
|
||||
File.open(INDEX_FILENAME, "rb") do |file|
|
||||
serialized_data = Zlib::GzipReader.new(file).read
|
||||
serialized_data.force_encoding Encoding::BINARY
|
||||
INDEX = Marshal.load(serialized_data)
|
||||
end
|
||||
|
||||
def self.decompress_index(index, level)
|
||||
index.flat_map{ |value|
|
||||
if level > 0
|
||||
if value.instance_of?(Array)
|
||||
value[15] ||= nil
|
||||
decompress_index(value, level - 1)
|
||||
else
|
||||
decompress_index([value] * 16, level - 1)
|
||||
end
|
||||
else
|
||||
if value.instance_of?(Array)
|
||||
value[15] ||= nil
|
||||
value
|
||||
else
|
||||
[value] * 16
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
warn "You are loading 'unicode-display_width/no_string_ext'\n" \
|
||||
"Beginning with version 2.0, this is not necessary anymore\n"\
|
||||
"You can just require 'unicode-display_width' now and no\n"\
|
||||
"string extension will be loaded"
|
||||
|
||||
require_relative "../display_width"
|
||||
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../display_width" unless defined? Unicode::DisplayWidth
|
||||
|
||||
class String
|
||||
def display_width(ambiguous = 1, overwrite = {}, options = {})
|
||||
Unicode::DisplayWidth.of(self, ambiguous, overwrite, options)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user