Module: WTF8::Surrogates

Defined in:
lib/wtf8/surrogates.rb,
sig/wtf8/surrogates.rbs

Constant Summary collapse

RANGE =

Returns:

  • (Object)
0xD800..0xDFFF
LEAD_RANGE =

Returns:

  • (Object)
0xD800..0xDBFF
TRAIL_RANGE =

Returns:

  • (Object)
0xDC00..0xDFFF
PREFIX_BYTE =

Returns:

  • (::Integer)
0xED
LEAD_SECOND_BYTE =

Returns:

  • (Object)
0xA0..0xAF
TRAIL_SECOND_BYTE =

Returns:

  • (Object)
0xB0..0xBF

Class Method Summary collapse

Class Method Details

.combine(lead, trail) ⇒ Integer

: (Integer, Integer) -> Integer

Parameters:

  • (Integer)
  • (Integer)

Returns:

  • (Integer)


29
30
31
# File 'lib/wtf8/surrogates.rb', line 29

def self.combine(lead, trail)
  0x10000 + ((lead - 0xD800) << 10) + (trail - 0xDC00)
end

.lead?(code_point) ⇒ Boolean

: (Integer) -> bool

Parameters:

  • (Integer)

Returns:

  • (Boolean)


19
20
21
# File 'lib/wtf8/surrogates.rb', line 19

def self.lead?(code_point)
  LEAD_RANGE.cover?(code_point)
end

.split(code_point) ⇒ Array[Integer]

: (Integer) -> Array

Parameters:

  • (Integer)

Returns:

  • (Array[Integer])


34
35
36
37
38
# File 'lib/wtf8/surrogates.rb', line 34

def self.split(code_point)
  remainder = code_point - 0x10000

  [0xD800 + (remainder >> 10), 0xDC00 + (remainder & 0x3FF)]
end

.surrogate?(code_point) ⇒ Boolean

: (Integer) -> bool

Parameters:

  • (Integer)

Returns:

  • (Boolean)


14
15
16
# File 'lib/wtf8/surrogates.rb', line 14

def self.surrogate?(code_point)
  RANGE.cover?(code_point)
end

.trail?(code_point) ⇒ Boolean

: (Integer) -> bool

Parameters:

  • (Integer)

Returns:

  • (Boolean)


24
25
26
# File 'lib/wtf8/surrogates.rb', line 24

def self.trail?(code_point)
  TRAIL_RANGE.cover?(code_point)
end