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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2001-2004 Unicode, Inc.
michael@0 3 *
michael@0 4 * Disclaimer
michael@0 5 *
michael@0 6 * This source code is provided as is by Unicode, Inc. No claims are
michael@0 7 * made as to fitness for any particular purpose. No warranties of any
michael@0 8 * kind are expressed or implied. The recipient agrees to determine
michael@0 9 * applicability of information provided. If this file has been
michael@0 10 * purchased on magnetic or optical media from Unicode, Inc., the
michael@0 11 * sole remedy for any claim will be exchange of defective media
michael@0 12 * within 90 days of receipt.
michael@0 13 *
michael@0 14 * Limitations on Rights to Redistribute This Code
michael@0 15 *
michael@0 16 * Unicode, Inc. hereby grants the right to freely use the information
michael@0 17 * supplied in this file in the creation of products supporting the
michael@0 18 * Unicode Standard, and to make copies of this file in any form
michael@0 19 * for internal or external distribution as long as this notice
michael@0 20 * remains attached.
michael@0 21 */
michael@0 22
michael@0 23 /* ---------------------------------------------------------------------
michael@0 24
michael@0 25 Conversions between UTF32, UTF-16, and UTF-8. Header file.
michael@0 26
michael@0 27 Several funtions are included here, forming a complete set of
michael@0 28 conversions between the three formats. UTF-7 is not included
michael@0 29 here, but is handled in a separate source file.
michael@0 30
michael@0 31 Each of these routines takes pointers to input buffers and output
michael@0 32 buffers. The input buffers are const.
michael@0 33
michael@0 34 Each routine converts the text between *sourceStart and sourceEnd,
michael@0 35 putting the result into the buffer between *targetStart and
michael@0 36 targetEnd. Note: the end pointers are *after* the last item: e.g.
michael@0 37 *(sourceEnd - 1) is the last item.
michael@0 38
michael@0 39 The return result indicates whether the conversion was successful,
michael@0 40 and if not, whether the problem was in the source or target buffers.
michael@0 41 (Only the first encountered problem is indicated.)
michael@0 42
michael@0 43 After the conversion, *sourceStart and *targetStart are both
michael@0 44 updated to point to the end of last text successfully converted in
michael@0 45 the respective buffers.
michael@0 46
michael@0 47 Input parameters:
michael@0 48 sourceStart - pointer to a pointer to the source buffer.
michael@0 49 The contents of this are modified on return so that
michael@0 50 it points at the next thing to be converted.
michael@0 51 targetStart - similarly, pointer to pointer to the target buffer.
michael@0 52 sourceEnd, targetEnd - respectively pointers to the ends of the
michael@0 53 two buffers, for overflow checking only.
michael@0 54
michael@0 55 These conversion functions take a ConversionFlags argument. When this
michael@0 56 flag is set to strict, both irregular sequences and isolated surrogates
michael@0 57 will cause an error. When the flag is set to lenient, both irregular
michael@0 58 sequences and isolated surrogates are converted.
michael@0 59
michael@0 60 Whether the flag is strict or lenient, all illegal sequences will cause
michael@0 61 an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
michael@0 62 or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
michael@0 63 must check for illegal sequences.
michael@0 64
michael@0 65 When the flag is set to lenient, characters over 0x10FFFF are converted
michael@0 66 to the replacement character; otherwise (when the flag is set to strict)
michael@0 67 they constitute an error.
michael@0 68
michael@0 69 Output parameters:
michael@0 70 The value "sourceIllegal" is returned from some routines if the input
michael@0 71 sequence is malformed. When "sourceIllegal" is returned, the source
michael@0 72 value will point to the illegal value that caused the problem. E.g.,
michael@0 73 in UTF-8 when a sequence is malformed, it points to the start of the
michael@0 74 malformed sequence.
michael@0 75
michael@0 76 Author: Mark E. Davis, 1994.
michael@0 77 Rev History: Rick McGowan, fixes & updates May 2001.
michael@0 78 Fixes & updates, Sept 2001.
michael@0 79
michael@0 80 ------------------------------------------------------------------------ */
michael@0 81
michael@0 82 /* ---------------------------------------------------------------------
michael@0 83 The following 4 definitions are compiler-specific.
michael@0 84 The C standard does not guarantee that wchar_t has at least
michael@0 85 16 bits, so wchar_t is no less portable than unsigned short!
michael@0 86 All should be unsigned values to avoid sign extension during
michael@0 87 bit mask & shift operations.
michael@0 88 ------------------------------------------------------------------------ */
michael@0 89
michael@0 90 typedef unsigned long UTF32; /* at least 32 bits */
michael@0 91 typedef unsigned short UTF16; /* at least 16 bits */
michael@0 92 typedef unsigned char UTF8; /* typically 8 bits */
michael@0 93 typedef unsigned char Boolean; /* 0 or 1 */
michael@0 94
michael@0 95 /* Some fundamental constants */
michael@0 96 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
michael@0 97 #define UNI_MAX_BMP (UTF32)0x0000FFFF
michael@0 98 #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
michael@0 99 #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
michael@0 100 #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
michael@0 101
michael@0 102 typedef enum {
michael@0 103 conversionOK, /* conversion successful */
michael@0 104 sourceExhausted, /* partial character in source, but hit end */
michael@0 105 targetExhausted, /* insuff. room in target for conversion */
michael@0 106 sourceIllegal /* source sequence is illegal/malformed */
michael@0 107 } ConversionResult;
michael@0 108
michael@0 109 typedef enum {
michael@0 110 strictConversion = 0,
michael@0 111 lenientConversion
michael@0 112 } ConversionFlags;
michael@0 113
michael@0 114 /* This is for C++ and does no harm in C */
michael@0 115 #ifdef __cplusplus
michael@0 116 extern "C" {
michael@0 117 #endif
michael@0 118
michael@0 119 ConversionResult ConvertUTF8toUTF16 (const UTF8** sourceStart, const UTF8* sourceEnd,
michael@0 120 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
michael@0 121
michael@0 122 ConversionResult ConvertUTF16toUTF8 (const UTF16** sourceStart, const UTF16* sourceEnd,
michael@0 123 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
michael@0 124
michael@0 125 ConversionResult ConvertUTF8toUTF32 (const UTF8** sourceStart, const UTF8* sourceEnd,
michael@0 126 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
michael@0 127
michael@0 128 ConversionResult ConvertUTF32toUTF8 (const UTF32** sourceStart, const UTF32* sourceEnd,
michael@0 129 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
michael@0 130
michael@0 131 ConversionResult ConvertUTF16toUTF32 (const UTF16** sourceStart, const UTF16* sourceEnd,
michael@0 132 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
michael@0 133
michael@0 134 ConversionResult ConvertUTF32toUTF16 (const UTF32** sourceStart, const UTF32* sourceEnd,
michael@0 135 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
michael@0 136
michael@0 137 Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
michael@0 138
michael@0 139 #ifdef __cplusplus
michael@0 140 }
michael@0 141 #endif
michael@0 142
michael@0 143 /* --------------------------------------------------------------------- */

mercurial