Module: SJCL::Codec::UTF8String
- Defined in:
- lib/sjcl/codec_string.rb
Class Method Summary collapse
Class Method Details
.fromBits(arr) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sjcl/codec_string.rb', line 6 def self.fromBits(arr) out = [] bl = SJCL::BitArray.bitLength(arr) i = 0 tmp = 0 (bl/8).times do if ((i&3) === 0) tmp = arr[i/4] end out << (tmp >> 24) tmp <<= 8 i += 1 end out.pack('C*').force_encoding('utf-8') end |
.toBits(str) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sjcl/codec_string.rb', line 22 def self.toBits(str) str_arr = str.unpack("C*") out = [] tmp=0 i=0 str_arr.length.times do tmp = tmp << 8 | str_arr[i] if ((i&3) === 3) out.push(tmp); tmp = 0; end i += 1 end if (i&3 != 0) out.push(SJCL::BitArray.partial(8*(i&3), tmp)); end return out end |