Generate mask on the fly
This commit is contained in:
@@ -7,17 +7,6 @@ import (
|
|||||||
|
|
||||||
type GSM7Coder struct{}
|
type GSM7Coder struct{}
|
||||||
|
|
||||||
var masks = []byte{
|
|
||||||
0b00000000,
|
|
||||||
0b00000001,
|
|
||||||
0b00000011,
|
|
||||||
0b00000111,
|
|
||||||
0b00001111,
|
|
||||||
0b00011111,
|
|
||||||
0b00111111,
|
|
||||||
0b01111111,
|
|
||||||
0b11111111,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *GSM7Coder) Encode(s string, buf *bytes.Buffer) error {
|
func (c *GSM7Coder) Encode(s string, buf *bytes.Buffer) error {
|
||||||
// utf8 := *(*[]byte)(unsafe.Pointer(&s))
|
// utf8 := *(*[]byte)(unsafe.Pointer(&s))
|
||||||
@@ -33,14 +22,14 @@ func (c *GSM7Coder) Encode(s string, buf *bytes.Buffer) error {
|
|||||||
if bindex == 0 {
|
if bindex == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mask := masks[bitshift]
|
mask := byte(255 >> (8 - bitshift))
|
||||||
masked := (mask & septet) << (8 - bitshift)
|
masked := (mask & septet) << (8 - bitshift)
|
||||||
utf8[bindex-offset] |= masked
|
utf8[bindex-offset] |= masked
|
||||||
utf8[bindex] >>= bitshift
|
utf8[bindex] >>= bitshift
|
||||||
|
|
||||||
buf.WriteByte(utf8[bindex-offset])
|
buf.WriteByte(utf8[bindex-offset])
|
||||||
bitshift++
|
bitshift++
|
||||||
if utf8[bindex] == 0 {
|
if bitshift == 8 {
|
||||||
offset++
|
offset++
|
||||||
bitshift = 1
|
bitshift = 1
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user