X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=blobdiff_plain;f=core%2Fio%2Fencodings%2Futf16%2Futf16.factor;h=ccdac29173a58f74d6c08bbc53f606e23ccfc960;hp=845271292def30ef60b2abb45cca49522e20fc63;hb=943596575ad294c074dfa381b70af74dba5992b1;hpb=e738c7206c32bd9b76f3cee31e950835e1b1ee24 diff --git a/core/io/encodings/utf16/utf16.factor b/core/io/encodings/utf16/utf16.factor index 845271292d..ccdac29173 100644 --- a/core/io/encodings/utf16/utf16.factor +++ b/core/io/encodings/utf16/utf16.factor @@ -25,9 +25,9 @@ ERROR: missing-bom ; : quad-be ( stream byte -- stream char ) double-be over stream-read1 [ - dup -2 shift BIN: 110111 number= [ - [ 2 shift ] dip BIN: 11 bitand bitor - over stream-read1 swap append-nums HEX: 10000 + + dup -2 shift 0b110111 number= [ + [ 2 shift ] dip 0b11 bitand bitor + over stream-read1 swap append-nums 0x10000 + ] [ 2drop dup stream-read1 drop replacement-char ] if ] when* ; @@ -35,9 +35,9 @@ ERROR: missing-bom ; dup stream-read1 drop replacement-char ; : begin-utf16be ( stream byte -- stream char ) - dup -3 shift BIN: 11011 number= [ - dup BIN: 00000100 bitand zero? - [ BIN: 11 bitand quad-be ] + dup -3 shift 0b11011 number= [ + dup 0b00000100 bitand zero? + [ 0b11 bitand quad-be ] [ drop ignore ] if ] [ double-be ] if ; @@ -48,14 +48,14 @@ M: utf16be decode-char : quad-le ( stream ch -- stream char ) over stream-read1 swap 10 shift bitor - over stream-read1 dup -2 shift BIN: 110111 = [ - BIN: 11 bitand append-nums HEX: 10000 + + over stream-read1 dup -2 shift 0b110111 = [ + 0b11 bitand append-nums 0x10000 + ] [ 2drop replacement-char ] if ; : double-le ( stream byte1 byte2 -- stream char ) - dup -3 shift BIN: 11011 = [ - dup BIN: 100 bitand 0 number= - [ BIN: 11 bitand 8 shift bitor quad-le ] + dup -3 shift 0b11011 = [ + dup 0b100 bitand 0 number= + [ 0b11 bitand 8 shift bitor quad-le ] [ 2drop replacement-char ] if ] [ append-nums ] if ; @@ -69,19 +69,19 @@ M: utf16le decode-char : encode-first ( char -- byte1 byte2 ) -10 shift - [ -8 shift BIN: 11011000 bitor ] [ HEX: FF bitand ] bi ; inline + [ -8 shift 0b11011000 bitor ] [ 0xFF bitand ] bi ; inline : encode-second ( char -- byte3 byte4 ) - BIN: 1111111111 bitand - [ -8 shift BIN: 11011100 bitor ] [ BIN: 11111111 bitand ] bi ; inline + 0b1111111111 bitand + [ -8 shift 0b11011100 bitor ] [ 0b11111111 bitand ] bi ; inline : stream-write2 ( char1 char2 stream -- ) [ B{ } 2sequence ] dip stream-write ; inline ! [ stream-write1 ] curry bi@ ; inline : char>utf16be ( char stream -- ) - over HEX: FFFF > [ - [ HEX: 10000 - ] dip + over 0xFFFF > [ + [ 0x10000 - ] dip [ [ encode-first ] dip stream-write2 ] [ [ encode-second ] dip stream-write2 ] 2bi ] [ [ h>b/b swap ] dip stream-write2 ] if ; inline @@ -90,8 +90,8 @@ M: utf16be encode-char ( char stream encoding -- ) drop char>utf16be ; : char>utf16le ( char stream -- ) - over HEX: FFFF > [ - [ HEX: 10000 - ] dip + over 0xFFFF > [ + [ 0x10000 - ] dip [ [ encode-first swap ] dip stream-write2 ] [ [ encode-second swap ] dip stream-write2 ] 2bi ] [ [ h>b/b ] dip stream-write2 ] if ; inline @@ -133,9 +133,9 @@ M: utf16be guess-decoded-length drop 2 /i ; inline ! UTF-16 -CONSTANT: bom-le B{ HEX: ff HEX: fe } +CONSTANT: bom-le B{ 0xff 0xfe } -CONSTANT: bom-be B{ HEX: fe HEX: ff } +CONSTANT: bom-be B{ 0xfe 0xff } : bom>le/be ( bom -- le/be ) dup bom-le sequence= [ drop utf16le ] [