home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / libi18n.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  91.3 KB  |  2,652 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. /* libi18n.h */
  21.  
  22.  
  23. #ifndef INTL_LIBI18N_H
  24. #define INTL_LIBI18N_H
  25.  
  26. #include "xp.h"
  27. #ifndef iDocumentContext
  28. #define iDocumentContext MWContext *
  29. #endif
  30. #define Stream NET_StreamClass
  31. #define URL URL_Struct
  32. #include "csid.h"
  33.  
  34. #ifdef _UNICVT_DLL_
  35.  
  36. #ifdef XP_WIN32
  37. #define UNICVTAPI __declspec(dllexport)
  38.  
  39. #else
  40. #define UNICVTAPI
  41. #endif
  42.  
  43. #else /* _UNICVT_DLL is undefined */
  44. #define UNICVTAPI
  45. #endif
  46.  
  47. /* Enum for INTL_CSIDIteratorCreate */
  48. enum {
  49.     csiditerate_TryIMAP4Search = 1
  50. };
  51.  
  52.  
  53.  
  54. /*
  55.  * To be called when backend catches charset info on <meta ... charset=...> tag.
  56.  * This will force netlib to go get fresh data again either through cache or
  57.  * network.
  58.  */
  59. enum
  60. {
  61.     METACHARSET_NONE = 0,
  62.     METACHARSET_HASCHARSET,
  63.     METACHARSET_REQUESTRELAYOUT,
  64.     METACHARSET_FORCERELAYOUT,
  65.     METACHARSET_RELAYOUTDONE
  66. };
  67.  
  68. XP_BEGIN_PROTOS
  69.  
  70.  
  71. /*=======================================================*/
  72. /* Character Code Conversion (CCC).
  73.  *
  74.  *
  75.  * CCCDataObject accessor functions are
  76.  * build as a table to allow access from a DLL
  77.  *
  78.  * Note: new functions must be added at the end
  79.  *       or old apps using the new dll will fail
  80.  */
  81. /**@name Character Code Conversion (CCC) */
  82. /*@{*/
  83.  
  84. /**
  85.  * Function Prototype for the codeset conversion function.
  86.  * 
  87.  * @param obj Specifies the converter object
  88.  * @param src Specifies the text to be converted
  89.  * @param srclen Specifies the length of src
  90.  * @return the converted text. The length of the converted result could be 
  91.  *         access via INTL_GetCCCLen(obj) 
  92.  * @see INTL_GetCCCLen
  93.  * @see INTL_SetCCCCvtfunc
  94.  * 
  95.  */
  96. typedef unsigned char *(*CCCFunc)(CCCDataObject obj, const unsigned char * src, int32 srclen);
  97.  
  98. /**
  99.  * Function Prototype for the Report Auto Detect Result function.
  100.  * 
  101.  * @param closure Specifies the closure which associated with the converter 
  102.  *                object by calling INTL_SetCCCReportAutoDetect
  103.  * @param obj Specifies the converter object
  104.  * @param doc_csid Specifies the auto-detected document csid
  105.  * @see INTL_SetCCCReportAutoDetect
  106.  * 
  107.  */
  108. typedef void (*CCCRADFunc)(void * closure, CCCDataObject obj, uint16 doc_csid);
  109.  
  110. /**
  111.  * Opaque converter object. 
  112.  *
  113.  * This struct is an opaque converter object.
  114.  */
  115. struct OpaqueCCCDataObject { /* WARNING: MUST MATCH REAL STRUCT */
  116.         /** pointer to the converter object private functions struct */
  117.     struct INTL_CCCFuncs *funcs_pointer;
  118. };
  119.  
  120. /**
  121.  * This structure hold the private functions of a conversion object.
  122.  * 
  123.  * <B>WARNING: THIS STRUCT AND THE TABLE MUST BE IN SYNC WITH EACH OTHER </B>
  124.  */
  125. struct INTL_CCCFuncs {
  126.     /** The private function of INTL_SetCCCReportAutoDetect. */
  127.     void           (*set_report_autodetect)(CCCDataObject, CCCRADFunc, void*); 
  128.     /** The private function of INTL_CallCCCReportAutoDetect. */
  129.     void           (*call_report_autodetect)(CCCDataObject, uint16);
  130.     /** The private function of INTL_SetCCCCvtfunc. */
  131.     void           (*set_cvtfunc)(CCCDataObject, CCCFunc);
  132.     /** The private function of INTL_GetCCCCvtfunc. */
  133.     CCCFunc        (*get_cvtfunc)(CCCDataObject);
  134.     /** The private function of INTL_SetCCCJismode. */
  135.     void           (*set_jismode)(CCCDataObject,int32);
  136.     /** The private function of INTL_GetCCCJismode. */
  137.     int32          (*get_jismode)(CCCDataObject);
  138.     /** The private function of INTL_SetCCCCvtflag. */
  139.     void           (*set_cvtflag)(CCCDataObject,int32);
  140.     /** The private function of INTL_GetCCCCvtflag. */
  141.     int32          (*get_cvtflag)(CCCDataObject);
  142.     /** The private function of INTL_GetCCCUncvtbuf. */
  143.     unsigned char* (*get_uncvtbuf)(CCCDataObject);
  144.     /** The private function of INTL_SetCCCDefaultCSID. */
  145.     void           (*set_default_doc_csid)(CCCDataObject, uint16);
  146.     /** The private function of INTL_GetCCCDefaultCSID. */
  147.     uint16         (*get_default_doc_csid)(CCCDataObject);
  148.     /** The private function of INTL_SetCCCFromCSID. */
  149.     void           (*set_from_csid)(CCCDataObject, uint16);
  150.     /** The private function of INTL_GetCCCFromCSID. */
  151.     uint16         (*get_from_csid)(CCCDataObject);
  152.     /** The private function of INTL_SetCCCToCSID. */
  153.     void           (*set_to_csid)(CCCDataObject, uint16);
  154.     /** The private function of INTL_GetCCCToCSID. */
  155.     uint16         (*get_to_csid)(CCCDataObject);
  156.     /** The private function of INTL_SetCCCRetval. */
  157.     void           (*set_retval)(CCCDataObject, int);
  158.     /** The private function of INTL_GetCCCRetval. */
  159.     int            (*get_retval)(CCCDataObject);
  160.     /** The private function of INTL_SetCCCLen. */
  161.     void           (*set_len)(CCCDataObject, int32);
  162.     /** The private function of INTL_GetCCCLen. */
  163.     int32          (*get_len)(CCCDataObject);
  164. };
  165.  
  166. /**
  167.  * Create and initialize Character Code Converter Object.
  168.  *
  169.  * Create and initialize character code converter.
  170.  * It also set up a converter if a doc_csid is known (by DOC_CSID_KNOWN).
  171.  * Caller is responsible for deallocation of an allocated memory.
  172.  * 
  173.  * @param     c    Pointer to an i18n private data structure.
  174.  * @param     default_doc_csid    Default doc_csid to be used.
  175.  * @return    CCCDataObject Created character code converter object pointer.
  176.  */
  177. PUBLIC CCCDataObject INTL_CreateDocumentCCC(
  178.     INTL_CharSetInfo c,
  179.     uint16 default_doc_csid
  180. );
  181.  
  182. /**
  183.  * Look for a converter from one charset to another.
  184.  *
  185.  * If the from_csid is CS_DEFAULT, this function uses the ID returned by
  186.  * INTL_GetCCCDefaultCSID. If the to_csid is zero, this function uses the ID
  187.  * returned by INTL_DocToWinCharSetID for the from_csid determined above.
  188.  * If found, the converter function is stored in the given character code
  189.  * conversion object.
  190.  *
  191.  * @param from_csid  Specifies the charset ID to convert from
  192.  * @param to_csid    Specifies the charset ID to convert to
  193.  * @param obj        Specifies the character code converter object
  194.  * @return 1 for success, 0 for failure
  195.  * @see INTL_CreateCharCodeConverter, INTL_CallCharCodeConverter
  196.  */
  197. PUBLIC int INTL_GetCharCodeConverter(
  198.     int16 from_csid,
  199.     int16 to_csid,
  200.     CCCDataObject obj
  201. );
  202.  
  203. /**
  204.  * Set up charset internal data by meta charset.
  205.  *
  206.  * Given a charset name, this will set up i18n private charset info
  207.  * which is obtained by a given context.
  208.  * Input charset name should be obtained from HTML META tag.
  209.  * 
  210.  * @param     context    Context to be set up.
  211.  * @param     charset_tag    Charset name as an input (e.g. iso-8859-1).
  212.  * @see       INTL_CSIReportMetaCharsetTag
  213.  */
  214. PUBLIC void INTL_CCCReportMetaCharsetTag(
  215.     MWContext *context, 
  216.     char *charset_tag
  217. );
  218.  
  219. /**
  220.  * Passes some more text to the character code converter.
  221.  *
  222.  * The character code converter object keeps track of the current state as it
  223.  * receives data to convert. If partial characters are received, they are
  224.  * buffered until this function is called again.
  225.  * INTL_GetCharCodeConverter must first be called before calling this function. 
  226.  *
  227.  * In some cases, the text is converted in place (in the input buffer).
  228.  *
  229.  * @param obj  Specifies the character code converter object
  230.  * @param str  Specifies the text to be converted
  231.  * @param len  Specifies the length in bytes of the text
  232.  * @return The converted text, null terminated
  233.  * @see INTL_GetCharCodeConverter
  234.  */
  235. PUBLIC unsigned char *INTL_CallCharCodeConverter(
  236.     CCCDataObject obj,
  237.     const unsigned char *str,
  238.     int32 len
  239. );
  240.  
  241. /**
  242.  * Initialize and set up a character code converter for a mail charset.
  243.  *
  244.  * Allocate memory and initialize for character code converter.
  245.  * From/To charset is determined by given context or by parsing the source
  246.  * buffer in case of HTML.
  247.  * After charsets are determined, it set up a converter function.
  248.  * Caller is responsible for deallocation of an allocated memory.
  249.  * 
  250.  * @param     context    Context to access charset info.
  251.  * @param     isHTML    If TRUE then the input stream is parsed for meta tag. 
  252.  * @param     buffer   Source buffer.
  253.  * @param     buffer_size   the length of the source buffer.
  254.  * @return    CCCDataObject Created character code converter object pointer.
  255.  * @see       INTL_CreateCharCodeConverter
  256.  */
  257. PUBLIC CCCDataObject INTL_CreateDocToMailConverter(
  258.     iDocumentContext context, 
  259.     XP_Bool isHTML, 
  260.     unsigned char *buffer, 
  261.     uint32 buffer_size
  262. );
  263.  
  264. /**
  265.  * Create a character code converter object used for codeset conversion.
  266.  *
  267.  * @return The new character code converter object
  268.  * @see INTL_CreateDocumentCCC, INTL_GetCharCodeConverter,
  269.  *      INTL_DestroyCharCodeConverter
  270.  * @deprecated Obsolescent. Please use INTL_CreateDocumentCCC. 
  271.  */
  272. PUBLIC CCCDataObject INTL_CreateCharCodeConverter(void);
  273.  
  274. /**
  275.  * Frees the given character code conversion object.
  276.  *
  277.  * This function destroys the code conversion object created by 
  278.  * INTL_CreateCharCodeConverter.
  279.  *
  280.  * @param obj  Specifies the character code conversion object to free
  281.  * @see INTL_CreateCharCodeConverter
  282.  */
  283. PUBLIC void INTL_DestroyCharCodeConverter(
  284.     CCCDataObject obj
  285. );
  286.  
  287. /**
  288.  * Converts a piece of text from one charset to another.
  289.  *
  290.  * This function does not do charset ID auto-detection. The caller must pass
  291.  * the from/to charset IDs. This function does not keep state. Don't use it to
  292.  * convert a stream of data. Only use this when you want to convert a string,
  293.  * and you have no way to hold on to the converter object.
  294.  *
  295.  * If the string gets converted in place (use the input buffer), then this
  296.  * function returns NULL.
  297.  *
  298.  * @param fromcsid    Specifies the charset ID to convert from
  299.  * @param tocsid      Specifies the charset ID to convert to
  300.  * @param pSrc        Specifies the input text
  301.  * @param block_size  Specifies the number of bytes in the input text
  302.  * @return The converted text, null terminated, or NULL if converted in place
  303.  * @see INTL_CallCharCodeConverter
  304.  */
  305. PUBLIC unsigned char *INTL_ConvertLineWithoutAutoDetect(
  306.     int16 fromcsid,
  307.     int16 tocsid,
  308.     unsigned char *pSrc,
  309.     uint32 block_size
  310. );
  311.  
  312. /**
  313.  * Returns the window charset ID corresponding to the given document charset ID.
  314.  *
  315.  * This function searches a built-in table to find the first entry that
  316.  * matches the given document charset ID. If no such entry is found, it
  317.  * returns CS_FE_ASCII.
  318.  *
  319.  * @param csid  Specifies the document charset ID
  320.  * @return The corresponding window charset ID
  321.  */
  322. PUBLIC int16 INTL_DocToWinCharSetID(
  323.     int16 csid
  324. );
  325.  
  326. /**
  327.  * Return the charset used in internet message from a specified charset.
  328.  *
  329.  * In the current implementation of Communicator, we assume there is a many to
  330.  * one relationship between a encoding and a encoding used on internet mail
  331.  * message. This routines is used to get the outgoing encoding for a specified
  332.  * encoding. The caller than can convert the text of the specified encoding to
  333.  * the return encoding and before send out the internet message. Usually the
  334.  * relationship is the same as the newsgroup posting and this one. However, for
  335.  * some region/country like Korean, it is not the same. In such region/country,
  336.  * they use different encodings in internet mail message and newsgroup posting.
  337.  * In that case INTL_DefaultNewsCharSetID should be used instead.
  338.  *
  339.  * Issues: The current model assume the text of a particular encoding is always
  340.  * sending out as one encoding. Such assumption break when people want send out
  341.  * message in different Cyrillic, Chinese, or Unicode encoding. Therefore, we
  342.  * may change this architecture in the near future.
  343.  *
  344.  * The mapping are: 
  345.  *   <UL>
  346.  *   <LI>CS_ASCII: CS_ASCII 
  347.  *   <LI>CS_LATIN1: CS_LATIN1 
  348.  *   <LI>CS_JIS: CS_JIS 
  349.  *   <LI>CS_SJIS: CS_JIS 
  350.  *   <LI>CS_EUCJP: CS_JIS 
  351.  *   <LI>CS_JIS_AUTO: CS_JIS 
  352.  *   <LI>CS_SJIS_AUTO: CS_JIS 
  353.  *   <LI>CS_EUCJP_AUTO: CS_JIS 
  354.  *   <LI>CS_KSC_8BIT: CS_2022_KR [Note 1]
  355.  *   <LI>CS_KSC_8BIT_AUTO: CS_2022_KR [Note 1]
  356.  *   <LI>CS_GB_8BIT: CS_GB_8BIT 
  357.  *   <LI>CS_BIG5: CS_BIG5 
  358.  *   <LI>CS_CNS_8BIT: CS_BIG5 
  359.  *   <LI>CS_MAC_ROMAN: CS_LATIN1 
  360.  *   <LI>CS_LATIN2: CS_LATIN2 
  361.  *   <LI>CS_MAC_CE,: CS_LATIN2 
  362.  *   <LI>CS_CP_1250: CS_LATIN2 
  363.  *   <LI>CS_8859_5: CS_KOI8_R [Note 2]
  364.  *   <LI>CS_KOI8_R: CS_KOI8_R [Note 2] 
  365.  *   <LI>CS_MAC_CYRILLIC: CS_KOI8_R  [Note 2]
  366.  *   <LI>CS_CP_1251:  CS_KOI8_R [Note 2]
  367.  *   <LI>CS_8859_7: CS_8859_7 
  368.  *   <LI>CS_CP_1253: CS_8859_7 
  369.  *   <LI>CS_MAC_GREEK: CS_8859_7 
  370.  *   <LI>CS_8859_9: CS_8859_9 
  371.  *   <LI>CS_MAC_TURKISH: CS_8859_9 
  372.  *   <LI>CS_UTF8: CS_UTF7 
  373.  *   <LI>CS_UTF7: CS_UTF7 
  374.  *   <LI>CS_UCS2: CS_UTF7 
  375.  *   <LI>CS_UCS2_SWAP: CS_UTF7 
  376.  *   </UL>
  377.  *   Note:
  378.  *   <OL>
  379.  *   <LI>For INTL_DefaultNewsCharSetID, this value is different
  380.  *   <LI>The value is the one specified in preference
  381.  *       "intl.mailcharset.cyrillic". The default value is CS_KOI_R. See
  382.  *       <A HREF=http://people.netscape.com/ftang/cyrillicmail.html>
  383.  *       http://people.netscape.com/ftang/cyrillicmail.html</A> for details.
  384.  *   </OL>
  385.  *
  386.  * @param Specifies the encoding
  387.  * @return the encoding should be send out for the internet mail message.
  388.  * @see INTL_DefaultNewsCharSetID
  389.  */
  390. PUBLIC int16 INTL_DefaultMailCharSetID(int16 csid);
  391.  
  392. /**
  393.  * Return the charset used in internet message from a specified charset.
  394.  *
  395.  * In the current implementation of Communicator, we assume there is a many to
  396.  * one relationship between a encoding and a encoding used on internet
  397.  * newsgroup posting. This routines is used to get the outgoing encoding for a
  398.  * specified encoding. The caller than can convert the text of the specified
  399.  * encoding to the return encoding and before post the message to the
  400.  * newsgroup. Usually the relationship is the same as the newsgroup posting
  401.  * and this one. However, for some region/country like Korean, it is not the
  402.  * same. In such region/country, they use different encodings in internet mail
  403.  * message and newsgroup posting. In that case INTL_DefaultMailCharSetID should
  404.  * be used instead.
  405.  *
  406.  * Issues: The current model assume the text of a particular encoding is always
  407.  * sending out as one encoding. Such assumption break when people want send out
  408.  * message in different Cyrillic, Chinese, or Unicode encoding. Therefore, we
  409.  * may change this architecture in the near future.
  410.  *
  411.  * The mapping are:
  412.  *  <UL>
  413.  *  <LI>ASCII: CS_ASCII 
  414.  *  <LI>LATIN1: CS_LATIN1 
  415.  *  <LI>JIS: CS_JIS 
  416.  *  <LI>SJIS: CS_JIS 
  417.  *  <LI>EUCJP: CS_JIS 
  418.  *  <LI>JIS_AUTO: CS_JIS 
  419.  *  <LI>SJIS_AUTO: CS_JIS 
  420.  *  <LI>EUCJP_AUTO: CS_JIS 
  421.  *  <LI>KSC_8BIT: CS_KSC_8BIT [Note 1]
  422.  *  <LI>KSC_8BIT_AUTO: CS_KSC_8BIT [Note 1]
  423.  *  <LI>GB_8BIT: CS_GB_8BIT 
  424.  *  <LI>BIG5: CS_BIG5 
  425.  *  <LI>CNS_8BIT: CS_BIG5 
  426.  *  <LI>MAC_ROMAN: CS_LATIN1 
  427.  *  <LI>LATIN2: CS_LATIN2 
  428.  *  <LI>MAC_CE,: CS_LATIN2 
  429.  *  <LI>CP_1250: CS_LATIN2 
  430.  *  <LI>8859_5: CS_KOI8_R [Note 2]
  431.  *  <LI>KOI8_R: CS_KOI8_R [Note 2] 
  432.  *  <LI>MAC_CYRILLIC: CS_KOI8_R  [Note 2]
  433.  *  <LI>CP_1251:  CS_KOI8_R [Note 2]
  434.  *  <LI>8859_7: CS_8859_7 
  435.  *  <LI>CP_1253: CS_8859_7 
  436.  *  <LI>MAC_GREEK: CS_8859_7 
  437.  *  <LI>8859_9: CS_8859_9 
  438.  *  <LI>MAC_TURKISH: CS_8859_9 
  439.  *  <LI>UTF8: CS_UTF7 
  440.  *  <LI>UTF7: CS_UTF7
  441.  *  <LI>UCS2: CS_UTF7
  442.  *  <LI>UCS2_SWAP: CS_UTF7 
  443.  *  </UL>
  444.  *  Note:
  445.  *  <OL>   
  446.  *  <LI>For INTL_DefaultMailCharSetID, this value is different
  447.  *  <LI>The value is the one specified in preference
  448.  *      "intl.mailcharset.cyrillic". The default value is CS_KOI_R. See
  449.  *      <A HREF=http://people.netscape.com/ftang/cyrillicmail.html>
  450.  *      http://people.netscape.com/ftang/cyrillicmail.html</A> for details.
  451.  *  </OL>
  452.  *
  453.  * @param Specifies the encoding
  454.  * @return the encoding should be send out for the internet newsgroup.
  455.  * @see INTL_DefaultMailCharSetID
  456.  */
  457. PUBLIC int16 INTL_DefaultNewsCharSetID(int16 csid);
  458.  
  459. /**
  460.  * Tell libi18n which font charset IDs are available in the front end.
  461.  *
  462.  * The front end (FE) calls this function to inform libi18n of the charset IDs
  463.  * of the fonts that are currently available.
  464.  *
  465.  * This function calls INTL_SetUnicodeCSIDList to set up the Unicode
  466.  * machinery.
  467.  *
  468.  * The front end must allocate space for this array using malloc/calloc. If
  469.  * this function is called more than once, the array passed in a previous call
  470.  * is freed by this function. However, the front end is responsible for
  471.  * freeing the array at exit time.
  472.  *
  473.  * @param charsets  Specifies a null-terminated array of charset IDs
  474.  */
  475. PUBLIC void INTL_ReportFontCharSets(
  476.     int16 *charsets
  477. );
  478.  
  479. /**
  480.  * Get the "Unconverted Buffer" from the Converter Object.
  481.  * 
  482.  * @param obj Specifies the converter object
  483.  * @return the unconverted buffer in the converter object
  484.  */
  485. #define INTL_GetCCCUncvtbuf(obj) (obj->funcs_pointer->get_uncvtbuf)(obj)
  486.  
  487. /**
  488.  * Set the "conversion result length" to the converter object.
  489.  * 
  490.  * @param obj Specifies the converter object
  491.  * @param len Specifies the length of current conversion result.
  492.  * @see INTLGetCCCLen
  493.  */
  494. #define INTL_SetCCCLen(obj,len) ((obj)->funcs_pointer->set_len)((obj), (len))
  495.  
  496. /**
  497.  * Get the "conversion result length" from the converter object.
  498.  * 
  499.  * @param obj Specifies the converter object
  500.  * @return the length of conversion result stored in the converter object
  501.  * @see INTL_SetCCCLen
  502.  */
  503. #define INTL_GetCCCLen(obj) ((obj)->funcs_pointer->get_len)(obj)
  504.  
  505. /**
  506.  * Set a private flag "Jismode" to the converter object.
  507.  * 
  508.  * There are no reason any code outside libi18n should call this. 
  509.  * We are considering move this into intlpriv.h. 
  510.  * Don't call this macro unless you are changing libi18n.
  511.  *
  512.  * The name "jismode" refers to the ISO 2022 state (JIS mode). 
  513.  * This is what the field was first used for. 
  514.  * It is now used for other purposes as well, so the name is no longer
  515.  * appropriate. 
  516.  *
  517.  * @param obj Specifies the converter object
  518.  * @param jismode Specifies the Jismode
  519.  * @see INTL_GetCCCJismode
  520.  */
  521. #define INTL_SetCCCJismode(obj,jismode) \
  522.                 ((obj)->funcs_pointer->set_jismode)((obj), (jismode))
  523. /**
  524.  * Get a private flag "Jismode" from the converter object.
  525.  * 
  526.  * There are no reason any code outside libi18n should call this. 
  527.  * We are considering move this into intlpriv.h. 
  528.  * Don't call this macro unless you are changing libi18n
  529.  *
  530.  * The name "jismode" refers to the ISO 2022 state (JIS mode). 
  531.  * This is what the field was first used for. 
  532.  * It is now used for other purposes as well, so the name is no longer
  533.  * appropriate. 
  534.  *
  535.  * @param obj Specifies the converter object
  536.  * @return the Jismode stored in the converter object
  537.  * @see INTL_SetCCCJismode
  538.  */
  539. #define INTL_GetCCCJismode(obj) ((obj)->funcs_pointer->get_jismode)(obj)
  540.  
  541. /**
  542.  * Set a private flag "Cvtflag" to the converter object.
  543.  * 
  544.  * There are no reason any code outside libi18n should call this. 
  545.  * We are considering move this into intlpriv.h. 
  546.  * Don't call this macro unless you are changing libi18n
  547.  *
  548.  * @param obj Specifies the converter object
  549.  * @param cvtflag Specifies the Cvtflag
  550.  * @see INTL_GetCCCCvtflag
  551.  */
  552. #define INTL_SetCCCCvtflag(obj,cvtflag) \
  553.                 ((obj)->funcs_pointer->set_cvtflag)((obj), (cvtflag))
  554. /**
  555.  * Get a private flag "Cvtflag" from the converter object.
  556.  * 
  557.  * There are no reason any code outside libi18n should call this. 
  558.  * We are considering move this into intlpriv.h. 
  559.  * Don't call this macro unless you are changing libi18n
  560.  *
  561.  * @param obj Specifies the converter object
  562.  * @return the Cvtflag stored in the converter object
  563.  * @see INTL_SetCCCCvtflag
  564.  */
  565. #define INTL_GetCCCCvtflag(obj) ((obj)->funcs_pointer->get_cvtflag)(obj)
  566.  
  567. /**
  568.  * Set the "Convert To CSID" to the converter object.
  569.  * 
  570.  * There are no reason any code outside libi18n should call this. 
  571.  * We are considering move this into intlpriv.h. 
  572.  * Don't call this macro unless you are changing libi18n
  573.  *
  574.  * @param obj Specifies the converter object
  575.  * @param to_csid Specifies the Convert To CSID
  576.  * @see INTL_SetCCCToCSID
  577.  */
  578. #define INTL_SetCCCToCSID(obj,to_csid) \
  579.             (((obj)->funcs_pointer->set_to_csid)((obj),(to_csid)))
  580. /**
  581.  * Get the "Convert To CSID" from the converter object.
  582.  *
  583.  * @param obj Specifies the converter object
  584.  * @return the "Convert To CSID" stored in the converter object
  585.  * @see INTL_SetCCCToCSID
  586.  */
  587. #define INTL_GetCCCToCSID(obj) (((obj)->funcs_pointer->get_to_csid)(obj))
  588.  
  589. /**
  590.  * Set the "Convert From CSID" to the converter object.
  591.  * 
  592.  * There are no reason any code outside libi18n should call this. 
  593.  * We are considering move this into intlpriv.h. 
  594.  * Don't call this macro unless you are changing libi18n
  595.  *
  596.  * @param obj Specifies the converter object
  597.  * @param from_csid Specifies the Convert From CSID
  598.  * @see INTL_SetCCCFromCSID
  599.  */
  600. #define INTL_SetCCCFromCSID(obj,from_csid) \
  601.             (((obj)->funcs_pointer->set_from_csid)((obj),(from_csid)))
  602. /**
  603.  * Get the "Convert From CSID" from the converter object.
  604.  *
  605.  * @param obj Specifies the converter object
  606.  * @return the "Convert From CSID" stored in the converter object
  607.  * @see INTL_SetCCCFromCSID
  608.  */
  609. #define INTL_GetCCCFromCSID(obj) (((obj)->funcs_pointer->get_from_csid)(obj))
  610.  
  611. /**
  612.  * Set the "Return Value" to the converter object.
  613.  * 
  614.  * There are no reason any code outside libi18n should call this. 
  615.  * We are considering move this into intlpriv.h. 
  616.  * Don't call this macro unless you are changing libi18n
  617.  *
  618.  * @param obj Specifies the converter object
  619.  * @param retval Specifies the "Return Value"
  620.  * @see INTL_GetCCCRetval
  621.  */
  622. #define INTL_SetCCCRetval(obj,retval) \
  623.             (((obj)->funcs_pointer->set_retval)((obj),(retval)))
  624. /**
  625.  * Get the "Return Value" from the converter object.
  626.  * 
  627.  * There are no reason any code outside libi18n should call this. 
  628.  * We are considering move this into intlpriv.h. 
  629.  * Don't call this macro unless you are changing libi18n
  630.  *
  631.  * @param obj Specifies the converter object
  632.  * @return  the "Return Value" stored in the converter object
  633.  * @see INTL_SetCCCRetval
  634.  */
  635. #define INTL_GetCCCRetval(obj) (((obj)->funcs_pointer->get_retval)(obj))
  636.  
  637. /**
  638.  * Set the "Conversion Function" to the converter object.
  639.  * 
  640.  * There are no reason any code outside libi18n should call this. 
  641.  * We are considering move this into intlpriv.h. 
  642.  * Don't call this macro unless you are changing libi18n
  643.  *
  644.  * @param obj Specifies the converter object
  645.  * @param func Specifies the "Conversion Function" stored in the converter
  646.  *             object
  647.  * @see INTL_GetCCCCvtfunc
  648.  */
  649. #define INTL_SetCCCCvtfunc(obj,func) \
  650.                 (((obj)->funcs_pointer->set_cvtfunc)((obj),(func)))
  651.  
  652. /**
  653.  * Get the "Conversion Function" from the converter object.
  654.  * 
  655.  * @param obj Specifies the converter object
  656.  * @return  the "Conversion Function" stored in the converter object
  657.  * @see INTL_SetCCCCvtfunc
  658.  */
  659. #define INTL_GetCCCCvtfunc(obj) ((obj)->funcs_pointer->get_cvtfunc)(obj)
  660.  
  661. /**
  662.  * Set the "Report Auto Detect Result Function" to the converter object.
  663.  * 
  664.  * @param obj Specifies the converter object
  665.  * @param func Specifies the "Auto Detect Result Reporting Function" 
  666.  * @param closure Specifies the closure which will be pass to the "Auto
  667.  *                Detect Result Reporting Function" 
  668.  * @see INTL_CallCCCReportAutoDetect
  669.  */
  670. #define INTL_SetCCCReportAutoDetect(obj,func,closure) \
  671.     (((obj)->funcs_pointer->set_report_autodetect)((obj), (func), (closure)))
  672.  
  673. /**
  674.  * Call the "Report Auto Detect Result Function" associated with the 
  675.  * converter object.
  676.  * 
  677.  * @param obj Specifies the converter object
  678.  * @param doc_csid Specifies the document csid which be auto detected
  679.  * @see INTL_CallCCCReportAutoDetect
  680.  */
  681. #define INTL_CallCCCReportAutoDetect(obj,doc_csid) \
  682.         (((obj)->funcs_pointer->call_report_autodetect)((obj), (doc_csid)))
  683.  
  684. /**
  685.  * Set the "Default Document CSID" to the converter object.
  686.  * 
  687.  * There are no reason any code outside libi18n should call this. 
  688.  * We are considering move this into intlpriv.h. 
  689.  * Don't call this macro unless you are changing libi18n
  690.  *
  691.  * @param obj Specifies the converter object
  692.  * @param default_doc_csid Specifies the Default Document CSID
  693.  * @see  INTL_GetCCCDefaultCSID
  694.  */
  695. #define INTL_SetCCCDefaultCSID(obj,default_doc_csid) \
  696.         ((obj)->funcs_pointer->set_default_doc_csid)((obj), (default_doc_csid))
  697.  
  698. /**
  699.  * Get the "Default Document CSID" from the converter object.
  700.  * 
  701.  * There are no reason any code outside libi18n should call this. 
  702.  * We are considering move this into intlpriv.h. 
  703.  * Don't call this macro unless you are changing libi18n
  704.  *
  705.  * @param obj Specifies the converter object
  706.  * @return  the Default Document CSID stored in the converter object
  707.  * @see  INTL_GetCCCDefaultCSID
  708.  */
  709. #define INTL_GetCCCDefaultCSID(obj) \
  710.         (((obj)->funcs_pointer->get_default_doc_csid)(obj))
  711.  
  712. /*@}*/
  713. /*=======================================================*/
  714. /**@name CharSetID and Charset Name Mapping */
  715. /*@{*/
  716. /**
  717.  * Returns the preferred MIME charset name corresponding to the given
  718.  * charset ID.
  719.  *
  720.  * Charset names are registered by IANA (Internet Assigned Numbers Authority).
  721.  * The current charset name database can be found at:
  722.  *
  723.  * <A HREF=ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets>
  724.  *         ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets</A>.
  725.  *
  726.  * This function returns the charset name for the given Character Set ID
  727.  * which in most cases corresponds to the "(preferred MIME name)" registered
  728.  * with IANA.  This function may return private names not found in the
  729.  * registered. Private names start with "x-". See INTL_CharSetNameToID for 
  730.  * information about charset IDs.
  731.  *
  732.  * @param charSetID            Specifies the charset ID
  733.  * @param charset_return  Returns the corresponding charset name, max 128 bytes
  734.  * @see INTL_CharSetNameToID
  735.  */
  736. PUBLIC void INTL_CharSetIDToName(
  737.     int16 charSetID,
  738.     char *charset_return
  739. );
  740.  
  741. /**
  742.  * Returns the charset ID corresponding to the given charset name.
  743.  *
  744.  * The charset ID is a private 16-bit integer, described in
  745.  * ns/include/csid.h. If the given charset is unknown, CS_UNKNOWN is returned.
  746.  * If the given charset is NULL, CS_DEFAULT is returned. Charset names are not
  747.  * case-sensitive. See INTL_CharSetIDToName for a description of charset names.
  748.  *
  749.  * @param charset  Specifies the charset name
  750.  * @return the corresponding charset ID
  751.  * @see INTL_CharSetIDToName
  752.  */
  753. PUBLIC int16 INTL_CharSetNameToID(
  754.     char *charset
  755. );
  756.  
  757. /**
  758.  * Returns a pointer to the preferred MIME charset name corresponding 
  759.  * to the given charset ID.
  760.  *
  761.  * This function is similar to INTL_CharSetIDToName. It returns a pointer to
  762.  * the charset name. See INTL_CharSetIDToName for other details.
  763.  *
  764.  * @param charSetID  Specifies the charset ID
  765.  * @return The corresponding charset name
  766.  * @see INTL_CharSetIDToName
  767.  */
  768. PUBLIC unsigned char *INTL_CsidToCharsetNamePt(
  769.     int16 charSetID
  770. );
  771.  
  772. /**
  773.  * Returns the Java charset name corresponding to the given charset ID.
  774.  *
  775.  * The Java charset name is one that JDK 1.1 and up will understand.
  776.  * The Java name is defined in 
  777.  * <A HREF=
  778.  * http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303>
  779.  * http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303</A>
  780.  *
  781.  * @param charSetID       Specifies the charset ID
  782.  * @param charset_return  Returns the corresponding Java charset name,
  783.  *                        max 128 bytes
  784.  * @see INTL_CharSetIDToJavaCharSetName
  785.  */
  786. PUBLIC void INTL_CharSetIDToJavaName(
  787.     int16 charSetID,
  788.     char *charset_return
  789. );
  790.  
  791. /**
  792.  * Returns the Java charset name corresponding to the given charset ID.
  793.  *
  794.  * The Java charset name is a name used in JDK 1.1 and up.
  795.  * The Java name is defined in 
  796.  * <A HREF=
  797.  * http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303>
  798.  * http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303</A>
  799.  *
  800.  * @param charSetID  Specifies the charset ID
  801.  * @return the corresponding Java charset name
  802.  * @see INTL_CharSetIDToJavaName
  803.  */
  804. PUBLIC const char * PR_CALLBACK INTL_CharSetIDToJavaCharSetName(
  805.     int16 charSetID
  806. );
  807.  
  808. /**
  809.  * Returns a pointer to the Java charset name corresponding to
  810.  * the given charset ID.
  811.  *
  812.  * This function is similar to INTL_CharSetIDToJavaCharSetName. See
  813.  * INTL_CharSetIDToJavaCharSetName for further details.
  814.  *
  815.  * @param charSetID  Specifies the charset ID
  816.  * @return The corresponding Java charset name
  817.  * @see INTL_CharSetIDToJavaCharSetName
  818.  */
  819. PUBLIC unsigned char *INTL_CsidToJavaCharsetNamePt(
  820.     int16 charSetID
  821. );
  822.  
  823. /*@}*/
  824. /*=======================================================*/
  825. /**@name Character Set Properties */
  826. /*@{*/
  827.  
  828. /**
  829.  * Returns whether or not auto-detection is available for the given charset ID.
  830.  *
  831.  * For example, this routine will return TRUE for any of the Japanese charset
  832.  * IDs, since a Japanese auto-detection routine is available.
  833.  *
  834.  * @param csid  Specifies the charset ID
  835.  * @return Whether or not auto-detection is available for the charset ID
  836.  * @see INTL_GetCharCodeConverter
  837.  */
  838. PUBLIC XP_Bool INTL_CanAutoSelect(
  839.     int16 csid
  840. );
  841.  
  842. /**
  843.  * Returns the charset type.
  844.  *
  845.  * Returns the type of the given charset ID. The charset types are defined in
  846.  * csid.h.
  847.  *
  848.  * <UL>
  849.  * <LI>SINGLEBYTE: single-byte charset (e.g. ISO-8859-1, MacRoman)
  850.  * <LI>MULTIBYTE: multi-byte charset (e.g. Shift-JIS, Big5)
  851.  * <LI>STATEFUL: stateful charset (e.g. ISO-2022-JP, UTF-7)
  852.  * <LI>WIDECHAR: wide character charset (e.g. UCS-2, UCS-4)
  853.  * </UL>
  854.  *
  855.  * @param charsetid Specifies the charset ID.
  856.  * @return The charset type. 
  857.  */
  858. #define INTL_CharSetType(charsetid) (charsetid & 0x700)
  859.  
  860. /*@}*/
  861. /*=======================================================*/
  862. /**@name Finding Character Boundaries */
  863. /*@{*/
  864.  
  865. /**
  866.  * Returns the number of bytes in the given character.
  867.  *
  868.  * This function checks for zero bytes within the text, returning the actual
  869.  * length even if the preceding byte(s) would normally indicate a longer
  870.  * multibyte character.
  871.  *
  872.  * @param charSetID  Specifies the charset ID of the text
  873.  * @param pstr       Specifies the 1st byte of the character
  874.  * @return The number of bytes in the given character
  875.  * @see INTL_IsLeadByte
  876.  */
  877. PUBLIC int INTL_CharLen(
  878.     int charSetID,
  879.     unsigned char *pstr
  880. );
  881.  
  882. /**
  883.  * Returns number of bytes in given character, minus 1.
  884.  *
  885.  * This function returns the number of bytes in a character that starts with
  886.  * the given byte, minus 1. I.e. for a single-byte character, it returns zero.
  887.  * For a double-byte character, it returns 1. And so on. Hence, this function
  888.  * returns a non-zero value if the given byte is the "lead byte" of a multibyte
  889.  * character.
  890.  * This function should not be confused with Windows API isleadbyte().
  891.  *
  892.  * @param charSetID  Specifies the charset ID of the text
  893.  * @param ch         Specifies the first byte of a character in the text
  894.  * @return The number of bytes in the given character, minus 1
  895.  * @see INTL_CharLen
  896.  */
  897. PUBLIC int 
  898. #ifdef NSPR20
  899. PR_CALLBACK 
  900. #endif
  901. INTL_IsLeadByte(
  902.     int charSetID,
  903.     unsigned char ch
  904. );
  905.  
  906. /**
  907.  * Returns a pointer to the 1st byte of the next character.
  908.  *
  909.  * This function checks for zero bytes and returns pstr+1 if any are found,
  910.  * even if the preceding byte(s) would normally indicate a longer character.
  911.  *
  912.  * @param charSetID  Specifies the charset ID of the text
  913.  * @param pstr       Specifies the 1st byte of any previous character
  914.  * @return The 1st byte of the next character
  915.  * @see INTL_CharLen
  916.  */
  917. PUBLIC char *INTL_NextChar(
  918.     int charSetID,
  919.     char *pstr
  920. );
  921.  
  922. /**
  923.  * Returns the number of the byte pointed to by the given position.
  924.  *
  925.  * Determines whether the byte at the given position is the 1st, 2nd, 3rd
  926.  * or 4th byte of the character at that position. The pstr pointer must point
  927.  * to the first byte of any preceding character in the string. The pos
  928.  * position must be greater than zero, and is the index into pstr plus one.
  929.  * I.e. the byte at pstr[0] has pos 1.
  930.  *
  931.  * If pos points to the only byte in a single-byte character, this function
  932.  * returns zero. Otherwise, if pos points to the 1st byte, it returns 1. If
  933.  * pos points to the 2nd byte, it returns 2. And so on.
  934.  *
  935.  * @param charSetID  Specifies the charset ID of the given text
  936.  * @param pstr       Specifies the beginning of a character in the string
  937.  * @param pos        Specifies the byte position within the string
  938.  * @return The number of the byte at the given position
  939.  * @see INTL_CharLen
  940.  */
  941. PUBLIC int INTL_NthByteOfChar(
  942.     int charSetID,
  943.     char *pstr,
  944.     int pos
  945. );
  946.  
  947. /**
  948.  * Returns the byte index of the next character.
  949.  *
  950.  * Given the position of a character in some text, this function returns the
  951.  * position of the next character.
  952.  *
  953.  * @param charSetID  Specifies the charset ID of the text
  954.  * @param text  Specifies the beginning of the text
  955.  * @param pos   Specifies the current position within the text
  956.  * @return The position of the next character
  957.  * @see INTL_PrevCharIdxInText
  958.  */
  959. PUBLIC int INTL_NextCharIdxInText(
  960.     int16 charSetID,
  961.     unsigned char *text,
  962.     int pos
  963. );
  964.  
  965. /**
  966.  * Returns the byte index of the previous character.
  967.  *
  968.  * Given the position of a character in some text, this function returns the
  969.  * position of the previous character.
  970.  *
  971.  * @param charSetID  Specifies the charset ID of the text
  972.  * @param text  Specifies the beginning of the text
  973.  * @param pos   Specifies the current position within the text
  974.  * @return The position of the previous character
  975.  * @see INTL_NextCharIdxInText
  976.  */
  977. PUBLIC int INTL_PrevCharIdxInText(
  978.     int16 charSetID,
  979.     unsigned char *text,
  980.     int pos
  981. );
  982.  
  983.  
  984. /**
  985.  * Convert number of bytes to number of characters.
  986.  *
  987.  * Given a number of bytes in a given string, this function determines the
  988.  * number of characters.
  989.  *
  990.  * @param charSetID       Specifies the charset ID of the text
  991.  * @param text       Specifies the text
  992.  * @param byteCount  Specifies the number of bytes
  993.  * @return The number of characters
  994.  * @see INTL_TextCharLenToByteCount
  995.  */
  996. PUBLIC int32 INTL_TextByteCountToCharLen(
  997.     int16 charSetID,
  998.     unsigned char *text,
  999.     uint32 byteCount
  1000. );
  1001.  
  1002. /**
  1003.  * Convert number of characters to number of bytes.
  1004.  *
  1005.  * Given a number of characters in a given string, this function determines the
  1006.  * number of bytes.
  1007.  *
  1008.  * @param charSetID     Specifies the charset ID of the text
  1009.  * @param text     Specifies the text
  1010.  * @param charLen  Specifies the number of characters
  1011.  * @return The number of bytes
  1012.  * @see INTL_TextByteCountToCharLen
  1013.  */
  1014. PUBLIC int32 INTL_TextCharLenToByteCount(
  1015.     int16 charSetID,
  1016.     unsigned char *text,
  1017.     uint32 charLen
  1018. );
  1019.  
  1020.  
  1021. /**
  1022.  * Returns the byte index of the next character.
  1023.  *
  1024.  * Given the position of any byte of any character in some text, this function
  1025.  * returns the position of the 1st byte of the next character. The
  1026.  * difference between this function and INTL_NextCharIdxInText is that this
  1027.  * function will accept the position of any byte of a character rather than
  1028.  * just the 1st byte of a character.
  1029.  *
  1030.  * @param charSetID  Specifies the charset ID of the text
  1031.  * @param str   Specifies the beginning of the text
  1032.  * @param pos   Specifies any byte of any character
  1033.  * @return The index of the next character
  1034.  * @see INTL_NextCharIdxInText, INTL_PrevCharIdx
  1035.  */
  1036. PUBLIC int INTL_NextCharIdx(
  1037.     int16 charSetID,
  1038.     unsigned char *str,
  1039.     int pos
  1040. );
  1041.  
  1042. /**
  1043.  * Returns the byte index of the previous character.
  1044.  *
  1045.  * Given the position of any byte of any character in some text, this function
  1046.  * returns the position of the 1st byte of the previous character. The
  1047.  * difference between this function and INTL_PrevCharIdxInText is that this
  1048.  * function will accept the position of any byte of a character rather than
  1049.  * just the 1st byte of a character.
  1050.  *
  1051.  * @param charSetID  Specifies the charset ID of the text
  1052.  * @param str   Specifies the beginning of the text
  1053.  * @param pos   Specifies any byte of any character
  1054.  * @return The index of the previous character
  1055.  * @see INTL_PrevCharIdxInText, INTL_NextCharIdx
  1056.  */
  1057. PUBLIC int INTL_PrevCharIdx(
  1058.     int16 charSetID,
  1059.     unsigned char *str,
  1060.     int pos
  1061. );
  1062.  
  1063. /*@}*/
  1064. /*=======================================================*/
  1065. /**@name Single-Byte Charset Conversion Tables (Obsolescent) */
  1066. /*@{*/
  1067.  
  1068. /**
  1069.  * Free a single-byte charset conversion table.
  1070.  *
  1071.  * This is not really a public function. However, ns/sun-java/awt/macos needs
  1072.  * it, so we have to put it here.
  1073.  *
  1074.  * @see INTL_GetSingleByteTable
  1075.  * @version DEPRECATED. Obsolescent. Use INTL_DestroyCharCodeConverter instead.
  1076.  */
  1077. MODULE_PRIVATE void INTL_FreeSingleByteTable(char **cvthdl);
  1078.  
  1079. /**
  1080.  * Get a single-byte charset conversion table.
  1081.  *
  1082.  * This is not really a public function. However, ns/sun-java/awt/macos needs
  1083.  * it, so we have to put it here.
  1084.  *
  1085.  * @see INTL_FreeSingleByteTable
  1086.  * @see INTL_LockTable
  1087.  * @version DEPRECATED. Obsolescent. Use INTL_GetCharCodeConverter instead.
  1088.  */
  1089. MODULE_PRIVATE char **INTL_GetSingleByteTable(
  1090.     int16 fromcsid, 
  1091.     int16 tocsid,
  1092.     int32 func_ctx
  1093. );
  1094.  
  1095. /**
  1096.  * Lock the given single-byte charset conversion table in memory.
  1097.  *
  1098.  * This is not really a public function. However, ns/sun-java/awt/macos needs
  1099.  * it, so we have to put it here.
  1100.  *
  1101.  * @see INTL_GetSingleByteTable
  1102.  * @version DEPRECATED. Obsolescent. See INTL_GetSingleByteTable.
  1103.  */
  1104. MODULE_PRIVATE char *INTL_LockTable(char **cvthdl);
  1105.  
  1106. /*@}*/
  1107. /*=======================================================*/
  1108. /**@name HTTP Headers */
  1109. /*@{*/
  1110.  
  1111. /**
  1112.  * Return the AcceptLanguage preference.
  1113.  *
  1114.  * Get the HTTP Accept-Language header from preference settings.
  1115.  * 
  1116.  * @return    Accept-Language header (null-terminated string).
  1117.  * @see       INTL_GetAcceptCharset
  1118.  */
  1119. PUBLIC char *INTL_GetAcceptLanguage(void); 
  1120.  
  1121. /**
  1122.  * Return the AcceptCharset preference.
  1123.  *
  1124.  * Get the HTTP Accept-Charset header from preference settings.
  1125.  * 
  1126.  * @return    Accept-Charset header (null-terminated string).
  1127.  * @see       INTL_GetAcceptLanguage
  1128.  */
  1129. PUBLIC char *INTL_GetAcceptCharset(void);
  1130.  
  1131. /*@}*/
  1132. /*=======================================================*/
  1133. /**@name Message Header Processing */
  1134. /*@{*/
  1135.  
  1136. /**
  1137.  * Decode and convert message header.
  1138.  *
  1139.  * This is a convenience macro that calls INTL_DecodeMimePartIIStr. It is
  1140.  * similar to INTL_DecodeMimePartIIStr, with the exception that it always
  1141.  * attempts to allocate a new buffer instead of returning the original input
  1142.  * buffer where the decoding/conversion may have been performed in place.
  1143.  *
  1144.  * @param r Returns the decoded/converted message header
  1145.  * @param b Specifies the message header
  1146.  * @param c Specifies the target window charset ID
  1147.  * @param f Specifies whether to convert the string into the wincsid or not
  1148.  * @return the decoded/converted message header (r)
  1149.  * @see INTL_DecodeMimePartIIStr
  1150.  */
  1151. #define INTL_DECODE_MIME_PART_II(r,b,c,f)  \
  1152.     (r = INTL_DecodeMimePartIIStr((b),(c),(f))), \
  1153.     ((NULL!=r) && ((r)!=(b))) ? r : (r = XP_STRDUP(b))
  1154.  
  1155. /**
  1156.  * Decode and convert message header.
  1157.  *
  1158.  * If the message header contains an RFC 2047 encoded-word, that word is
  1159.  * decoded. Then it performs charset conversion if the dontConvert parameter is
  1160.  * false. Otherwise, it will only decode the string and return. The conversion
  1161.  * may happen later in the process. The flag is needed to work around a double
  1162.  * conversion problem.
  1163.  *
  1164.  * @param header       Specifies the message string to be decoded/converted.
  1165.  * @param wincsid      Specifies the target window charset ID.
  1166.  * @param dontConvert  Specifies whether to convert the string into the wincsid
  1167.  *                     or not. If the value is true, then it will only decode 
  1168.  *                     any RFC 2047 encoded-words, without converting their
  1169.  *                     charsets. If the value is false, then it will decode RFC
  1170.  *                     2047 encoded-words AND convert them into the specified
  1171.  *                     wincsid.
  1172.  * @return Decoded and/or converted message header. If the return value is
  1173.  *         different from the input buffer, the caller must free the output
  1174.  *         buffer by calling XP_FREE when it is no longer needed.
  1175.  * @see INTL_DECODE_MIME_PART_II
  1176.  * @see INTL_EncodeMimePartIIStr
  1177.  * @see INTL_EncodeMimePartIIStr_VarLen
  1178.  */
  1179. PUBLIC char *INTL_DecodeMimePartIIStr(
  1180.     const char *header, 
  1181.     int16 wincsid, 
  1182.     XP_Bool dontConvert
  1183. );
  1184.  
  1185. /**
  1186.  * Convert and encode message header.
  1187.  *
  1188.  * Convert the string into an encoding used in Internet messages and encode 
  1189.  * them as per RFC 2047. It will (1) perform the codeset conversion and 
  1190.  * (2) RFC 1522 encoding algorithm (if bUseMime is true or the internet message
  1191.  * encoding is ISO-2022-KR or ISO-2022-JP). This is a restrict version of 
  1192.  * INTL_EncodeMimePartIIStr_VarLen which always use 72 for encodedWordSize
  1193.  *
  1194.  * @param    header     Specifies the RFC 1522 string to be encoded.
  1195.  * @param    wincsid    Specifies the source encoding
  1196.  * @param    bUseMime   Specifies apply RFC 1522 rule or not. If the value is 
  1197.  *                      true or the internet message encoding is ISO-2022-JP 
  1198.  *                      or ISO-2022-KR, then it perform RFC1522 encoding after
  1199.  *                      convert the text into the internet message encoding, 
  1200.  *                      Otherwise, it only convert the text into internet
  1201.  *                      message encoding.
  1202.  * @return   the encoded/converted header. The caller need to free this by
  1203.  *           calling XP_FREE when the result is no longer needed.
  1204.  * @see      INTL_DecodeMimePartIIStr
  1205.  * @see      INTL_EncodeMimePartIIStr_VarLen
  1206.  */
  1207. PUBLIC char *INTL_EncodeMimePartIIStr(
  1208.     char *header, 
  1209.     int16 wincsid, 
  1210.     XP_Bool bUseMime
  1211. );
  1212.  
  1213. /**
  1214.  * Convert and encode text into RFC 1522 header.
  1215.  *
  1216.  * Convert the string into the encoding used in internet message and encode 
  1217.  * them into RFC 1522 form. It will (1) perform the codeset conversion and 
  1218.  * (2) RFC 1522 encoding algorithm (if bUseMime is true or the internet message
  1219.  * encoding is ISO-2022-KR or ISO-2022-JP). It is same as
  1220.  * INTL_EncodeMimePartIIStr except it allow encodedWordSize value other than 72.
  1221.  *
  1222.  * @param header           Specifies the RFC 1522 string to be encoded.
  1223.  * @param wincsid          Specifies the source encoding
  1224.  * @param bUseMime         Specifies apply RFC 1522 rule or not. If the value
  1225.  *                         is true or the internet message encoding is
  1226.  *                         ISO-2022-JP or ISO-2022-KR, then it perform RFC1522
  1227.  *                         encoding after convert the text into the internet
  1228.  *                         message encoding. Otherwise, it only convert the
  1229.  *                         text into internet message encoding.
  1230.  * @param encodedWordSize  Specifies the maximum length of encoded word.
  1231.  * @return the encoded/converted header. The caller need to free this by
  1232.  *         calling XP_FREE when the result is no longer needed.
  1233.  * @see INTL_DecodeMimePartIIStr
  1234.  * @see INTL_EncodeMimePartIIStr
  1235.  */
  1236. PUBLIC char *INTL_EncodeMimePartIIStr_VarLen(
  1237.     char * header, 
  1238.     int16 wincsid, 
  1239.     XP_Bool bUseMime, 
  1240.     int encodedWordSize
  1241. );
  1242.  
  1243. /**
  1244.  * [OBSOLETE!!!] We should use the INTL_DecodeMimePartIIStr instead of this. 
  1245.  * We keep this Macro until we change all the callers.
  1246.  * Please do not use this in the future.
  1247.  */
  1248. #define IntlDecodeMimePartIIStr INTL_DecodeMimePartIIStr
  1249.  
  1250. /**
  1251.  * [OBSOLETE!!!] We should use the INTL_EncodeMimePartIIStr instead of this. 
  1252.  * We keep this Macro until we change all the callers.
  1253.  * Please do not use this in the future.
  1254.  */
  1255. #define IntlEncodeMimePartIIStr INTL_EncodeMimePartIIStr
  1256.  
  1257.  
  1258.  
  1259. /**
  1260.  * Set a private flag to remember a state mail/news. 
  1261.  *
  1262.  * A flag is used inside libi18n to remember whether we are sending mail or
  1263.  * news. This is because mail encoding and news encoding is different 
  1264.  * for Korean.
  1265.  * Note that this should be used carefully since it depends on
  1266.  * the current mail/news implementation.
  1267.  * This is really a hack. It will be removed in the future.
  1268.  * 
  1269.  * @param toNews     Boolean value to be set to the private flag.
  1270.  */
  1271. PUBLIC void
  1272. INTL_MessageSendToNews(XP_Bool toNews);
  1273.  
  1274.  
  1275. /**
  1276.  * Convert a string from RFC1522 encoded header and normalize it, by dropping 
  1277.  * the case of the character.
  1278.  *
  1279.  * The return value could be used with INTL_StrContains, INTL_StrIs,
  1280.  * INTL_StrBeginWith or INTL_StrEndWith to perform string matching. This
  1281.  * function will normalize a string by dropping the case of character according
  1282.  * to the csid the caller passed in. It will also ignore CR and LF characters.
  1283.  *
  1284.  * @param    csid    Specifies the encoding of str
  1285.  * @param    str     Specifies the to-be-normalized string.
  1286.  * @return   a normalized string which could be used in INTL_StrContains, 
  1287.  *           INTL_StrIs , INTL_StrBeginWith and INTL_StrEndWith The caller 
  1288.  *           should free it by calling XP_FREE when it is not needed.
  1289.  * @see      INTL_GetNormalizeStr
  1290.  * @see      INTL_StrContains
  1291.  * @see      INTL_StrIs
  1292.  * @see      INTL_StrBeginWith
  1293.  * @see      INTL_StrEndWith
  1294.  */
  1295. PUBLIC unsigned char* INTL_GetNormalizeStrFromRFC1522(
  1296.     int16 csid, 
  1297.     unsigned char* rfc1522header
  1298. );
  1299.  
  1300.  
  1301. /*@}*/
  1302. /*=======================================================*/
  1303. /**@name Unicode (UCS-2) Strings */
  1304. /*@{*/
  1305.  
  1306. /**
  1307.  * Unicode character typedef.
  1308.  *
  1309.  * This is used to represent a 16-bit Unicode (UCS-2) character.
  1310.  */
  1311. typedef uint16 INTL_Unicode;
  1312.  
  1313. /**
  1314.  * Return the length of a Unicode string.
  1315.  *
  1316.  * The given Unicode string must be terminated by U+0000.
  1317.  *
  1318.  * @param  ustr  Specifies the Unicode string
  1319.  * @return The length of ustr in UCS-2 units, not bytes
  1320.  */
  1321. PUBLIC uint32 INTL_UnicodeLen(INTL_Unicode *ustr);
  1322.  
  1323. /*@}*/
  1324. /*=======================================================*/
  1325. /**@name Compound Strings */
  1326. /*@{*/
  1327.  
  1328. /**
  1329.  * A typedef for encoding IDs (charset IDs).
  1330.  *
  1331.  * These are equivalent to charset IDs in the current code base.
  1332.  */
  1333. typedef uint16 INTL_Encoding_ID;
  1334.  
  1335. /*
  1336.  * See comment below.
  1337.  */
  1338. typedef struct INTL_CompoundStr INTL_CompoundStr;
  1339.  
  1340. /**
  1341.  * Compound String.
  1342.  * 
  1343.  * A Compound String is constructed as a linked list. Each node has two fields
  1344.  * and a pointer to the next node. The two fields store a pointer to a
  1345.  * uniformly encoded piece of text and the encoding of that text.
  1346.  */
  1347. struct INTL_CompoundStr {
  1348.     /** The encoding of the text in this node. */
  1349.     INTL_Encoding_ID encoding;
  1350.     /** The uniformly encoded text. */
  1351.     unsigned char    *text;
  1352.     /** A pointer to the next node. NULL if there are no more nodes. */
  1353.     INTL_CompoundStr *next;
  1354. };
  1355.  
  1356. /**
  1357.  * INTL_CompoundStrIterator should really be opaque, but we need to change the
  1358.  * callers first. 
  1359.  */
  1360. typedef INTL_CompoundStr *INTL_CompoundStrIterator; 
  1361.  
  1362. /** 
  1363.  * Construct an INTL_CompoundStr, given some text and its encoding.
  1364.  *
  1365.  * Use this with INTL_CompoundStrCat to create multi-encoding
  1366.  * INTL_CompoundStrs.
  1367.  *
  1368.  * @param inencoding  Specifies the encoding of intext.
  1369.  * @param intext      Specifies the text to be stored. Null-terminated string.
  1370.  * @return INTL_CompoundStr. The caller should use INTL_CompoundStrDestroy to 
  1371.  *         destroy it when it is no longer needed.
  1372.  * @see INTL_CompoundStrDestroy
  1373.  */
  1374. PUBLIC INTL_CompoundStr* INTL_CompoundStrFromStr(
  1375.     INTL_Encoding_ID inencoding, 
  1376.     unsigned char* intext
  1377. );
  1378.  
  1379. /**
  1380.  * Convert the given Unicode string to an INTL_CompoundStr.
  1381.  *
  1382.  * This routine uses information provided by the front end through
  1383.  * INTL_SetUnicodeCSIDList. It converts from Unicode to substrings in the
  1384.  * encodings that the front end said were available (in the font system).
  1385.  *
  1386.  * @param inunicode  Specifies the Unicode text to be converted.
  1387.  * @param inlen      Specifies the length of inunicode in UCS-2 units,
  1388.  *                   not bytes.
  1389.  * @return INTL_CompoundStr. The caller should use INTL_CompoundStrDestroy to 
  1390.  *         destroy it when it is no longer needed.
  1391.  * @see INTL_CompoundStrDestroy
  1392.  */
  1393. PUBLIC INTL_CompoundStr* INTL_CompoundStrFromUnicode(
  1394.     INTL_Unicode* inunicode, 
  1395.     uint32 inlen
  1396. );
  1397.  
  1398. /**
  1399.  * Destroy an INTL_CompoundStr.
  1400.  *
  1401.  * This function destroys the INTL_CompoundStr created by 
  1402.  * INTL_CompoundStrFromStr or INTL_CompoundStrFromUnicode.
  1403.  *
  1404.  * @param Specifies the INTL_CompoundStr to be destroyed.
  1405.  * @see INTL_CompoundStrFromStr
  1406.  * @see INTL_CompoundStrFromUnicode
  1407.  */
  1408. PUBLIC void INTL_CompoundStrDestroy(INTL_CompoundStr* This);
  1409.  
  1410. /**
  1411.  * Concatenate two INTL_CompoundStrs.
  1412.  *
  1413.  * @param    s1    Specifies the first INTL_CompoundStr and returns the
  1414.  *                 concatenated INTL_CompoundStr
  1415.  * @param    s2    Specifies the second INTL_CompoundStr
  1416.  * @see      INTL_CompoundStrDestroy
  1417.  */
  1418. PUBLIC void INTL_CompoundStrCat(
  1419.     INTL_CompoundStr* s1, 
  1420.     INTL_CompoundStr* s2
  1421. );
  1422.  
  1423. /**
  1424.  * Clone an INTL_CompoundStr.
  1425.  *
  1426.  * This function clones an INTL_CompoundStr.
  1427.  *
  1428.  * @param s  Specifies the INTL_CompoundStr to be cloned
  1429.  * @return a cloned INTL_CompoundStr. The caller should use
  1430.  *         INTL_CompoundStrDestroy to destroy it when it is no longer needed.
  1431.  * @see INTL_CompoundStrDestroy
  1432.  */
  1433. PUBLIC INTL_CompoundStr* INTL_CompoundStrClone(INTL_CompoundStr* s1);
  1434.  
  1435. /**
  1436.  * Start iterating an INTL_CompoundStr.
  1437.  *
  1438.  * Initialize the iterating state and perform the first iteration of an
  1439.  * INTL_CompoundStr.
  1440.  *
  1441.  * @param This         Specifies the INTL_CompoundStr to be iterated
  1442.  * @param outencoding  Returns the encoding of the first node
  1443.  * @param outtext      Returns the text of the first node. The caller should
  1444.  *                     not free it.
  1445.  * @return INTL_CompoundStrIterator. The state of the iteration. Should be
  1446.  *         passed to INTL_CompoundStrNextStr. NULL if the iteration is
  1447.  *         finished.
  1448.  * @see INTL_CompoundStrNextStr
  1449.  */
  1450. PUBLIC INTL_CompoundStrIterator INTL_CompoundStrFirstStr(
  1451.     INTL_CompoundStr* This, 
  1452.     INTL_Encoding_ID *outencoding, 
  1453.     unsigned char** outtext
  1454. );
  1455.  
  1456. /**
  1457.  * Iterating INTL_CompoundStr.
  1458.  *
  1459.  * This function iterates through the INTL_CompoundStr for the given 
  1460.  * INTL_CompoundStrIterator.
  1461.  *
  1462.  * @param    iterator    Specifies the INTL_CompoundStrIterator
  1463.  * @param    outencoding    Returns the encoding of the current node
  1464.  * @param    outtext    Returns the text of the current node. The caller should 
  1465.  *                      not free it.
  1466.  * @return INTL_CompoundStrIterator. The state of the iteration. Should be
  1467.  *         passed to INTL_CompoundStrNextStr. NULL if the iteration is
  1468.  *         finished.
  1469.  * @see INTL_CompoundStrFirstStr
  1470.  */
  1471. PUBLIC INTL_CompoundStrIterator INTL_CompoundStrNextStr(
  1472.     INTL_CompoundStrIterator iterator, 
  1473.     INTL_Encoding_ID *outencoding, 
  1474.     unsigned char** outtext
  1475. );
  1476.  
  1477. /*@}*/
  1478. /*=======================================================*/
  1479. /**@name Unicode Conversion */
  1480. /*@{*/
  1481. /** 
  1482.  * An opaque data object used to iterate through Unicode text for 
  1483.  * conversion to font encodings.
  1484.  *
  1485.  * See also the functions that use this object.
  1486.  *
  1487.  * @see INTL_UnicodeToStrIteratorCreate
  1488.  * @see INTL_UnicodeToStrIterate
  1489.  * @see INTL_UnicodeToStrIteratorDestroy
  1490.  *
  1491. */
  1492. typedef void* INTL_UnicodeToStrIterator ;
  1493.  
  1494. /**
  1495.  * Create an INTL_UnicodeToStrIterator and iterate through it once.
  1496.  *
  1497.  * This function creates an INTL_UnicodeToStrIterator and iterates through it
  1498.  * once to get the first element of Unicode text for font encoding conversion.
  1499.  * The function uses the prioritized Character Set ID list (CSIDList) to
  1500.  * decide which font encoding it will convert to. The iteration stops if the
  1501.  * whole Unicode string is converted. Otherwise, it continues iterating and
  1502.  * uses the next charset in the CSIDlist to convert the Unicode text.
  1503.  *
  1504.  * @param    ustr        Specifies Unicode string to be converted
  1505.  * @param    ustrlen    Specifies length of ustr in UCS-2 units not bytes
  1506.  * @param    encoding    Returns the encoding of the first element. 
  1507.  *                        Returns 0 if there are no more to iterate.
  1508.  * @param    dest        Specifies the buffer for output and returns the
  1509.  *                        converted string for the first iteration
  1510.  * @param    destbuflen    Specifies the length of dest in bytes
  1511.  * @return               Iterator which keeps the iteration state
  1512.  * @see      INTL_GetUnicodeCSIDList
  1513.  * @see      INTL_SetUnicodeCSIDList
  1514.  * @see      INTL_UnicodeToStrIterate
  1515.  * @see      INTL_UnicodeToStrIteratorDestroy
  1516.  * @see      INTL_GetUnicodeCharsetList
  1517.  */
  1518. PUBLIC INTL_UnicodeToStrIterator INTL_UnicodeToStrIteratorCreate(
  1519.     INTL_Unicode* ustr,
  1520.     uint32 ustrlen,
  1521.     INTL_Encoding_ID *encoding,
  1522.     unsigned char* dest, 
  1523.     uint32 destbuflen
  1524. );
  1525.  
  1526. /**
  1527.  * Iterate through a Unicode object and convert to font encoding.
  1528.  * 
  1529.  * Iterate the INTL_UnicodeToStrIterator to get Unicode to font encoding
  1530.  * conversion.
  1531.  *
  1532.  * @param iterator        Specifies iterator that keeps the last iteration state
  1533.  * @param encoding        Returns the encoding of the first element. Returns 0
  1534.  *                        if there are no more to iterate.
  1535.  * @param dest            Specifies the buffer for output and returns the
  1536.  *                        converted string for the current iteration
  1537.  * @param destbuflen    Specifies the length of dest in bytes
  1538.  * @return                0 if there are no more elements to iterate.
  1539.  * @see INTL_GetUnicodeCSIDList
  1540.  * @see INTL_SetUnicodeCSIDList
  1541.  * @see INTL_UnicodeToStrIteratorCreate
  1542.  * @see INTL_UnicodeToStrIteratorDestroy
  1543.  * @see INTL_GetUnicodeCharsetList
  1544.  */
  1545. PUBLIC int INTL_UnicodeToStrIterate(
  1546.     INTL_UnicodeToStrIterator iterator,
  1547.     INTL_Encoding_ID *encoding,
  1548.     unsigned char* dest, 
  1549.     uint32 destbuflen
  1550. );
  1551.  
  1552. /**
  1553.  * Destroy an INTL_UnicodeToStrIterator.
  1554.  *
  1555.  * This function destroys the INTL_UnicodeToStrIterator created by 
  1556.  * INTL_UnicodeToStrIterateCreate.
  1557.  *
  1558.  * @param    iterator    Specifies the iterator to be destroyed
  1559.  * @see      INTL_GetUnicodeCSIDList
  1560.  * @see      INTL_SetUnicodeCSIDList
  1561.  * @see      INTL_UnicodeToStrIteratorCreate
  1562.  * @see      INTL_UnicodeToStrIterate
  1563.  * @see      INTL_GetUnicodeCharsetList
  1564.  */
  1565. PUBLIC void INTL_UnicodeToStrIteratorDestroy(
  1566.     INTL_UnicodeToStrIterator iterator
  1567. );
  1568.  
  1569. /**
  1570.  * Return memory requirement for INTL_UnicodeToStr.
  1571.  *
  1572.  * Returns the maximum memory required for text converted from a Unicode
  1573.  * string to a specified encoding. Call this to prepare memory for
  1574.  * INTL_UnicodeToStr.
  1575.  *
  1576.  * @param    encoding    Specifies the target encoding
  1577.  * @param    ustr        Specifies the buffer containing UCS-2 data
  1578.  * @param    ustrlen    Specifies the valid length of ustr in UCS-2 units
  1579.  *                        not bytes
  1580.  * @return                Number of bytes needed to store the converted result
  1581.  * @see      INTL_UnicodeToStr
  1582.  */
  1583. PUBLIC uint32 INTL_UnicodeToStrLen(
  1584.     INTL_Encoding_ID encoding,
  1585.     INTL_Unicode* ustr,
  1586.     uint32 ustrlen
  1587. );
  1588.  
  1589. /**
  1590.  * Convert Unicode string to a specified encoding.
  1591.  *
  1592.  * The caller needs to call INTL_UnicodeToStrLen first to prepare memory and
  1593.  * pass into dest.
  1594.  *
  1595.  * @param    encoding    Specifies the target encoding
  1596.  * @param    ustr        Specifies the buffer containing UCS-2 data
  1597.  * @param    ustrlen    Specifies the valid length of ustr in UCS-2 units
  1598.  *                       not bytes
  1599.  * @param    dest        Specifies the buffer for the converted text and 
  1600.  *                      returns the converted text
  1601.  * @param    destbuflen    Specifies the size of dest in bytes
  1602.  * @see INTL_UnicodeToStrLen
  1603.  */
  1604. PUBLIC void    INTL_UnicodeToStr(
  1605.     INTL_Encoding_ID encoding,
  1606.     INTL_Unicode* ustr, 
  1607.     uint32 ustrlen,
  1608.     unsigned char* dest, 
  1609.     uint32 destbuflen
  1610. );
  1611.  
  1612. /**
  1613.  * Convert Unicode to text in one encoding by trial and error.
  1614.  * 
  1615.  * This routine tries to convert the given Unicode string into text of one
  1616.  * non-Unicode encoding. This is a trial and error function which may be 
  1617.  * slow in "THE WORST CASE". However, it does it's best in the best case and
  1618.  * average case. 
  1619.  *
  1620.  * @param    ustr        Specifies the buffer containing UCS-2 data
  1621.  * @param    ustrlen    Specifies the valid length of ustr in UCS-2 units
  1622.  *                       not bytes
  1623.  * @param    dest        Specifies the buffer for the converted text and 
  1624.  *                       returns the converted text
  1625.  * @return                Encoding of the converted text
  1626.  */
  1627. PUBLIC INTL_Encoding_ID    INTL_UnicodeToEncodingStr(
  1628.     INTL_Unicode*    ustr,
  1629.     uint32  ustrlen,
  1630.     unsigned char*   dest,
  1631.     uint32           destbuflen
  1632. );
  1633.  
  1634. /**
  1635.  * Return memory requirement for INTL_StrToUnicode.
  1636.  *
  1637.  * Return the maximum memory requirement for text converted from the 
  1638.  * specified encoding to Unicode. Call this to prepare memory for 
  1639.  * INTL_StrToUnicode. The difference between INTL_TextToUnicodeLen is
  1640.  * the input string is specified by a NULL terminated string. 
  1641.  *
  1642.  * @param    encoding    Specifies the encoding of text in src
  1643.  * @param    src        Specifies the text to be converted
  1644.  * @return               Size of Unicode to store the converted output (in
  1645.  *                        UCS-2 units not bytes)
  1646.  * @see      INTL_StrToUnicode
  1647.  * @see      INTL_TextToUnicodeLen
  1648.  */
  1649. PUBLIC uint32 INTL_StrToUnicodeLen(
  1650.     INTL_Encoding_ID encoding,
  1651.     unsigned char* src 
  1652. );
  1653.  
  1654. /**
  1655.  * Convert non-Unicode text to Unicode. 
  1656.  *
  1657.  * The caller needs to call INTL_StrToUnicodeLen first to prepare memory and
  1658.  * pass into ustr. The difference between INTL_TextToUnicode is the input
  1659.  * string is specified by a NULL terminated string.
  1660.  *
  1661.  * @param encoding    Specifies the encoding of text in src
  1662.  * @param src        Specifies the text to be converted
  1663.  * @param ustr        Specifies the buffer for Unicode and returns the converted
  1664.  *                  Unicode
  1665.  * @param ubuflen    Specifies the size of the ustr in UCS-2 units not bytes
  1666.  * @return            Size of the converted Unicode (in UCS-2 units not bytes)
  1667.  * @see INTL_StrToUnicodeLen
  1668.  * @see INTL_TextToUnicode
  1669.  */
  1670. PUBLIC uint32    INTL_StrToUnicode(
  1671.     INTL_Encoding_ID encoding,
  1672.     unsigned char* src, 
  1673.     INTL_Unicode* ustr, 
  1674.     uint32 ubuflen
  1675. );
  1676.  
  1677. /**
  1678.  * Return memory requirement for INTL_TextToUnicode.
  1679.  *
  1680.  * Return the maximum memory requirement for text converted from a specified 
  1681.  * encoding to Unicode . Call this to prepare memory for INTL_TextToUnicode. 
  1682.  * The difference between INTL_StrToUnicodeLen is the input is not specified 
  1683.  * by a NULL terminated string, but a pointer and length.
  1684.  *
  1685.  * @param encoding  Specifies the encoding of text in src
  1686.  * @param src       Specifies the text to be converted
  1687.  * @param srclen    Specifies the number of bytes in src
  1688.  * @return            Size of Unicode to store the converted output (in UCS-2
  1689.  *                    units not bytes)
  1690.  * @see INTL_TextToUnicode
  1691.  * @see INTL_StrToUnicodeLen
  1692.  */
  1693. PUBLIC uint32 INTL_TextToUnicodeLen(
  1694.     INTL_Encoding_ID encoding,
  1695.     unsigned char* src,
  1696.     uint32 srclen
  1697. );
  1698.  
  1699. /**
  1700.  * Convert text from non-Unicode to Unicode. 
  1701.  *
  1702.  * The caller needs to call INTL_TextToUnicodeLen first to prepare memory and 
  1703.  * pass into ustr. The difference between INTL_StrToUnicode is the input is
  1704.  * not specified by a NULL terminated string, but a pointer and length.
  1705.  *
  1706.  * @param encoding  Specifies the encoding of text in src
  1707.  * @param src       Specifies the text to be converted
  1708.  * @param srclen    Specifies the number of bytes in src
  1709.  * @param ustr      Specifies the buffer for the Unicode string and returns
  1710.  *                  the converted Unicode string
  1711.  * @param ubuflen   Specifies the size of the ustr in the UCS-2 units not
  1712.  *                  bytes
  1713.  * @return            Size of converted Unicode (in UCS-2 units not bytes)
  1714.  * @see INTL_TextToUnicodeLen
  1715.  * @see INTL_StrToUnicode
  1716.  */
  1717. PUBLIC uint32 INTL_TextToUnicode(
  1718.     INTL_Encoding_ID encoding,
  1719.     unsigned char* src, 
  1720.     uint32 srclen,
  1721.     INTL_Unicode* ustr, 
  1722.     uint32 ubuflen
  1723. );
  1724.  
  1725.  
  1726. /**
  1727.  * Initial Unicode conversion routines from a list of Character Set ID (CSID)
  1728.  * for Unicode rendering.
  1729.  *
  1730.  * It should only be called once in the application life time. It should be
  1731.  * called by front end before calling any other Unicode conversion functions.
  1732.  * The list could be retrieved through INTL_GetUnicodeCSIDList or
  1733.  * INTL_GetUnicodeCharsetList.
  1734.  * 
  1735.  * @param    numberOfItem    Specifies the valid number in the csidlist
  1736.  * @param    csidlist    Specifies a prioritized list of csid to be used for
  1737.  *                       Unicode to font charset conversion. The function will
  1738.  *                       make a copy of the list the caller pass in. The caller
  1739.  *                       could free the pass in list after this function.
  1740.  * @ see     INTL_GetUnicodeCSIDList
  1741.  * @ see     INTL_UnicodeToStrIteratorCreate
  1742.  * @ see     INTL_UnicodeToStrIterate
  1743.  * @ see     INTL_UnicodeToStrIteratorDestroy
  1744.  * @ see     INTL_GetUnicodeCharsetList
  1745.  */
  1746. PUBLIC void INTL_SetUnicodeCSIDList(
  1747.     uint16 numOfItems, 
  1748.     int16 *csidlist);    
  1749.  
  1750. /**
  1751.  * Returns a list of Character Set ID (CSID) used for converting Unicode
  1752.  * to font encoding. 
  1753.  * 
  1754.  * The list is set in the initialization time by the front end through 
  1755.  * INTL_SetUnicodeCSIDList. The only difference between INTL_GetUnicodeCSIDList
  1756.  * and INTL_GetUnicodeCharsetList is that INTL_GetUnicodeCSIDList returns a 
  1757.  * list of CSIDs and the INTL_GetUnicodeCharsetList returns a list of charset 
  1758.  * names (strings).
  1759.  *
  1760.  * @param    outnum    Returns the number of items in the returned CSID array.
  1761.  * @return        Array of CSIDs. Caller should change or free the returned array.
  1762.  * @see      INTL_SetUnicodeCSIDList
  1763.  * @see      INTL_UnicodeToStrIteratorCreate
  1764.  * @see      INTL_UnicodeToStrIterate
  1765.  * @see      INTL_UnicodeToStrIteratorDestroy
  1766.  * @see      INTL_GetUnicodeCharsetList
  1767.  */
  1768. PUBLIC int16*  INTL_GetUnicodeCSIDList(int16 * outnum);
  1769.  
  1770. /**
  1771.  * Return a list of charset names (strings) used for converting Unicode to font
  1772.  * encoding.
  1773.  *
  1774.  * The list is set in the initialization time by front end through 
  1775.  * INTL_SetUnicodeCSIDList. The only difference between INTL_GetUnicodeCSIDList
  1776.  * and INTL_GetUnicodeCharsetList is that INTL_GetUnicodeCSIDList returns a
  1777.  * list of CSIDs and INTL_GetUnicodeCharsetList returns a list of charset
  1778.  * names (strings).
  1779.  *
  1780.  * @param outnum    Returns the number of items in the returned charset array
  1781.  * @return        Array of charset names. Caller should not change or free the 
  1782.  *                returned array.
  1783.  * @see      INTL_GetUnicodeCSIDList
  1784.  * @see      INTL_SetUnicodeCSIDList
  1785.  * @see      INTL_UnicodeToStrIteratorCreate
  1786.  * @see      INTL_UnicodeToStrIterate
  1787.  * @see      INTL_UnicodeToStrIteratorDestroy
  1788.  */
  1789. PUBLIC unsigned char **INTL_GetUnicodeCharsetList(int16 * outnum);
  1790.  
  1791. /**
  1792.  * Converts a UTF-8 sub-string to the appropriate font encoding.
  1793.  *
  1794.  * Converts characters until the encoding changes or
  1795.  * input/output space runs out.
  1796.  *
  1797.  * The segment is NOT NULL TERMINATED
  1798.  *
  1799.  * @param    utf8p            Specifies the UTF-8 string
  1800.  * @param    utf8len        Specifies the length of utf8p 
  1801.  * @param    LE_string        Specifies and returns the (pre-allocated) buffer
  1802.  *                            for the string converted to the font encoding
  1803.  * @param    LE_string_len    Specifies the length of the buffer for LE_string
  1804.  * @param    LE_written_len    Returns the valid length of the return LE_string
  1805.  * @param    LE_string_csid    Returns the CSID of the return LE_string:
  1806.  * <UL>
  1807.  * <LI>
  1808.  *                                >0 if successful (valid CSID).
  1809.  * <LI>
  1810.  *                                -1 if not Unicode.
  1811.  * <LI>
  1812.  *                                -2 if no font encoding.
  1813.  * </UL>
  1814.  * @return                    Length of converted UTF-8 string
  1815.  */
  1816. PUBLIC int utf8_to_local_encoding(
  1817.     const unsigned char *utf8p, 
  1818.     const int utf8len,
  1819.     unsigned char *LE_string, 
  1820.     int LE_string_len,
  1821.     int *LE_written_len, 
  1822.     int16 *LE_string_csid
  1823. );
  1824.  
  1825. /**
  1826.  * Convert text from UTF-8 to UCS-2 encoding.
  1827.  *
  1828.  * UCS-2 is the abbreviation for the two byte form of Unicode.
  1829.  * UTF-8 is a transformation encoding for Unicode.
  1830.  * For more information about UTF-8 look at RFC 2279 in
  1831.  * <A HREF=ftp://ds.internic.net/rfc/rfc2279.txt>
  1832.  *         ftp://ds.internic.net/rfc/rfc2279.txt</A> .
  1833.  * For more information about UCS-2, look at <A HREF=http://www.unicode.org>
  1834.  * http://www.unicode.org</A>.
  1835.  *
  1836.  * @param utf8p        Specifies the UTF-8 text buffer. It is NULL terminated.
  1837.  * @param num_chars    Returns the length of the converted UCS-2 in UCS-2 units
  1838.  *                    not bytes
  1839.  * @return            UCS-2 string, NULL terminated by U+0000, or NULL. The
  1840.  *                    caller should free it by calling XP_FREE when it is no
  1841.  *                    longer needed.
  1842.  * @see INTL_UCS2ToUTF8
  1843.  */
  1844. PUBLIC UNICVTAPI uint16 *INTL_UTF8ToUCS2(
  1845.     const unsigned char *utf8p, 
  1846.     int32 *num_chars
  1847. );
  1848.  
  1849. /**
  1850.  * Convert text from UCS-2 to UTF-8 encoding.
  1851.  *
  1852.  * UCS-2 is the abbreviation for the two byte form of Unicode.
  1853.  * UTF-8 is a transformation encoding for Unicode.
  1854.  * For more information about UTF-8 look at RFC 2279 in
  1855.  * <A HREF=ftp://ds.internic.net/rfc/rfc2279.txt>
  1856.  * ftp://ds.internic.net/rfc/rfc2279.txt</A> .
  1857.  * For more information about UCS-2, look at <A HREF= http://www.unicode.org>
  1858.  * http://www.unicode.org</A>.
  1859.  *
  1860.  * @param ucs2p        Specifies the UCS-2 text buffer
  1861.  * @param num_chars    Specifies the length of ucs2p, in UCS-2 units not bytes
  1862.  * @return            NULL terminated UTF-8 string or NULL. The caller should
  1863.  *                    free it by calling XP_FREE when it is no longer needed.
  1864.  * @see INTL_UTF8ToUCS2
  1865.  */
  1866. PUBLIC UNICVTAPI unsigned char *INTL_UCS2ToUTF8(
  1867.     const uint16 *ucs2p, 
  1868.     int32 num_chars
  1869. ); 
  1870. /*@}*/
  1871. /*=======================================================*/
  1872. /**@name String Comparison */
  1873. /*@{*/
  1874.  
  1875. /**
  1876.  * Case insensitive comparison. 
  1877.  *
  1878.  * This function is multibyte charset safe. It will consider characters 
  1879.  * boundary correctly. It also ignore case by considering the charset 
  1880.  * it used.
  1881.  *
  1882.  * @param    charSetID    Specifies the encoding of text1 and text2.
  1883.  * @param text1    Specifies address of text1.
  1884.  * @param text2    Specifies address of text2.
  1885.  * @param    charlen    Returns the length in byte of text1.
  1886.  * @return   true if the text1 and text2 point to the same character, 
  1887.  *           ignoring the case, false otherwise.
  1888.  * @see      INTL_MatchOneCaseChar 
  1889.  * @see      INTL_Strstr 
  1890.  * @see      INTL_Strcasestr 
  1891.  */
  1892. PUBLIC XP_Bool INTL_MatchOneChar(
  1893.     int16 charSetID, 
  1894.     unsigned char *text1,
  1895.     unsigned char *text2,
  1896.     int *charlen
  1897. );
  1898.  
  1899. /**
  1900.  * Case sensitive comparison. 
  1901.  *
  1902.  * This function is multibyte charset safe. It will consider characters 
  1903.  * boundary correctly.
  1904.  *
  1905.  * @param charSetID     Specifies the encoding of text1 and text2.
  1906.  * @param text1    Specifies address of text1.
  1907.  * @param text2    Specifies address of text2.
  1908.  * @param charlen  Returns length in bytes of text1.
  1909.  * @return true if the text1 and text2 point to the same character (same case), 
  1910.  *         false otherwise.
  1911.  * @see INTL_MatchOneChar 
  1912.  * @see INTL_Strstr 
  1913.  * @see INTL_Strcasestr 
  1914.  */
  1915. PUBLIC XP_Bool INTL_MatchOneCaseChar(
  1916.     int16 charSetID, 
  1917.     unsigned char *text1,
  1918.     unsigned char *text2,
  1919.     int *charlen
  1920. );
  1921.  
  1922. /**
  1923.  * Case sensitive sub-string search. 
  1924.  *
  1925.  * This function is multibyte charset safe. It will consider characters 
  1926.  * boundary correctly. 
  1927.  *
  1928.  * @param    charSetID    Specifies the encoding of s1 and s2.
  1929.  * @param    s1    Specifies the first string
  1930.  * @param    s2    Specifies the second string
  1931.  * @return   NULL if s1 does not contains s2, 
  1932.  *           otherwise, return the address of the sub-string in s1.
  1933.  * @see      INTL_MatchOneChar 
  1934.  * @see      INTL_MatchOneCaseChar 
  1935.  * @see      INTL_Strcasestr 
  1936.  */
  1937. PUBLIC char *INTL_Strstr(
  1938.     int16 charSetID, 
  1939.     const char *s1,
  1940.     const char *s2
  1941. );
  1942.  
  1943. /**
  1944.  * Case insensitive sub-string search. 
  1945.  *
  1946.  * This function is multibyte charset safe. It will consider characters 
  1947.  * boundary correctly. It also ignore case by considering the charset it 
  1948.  * used.
  1949.  *
  1950.  * @param    charSetID    Specifies the encoding of s1 and s2.
  1951.  * @param    s1    Specifies the first string
  1952.  * @param    s2    Specifies the second string
  1953.  * @return   NULL if s1 does not contains s2, 
  1954.  *           otherwise, return the address of the sub-string in s1.
  1955.  * @see      INTL_MatchOneChar 
  1956.  * @see      INTL_MatchOneCaseChar 
  1957.  * @see      INTL_Strstr 
  1958.  */
  1959. PUBLIC char *INTL_Strcasestr(
  1960.     int16 charSetID, 
  1961.     const char *s1, 
  1962.     const char *s2
  1963. );
  1964.  
  1965.  
  1966. /*
  1967.   Function to support correct mail/news comparison:
  1968.     INTL_GetNormalizeStr
  1969.     INTL_GetNormalizeStrFromRFC1522
  1970.     INTL_StrContains
  1971.     INTL_StrIs
  1972.     INTL_StrBeginWith
  1973.     INTL_StrEndWith
  1974.  
  1975.   Example:
  1976.  
  1977.     XP_Bool MailHeaderContains(csid, header, str)
  1978.     {
  1979.         XP_Bool result = FALSE;
  1980.         unsigned char* n_str = INTL_GetNormalizeStr(csid, str);
  1981.         unsigned char* n_header = INTL_GetNormalizeStrFromRFC1522(csid, header);
  1982.  
  1983.         if((NULL != n_str) && (NULL != n_header))
  1984.             result = INTL_StrContains(csid, n_header, n_str);
  1985.         if(n_str)
  1986.             XP_FREE(n_str);
  1987.         if(n_header)
  1988.             XP_FREE(n_header);
  1989.         return result;
  1990.     }
  1991.  
  1992. */
  1993.  
  1994. /**
  1995.  * Normalize a string, by dropping the case of the characters.
  1996.  *
  1997.  * The return value could be used with INTL_StrContains, INTL_StrIs,
  1998.  * INTL_StrBeginWith or INTL_StrEndWith to perform string matching. This
  1999.  * function normalizes a string by dropping the case of character according to
  2000.  * the charSetID the caller passed in. It also ignores CR and LF characters.
  2001.  *
  2002.  * @param    charSetID    Specifies the encoding of str
  2003.  * @param    str    Specifies the to-be-normalized string.
  2004.  * @return a normalized string which could be used in  INTL_StrContains, 
  2005.  *         INTL_StrIs, INTL_StrBeginWith and INTL_StrEndWith The caller should
  2006.  *         free it by calling XP_FREE when it is not needed.
  2007.  * @see      INTL_GetNormalizeStrFromRFC1522
  2008.  * @see      INTL_StrContains
  2009.  * @see      INTL_StrIs
  2010.  * @see      INTL_StrBeginWith
  2011.  * @see      INTL_StrEndWith
  2012.  */
  2013. PUBLIC unsigned char* INTL_GetNormalizeStr(
  2014.     int16 charSetID, 
  2015.     unsigned char* str
  2016. );
  2017.  
  2018. /**
  2019.  * Test if string s1 contains string s2.
  2020.  *
  2021.  * This function is multibyte charset safe. It will consider characters
  2022.  * boundary correctly.  To do string matching with ignoring the case of
  2023.  * character, call INTL_GetNormalizeStr (or INTL_GetNormalizeStrFromRFC1522)
  2024.  * before call this function.
  2025.  *
  2026.  * @param    charSetID    Specifies the encoding for s1 and s2.
  2027.  * @param    s1    Specifies the first string
  2028.  * @param    s2    Specifies the second string
  2029.  * @return   true if s1 contains s2, 
  2030.  *           false otherwise
  2031.  * @see      INTL_GetNormalizeStr
  2032.  * @see      INTL_GetNormalizeStrFromRFC1522
  2033.  * @see      INTL_StrIs
  2034.  * @see      INTL_StrBeginWith
  2035.  * @see      INTL_StrEndWith
  2036.  */
  2037. PUBLIC XP_Bool INTL_StrContains(
  2038.     int16 charSetID, 
  2039.     unsigned char* str1, 
  2040.     unsigned char* str2
  2041. );
  2042.  
  2043. /**
  2044.  * Test if string s1 is string s2.
  2045.  *
  2046.  * This function is multibyte charset safe. It will consider characters boundary
  2047.  * correctly.  To do string matching with ignoring the case of character, call
  2048.  * INTL_GetNormalizeStr (or INTL_GetNormalizeStrFromRFC1522) before calling this
  2049.  * function.
  2050.  *
  2051.  * @param    charSetID    Specifies the encoding for s1 and s2.
  2052.  * @param    s1    Specifies the first string
  2053.  * @param    s2    Specifies the second string
  2054.  * @return   true if two string are equal, false otherwise
  2055.  * @see      INTL_GetNormalizeStr
  2056.  * @see      INTL_GetNormalizeStrFromRFC1522
  2057.  * @see      INTL_StrContains
  2058.  * @see      INTL_StrBeginWith
  2059.  * @see      INTL_StrEndWith
  2060.  */
  2061. PUBLIC XP_Bool INTL_StrIs(
  2062.     int16 charSetID, 
  2063.     unsigned char* str1, 
  2064.     unsigned char* str2
  2065. );
  2066.  
  2067. /**
  2068.  * Test if string s1 begin with string s2.
  2069.  *
  2070.  * This function is multibyte charset safe. It will consider characters
  2071.  * boundary correctly.  To do string matching with ignoring the case of 
  2072.  * character, call INTL_GetNormalizeStr (or INTL_GetNormalizeStrFromRFC1522)
  2073.  * before calling this function.
  2074.  *
  2075.  * @param    charSetID    Specifies the encoding for s1 and s2.
  2076.  * @param    s1    Specifies the first string
  2077.  * @param    s2    Specifies the second string
  2078.  * @return   true if the first string is begin with the second string, 
  2079.  *           false otherwise
  2080.  * @see      INTL_GetNormalizeStr
  2081.  * @see      INTL_GetNormalizeStrFromRFC1522
  2082.  * @see      INTL_StrContains
  2083.  * @see      INTL_StrIs
  2084.  * @see      INTL_StrEndWith
  2085.  */
  2086. PUBLIC XP_Bool INTL_StrBeginWith(
  2087.     int16 charSetID, 
  2088.     unsigned char* str1, 
  2089.     unsigned char* str2
  2090. );
  2091.  
  2092. /**
  2093.  * Test if string s1 end with string s2.
  2094.  *
  2095.  * This function is multibyte charset safe. It will consider characters 
  2096.  * boundary correctly. To do string matching with ignoring the case of 
  2097.  * character, call INTL_GetNormalizeStr (or INTL_GetNormalizeStrFromRFC1522) 
  2098.  * before calling this function.
  2099.  *
  2100.  * @param    charSetID    Specifies the encoding for s1 and s2.
  2101.  * @param    s1    Specifies the first string
  2102.  * @param    s2    Specifies the second string
  2103.  * @return true if the first string is end with the second string, false
  2104.  *         otherwise.
  2105.  * @see      INTL_GetNormalizeStr
  2106.  * @see      INTL_GetNormalizeStrFromRFC1522
  2107.  * @see      INTL_StrContains
  2108.  * @see      INTL_StrIs
  2109.  * @see      INTL_StrBeginWith
  2110.  */
  2111. PUBLIC XP_Bool INTL_StrEndWith(
  2112.     int16 charSetID, 
  2113.     unsigned char* str1, 
  2114.     unsigned char* str2
  2115. );
  2116.  
  2117. /**
  2118.  * Return a (hacky) XPAT pattern for NNTP server for searching pre 
  2119.  * RFC 1522 message header.
  2120.  *
  2121.  * This is a hacky function which try to work around another HACK!!! The 
  2122.  * problem it tries to solve is to search on NNTP, internet newsgroup server.   
  2123.  * Unfortunately, the NNTP server does not have non-ASCII text searching
  2124.  * command. The only functionality in the NNTP protocol we could use is the
  2125.  * XPAT extension of NNTP (see
  2126.  * <A HREF=ftp://ds.internic.net/internet-drafts/draft-ietf-nntpext-imp-01.txt>
  2127.  * ftp://ds.internic.net/internet-drafts/draft-ietf-nntpext-imp-01.txt</A> or
  2128.  * <A HREF=ftp://ds.internic.net/internet-drafts/draft-barber-nntp-imp-07.txt>
  2129.  * ftp://ds.internic.net/internet-drafts/draft-barber-nntp-imp-07.txt</A> ).
  2130.  * XPAT use wildmat regular expression (see <A HREF=
  2131.  * http://oac.hsc.uth.tmc.edu/oac_sysadmin/services/INN/man/wildmat.3.html>
  2132.  * http://oac.hsc.uth.tmc.edu/oac_sysadmin/services/INN/man/wildmat.3.html</A>
  2133.  * for details) to provide string matching. Unfortunately, wildmat is not
  2134.  * designed to support non-ASCII text. It work for English header but not for
  2135.  * header in other language like Japanese, French, or German. The problem is
  2136.  * the XPAT/wildmat cannot deal with (1) ISO-2022-xx encoding nor (2) RFC 1522
  2137.  * header. To work around the limitation in the protocol, we put together this
  2138.  * function to support the first limitation as possible as we can. This
  2139.  * function take one search string, and return a XPAT pattern which could then
  2140.  * be used to send to NNTP XPAT as search argument. However, there are some
  2141.  * limitation here. (1) It may cause NNTP return more message than it should,
  2142.  * the reason is the XPAT won't respect to the multibyte character boundary
  2143.  * when it try to match the string. To improve this in the future, the client
  2144.  * double check the header after it receive message from the server and narrow
  2145.  * it down to the correct case.  (2) The pattern it generated won't match RFC
  2146.  * 1522 header so it could return less message than it should. This is because
  2147.  * there are more than one XPAT could match the sting in the case of RFC 1522
  2148.  * header. To improve this in the future, the client side should send several
  2149.  * possible XPAT patterns (with the patterned return by this function), collect
  2150.  * the result, and then double checking in the client side. Of course, improve
  2151.  * the NNTP protocol itself is the real solution. But the improvement stated
  2152.  * above is also needed for the server support the current NNTP protocol.  This
  2153.  * function (1) convert the text from the encoding the argument specified into
  2154.  * the encoding used in the corresponding internet newsgroup, (2) strip out
  2155.  * leading or trailing ISO-2022 escape sequence if present, (3) escape the
  2156.  * wildmat special characters (any characters which is not from 0-9, a-z, A-Z),
  2157.  * and return.
  2158.  *
  2159.  * @param winCharSetID       Specifies the encoding of searchString.
  2160.  * @param searchString  Specifies the string to be search through NNTP XPAT
  2161.  *                      command.
  2162.  * @return the pattern should be send to NNTP XPAT command for searching
  2163.  *         non-ASCII header. The caller need to free this by calling XP_FREE
  2164.  *         when the result is no longer needed.
  2165.  */
  2166. PUBLIC unsigned char* INTL_FormatNNTPXPATInNonRFC1522Format(
  2167.     int16 winCharSetID, 
  2168.     unsigned char* searchString
  2169. );
  2170.  
  2171. /*@}*/
  2172. /*=======================================================*/
  2173. /**@name Charset ID Iterator */
  2174. /*@{*/
  2175.  
  2176.  
  2177. /** 
  2178.  * An object that can iterate through a list of charset ID.
  2179.  *
  2180.  * @see INTL_CSIDIteratorCreate
  2181.  * @see INTL_CSIDIteratorDestroy
  2182.  * @see INTL_CSIDIteratorNext
  2183.  */
  2184. typedef void* INTL_CSIDIterator;    
  2185.  
  2186. /**
  2187.  * Returns a new iterator object to search charset IDs for a particular
  2188.  * conversion.
  2189.  *
  2190.  * This function searches a built-in table to look for charset converters
  2191.  * that could be used for a particular purpose. The only purpose currently
  2192.  * supported is the IMAP4 conversion. This function puts the mail and news
  2193.  * charset IDs corresponding to the given charset ID at the top of the list
  2194.  * of IDs to try. After that, it inserts the "to" charset IDs of all entries
  2195.  * matching the given "from" ID.
  2196.  *
  2197.  * @param iterator_return  Returns a new iterator object
  2198.  * @param charSetID        Specifies the charset ID to convert from
  2199.  * @param flag             Specifies the type of conversion
  2200.  *                         Currently, the only valid value is 
  2201.  *                         csiditerate_TryIMAP4Search  .
  2202.  * 
  2203.  * @see INTL_CSIDIteratorNext, INTL_CSIDIteratorDestroy
  2204.  */
  2205. PUBLIC void INTL_CSIDIteratorCreate(
  2206.     INTL_CSIDIterator *iterator,
  2207.     int16 charSetID,
  2208.     int flag
  2209. );
  2210.  
  2211. /**
  2212.  * Frees the given iterator, and sets given pointer to NULL.
  2213.  *
  2214.  * This function destroys the object created by INTL_CSIDIteratorCreate.
  2215.  *
  2216.  * @param iterator  Specifies the iterator object to destroy
  2217.  * @see INTL_CSIDIteratorCreate
  2218.  */
  2219. PUBLIC void INTL_CSIDIteratorDestroy(
  2220.     INTL_CSIDIterator *iterator
  2221. );
  2222.  
  2223. /**
  2224.  * Returns the next charset ID in the given iterator, if any.
  2225.  *
  2226.  * The return value is TRUE if a charset ID was found. The charset ID
  2227.  * is returned in pCharSetID. Otherwise, the return value is FALSE, and
  2228.  * pCharSetID remains untouched.
  2229.  *
  2230.  * @param iterator    Specifies the iterator object
  2231.  * @param pCharSetID  Returns the next charset ID
  2232.  * @return TRUE if there are more elements to be iterate, otherwise FALSE
  2233.  * @see INTL_CSIDIteratorCreate, INTL_CSIDIteratorDestroy
  2234.  */
  2235. PUBLIC XP_Bool INTL_CSIDIteratorNext(
  2236.     INTL_CSIDIterator *iterator,
  2237.     int16 *pCharSetID
  2238. );
  2239.  
  2240. /*@}*/
  2241. /*=======================================================*/
  2242. /**@name Line/Word Breaking */
  2243. /*@{*/
  2244.  
  2245. /**
  2246.  *  Line breaking information.
  2247.  * 
  2248.  *  <UL>
  2249.  *  <LI>
  2250.  *  PROHIBIT_NOWHERE - 
  2251.  *  It is a breakable character. It could be break before 
  2252.  *      or after this character. This class is for all 
  2253.  *      Kanji ideographic character.
  2254.  *  <LI>
  2255.  *  PROHIBIT_BEGIN_OF_LINE - 
  2256.  *  It should not appeared in the beginning of the line.
  2257.  *  <LI>
  2258.  *  PROHIBIT_END_OF_LINE - 
  2259.  *  It should not appeared in the end of the line.
  2260.  *  <LI>
  2261.  *  PROHIBIT_WORD_BREAK - 
  2262.  *  It is non breakable character. It cannot be break
  2263.  *      if the next (or previous) character is also 
  2264.  *      PROHIBIT_WORD_BREAK. 
  2265.  *  </UL>
  2266.  *
  2267.  * @see INTL_KinsokuClass
  2268.  */
  2269. enum LINE_WRAP_PROHIBIT_CLASS{
  2270.     PROHIBIT_NOWHERE,
  2271.     PROHIBIT_BEGIN_OF_LINE,
  2272.     PROHIBIT_END_OF_LINE,
  2273.     PROHIBIT_WORD_BREAK
  2274. };
  2275.  
  2276. /**
  2277.  * Basic Japanese word breaking information.
  2278.  * 
  2279.  * <UL>
  2280.  * <LI>
  2281.  * SEVEN_BIT_CHAR - e.g. ASCII
  2282.  * <LI>
  2283.  * HALFWIDTH_PRONOUNCE_CHAR - e.g. Japanese Katakana
  2284.  * <LI>
  2285.  * FULLWIDTH_ASCII_CHAR - e.g. ASCII in JIS
  2286.  * <LI>
  2287.  * FULLWIDTH_PRONOUNCE_CHAR - e.g. Japanese Hiragana, Katakana
  2288.  * <LI>
  2289.  * KANJI_CHAR - ideographic
  2290.  * <LI>
  2291.  * UNCLASSIFIED_CHAR - others
  2292.  * </UL>
  2293.  * 
  2294.  * @see       INTL_CharClass
  2295.  */
  2296. enum WORD_BREAK_CLASS{
  2297.     SEVEN_BIT_CHAR,
  2298.     HALFWIDTH_PRONOUNCE_CHAR,
  2299.     FULLWIDTH_ASCII_CHAR,
  2300.     FULLWIDTH_PRONOUNCE_CHAR,
  2301.     KANJI_CHAR,
  2302.     UNCLASSIFIED_CHAR
  2303. };
  2304. /**
  2305.  * Returns the code point that represent the non-breaking space character.
  2306.  * 
  2307.  * The current implementation return the same value regardless of the given
  2308.  * charset. However, the return value is platform dependent.
  2309.  * The information then is used by parser and layout code.
  2310.  * 
  2311.  * Using this function with caution as it is tied to
  2312.  * the current HTML parser implementation.
  2313.  * 
  2314.  * @param     winCharSetID   Specifies the window charset id.
  2315.  * @return    the code point which Non Breaking Space in a 
  2316.  *            C style NULL terminated string.
  2317.  * @see       
  2318.  */
  2319. PUBLIC const char *INTL_NonBreakingSpace(
  2320.     uint16 winCharSetID
  2321. );
  2322.  
  2323. /**
  2324.  * Returns information for basic Japanese word breaking.
  2325.  *
  2326.  * Given a character pointer and charset, returns a word breaking 
  2327.  * character class for the given character.
  2328.  * It is necessary to pass a pointer because the
  2329.  * character may be more than one byte.
  2330.  *
  2331.  * In the future, the definition of word breaking classes needs to be 
  2332.  * extended.
  2333.  * 
  2334.  * @param     winCharSetID    Specifies the window charset ID
  2335.  * @param     pstr            Specifies the pointer to the character 
  2336.  * @return                    Character class for word breaking:
  2337.  * <UL>
  2338.  * <LI>
  2339.  * SEVEN_BIT_CHAR - e.g. ASCII
  2340.  * <LI>
  2341.  * HALFWIDTH_PRONOUNCE_CHAR - e.g. Japanese Katakana
  2342.  * <LI>
  2343.  * FULLWIDTH_ASCII_CHAR - e.g. ASCII in JIS
  2344.  * <LI>
  2345.  * FULLWIDTH_PRONOUNCE_CHAR - e.g. Japanese Hiragana, Katakana
  2346.  * <LI>
  2347.  * KANJI_CHAR - ideographic
  2348.  * <LI>
  2349.  * UNCLASSIFIED_CHAR - others
  2350.  * </UL>
  2351.  * @see       INTL_KinsokuClass
  2352.  * @see       WORD_BREAK_CLASS
  2353.  */
  2354. PUBLIC int INTL_CharClass(
  2355.     int winCharSetID, 
  2356.     unsigned char *pstr
  2357. );
  2358.  
  2359. /**
  2360.  * Returns line breaking information.
  2361.  *
  2362.  * Given a character pointer and charset, returns a line breaking 
  2363.  * character class for the given character.
  2364.  * It is necessary to pass a pointer because the
  2365.  * character may be more than one byte.
  2366.  *
  2367.  *
  2368.  * Please notice that the function currently only supports multibyte charsets.
  2369.  * If this is called for ascii charset, it always return PROHIBIT_WORD_BREAK.
  2370.  * 
  2371.  * References for line breaking:
  2372.  * <UL>
  2373.  * <LI>
  2374.  * Japanese Standard Association,
  2375.  * JIS X 4501 1995 - Japanese Industrial Standard - 
  2376.  *     Line Composition rules for Japanese documents
  2377.  * <LI>
  2378.  * Ken Lunde,
  2379.  * Understanding Japanese Information Processing,
  2380.  * O'Reilly & Associates, Inc.,
  2381.  * ISBN:1-56592-043-0, 
  2382.  * pp.148
  2383.  * <LI>
  2384.  * Nadine Kano,
  2385.  * Developing International Software For Windows 95 and Windows NT,
  2386.  * Microsoft Press,
  2387.  * ISBN:1-556-15-840-8,
  2388.  * pp.239-244
  2389.  * </UL>
  2390.  * 
  2391.  * 
  2392.  * @param     winCharSetID   Specifies window charset ID.
  2393.  * @param     pstr    Specifies the pointer to the character 
  2394.  * @return    the kinsoku class for line breaking:
  2395.  * <UL>
  2396.  * <LI>
  2397.  *  PROHIBIT_NOWHERE - 
  2398.  *  It is a breakable character. It could be break before 
  2399.  *      or after this character. This class is for all 
  2400.  *      Kanji ideographic character.
  2401.  * <LI>
  2402.  *  PROHIBIT_BEGIN_OF_LINE - 
  2403.  *  It should not appeared in the beginning of the line.
  2404.  * <LI>
  2405.  *  PROHIBIT_END_OF_LINE - 
  2406.  *  It should not appeared in the end of the line.
  2407.  * <LI>
  2408.  *  PROHIBIT_WORD_BREAK - 
  2409.  *  It is non breakable character. It cannot be break
  2410.  *      if the next (or previous) character is also 
  2411.  *      PROHIBIT_WORD_BREAK. 
  2412.  * </UL>
  2413.  * @see       INTL_CharClass
  2414.  * @see       LINE_WRAP_PROHIBIT_CLASS
  2415.  */
  2416. PUBLIC int INTL_KinsokuClass(
  2417.     int16 winCharSetID, 
  2418.     unsigned char *pstr
  2419. );
  2420.  
  2421. /**
  2422.  * Returns the column width of the given character.
  2423.  *
  2424.  * In some countries, old terminals use full-width and half-width characters.
  2425.  * This function returns the number of "columns" taken up by the given
  2426.  * character. For example, in Japan, normal characters take up 2 columns,
  2427.  * while half-width characters take up 1 column each.
  2428.  *
  2429.  * Returns 1 for charsets that do not distinguish between half-width and
  2430.  * full-width characters.
  2431.  *
  2432.  * @param winCharSetID  Specifies the charset ID of the text
  2433.  * @param pstr          Specifies the character
  2434.  * @return              The column width of the given character
  2435.  * @see                 INTL_IsHalfWidth
  2436.  */
  2437. PUBLIC int INTL_ColumnWidth(
  2438.     int winCharSetID,
  2439.     unsigned char *pstr
  2440. );
  2441.  
  2442. /**
  2443.  * Truncates a long string by replacing excess characters in the middle
  2444.  * with "...".
  2445.  *
  2446.  * The output_return pointer may be the same as the input pointer.
  2447.  *
  2448.  * @param winCharSetID   Specifies the charset ID of the text
  2449.  * @param input          Specifies the text to be mid-truncated
  2450.  * @param output_return  Returns the mid-truncated text
  2451.  * @param max_length     Specifies the desired number of bytes to be placed in
  2452.  *                       the output buffer, minus 1 for null terminator
  2453.  */
  2454. PUBLIC void INTL_MidTruncateString(
  2455.     int16 winCharSetID,
  2456.     const char *input,
  2457.     char *output_return,
  2458.     int max_length
  2459. );
  2460.  
  2461. /**
  2462.  * Returns whether or not the given character is a half-width character.
  2463.  *
  2464.  * In some countries, certain characters are normal width on old terminals,
  2465.  * while other characters are half-width. For example, normal Japanese
  2466.  * characters are considered normal width, while "hankaku kana" are
  2467.  * half-width, as are the ASCII characters.
  2468.  *
  2469.  * @param winCharSetID  Specifies the charset ID of the text
  2470.  * @param pstr          Specifies the character
  2471.  * @return 
  2472.  *         0 if the given character is ASCII or the charset do not normally
  2473.  *           distinguish between half-width and full-width,
  2474.  *         1 if the given character is half-width
  2475.  * @see INTL_ColumnWidth
  2476.  */
  2477. PUBLIC int INTL_IsHalfWidth(
  2478.     uint16  winCharSetID,
  2479.     unsigned char *pstr
  2480. );
  2481.  
  2482. /*@}*/
  2483. /*=======================================================*/
  2484. /**@name Document Context Handling */
  2485. /*@{*/
  2486. /** 
  2487.  * Request a re-layout of the document.
  2488.  *
  2489.  * Libi18n calls this function in those cases where a different document
  2490.  * encoding is detected after document conversion and layout has begun.
  2491.  * This can occur because the parsing and layout of the document begins
  2492.  * immediately when the document data begins to stream in - at which time
  2493.  * all the data needed to determine the charset may not be available.  If
  2494.  * this occurs, the layout engine needs to be notified to pull the data from
  2495.  * the source (cache) again so the data will be converted by the correct
  2496.  * character codeset conversion module in the data stream.
  2497.  * 
  2498.  * @param context Specifies the context which should be relayout again. 
  2499.  */
  2500. PUBLIC void 
  2501. INTL_Relayout(iDocumentContext context);
  2502.  
  2503. /**
  2504.  * Returns name of the document charset.
  2505.  *
  2506.  * The returned string is suitable for use in the window brought up by
  2507.  * View | Page Info (previously known as Document Info). It also provides
  2508.  * information such as whether this charset was auto-detected.
  2509.  *
  2510.  * @param  doc_context    Specifies the document context
  2511.  * @return                Name (string) of the document charset
  2512.  */
  2513. PUBLIC char *INTL_CharSetDocInfo(
  2514.     iDocumentContext doc_context
  2515. );
  2516.  
  2517. /**
  2518.  * Get the UI charset encoding setting.
  2519.  *
  2520.  * Gets the currently selected charset encoding for this document 
  2521.  * (not the global default and not the detected document encoding).
  2522.  * 
  2523.  * @param     context    Specifies document context
  2524.  * @return    Document charset ID selected by the user
  2525.  * @see       
  2526.  */
  2527. PUBLIC uint16 FE_DefaultDocCharSetID(
  2528.     iDocumentContext context
  2529. );
  2530.  
  2531. /**
  2532.  * Change the default document charset ID.
  2533.  * 
  2534.  * This function is currently only implemented and called by the Windows
  2535.  * platform.  It will be removed in the future to keep the consistency between
  2536.  * platforms.
  2537.  *
  2538.  * @param defaultDocCharSetID Specifies the new default document charset ID
  2539.  * @version DEPRECATED. Do not use this function.
  2540.  */
  2541. #if defined(XP_WIN) || defined(XP_OS2)
  2542. PUBLIC void
  2543. INTL_ChangeDefaultCharSetID(int16 defaultDocCharSetID);
  2544. #endif
  2545.  
  2546. /**
  2547.  * Return default charset from preference or from current encoding 
  2548.  * menu selection. 
  2549.  * 
  2550.  * @param context    Specifies the context
  2551.  * @return            Default document charset ID.  If the context is NULL
  2552.  *                    then it returns default charset from the user preference.
  2553.  *                    If the context is specified then it returns current
  2554.  *                    encoding menu selection.
  2555.  */
  2556. PUBLIC int16
  2557. INTL_DefaultDocCharSetID(iDocumentContext context);
  2558.  
  2559. /**
  2560.  * Returns the default window charset ID for the given document context.
  2561.  *
  2562.  * If context is NULL, or the context's window charset ID is zero, this
  2563.  * function calls INTL_DefaultWinCharSetID, passing the same context.
  2564.  *
  2565.  * @param context    Specifies the document context
  2566.  * @return            The default window charset ID for this document context
  2567.  * @see INTL_DefaultWinCharSetID
  2568.  */
  2569. PUBLIC int16 INTL_DefaultTextAttributeCharSetID(
  2570.     iDocumentContext context
  2571. );
  2572.  
  2573. /**
  2574.  * Returns the default window charset ID for the given document context.
  2575.  *
  2576.  * If context is NULL, or if the context's window charset ID is zero, this
  2577.  * function calls INTL_DefaultDocCharSetID, passing the same context, and then
  2578.  * calls INTL_DocToWinCharSetID on the result.
  2579.  *
  2580.  * @param context    Specifies the document context
  2581.  * @return            Default window charset ID for this document context
  2582.  * @see INTL_DefaultDocCharSetID, INTL_DocToWinCharSetID
  2583.  */
  2584. PUBLIC int16 INTL_DefaultWinCharSetID(
  2585.     iDocumentContext context
  2586. );
  2587. /**
  2588.  * Set up the charset conversion stream module.
  2589.  *
  2590.  * This function gets the charset info object from the context, and then
  2591.  * picks up the relayout flag and the document charset ID before calling
  2592.  * INTL_CSIInitialize. It then creates the appropriate charset converter
  2593.  * to convert from the document to window charset. The stream is set up
  2594.  * by setting the various function pointers (put, abort, complete, etc).
  2595.  * It then hooks up to the next stream module "INTERNAL_PARSER", the HTML
  2596.  * parser and layout engine. This is done by rewriting URL_s' content_type
  2597.  * field.
  2598.  *
  2599.  * @param format_out  Specifies the type of stream
  2600.  * @param data_obj    Ignored
  2601.  * @param URL_s       Specifies the URL object
  2602.  * @param window_id   Specifies the context
  2603.  * @return        Stream object corresponding to this charset conversion module
  2604.  * @see INTL_CSIInitialize, NET_StreamBuilder
  2605.  */
  2606. PUBLIC Stream *INTL_ConvCharCode(
  2607.     int format_out,
  2608.     void *data_obj,
  2609.     URL *URL_s,
  2610.     iDocumentContext window_id
  2611. );
  2612.  
  2613. /**
  2614.  * Converts mail charset to display charset used by current window. 
  2615.  *
  2616.  * It decides which display charset to use based on current default language.
  2617.  * Caller is responsible for deallocating memory.
  2618.  * 
  2619.  * @param context     the context (window ID).
  2620.  * @param bit7buff    Source buffer.
  2621.  * @param block_size  the length of the source buffer.
  2622.  * @return Destination buffer. If NULL, this means either conversion failed or
  2623.  *         did single-byte to single-byte conversion.
  2624.  */
  2625. PUBLIC unsigned char *INTL_ConvMailToWinCharCode(
  2626.     iDocumentContext context,
  2627.     unsigned char *bit7buff,
  2628.     uint32 block_size
  2629. );
  2630.  
  2631. /*@}*/
  2632. /*=======================================================*/
  2633. /**@name Platform Independent String Resources */
  2634. /*@{*/
  2635. /**
  2636.  * Return the Charset name of the translated resource.
  2637.  *
  2638.  * @return    MIME charset of the cross-platform string resource and FE
  2639.  * resources
  2640.  * @see XP_GetString
  2641.  * @see XP_GetStringForHTML
  2642.  */
  2643. PUBLIC char *
  2644. INTL_ResourceCharSet(void);
  2645.  
  2646. /*@}*/
  2647. /*=======================================================*/
  2648.  
  2649. XP_END_PROTOS
  2650.  
  2651. #endif /* INTL_LIBI18N_H */
  2652.