Standard Compression Scheme for Unicode

From HandWiki
(Redirected from SCSU (Unicode))
Short description: Unicode Technical Standard

The Standard Compression Scheme for Unicode (SCSU)[1] is a Unicode Technical Standard for reducing the number of bytes needed to represent Unicode text, especially if that text uses mostly characters from one or a small number of per-language character blocks. It does so by dynamically mapping values in the range 128–255 to offsets within particular blocks of 128 characters. The initial conditions of the encoder mean that existing strings in ASCII and ISO-8859-1 that do not contain C0 control codes other than NULL TAB CR and LF can be treated as SCSU strings. Since most alphabets do reside in blocks of contiguous Unicode codepoints, texts that use small alphabets and either ASCII punctuation or punctuation that fits within the window for the main alphabet can be encoded at one byte per character (plus setup overhead, which for common languages is often only 1 byte), most other punctuation can be encoded at 2 bytes per symbol through non-locking shifts. SCSU can also switch to UTF-16 internally to handle non-alphabetic languages.

History & use

Reuters originally developed SCSU, then under the name RCSU for Reuters Compression Scheme for Unicode.[2][3][4][5]

At first the Unicode Consortium considered it to be a character encoding,[6] but in 1999 changed its mind: although it was still considered a transfer encoding syntax, for a while it was no longer considered a character encoding because different compressors might yield different outputs for the same text.[7] However, in 2004 this decision was reverted and now SCSU is considered a compressing character encoding scheme, as opposed to a simple or compound character encoding scheme.[8][9]

Roman Czyborra (of GNU Unifont) wrote a decompressor.[10] The IBM-contributed decompressor is found in International Components for Unicode, along with a compressor written in Java.[11] Simpler reference codecs are available as attachments to TR6.

Symbian OS, an operating system for mobile phones and other mobile devices, uses SCSU to serialize strings.

SQL Server 2008 R2 uses SCSU to compress Unicode values (there meaning from strings in UCS-2 encoding) stored in nchar(n) and nvarchar(n) columns, achieving space savings between 15% and 50% (while UTF-8 only has this 50% reduction for ASCII subset of Unicode), depending on the language of the data.[12]

The scheme

The following sections briefly describe the anatomy of a compressed SCSU stream. For a full description (matching that of a decompressor), see the UTS #6 document.

Encoding modes

SCSU starts in the single-byte mode, which uses the compressed Window encoding. There exist commands to switch to a UTF-16BE "Unicode" mode, and to switch to the single-byte mode from that mode.

Window encoding

The core of SCSU lies in the windows for which the meanings of bytes 0x80-0xff are defined. There are eight static windows for simpler scripts and punctuation, and 6 types of dynamic windows (plus "half Unicode block" windows and custom Windows for the supplementary planes) for scripts making use of more characters.

Both simple and dynamic windows are selected by special command characters. For individual characters that do not fit into the current block, command characters for quoting are provided.

Comparison with general-purpose plain text compression schemes

Because UTF-16 or UTF-8 text might occupy more space than its equivalent in pre-Unicode encodings did, one might want to use compression such as SCSU to mitigate this problem.[13] In comparison with general-purpose compressors, it is not necessarily advantageous to use SCSU.[5] Also, while it can be used as a text encoding, because of the stateful nature of the algorithm difficulties may arise when using it as an internal text representation since basic text operations become non-trivial.

Treated purely as a compression algorithm, SCSU is inferior to most commonly used general-purpose algorithms for texts of over a few kilobytes.

SCSU does have the advantage that it can usefully compress texts that are only a few characters long, whereas most full-scale compressors need hundreds of bytes of data to break even against their own overhead. In Symbian OS, SCSU is used even for Clipboard operations, e.g. Cut, Copy & Paste of small strings of text.

In HTML

Supporting SCSU in HTML documents is prohibited by the W3C[14][15] and WHATWG[16] HTML standards because HTML wasn't designed with non-ASCII-compatible encodings in mind. In the past, cross-site scripting vulnerabilities due to browsers' poor handling of such encodings have been demonstrated.[17]

See also

References

  1. "UTS #6: Compression Scheme for Unicode". 2005-05-06. https://www.unicode.org/reports/tr6/. "SCSU defines a compact encoding, which is sometimes useful. However, Unicode text is much more commonly stored and transmitted in UTF-8 which is less compact (except for ASCII), much simpler, and does not present any security issues. For longer texts, general-purpose compression is effective and common." 
  2. "Ninth International Unicode Conference - Friday - Track B". https://unicode.org/iuc/iuc9/Friday2.html#b3. 
  3. "Tenth International Unicode Conference - Conference Program". https://unicode.org/iuc/iuc10/program.html. 
  4. "Compression Scheme for Unicode". https://unicode.org/reports/tr6-10.html. 
  5. 5.0 5.1 "A survey of Unicode compression". https://www.unicode.org/notes/tn14/UnicodeCompression.pdf. 
  6. "UTR#17: Character Encoding Model". https://unicode.org/reports/tr17/tr17-2.html. 
  7. https://unicode.org/reports/tr17/tr17-3.html#Transfer Encoding Syntax
  8. "UTR#17: Character Encoding Model". 2004-07-14. https://unicode.org/L2/L2004/04288-tr17-5d2.html#CharacterEncodingScheme. 
  9. "UTR#17: Unicode Character Encoding Model". https://unicode.org/reports/tr17/. 
  10. https://czyborra.com/scsu/scsu.c[bare URL plain text file]
  11. "International Components for Unicode". 22 October 2021. https://github.com/unicode-org/icu/blob/3f043c7693e20c8cded76035918dad104e7256e3/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetSCSU.java. 
  12. "Unicode Compression Implementation (SQL Server 2008 R2 Books Online)". https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ee240835(v=sql.105). 
  13. https://unicode.org/versions/Unicode3.0.0/ch05.pdf[bare URL PDF]
  14. "8.2.2.3. Character encodings". W3C. https://www.w3.org/TR/html51/syntax.html#character-encodings. 
  15. "8.2.2.3. Character encodings". W3C. https://www.w3.org/TR/html5/syntax.html#character-encodings. 
  16. "12.2.3.3 Character encodings". WHATWG. https://html.spec.whatwg.org/multipage/parsing.html#character-encodings. 
  17. "<meta> - HTML". Mozilla. Archived from the original on 3 October 2018. https://web.archive.org/web/20181003090922/https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta.