class Integer
Public Instance Methods
to_utf8_char()
click to toggle source
# File lib/bidi/bidi.rb, line 6 def to_utf8_char raise RangeError "Value #{self} is out of range for UTF8 Char" if self<0 or self > 0x10fffd if self >> 7 == 0 # less than 0x80? If so, return an ASCII char return self.chr end prefix = 0x80 # First UTF-8 byte, the initial value of the # prefix is 110b temp = self byte_arr=Array.new bytes_to_shift=0 rem_digits = 6 while true rest=temp >> rem_digits rem_digits -= 1 if rest == 0 byte_arr.push prefix | temp break else byte_arr.push 0x80 | (temp & 0x3f) temp >>= 6 prefix >>= 1 prefix |= 0x80 end end last_pos=byte_arr.length - 1 ret_value=String.new last_pos.downto 0 do |i| ret_value << byte_arr[i].chr end ret_value.force_encoding 'UTF-8' end