827
erts_bs_put_utf8(ERL_BITS_PROTO_1(Eterm arg))
829
Uint bin_offset = erts_bin_offset;
836
if (is_not_small(arg)) {
839
val = signed_val(arg);
844
if ((bit_offset = BIT_OFFSET(bin_offset)) == 0) {
845
/* We can write directly into the destination binary. */
846
dst = erts_current_bin+BYTE_OFFSET(bin_offset);
848
/* Unaligned destination binary. Must use a temporary buffer. */
854
} else if (val < 0x800) {
855
dst[0] = 0xC0 | (val >> 6);
856
dst[1] = 0x80 | (val & 0x3F);
858
} else if (val < 0x10000UL) {
859
if ((0xD800 <= val && val <= 0xDFFF) ||
860
val == 0xFFFE || val == 0xFFFF) {
863
dst[0] = 0xE0 | (val >> 12);
864
dst[1] = 0x80 | ((val >> 6) & 0x3F);
865
dst[2] = 0x80 | (val & 0x3F);
867
} else if (val < 0x110000) {
868
dst[0] = 0xF0 | (val >> 18);
869
dst[1] = 0x80 | ((val >> 12) & 0x3F);
870
dst[2] = 0x80 | ((val >> 6) & 0x3F);
871
dst[3] = 0x80 | (val & 0x3F);
877
if (bin_offset != 0) {
878
erts_copy_bits(dst, 0, 1, erts_current_bin, bin_offset, 1, num_bits);
881
erts_bin_offset += num_bits;
887
erts_bs_put_utf16(ERL_BITS_PROTO_2(Eterm arg, Uint flags))
889
Uint bin_offset = erts_bin_offset;
896
if (is_not_small(arg)) {
899
val = unsigned_val(arg);
900
if (val > 0x10FFFF || (0xD800 <= val && val <= 0xDFFF) ||
901
val == 0xFFFE || val == 0xFFFF) {
905
if ((bit_offset = BIT_OFFSET(bin_offset)) == 0) {
906
/* We can write directly into the destination binary. */
907
dst = erts_current_bin+BYTE_OFFSET(bin_offset);
909
/* Unaligned destination binary. Must use a temporary buffer. */
913
if (val < 0x10000UL) {
915
if (flags & BSF_LITTLE) {
926
val = val - 0x10000UL;
927
w1 = 0xD800 | (val >> 10);
928
w2 = 0xDC00 | (val & 0x3FF);
929
if (flags & BSF_LITTLE) {
942
if (bin_offset != 0) {
943
erts_copy_bits(dst, 0, 1, erts_current_bin, bin_offset, 1, num_bits);
946
erts_bin_offset += num_bits;
823
952
erts_new_bs_put_binary(ERL_BITS_PROTO_2(Eterm arg, Uint num_bits))
1408
1537
return LSB[0] | (LSB[1]<<8) | (LSB[2]<<16) | (LSB[3]<<24);
1541
erts_align_utf8_bytes(ErlBinMatchBuffer* mb, byte* buf)
1543
Uint bits = mb->size - mb->offset;
1546
* Copy up to 4 bytes into the supplied buffer.
1552
} else if (bits >= 32) {
1554
} else if (bits >= 24) {
1559
erts_copy_bits(mb->base, mb->offset, 1, buf, 0, 1, bits);
1563
erts_bs_get_utf16(ErlBinMatchBuffer* mb, Uint flags)
1566
Uint num_bits = mb->size - mb->offset;
1572
if (num_bits < 16) {
1573
return THE_NON_VALUE;
1577
* Set up the pointer to the source bytes.
1579
if ((bit_offset = BIT_OFFSET(mb->offset)) == 0) {
1580
/* We can access the binary directly because the bytes are aligned. */
1581
src = mb->base + BYTE_OFFSET(mb->offset);
1584
* We must copy the data to a temporary buffer. If possible,
1585
* get 4 bytes, otherwise two bytes.
1587
Uint n = num_bits < 32 ? 16 : 32;
1588
erts_copy_bits(mb->base, mb->offset, 1, tmp_buf, 0, 1, n);
1593
* Get the first (and maybe only) 16-bit word. See if we are done.
1595
if (flags & BSF_LITTLE) {
1596
w1 = src[0] | (src[1] << 8);
1598
w1 = (src[0] << 8) | src[1];
1600
if (w1 < 0xD800 || w1 > 0xDFFF) {
1601
if (w1 == 0xFFFE || w1 == 0xFFFF) {
1602
return THE_NON_VALUE;
1605
return make_small(w1);
1606
} else if (w1 > 0xDBFF) {
1607
return THE_NON_VALUE;
1611
* Get the second 16-bit word and combine it with the first.
1613
if (num_bits < 32) {
1614
return THE_NON_VALUE;
1615
} else if (flags & BSF_LITTLE) {
1616
w2 = src[2] | (src[3] << 8);
1618
w2 = (src[2] << 8) | src[3];
1620
if (!(0xDC00 <= w2 && w2 <= 0xDFFF)) {
1621
return THE_NON_VALUE;
1624
return make_small((((w1 & 0x3FF) << 10) | (w2 & 0x3FF)) + 0x10000UL);
1413
1628
get_bit(byte b, size_t offs)