toolkit/crashreporter/google-breakpad/src/common/convert_UTF.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/convert_UTF.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +/*
     1.5 + * Copyright 2001-2004 Unicode, Inc.
     1.6 + *
     1.7 + * Disclaimer
     1.8 + *
     1.9 + * This source code is provided as is by Unicode, Inc. No claims are
    1.10 + * made as to fitness for any particular purpose. No warranties of any
    1.11 + * kind are expressed or implied. The recipient agrees to determine
    1.12 + * applicability of information provided. If this file has been
    1.13 + * purchased on magnetic or optical media from Unicode, Inc., the
    1.14 + * sole remedy for any claim will be exchange of defective media
    1.15 + * within 90 days of receipt.
    1.16 + *
    1.17 + * Limitations on Rights to Redistribute This Code
    1.18 + *
    1.19 + * Unicode, Inc. hereby grants the right to freely use the information
    1.20 + * supplied in this file in the creation of products supporting the
    1.21 + * Unicode Standard, and to make copies of this file in any form
    1.22 + * for internal or external distribution as long as this notice
    1.23 + * remains attached.
    1.24 + */
    1.25 +
    1.26 +/* ---------------------------------------------------------------------
    1.27 +
    1.28 +Conversions between UTF32, UTF-16, and UTF-8.  Header file.
    1.29 +
    1.30 +Several funtions are included here, forming a complete set of
    1.31 +conversions between the three formats.  UTF-7 is not included
    1.32 +here, but is handled in a separate source file.
    1.33 +
    1.34 +Each of these routines takes pointers to input buffers and output
    1.35 +buffers.  The input buffers are const.
    1.36 +
    1.37 +Each routine converts the text between *sourceStart and sourceEnd,
    1.38 +putting the result into the buffer between *targetStart and
    1.39 +targetEnd. Note: the end pointers are *after* the last item: e.g.
    1.40 +*(sourceEnd - 1) is the last item.
    1.41 +
    1.42 +The return result indicates whether the conversion was successful,
    1.43 +and if not, whether the problem was in the source or target buffers.
    1.44 +(Only the first encountered problem is indicated.)
    1.45 +
    1.46 +After the conversion, *sourceStart and *targetStart are both
    1.47 +updated to point to the end of last text successfully converted in
    1.48 +the respective buffers.
    1.49 +
    1.50 +Input parameters:
    1.51 +sourceStart - pointer to a pointer to the source buffer.
    1.52 +The contents of this are modified on return so that
    1.53 +it points at the next thing to be converted.
    1.54 +targetStart - similarly, pointer to pointer to the target buffer.
    1.55 +sourceEnd, targetEnd - respectively pointers to the ends of the
    1.56 +two buffers, for overflow checking only.
    1.57 +
    1.58 +These conversion functions take a ConversionFlags argument. When this
    1.59 +flag is set to strict, both irregular sequences and isolated surrogates
    1.60 +will cause an error.  When the flag is set to lenient, both irregular
    1.61 +sequences and isolated surrogates are converted.
    1.62 +
    1.63 +Whether the flag is strict or lenient, all illegal sequences will cause
    1.64 +an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
    1.65 +or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
    1.66 +must check for illegal sequences.
    1.67 +
    1.68 +When the flag is set to lenient, characters over 0x10FFFF are converted
    1.69 +to the replacement character; otherwise (when the flag is set to strict)
    1.70 +they constitute an error.
    1.71 +
    1.72 +Output parameters:
    1.73 +The value "sourceIllegal" is returned from some routines if the input
    1.74 +sequence is malformed.  When "sourceIllegal" is returned, the source
    1.75 +value will point to the illegal value that caused the problem. E.g.,
    1.76 +in UTF-8 when a sequence is malformed, it points to the start of the
    1.77 +malformed sequence.
    1.78 +
    1.79 +Author: Mark E. Davis, 1994.
    1.80 +Rev History: Rick McGowan, fixes & updates May 2001.
    1.81 +Fixes & updates, Sept 2001.
    1.82 +
    1.83 +------------------------------------------------------------------------ */
    1.84 +
    1.85 +/* ---------------------------------------------------------------------
    1.86 +The following 4 definitions are compiler-specific.
    1.87 +The C standard does not guarantee that wchar_t has at least
    1.88 +16 bits, so wchar_t is no less portable than unsigned short!
    1.89 +All should be unsigned values to avoid sign extension during
    1.90 +bit mask & shift operations.
    1.91 +------------------------------------------------------------------------ */
    1.92 +
    1.93 +typedef unsigned long	UTF32;	/* at least 32 bits */
    1.94 +typedef unsigned short	UTF16;	/* at least 16 bits */
    1.95 +typedef unsigned char	UTF8;	/* typically 8 bits */
    1.96 +typedef unsigned char	Boolean; /* 0 or 1 */
    1.97 +
    1.98 +/* Some fundamental constants */
    1.99 +#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
   1.100 +#define UNI_MAX_BMP (UTF32)0x0000FFFF
   1.101 +#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
   1.102 +#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
   1.103 +#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
   1.104 +
   1.105 +typedef enum {
   1.106 +	conversionOK, 		/* conversion successful */
   1.107 +	sourceExhausted,	/* partial character in source, but hit end */
   1.108 +	targetExhausted,	/* insuff. room in target for conversion */
   1.109 +	sourceIllegal		/* source sequence is illegal/malformed */
   1.110 +} ConversionResult;
   1.111 +
   1.112 +typedef enum {
   1.113 +	strictConversion = 0,
   1.114 +	lenientConversion
   1.115 +} ConversionFlags;
   1.116 +
   1.117 +/* This is for C++ and does no harm in C */
   1.118 +#ifdef __cplusplus
   1.119 +extern "C" {
   1.120 +#endif
   1.121 +
   1.122 +ConversionResult ConvertUTF8toUTF16 (const UTF8** sourceStart, const UTF8* sourceEnd,
   1.123 +                                     UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
   1.124 +
   1.125 +ConversionResult ConvertUTF16toUTF8 (const UTF16** sourceStart, const UTF16* sourceEnd,
   1.126 +                                     UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
   1.127 +
   1.128 +ConversionResult ConvertUTF8toUTF32 (const UTF8** sourceStart, const UTF8* sourceEnd,
   1.129 +                                     UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
   1.130 +
   1.131 +ConversionResult ConvertUTF32toUTF8 (const UTF32** sourceStart, const UTF32* sourceEnd,
   1.132 +                                     UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
   1.133 +
   1.134 +ConversionResult ConvertUTF16toUTF32 (const UTF16** sourceStart, const UTF16* sourceEnd,
   1.135 +                                      UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
   1.136 +
   1.137 +ConversionResult ConvertUTF32toUTF16 (const UTF32** sourceStart, const UTF32* sourceEnd,
   1.138 +                                      UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
   1.139 +
   1.140 +Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
   1.141 +
   1.142 +#ifdef __cplusplus
   1.143 +}
   1.144 +#endif
   1.145 +
   1.146 +/* --------------------------------------------------------------------- */

mercurial