method
u16tou8
v1_8_6_287 -
Show latest stable
-
0 notes -
Class: Net::IMAP
- 1_8_6_287 (0)
- 1_8_7_72 (0)
- 1_8_7_330 (0)
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9
- 2_4_6
- 2_5_5
- 2_6_3
- What's this?
u16tou8(s)
private
Hide source
# File lib/net/imap.rb, line 1225 def self.u16tou8(s) len = s.length if len < 2 return "" end buf = "" i = 0 while i < len c = s[i] << 8 | s[i + 1] i += 2 if c == 0xfeff next elsif c < 0x0080 buf.concat(c) elsif c < 0x0800 b2 = c & 0x003f b1 = c >> 6 buf.concat(b1 | 0xc0) buf.concat(b2 | 0x80) elsif c >= 0xdc00 && c < 0xe000 raise DataFormatError, "invalid surrogate detected" elsif c >= 0xd800 && c < 0xdc00 if i + 2 > len raise DataFormatError, "invalid surrogate detected" end low = s[i] << 8 | s[i + 1] i += 2 if low < 0xdc00 || low > 0xdfff raise DataFormatError, "invalid surrogate detected" end c = (((c & 0x03ff)) << 10 | (low & 0x03ff)) + 0x10000 b4 = c & 0x003f b3 = (c >> 6) & 0x003f b2 = (c >> 12) & 0x003f b1 = c >> 18; buf.concat(b1 | 0xf0) buf.concat(b2 | 0x80) buf.concat(b3 | 0x80) buf.concat(b4 | 0x80) else # 0x0800-0xffff b3 = c & 0x003f b2 = (c >> 6) & 0x003f b1 = c >> 12 buf.concat(b1 | 0xe0) buf.concat(b2 | 0x80) buf.concat(b3 | 0x80) end end return buf end