home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icuapps / locexp / util / lx_utils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-22  |  5.0 KB  |  160 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998, 1999     *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File LX_utils.h
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *  8/25/1999     srl         moved a bunch of stuff here
  18. *******************************************************************************
  19. */
  20.  
  21. #ifndef _LXUTILS
  22. #define _LXUTILS
  23.  
  24. #include "ustdio.h"
  25. #include "ucnv.h"
  26. #include "ustring.h"
  27. #include "udat.h"
  28. #include "uloc.h"
  29. #include "ures.h"
  30. #include "ucol.h"
  31. #include "string.h"
  32. #include "ucal.h"
  33. #include "ctype.h"
  34.  
  35.  
  36. /* Some misc utils that were used in listrb but aren't specific 
  37.    to listrb. */
  38.  
  39. #define my_min(a,b) ((a<b)?(a):(b))
  40.  
  41. #define SORTKEYSIZE 100
  42.  
  43.  
  44.  
  45. typedef struct mysortable
  46. {
  47.   char key[SORTKEYSIZE];
  48.   uint32_t keySize;
  49.   const UChar *ustr;
  50.   const char *str;
  51.   
  52.   struct mysortable *subLocs;
  53.   struct mysortable *parent;
  54.   int32_t        nSubLocs;
  55.   int32_t        subLocsSize;
  56. } MySortable;
  57.  
  58.  
  59. /* Sort */
  60. void mySort(MySortable *root, UErrorCode *err, bool_t recurse);
  61.  
  62.  
  63. /**
  64.  * NON recursive exact match search
  65.  * @param toSort  the list of locales to search
  66.  * @param locale  locale to search for
  67.  * @return index into toSort.subLocs[], or -1 if not found
  68.  */
  69.  
  70. int32_t findLocaleNonRecursive(MySortable *toSort, const char *locale);
  71.  
  72. /** 
  73.  * Initialize a MySortable with the specified locale. Will reset all fields.
  74.  * TODO: limit displayname to just a part (default -> English -> United States -> California, instead of   .... -> English (United States) -> ... 
  75.  * @param s The MySortable struct to initialize
  76.  * @param locid The Locale that the MySortable should refer to
  77.  * @param inLocale The Locale which the MySortable's display name should be displayed 
  78.  * @param parent parent locale of the node
  79.  */
  80.  
  81. void initSortable(MySortable *s, const char *locid, const char *inLocale, MySortable *parent);
  82.  
  83. /**
  84.  * create a MySortable tree of locales. 
  85.  * default -> en, ja, de, ... -> en_US, en_CA, .. -> en_US_CALIFORNIA
  86.  * @param inLocale the Locale the tree should be created in
  87.  * @param localeCount [return] total # of items in the tree
  88.  * @return a new MySortable tree, owned by the caller.  Not sorted.
  89.  */
  90.  
  91. MySortable *createLocaleTree(const char *inLocale, int32_t *localeCount);
  92.  
  93.  
  94. /**
  95.  * Recursive search for the specified locale.
  96.  * Returns the parent node as well if requested.
  97.  * @param root The root of the tree to search
  98.  * @param locale The locale to search for 
  99.  * @return Pointer to a node matching the requested locale, or NULL
  100.  */
  101. MySortable *findLocale(MySortable *root, const char *locale);
  102.  
  103. /* Pick a better charset name */
  104. const char *MIMECharsetName(const char *origName);
  105.  
  106. /* Convert unichars to an escaped query (one containing \uXXXX, etc */
  107. void ucharsToEscapedUrlQuery(char *urlQuery, const UChar *src);
  108.  
  109. /* Decode escaped query field.  returns: # chars.  dstlen is a max. src can point to the beginning of the field (after the '='), it will terminate at & or \0 */
  110. int32_t unescapeAndDecodeQueryField(UChar *dst, int32_t dstLen, const char *src);
  111.  
  112. /* copy UChars around, WITHOUT termination, and convert \uXXXX back to the right chars */
  113. int32_t copyWithUnescaping( UChar* chars, const UChar* src, int32_t origLen);
  114.  
  115. /* Decode a URL query field  [%XX, +, etc.] */
  116. void doDecodeQueryField(const char *in, char *out, int32_t length);
  117.  
  118. /**
  119.  * Format the current date in the given style
  120.  * @param tz The timezone to format in (NULL for default)
  121.  * @param style Style to format in (try UDAT_FULL)
  122.  * @param status [returned] status of formatting, etc.
  123.  * @return pointer to the formatted chars. Caller must dispose of them.
  124.  */
  125. UChar *date(const UChar *tz, UDateFormatStyle style, UErrorCode *status);
  126.  
  127.  
  128. /* substitute with value, of the form: <B>\uXXXX</B>  */
  129. void
  130. UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE_HTML (UConverter * _this,
  131.              char **target,
  132.              const char *targetLimit,
  133.              const UChar ** source,
  134.              const UChar * sourceLimit,
  135.              int32_t *offsets,
  136.              bool_t flush,
  137.              UErrorCode * err);
  138.  
  139. /* substitute with value, of the form: \uXXXX  */
  140. void
  141. UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE (UConverter * _this,
  142.              char **target,
  143.              const char *targetLimit,
  144.              const UChar ** source,
  145.              const UChar * sourceLimit,
  146.              int32_t *offsets,
  147.              bool_t flush,
  148.              UErrorCode * err);
  149.  
  150. /**
  151.  * Replace all instances of 'from' with 'to'.
  152.  * @param str the string to modify. Null terminated
  153.  * @param from the char to look for
  154.  * @param to the char to change it to.
  155.  */
  156.  
  157. void u_replaceChar(UChar *str, UChar from, UChar to);
  158.  
  159. #endif
  160.