home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / drafts / draft_ietf_a_c / draft-ietf-acap-mlsf-01.txt < prev    next >
Text File  |  1997-06-09  |  24KB  |  789 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                          C. Newman
  8. Internet Draft: Multi-Lingual String Format                     Innosoft
  9. Document: draft-ietf-acap-mlsf-01.txt                          June 1997
  10.                                                    Expires in six months
  11.  
  12.  
  13.                    Multi-Lingual String Format (MLSF)
  14.  
  15.  
  16. Status of this memo
  17.  
  18.      This document is an Internet Draft.  Internet Drafts are working
  19.      documents of the Internet Engineering Task Force (IETF), its Areas,
  20.      and its Working Groups.  Note that other groups may also distribute
  21.      working documents as Internet Drafts.
  22.  
  23.      Internet Drafts are draft documents valid for a maximum of six
  24.      months.  Internet Drafts may be updated, replaced, or obsoleted by
  25.      other documents at any time.  It is not appropriate to use Internet
  26.      Drafts as reference material or to cite them other than as a
  27.      "working draft" or "work in progress".
  28.  
  29.      To learn the current status of any Internet-Draft, please check the
  30.      1id-abstracts.txt listing contained in the Internet-Drafts Shadow
  31.      Directories on ds.internic.net, nic.nordu.net, ftp.isi.edu, or
  32.      munnari.oz.au.
  33.  
  34.      A revised version of this draft document will be submitted to the
  35.      RFC editor as a Proposed Standard for the Internet Community.
  36.      Discussion and suggestions for improvement are requested.  This
  37.      document will expire six months after publication.  Distribution of
  38.      this draft is unlimited.
  39.  
  40.  
  41. Abstract
  42.  
  43.      The IAB charset workshop [IAB-CHARSET] concluded that for human
  44.      readable text there should always be a way to specify the natural
  45.      language.  Many protocols are designed with an attribute-value
  46.      model (including RFC 822, HTTP, LDAP, SNMP, DHCP, and ACAP) which
  47.      stores many small human readable text strings.  The primary
  48.      function of an attribute-value model is to simplify both
  49.      extensibility and searchability.  A solution is needed to provide
  50.      language tags in these small human readable text strings, which
  51.      does not interfere with these primary functions.
  52.  
  53.      This specification defines MLSF (Multi-Lingual String Format) which
  54.      applies another layer of encoding on top of UTF-8 [UTF-8] to permit
  55.  
  56.  
  57.  
  58. Newman                                                          [Page 1]
  59.  
  60. Internet Draft        Multi-Lingual String Format              June 1997
  61.  
  62.  
  63.      the addition of language tags anywhere within a text string.  In
  64.      addition, it defines an alternate form which can be used to include
  65.      alternative representations of the same text in different character
  66.      sets.  MLSF has the property that UTF-8 is a proper subset of MLSF.
  67.      This preserves the searchability requirement of the attribute-value
  68.      model.
  69.  
  70.      Appendix F of this document includes a brief discussion of the
  71.      background behind MLSF and why some other potential solutions were
  72.      rejected for this purpose.
  73.  
  74.  
  75. 1. Conventions used in this document
  76.  
  77.      The key words "MUST", "MUST NOT", "SHOULD", "SHOULD NOT", and "MAY"
  78.      in this document are to be interpreted as defined in "Key words for
  79.      use in RFCs to Indicate Requirement Levels" [KEYWORDS].
  80.  
  81.  
  82. 2. MLSF simple form
  83.  
  84.      MLSF uses "Tags for the Identification of Languages" [LANG-TAGS] as
  85.      the basis for language identification.
  86.  
  87.      Language tags are encoded by mapping them to upper-case, then
  88.      adding hexadecimal A0 to each octet.  The result is broken up into
  89.      groups of five octets followed by a final group of five or fewer
  90.      octets.  Each group is prefixed by a UTF-8-style length count with
  91.      the low bits set to 0.  See Appendix D for sample source code to
  92.      perform this conversion.
  93.  
  94.      MLSF simple form is defined by the MLSF-SIMPLE rule in section 7.
  95.      A quoted version of MLSF simple form is defined by the MLSF-
  96.      SIMPLE-QUOTED rule.
  97.  
  98.      Note that MLSF is not compatible with UTF-8.  A program which uses
  99.      MLSF MUST downconvert it to UTF-8 prior to using it in a context
  100.      where UTF-8 is required.  Sample code for this down conversion is
  101.      included in Appendix B.
  102.  
  103.  
  104. 3. MLSF alternative form
  105.  
  106.      A MLSF alternative form string may contain alternative
  107.      representations of the same text in different primary languages.
  108.      The octet with hexadecimal representation of FE is used to
  109.      introduce a new alternative.  This MUST be followed by a MLSF
  110.      language tag for the primary language of the alternative.
  111.  
  112.  
  113.  
  114. Newman                                                          [Page 2]
  115.  
  116. Internet Draft        Multi-Lingual String Format              June 1997
  117.  
  118.  
  119.      The component of the MLSF string prior to the first FE octet is
  120.      considered the "preferred" representation for the string.  This is
  121.      the version which will be displayed by MLSF clients which choose
  122.      not to support alternative representations.  The preferred
  123.      representation MAY be prefixed by a MLSF language tag.
  124.  
  125.      MLSF alternate form is defined by the MLSF-ALT rule in section 7.
  126.      A quoted version of MLSF alternate form is defined by the
  127.      MLSF-ALT-QUOTED rule.
  128.  
  129.      Note that MLSF alternate form is not compatible with UTF-8.  A
  130.      program which uses MLSF MUST downconvert it to UTF-8 prior to using
  131.      it in a context where UTF-8 is required.  Sample code for this down
  132.      conversion is included in Appendix B.
  133.  
  134.  
  135. 4. MLSF MIME character sets
  136.  
  137.      The character set label "XXXX-simple" will be registered to
  138.      indicate the use of MLSF simple form.  The character set label
  139.      "XXXX-alt" will be registered to indicate the use of MLSF alternate
  140.      form.
  141.  
  142.      MLSF may be used in conjunction with MIME header [MIME-HDR]
  143.      encoding to permit language tagging and alternative representations
  144.      in header fields.  A work in progress [MIME-LANG] will propose a
  145.      mechanism for language tagging in headers which is not dependent on
  146.      the use of UTF-8.
  147.  
  148.      For single language MIME body parts, the UTF-8 character set with
  149.      an appropriate Content-Language [LANG-TAG] header SHOULD be used
  150.      instead of MLSF.  Text/enriched [ENRICHED] or HTML with language
  151.      tags [HTML-I18N] are preferred to using MLSF for MIME bodies when
  152.      possible.
  153.  
  154.  
  155. 5. Security Considerations
  156.  
  157.      Multi-Lingual String Format is not believed to have any security
  158.      considerations beyond those for simple US-ASCII strings.  In
  159.      particular, unfiltered display of certain US-ASCII control
  160.      characters by a terminal emulator may result in modifying the
  161.      behavior of the terminal emulator (e.g. by redefining function
  162.      keys) such that security can be breached.  Programs which display
  163.      text to a potentially insecure terminal emulator channel are
  164.      encouraged to remove control characters to avoid these problems.
  165.  
  166.  
  167.  
  168.  
  169.  
  170. Newman                                                          [Page 3]
  171.  
  172. Internet Draft        Multi-Lingual String Format              June 1997
  173.  
  174.  
  175. 6. Formal Grammar
  176.  
  177.      This section defines the formal grammar for MLSF using Augmented
  178.      BNF [ABNF] notation.
  179.  
  180.      MLSF-ALT           = [[MLSF-LANG-TAG] MLSF-COMPONENT
  181.                            *(MLSF-ALTERNATE MLSF-COMPONENT)]
  182.  
  183.      MLSF-ALT-QUOTED    = <"> [[MLSF-LANG-TAG] MLSF-COMPONENT-Q
  184.                            *(MLSF-ALTERNATE MLSF-COMPONENT-Q)] <">
  185.  
  186.      MLSF-ALTERNATE     = %xFE MLSF-LANG-TAG
  187.  
  188.      MLSF-COMPONENT     = UTF8-NON-NUL *([MLSF-LANG-TAG] UTF8-NON-NUL)
  189.  
  190.      MLSF-COMPONENT-Q   = UTF8-QUOTED *([MLSF-LANG-TAG] UTF8-QUOTED)
  191.  
  192.      MLSF-LANG-TAG      = *MLSF-LANG-5 (MLSF-LANG-1 / MLSF-LANG-2 /
  193.                           MLSF-LANG-3 / MLSF-LANG-4 / MLSF-LANG-5)
  194.                           ;; Encoded version of Language-Tag from RFC 1766
  195.                           ;; characters converted to uppercase, with
  196.                           ;; A0 added and broken into MLSF-LANG components
  197.  
  198.      MLSF-LANG-CONT     = %xCD / %xE1..FA
  199.  
  200.      MLSF-LANG-1        = %xC0 MLSF-LANG-CONT
  201.  
  202.      MLSF-LANG-2        = %xE0 2MLSF-LANG-CONT
  203.  
  204.      MLSF-LANG-3        = %xF0 3MLSF-LANG-CONT
  205.  
  206.      MLSF-LANG-4        = %xF8 4MLSF-LANG-CONT
  207.  
  208.      MLSF-LANG-5        = %xFC 5MLSF-LANG-CONT
  209.  
  210.      MLSF-SIMPLE        = [[MLSF-LANG-TAG] MLSF-COMPONENT]
  211.  
  212.      MLSF-SIMPLE-QUOTED = <"> [[MLSF-LANG-TAG] MLSF-COMPONENT-Q] <">
  213.  
  214.      QUOTED             = "\" QUOTED-SPECIAL
  215.  
  216.      QUOTED-SPECIAL     = "\" / <">
  217.  
  218.      US-ASCII-SAFE      = %x01..09 / %x0B..0C / %x0E..21
  219.                           / %x23..5B / %x5D..7F
  220.                          ;; US-ASCII except QUOTED-SPECIALs, CR, LF, NUL
  221.  
  222.      UTF8-NON-NUL       = UTF8-SAFE / CR / LF / QUOTED-SPECIAL
  223.  
  224.  
  225.  
  226. Newman                                                          [Page 4]
  227.  
  228. Internet Draft        Multi-Lingual String Format              June 1997
  229.  
  230.  
  231.      UTF8-QUOTED        = UTF8-SAFE / QUOTED
  232.  
  233.      UTF8-SAFE          = US-ASCII-SAFE / UTF8-1 / UTF8-2 / UTF8-3
  234.                           / UTF8-4 / UTF8-5
  235.  
  236.      UTF8-CONT          = %x80..BF
  237.  
  238.      UTF8-1             = %xC0..DF UTF8-CONT
  239.  
  240.      UTF8-2             = %xE0..EF 2UTF8-CONT
  241.  
  242.      UTF8-3             = %xF0..F7 3UTF8-CONT
  243.  
  244.      UTF8-4             = %xF8..FB 4UTF8-CONT
  245.  
  246.      UTF8-5             = %xFC..FD 5UTF8-CONT
  247.  
  248.  
  249. 7. References
  250.  
  251.      [ABNF] Crocker, D., "Augmented BNF for Syntax Specifications:
  252.      ABNF", Work in progress: draft-ietf-drums-abnf-xx.txt
  253.  
  254.      [ENRICHED] Resnick, Walker, "The text/enriched MIME Content-type",
  255.      RFC 1896, Qualcomm, InterCon, February 1996.
  256.  
  257.          <ftp://ds.internic.net/rfc/rfc1896.txt>
  258.  
  259.      [HTML-I18N] Yergeau, Nicol, Adams, Duerst, "Internationalization of
  260.      the Hypertext Markup Language", RFC 2070,  Alis Technologies,
  261.      Electronic Book Technologies, Spyglass, University of Zurich,
  262.      January 1997.
  263.  
  264.          <ftp://ds.internic.net/rfc/rfc2070.txt>
  265.  
  266.      [IAB-CHARSET] Weider, Preston, Simonsen, Alvestrand, Atkinson,
  267.      Crispin, Svanberg, "The Report of the IAB Character Set Workshop
  268.      held 29 February - 1 March, 1996", RFC 2130, April 1997.
  269.  
  270.          <ftp://ds.internic.net/rfc/rfc2130.txt>
  271.  
  272.      [IMAP4] Crispin, "Internet Message Access Protocol - Version
  273.      4rev1", RFC 2060, University of Washington, December 1996.
  274.  
  275.          <ftp://ds.internic.net/rfc/rfc2060.txt>
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282. Newman                                                          [Page 5]
  283.  
  284. Internet Draft        Multi-Lingual String Format              June 1997
  285.  
  286.  
  287.      [KEYWORDS] Bradner, "Key words for use in RFCs to Indicate
  288.      Requirement Levels", RFC 2119, Harvard University, March 1997.
  289.  
  290.          <ftp://ds.internic.net/rfc/rfc2119.txt>
  291.  
  292.      [LANG-TAGS] Alvestrand, H., "Tags for the Identification of
  293.      Languages", RFC 1766.
  294.  
  295.          <ftp://ds.internic.net/rfc/rfc1766.txt>
  296.  
  297.      [MIME-HDR] Moore, "MIME (Multipurpose Internet Mail Extensions)
  298.      Part Three: Message Header Extensions for Non-ASCII Text", RFC
  299.      2047, University of Tennessee, November 1996.
  300.  
  301.          <ftp://ds.internic.net/rfc/rfc2047.txt>
  302.  
  303.      [MIME-IMB] Freed, Borenstein, "Multipurpose Internet Mail
  304.      Extensions (MIME) Part One: Format of Internet Message Bodies", RFC
  305.      2045, Innosoft, First Virtual, November 1996.
  306.  
  307.          <ftp://ds.internic.net/rfc/rfc2045.txt>
  308.  
  309.      [MIME-LANG] Freed, Moore, "MIME Parameter Value and Encoded Words:
  310.      Character Sets, Language, and Continuations", work in progress,
  311.      March 1997.
  312.  
  313.      [UTF8] Yergeau, F. "UTF-8, a transformation format of Unicode and
  314.      ISO 10646", RFC 2044, Alis Technologies, October 1996.
  315.  
  316.          <ftp://ds.internic.net/rfc/rfc2044.txt>
  317.  
  318.  
  319. 8. Acknowledgements
  320.  
  321.      Special thanks to Mark Crispin for the idea of using unused UTF-8
  322.      codes for this purpose.   Thanks are also due to participants of
  323.      the ACAP WG mailing list who helped review this proposal.
  324.  
  325.  
  326. 9. Author's Address
  327.  
  328.      Chris Newman
  329.      Innosoft International, Inc.
  330.      1050 East Garvey Ave. South
  331.      West Covina, CA 91790 USA
  332.  
  333.      Email: chris.newman@innosoft.com
  334.  
  335.  
  336.  
  337.  
  338. Newman                                                          [Page 6]
  339.  
  340. Internet Draft        Multi-Lingual String Format              June 1997
  341.  
  342.  
  343. Appendix A.  Client advice
  344.  
  345.      A simple UTF-8 client is likely to find the source code in Appendix
  346.      B useful.  A simple Latin-1 based client is likely to find the
  347.      source code in Appendix C useful.
  348.  
  349.      A more sophisticated client will allow the user to select a
  350.      preferred language and use something like the source code in
  351.      Appendix E to find the best alternative in an MLSF string.  Such
  352.      clients should also be aware that sometimes the client's preferred
  353.      language is misconfigured, and the user may wish to have the last
  354.      few messages repeated after they have changed languages.  For this
  355.      reason, such a client may wish to cache the last few MLSF strings
  356.      displayed to the user.
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. Newman                                                          [Page 7]
  395.  
  396. Internet Draft        Multi-Lingual String Format              June 1997
  397.  
  398.  
  399. Appendix B.  Sample code to convert to UTF-8
  400.  
  401. Here is sample C source code to convert from MLSF to UTF-8.
  402.  
  403. #include <stdio.h>
  404. #include <ctype.h>
  405.  
  406. /* a UTF8 lookup table */
  407. #define BAD 0x80
  408. #define SEP 0x40
  409. #define EXT 0x20
  410. static unsigned char utlen[256] = {
  411.         /* 0x00 */ BAD,   1,   1,   1,   1,   1,   1,   1,
  412.         /* 0x08 */   1,   1,   1,   1,   1,   1,   1,   1,
  413.         /* 0x10 */   1,   1,   1,   1,   1,   1,   1,   1,
  414.         /* 0x18 */   1,   1,   1,   1,   1,   1,   1,   1,
  415.         /* 0x20 */   1,   1,   1,   1,   1,   1,   1,   1,
  416.         /* 0x28 */   1,   1,   1,   1,   1,   1,   1,   1,
  417.         /* 0x30 */   1,   1,   1,   1,   1,   1,   1,   1,
  418.         /* 0x38 */   1,   1,   1,   1,   1,   1,   1,   1,
  419.         /* 0x40 */   1,   1,   1,   1,   1,   1,   1,   1,
  420.         /* 0x48 */   1,   1,   1,   1,   1,   1,   1,   1,
  421.         /* 0x50 */   1,   1,   1,   1,   1,   1,   1,   1,
  422.         /* 0x58 */   1,   1,   1,   1,   1,   1,   1,   1,
  423.         /* 0x60 */   1,   1,   1,   1,   1,   1,   1,   1,
  424.         /* 0x68 */   1,   1,   1,   1,   1,   1,   1,   1,
  425.         /* 0x70 */   1,   1,   1,   1,   1,   1,   1,   1,
  426.         /* 0x78 */   1,   1,   1,   1,   1,   1,   1,   1,
  427.         /* 0x80 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  428.         /* 0x88 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  429.         /* 0x90 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  430.         /* 0x98 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  431.         /* 0xA0 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  432.         /* 0xA8 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  433.         /* 0xB0 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  434.         /* 0xB8 */ EXT, EXT, EXT, EXT, EXT, EXT, EXT, EXT,
  435.         /* 0xC0 */   2,   2,   2,   2,   2,   2,   2,   2,
  436.         /* 0xC8 */   2,   2,   2,   2,   2,   2,   2,   2,
  437.         /* 0xD0 */   2,   2,   2,   2,   2,   2,   2,   2,
  438.         /* 0xD8 */   2,   2,   2,   2,   2,   2,   2,   2,
  439.         /* 0xE0 */   3,   3,   3,   3,   3,   3,   3,   3,
  440.         /* 0xE8 */   3,   3,   3,   3,   3,   3,   3,   3,
  441.         /* 0xF0 */   4,   4,   4,   4,   4,   4,   4,   4,
  442.         /* 0xF8 */   5,   5,   5,   5,   6,   6, SEP, BAD
  443. };
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450. Newman                                                          [Page 8]
  451.  
  452. Internet Draft        Multi-Lingual String Format              June 1997
  453.  
  454.  
  455. /* Down conversion from NUL terminated MLSF string to UTF-8.
  456.  *  this strips the language tags and only keeps the preferred
  457.  *  representation.
  458.  * It returns the length of the final string.
  459.  * The destination string will not be longer than the source string.
  460.  *  dst and src may be the same for in-place conversion.
  461.  */
  462. int MLSFtoUTF8(unsigned char *dst, unsigned char *src)
  463. {
  464.     unsigned char *start = dst;
  465.     int len;
  466.  
  467.     for (;;) {
  468.         len = utlen[*src];
  469.         if (len > 6) break;
  470.         /* skip language tags */
  471.         if (len > 1 && src[1] > 0xC0U) {
  472.             while (len && *src != '\0') {
  473.                 ++src;
  474.                 --len;
  475.             }
  476.             continue;
  477.         }
  478.         /* copy UTF8 character */
  479.         while (len && *src != '\0') {
  480.             *dst = *src;
  481.             ++dst;
  482.             ++src;
  483.             --len;
  484.         }
  485.     }
  486.     *dst = '\0';
  487.  
  488.     return (dst - start);
  489. }
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506. Newman                                                          [Page 9]
  507.  
  508. Internet Draft        Multi-Lingual String Format              June 1997
  509.  
  510.  
  511. Appendix C. Sample code to convert to Latin-1
  512.  
  513. /* Down conversion from NUL terminated MLSF string to 8859-1
  514.  * The destination string will not be longer than the source string.
  515.  *  fillc is used to fill untranslatable characters,
  516.  *  if fillc is NUL, untranslatable characters are ignored.
  517.  * returns 0 if source only contained latin-1, returns -1 otherwise.
  518.  */
  519. int MLSFtoLatin1(unsigned char *dst, unsigned char *src, int fillc)
  520. {
  521.     int len, result = 0;
  522.  
  523.     for (;;) {
  524.         len = utlen[*src];
  525.         /* copy US-ASCII */
  526.         if (len == 1) {
  527.             *dst = *src;
  528.             ++dst;
  529.             ++src;
  530.             continue;
  531.         }
  532.         /* stop at illegal character or end of string */
  533.         if (len > 6) break;
  534.         /* skip non-latin1 glyphs and language tags */
  535.         if (*src > 0xC3U || src[1] > 0xC0U) {
  536.             if (src[1] <= 0xC0U) {
  537.                 /* non-latin1 glyph found */
  538.                 result = -1;
  539.                 if (fillc) {
  540.                     *dst = fillc;
  541.                     ++dst;
  542.                 }
  543.             }
  544.             while (len && *src != '\0') {
  545.                 ++src;
  546.                 --len;
  547.             }
  548.             continue;
  549.         }
  550.         /* copy latin 1 character */
  551.         *dst = ((src[0] & 0x03) << 6) | (src[1] & 0x3F);
  552.         ++dst;
  553.         src += 2;
  554.     }
  555.     *dst = '\0';
  556.  
  557.     return (result);
  558. }
  559.  
  560.  
  561.  
  562. Newman                                                         [Page 10]
  563.  
  564. Internet Draft        Multi-Lingual String Format              June 1997
  565.  
  566.  
  567. Appendix D. Sample code for encoding/decoding language tags
  568.  
  569. /* encode a language tag
  570.  *  the destination must have a size of least (counting terminating NUL):
  571.  *        (6 * strlen(src) + 9) / 5
  572.  *  returns the length of the destination.
  573.  */
  574. int MLSFlangencode(unsigned char *dst, unsigned char *src)
  575. {
  576.     static unsigned char prefix[] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
  577.     unsigned char *start = dst;
  578.     int len;                    /* source length */
  579.     int complen;                /* component length */
  580.     int i;
  581.  
  582.     for (len = strlen(src); len > 0; len -= complen) {
  583.         /* find maximal component length */
  584.         complen = len;
  585.         if (len >= 5) {
  586.             complen = 5;
  587.         }
  588.         /* look up component prefix */
  589.         *dst = prefix[complen - 1];
  590.         ++dst;
  591.         /* copy and map characters in component */
  592.         for (i = 0; i < complen; ++i) {
  593.             *dst = (islower(*src) ? toupper(*src) : *src) + 0xA0U;
  594.             ++dst;
  595.             ++src;
  596.         }
  597.     }
  598.     *dst = '\0';
  599.  
  600.     return (dst - start);
  601. }
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618. Newman                                                         [Page 11]
  619.  
  620. Internet Draft        Multi-Lingual String Format              June 1997
  621.  
  622.  
  623. /* decode a language tag
  624.  *  the destination will not be longer than the source
  625.  *  dst and src may be the same for in-place conversion
  626.  * returns the length of the destination
  627.  */
  628. int MLSFlangdecode(unsigned char *dst, unsigned char *src)
  629. {
  630.     unsigned char *start = dst;
  631.     int complen;
  632.  
  633.     while (src[0] >= 0xC0U && src[1] > 0xC0U) {
  634.         for (complen = utlen[*src++]; complen > 1; --complen) {
  635.             *dst = *src - 0xA0U;
  636.             ++dst;
  637.             ++src;
  638.         }
  639.     }
  640.     *dst = '\0';
  641.  
  642.     return (dst - start);
  643. }
  644.  
  645.  
  646. Appendix E. Sample code for selecting the "best" alternative
  647.  
  648. /* select the "best" language match from an MLSF string
  649.  *  assume input language tag has been converted to upper case
  650.  *  assume language tags in string won't exceed 256 characters
  651.  *  "best" is calculated by matching RFC 1766 language tag components
  652.  * returns a pointer to the start of best matching component
  653.  */
  654. unsigned char *MLSFselect(unsigned char *str, unsigned char *tag)
  655. {
  656.     unsigned char ltag[256];
  657.     unsigned char *best, *match1, *match2;
  658.     int bestlen, mlen;
  659.  
  660.     /* start with match on preferred alternative */
  661.     best = str;
  662.     bestlen = 0;
  663.  
  664.     /* skip test if no language tag */
  665.     if (tag != NULL && *tag != '\0') {
  666.         do {
  667.             /* get language tag for this component */
  668.             MLSFlangdecode(ltag, str);
  669.  
  670.  
  671.  
  672.  
  673.  
  674. Newman                                                         [Page 12]
  675.  
  676. Internet Draft        Multi-Lingual String Format              June 1997
  677.  
  678.  
  679.             /* calculate match length of language tags */
  680.             match1 = ltag;
  681.             match2 = tag;
  682.             mlen = 0;
  683.             while (*match1 != '\0' && *match1 == *match2) {
  684.                 ++match1, ++match2;
  685.                 /* save length of partial match */
  686.                 if (*match2 == '-'
  687.                     && (*match1 == '-' || *match1 == '\0')) {
  688.                     mlen = match1 - ltag;
  689.                 }
  690.             }
  691.  
  692.             /* finish on exact match */
  693.             if (*match2 == '\0'
  694.                 && (*match1 == '-' || *match1 == '\0')) {
  695.                 best = str;
  696.                 break;
  697.             }
  698.  
  699.             /* remember best match */
  700.             if (mlen > bestlen) {
  701.                 best = str;
  702.                 bestlen = mlen;
  703.             }
  704.  
  705.             /* skip to next MLSF component */
  706.             while (*str != '\0' && *str++ != 0xFEU)
  707.                 ;
  708.         } while (*str != '\0');
  709.     }
  710.  
  711.     return (best);
  712. }
  713.  
  714. Appendix F. Background and Alternate Solutions
  715.  
  716.      MLSF was designed to deal with language tagging in the context of
  717.      the ACAP protocol, but is believed to be useful in other contexts.
  718.      Specific scenarios cited during discussion were human names in
  719.      address books, system administrator alert error messages, and error
  720.      messages which include identifiers potentially in a different
  721.      language from the client's preferred error message language.  Since
  722.      ACAP is an arbitrary attribute-value protocol, it is impossible to
  723.      imaging all possible scenarios in advance, so a general purpose
  724.      mechanism was needed.
  725.  
  726.      There have been several attempts to solve language tagging in
  727.  
  728.  
  729.  
  730. Newman                                                         [Page 13]
  731.  
  732. Internet Draft        Multi-Lingual String Format              June 1997
  733.  
  734.  
  735.      attribute value protocols.  RFC 822 poses a particularly
  736.      troublesome scenario, since headers must be 7-bit.  The MIME
  737.      solution to label character sets [MIME-HDR] and languages [MIME-
  738.      LANG] in headers is thus a necessary evil.  The result of this is
  739.      to make header searching services such as those provided by IMAP
  740.      [IMAP4] massively more complex.  If 8-bit headers were permitted a
  741.      solution like MLSF would have been far simpler and more efficient.
  742.  
  743.      Another approach taken is demonstrated by the current vCard,
  744.      iCalendar, and LDAPv3 proposals (all works in progress).  These
  745.      proposals overload the attribute namespace to provide language
  746.      tagging and creates a concept roughly described as attributes of
  747.      the attribute.  The result of this is that clients have to deal
  748.      with a multiple attribute response to a query where each attribute
  749.      may have multiple values.  The additional complexity this adds to
  750.      client processing was deemed unacceptable for ACAP where client
  751.      simplicity was an important design goal.
  752.  
  753.      Another possible approach is the use of a markup language such as
  754.      text/enriched [ENRICHED].  While this is certainly a suitable
  755.      language tagging solution for large text objects such as MIME
  756.      bodies, it is unsuitable for the attribute-value model where
  757.      searching is a primary function.
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786. Newman                                                         [Page 14]
  787.  
  788.  
  789.