lib/unibits.rb in unibits-2.4.0 vs lib/unibits.rb in unibits-2.5.0
- old
+ new
@@ -20,20 +20,22 @@
/^CP85/,
/^mac/,
/^TIS-620$/,
/^Windows-874$/,
/^KOI8/,
+ /^GB1988$/,
)
).sort.freeze
COLORS = {
invalid: "#FF0000",
- unassigned: "#FF5500",
control: "#0000FF",
blank: "#33AADD",
format: "#FF00FF",
mark: "#228822",
+ unassigned: "#FF5500",
+ ignorable: "#FFAA00",
}
DEFAULT_TERMINAL_WIDTH = 80
def self.of(string, encoding: nil, convert: nil, stats: true, wide_ambiguous: false, width: nil)
@@ -79,11 +81,21 @@
current_encoding_error = nil
puts
string.each_char{ |char|
char_info = Characteristics.create_for_type(char, type)
- double_check_utf32_validness!(char, char_info)
+
+ if RUBY_VERSION >= "2.4.1" ||
+ RUBY_VERSION < "2.4.0" && RUBY_VERSION >= "2.3.4" ||
+ RUBY_VERSION < "2.3.0" && RUBY_VERSION >= "2.2.7" ||
+ char_info.encoding.name[0, 6] != "UTF-32" ||
+ !char_info.valid?
+ # bug is fixed or not relevant
+ else
+ double_check_utf32_validness!(char, char_info)
+ end
+
current_color = determine_char_color(char_info)
current_encoding_error = nil if char_info.valid?
char.each_byte.with_index{ |byte, byteindex|
@@ -237,11 +249,15 @@
def self.determine_char_color(char_info)
if !char_info.valid?
COLORS[:invalid]
elsif !char_info.assigned?
- COLORS[:unassigned]
+ if char_info.unicode? && char_info.ignorable?
+ COLORS[:ignorable]
+ else
+ COLORS[:unassigned]
+ end
elsif char_info.blank?
COLORS[:blank]
elsif char_info.control?
COLORS[:control]
elsif char_info.format?
@@ -313,10 +329,9 @@
res << Paint[ bin_byte_2, current_color, :underline ] unless !bin_byte_2 || bin_byte_2.empty?
res
end
def self.double_check_utf32_validness!(char, char_info)
- return if RUBY_VERSION > "2.4.0" || char_info.encoding.name[0, 6] != "UTF-32" || !char_info.valid?
byte_values = char.b.unpack("C*")
le = char_info.encoding.name == 'UTF-32LE'
if byte_values[le ? 2 : 1] > 16 ||
byte_values[le ? 3 : 0] > 0 ||
byte_values[le ? 1 : 2] >= 216 && byte_values[le ? 1 : 2] <= 223