intl/icu/source/common/unisetspan.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 ******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 2007, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 ******************************************************************************
michael@0 8 * file name: unisetspan.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 2007mar01
michael@0 14 * created by: Markus W. Scherer
michael@0 15 */
michael@0 16
michael@0 17 #ifndef __UNISETSPAN_H__
michael@0 18 #define __UNISETSPAN_H__
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21 #include "unicode/uniset.h"
michael@0 22
michael@0 23 U_NAMESPACE_BEGIN
michael@0 24
michael@0 25 /*
michael@0 26 * Implement span() etc. for a set with strings.
michael@0 27 * Avoid recursion because of its exponential complexity.
michael@0 28 * Instead, try multiple paths at once and track them with an IndexList.
michael@0 29 */
michael@0 30 class UnicodeSetStringSpan : public UMemory {
michael@0 31 public:
michael@0 32 /*
michael@0 33 * Which span() variant will be used?
michael@0 34 * The object is either built for one variant and used once,
michael@0 35 * or built for all and may be used many times.
michael@0 36 */
michael@0 37 enum {
michael@0 38 FWD = 0x20,
michael@0 39 BACK = 0x10,
michael@0 40 UTF16 = 8,
michael@0 41 UTF8 = 4,
michael@0 42 CONTAINED = 2,
michael@0 43 NOT_CONTAINED = 1,
michael@0 44
michael@0 45 ALL = 0x3f,
michael@0 46
michael@0 47 FWD_UTF16_CONTAINED = FWD | UTF16 | CONTAINED,
michael@0 48 FWD_UTF16_NOT_CONTAINED = FWD | UTF16 | NOT_CONTAINED,
michael@0 49 FWD_UTF8_CONTAINED = FWD | UTF8 | CONTAINED,
michael@0 50 FWD_UTF8_NOT_CONTAINED = FWD | UTF8 | NOT_CONTAINED,
michael@0 51 BACK_UTF16_CONTAINED = BACK | UTF16 | CONTAINED,
michael@0 52 BACK_UTF16_NOT_CONTAINED= BACK | UTF16 | NOT_CONTAINED,
michael@0 53 BACK_UTF8_CONTAINED = BACK | UTF8 | CONTAINED,
michael@0 54 BACK_UTF8_NOT_CONTAINED = BACK | UTF8 | NOT_CONTAINED
michael@0 55 };
michael@0 56
michael@0 57 UnicodeSetStringSpan(const UnicodeSet &set, const UVector &setStrings, uint32_t which);
michael@0 58
michael@0 59 // Copy constructor. Assumes which==ALL for a frozen set.
michael@0 60 UnicodeSetStringSpan(const UnicodeSetStringSpan &otherStringSpan, const UVector &newParentSetStrings);
michael@0 61
michael@0 62 ~UnicodeSetStringSpan();
michael@0 63
michael@0 64 /*
michael@0 65 * Do the strings need to be checked in span() etc.?
michael@0 66 * @return TRUE if strings need to be checked (call span() here),
michael@0 67 * FALSE if not (use a BMPSet for best performance).
michael@0 68 */
michael@0 69 inline UBool needsStringSpanUTF16();
michael@0 70 inline UBool needsStringSpanUTF8();
michael@0 71
michael@0 72 // For fast UnicodeSet::contains(c).
michael@0 73 inline UBool contains(UChar32 c) const;
michael@0 74
michael@0 75 int32_t span(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
michael@0 76
michael@0 77 int32_t spanBack(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
michael@0 78
michael@0 79 int32_t spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const;
michael@0 80
michael@0 81 int32_t spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const;
michael@0 82
michael@0 83 private:
michael@0 84 // Special spanLength byte values.
michael@0 85 enum {
michael@0 86 // The spanLength is >=0xfe.
michael@0 87 LONG_SPAN=0xfe,
michael@0 88 // All code points in the string are contained in the parent set.
michael@0 89 ALL_CP_CONTAINED=0xff
michael@0 90 };
michael@0 91
michael@0 92 // Add a starting or ending string character to the spanNotSet
michael@0 93 // so that a character span ends before any string.
michael@0 94 void addToSpanNotSet(UChar32 c);
michael@0 95
michael@0 96 int32_t spanNot(const UChar *s, int32_t length) const;
michael@0 97 int32_t spanNotBack(const UChar *s, int32_t length) const;
michael@0 98 int32_t spanNotUTF8(const uint8_t *s, int32_t length) const;
michael@0 99 int32_t spanNotBackUTF8(const uint8_t *s, int32_t length) const;
michael@0 100
michael@0 101 // Set for span(). Same as parent but without strings.
michael@0 102 UnicodeSet spanSet;
michael@0 103
michael@0 104 // Set for span(not contained).
michael@0 105 // Same as spanSet, plus characters that start or end strings.
michael@0 106 UnicodeSet *pSpanNotSet;
michael@0 107
michael@0 108 // The strings of the parent set.
michael@0 109 const UVector &strings;
michael@0 110
michael@0 111 // Pointer to the UTF-8 string lengths.
michael@0 112 // Also pointer to further allocated storage for meta data and
michael@0 113 // UTF-8 string contents as necessary.
michael@0 114 int32_t *utf8Lengths;
michael@0 115
michael@0 116 // Pointer to the part of the (utf8Lengths) memory block that stores
michael@0 117 // the lengths of span(), spanBack() etc. for each string.
michael@0 118 uint8_t *spanLengths;
michael@0 119
michael@0 120 // Pointer to the part of the (utf8Lengths) memory block that stores
michael@0 121 // the UTF-8 versions of the parent set's strings.
michael@0 122 uint8_t *utf8;
michael@0 123
michael@0 124 // Number of bytes for all UTF-8 versions of strings together.
michael@0 125 int32_t utf8Length;
michael@0 126
michael@0 127 // Maximum lengths of relevant strings.
michael@0 128 int32_t maxLength16;
michael@0 129 int32_t maxLength8;
michael@0 130
michael@0 131 // Set up for all variants of span()?
michael@0 132 UBool all;
michael@0 133
michael@0 134 // Memory for small numbers and lengths of strings.
michael@0 135 // For example, for 8 strings:
michael@0 136 // 8 UTF-8 lengths, 8*4 bytes span lengths, 8*2 3-byte UTF-8 characters
michael@0 137 // = 112 bytes = int32_t[28].
michael@0 138 int32_t staticLengths[32];
michael@0 139 };
michael@0 140
michael@0 141 UBool UnicodeSetStringSpan::needsStringSpanUTF16() {
michael@0 142 return (UBool)(maxLength16!=0);
michael@0 143 }
michael@0 144
michael@0 145 UBool UnicodeSetStringSpan::needsStringSpanUTF8() {
michael@0 146 return (UBool)(maxLength8!=0);
michael@0 147 }
michael@0 148
michael@0 149 UBool UnicodeSetStringSpan::contains(UChar32 c) const {
michael@0 150 return spanSet.contains(c);
michael@0 151 }
michael@0 152
michael@0 153 U_NAMESPACE_END
michael@0 154
michael@0 155 #endif

mercurial