Module: Qt::StringCodec

Defined in:
lib/qt/string_codec.rb

Overview

Normalizes Ruby strings for bridge text paths.

Constant Summary collapse

REPLACEMENT_CHAR =
"\uFFFD"

Class Method Summary collapse

Class Method Details

.binary_bytes?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/qt/string_codec.rb', line 21

def binary_bytes?(value)
  return false unless value.is_a?(String)
  return false unless value.encoding == Encoding::ASCII_8BIT

  !value.dup.force_encoding(Encoding::UTF_8).valid_encoding?
end

.from_qt_text(value) ⇒ Object



17
18
19
# File 'lib/qt/string_codec.rb', line 17

def from_qt_text(value)
  normalize_binary_as_utf8(value.to_s)
end

.to_qt_text(value) ⇒ Object



10
11
12
13
14
15
# File 'lib/qt/string_codec.rb', line 10

def to_qt_text(value)
  text = value.to_s
  return normalize_binary_as_utf8(text) if text.encoding == Encoding::ASCII_8BIT

  normalize_encoded_text(text)
end