From 5443664df7c345f6212a124bd8df493aa1137a8d Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 16 Oct 2011 13:19:16 -0700 Subject: [PATCH] io.encodings.utf16: guess-*coded-length hints --- core/io/encodings/utf16/utf16-tests.factor | 5 +++++ core/io/encodings/utf16/utf16.factor | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/core/io/encodings/utf16/utf16-tests.factor b/core/io/encodings/utf16/utf16-tests.factor index e16c1f822e..2a5ac39ef7 100644 --- a/core/io/encodings/utf16/utf16-tests.factor +++ b/core/io/encodings/utf16/utf16-tests.factor @@ -23,3 +23,8 @@ IN: io.encodings.utf16.tests [ { CHAR: x } ] [ B{ HEX: fe HEX: ff 0 CHAR: x } utf16 decode >array ] unit-test [ { HEX: ff HEX: fe 120 0 52 216 30 221 } ] [ { CHAR: x HEX: 1d11e } >string utf16 encode >array ] unit-test + +! test ascii encoding path + +[ B{ CHAR: a 0 CHAR: b 0 CHAR: c 0 } ] [ "abc" utf16le encode ] unit-test +[ B{ 0 CHAR: a 0 CHAR: b 0 CHAR: c } ] [ "abc" utf16be encode ] unit-test diff --git a/core/io/encodings/utf16/utf16.factor b/core/io/encodings/utf16/utf16.factor index 527ad15b14..194e715df2 100644 --- a/core/io/encodings/utf16/utf16.factor +++ b/core/io/encodings/utf16/utf16.factor @@ -124,6 +124,12 @@ M: utf16be encode-string [ [ char>utf16be ] curry each ] [ ascii-string>utf16be ] if ; +M: utf16le guess-encoded-length drop 2 * ; inline +M: utf16le guess-decoded-length drop 2 /i ; inline + +M: utf16be guess-encoded-length drop 2 * ; inline +M: utf16be guess-decoded-length drop 2 /i ; inline + ! UTF-16 CONSTANT: bom-le B{ HEX: ff HEX: fe }