Sat, 03 Jan 2015 20:18:00 +0100
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 | * Copyright (c) 2001-2011, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | * Date Name Description |
michael@0 | 7 | * 11/19/2001 aliu Creation. |
michael@0 | 8 | ********************************************************************** |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef ICU_UTIL_H |
michael@0 | 12 | #define ICU_UTIL_H |
michael@0 | 13 | |
michael@0 | 14 | #include "unicode/utypes.h" |
michael@0 | 15 | #include "unicode/uobject.h" |
michael@0 | 16 | #include "unicode/unistr.h" |
michael@0 | 17 | |
michael@0 | 18 | //-------------------------------------------------------------------- |
michael@0 | 19 | // class ICU_Utility |
michael@0 | 20 | // i18n utility functions, scoped into the class ICU_Utility. |
michael@0 | 21 | //-------------------------------------------------------------------- |
michael@0 | 22 | |
michael@0 | 23 | U_NAMESPACE_BEGIN |
michael@0 | 24 | |
michael@0 | 25 | class UnicodeMatcher; |
michael@0 | 26 | |
michael@0 | 27 | class U_COMMON_API ICU_Utility /* not : public UObject because all methods are static */ { |
michael@0 | 28 | public: |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Append a number to the given UnicodeString in the given radix. |
michael@0 | 32 | * Standard digits '0'-'9' are used and letters 'A'-'Z' for |
michael@0 | 33 | * radices 11 through 36. |
michael@0 | 34 | * @param result the digits of the number are appended here |
michael@0 | 35 | * @param n the number to be converted to digits; may be negative. |
michael@0 | 36 | * If negative, a '-' is prepended to the digits. |
michael@0 | 37 | * @param radix a radix from 2 to 36 inclusive. |
michael@0 | 38 | * @param minDigits the minimum number of digits, not including |
michael@0 | 39 | * any '-', to produce. Values less than 2 have no effect. One |
michael@0 | 40 | * digit is always emitted regardless of this parameter. |
michael@0 | 41 | * @return a reference to result |
michael@0 | 42 | */ |
michael@0 | 43 | static UnicodeString& appendNumber(UnicodeString& result, int32_t n, |
michael@0 | 44 | int32_t radix = 10, |
michael@0 | 45 | int32_t minDigits = 1); |
michael@0 | 46 | |
michael@0 | 47 | /** |
michael@0 | 48 | * Return true if the character is NOT printable ASCII. |
michael@0 | 49 | * |
michael@0 | 50 | * This method should really be in UnicodeString (or similar). For |
michael@0 | 51 | * now, we implement it here and share it with friend classes. |
michael@0 | 52 | */ |
michael@0 | 53 | static UBool isUnprintable(UChar32 c); |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Escape unprintable characters using \uxxxx notation for U+0000 to |
michael@0 | 57 | * U+FFFF and \Uxxxxxxxx for U+10000 and above. If the character is |
michael@0 | 58 | * printable ASCII, then do nothing and return FALSE. Otherwise, |
michael@0 | 59 | * append the escaped notation and return TRUE. |
michael@0 | 60 | */ |
michael@0 | 61 | static UBool escapeUnprintable(UnicodeString& result, UChar32 c); |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Returns the index of a character, ignoring quoted text. |
michael@0 | 65 | * For example, in the string "abc'hide'h", the 'h' in "hide" will not be |
michael@0 | 66 | * found by a search for 'h'. |
michael@0 | 67 | * @param text text to be searched |
michael@0 | 68 | * @param start the beginning index, inclusive; <code>0 <= start |
michael@0 | 69 | * <= limit</code>. |
michael@0 | 70 | * @param limit the ending index, exclusive; <code>start <= limit |
michael@0 | 71 | * <= text.length()</code>. |
michael@0 | 72 | * @param c character to search for |
michael@0 | 73 | * @return Offset of the first instance of c, or -1 if not found. |
michael@0 | 74 | */ |
michael@0 | 75 | //?FOR FUTURE USE. DISABLE FOR NOW for coverage reasons. |
michael@0 | 76 | // static int32_t quotedIndexOf(const UnicodeString& text, |
michael@0 | 77 | // int32_t start, int32_t limit, |
michael@0 | 78 | // UChar c); |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Skip over a sequence of zero or more white space characters at pos. |
michael@0 | 82 | * @param advance if true, advance pos to the first non-white-space |
michael@0 | 83 | * character at or after pos, or str.length(), if there is none. |
michael@0 | 84 | * Otherwise leave pos unchanged. |
michael@0 | 85 | * @return the index of the first non-white-space character at or |
michael@0 | 86 | * after pos, or str.length(), if there is none. |
michael@0 | 87 | */ |
michael@0 | 88 | static int32_t skipWhitespace(const UnicodeString& str, int32_t& pos, |
michael@0 | 89 | UBool advance = FALSE); |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Skip over Pattern_White_Space in a Replaceable. |
michael@0 | 93 | * Skipping may be done in the forward or |
michael@0 | 94 | * reverse direction. In either case, the leftmost index will be |
michael@0 | 95 | * inclusive, and the rightmost index will be exclusive. That is, |
michael@0 | 96 | * given a range defined as [start, limit), the call |
michael@0 | 97 | * skipWhitespace(text, start, limit) will advance start past leading |
michael@0 | 98 | * whitespace, whereas the call skipWhitespace(text, limit, start), |
michael@0 | 99 | * will back up limit past trailing whitespace. |
michael@0 | 100 | * @param text the text to be analyzed |
michael@0 | 101 | * @param pos either the start or limit of a range of 'text', to skip |
michael@0 | 102 | * leading or trailing whitespace, respectively |
michael@0 | 103 | * @param stop either the limit or start of a range of 'text', to skip |
michael@0 | 104 | * leading or trailing whitespace, respectively |
michael@0 | 105 | * @return the new start or limit, depending on what was passed in to |
michael@0 | 106 | * 'pos' |
michael@0 | 107 | */ |
michael@0 | 108 | //?FOR FUTURE USE. DISABLE FOR NOW for coverage reasons. |
michael@0 | 109 | //? static int32_t skipWhitespace(const Replaceable& text, |
michael@0 | 110 | //? int32_t pos, int32_t stop); |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * Parse a single non-whitespace character 'ch', optionally |
michael@0 | 114 | * preceded by whitespace. |
michael@0 | 115 | * @param id the string to be parsed |
michael@0 | 116 | * @param pos INPUT-OUTPUT parameter. On input, pos[0] is the |
michael@0 | 117 | * offset of the first character to be parsed. On output, pos[0] |
michael@0 | 118 | * is the index after the last parsed character. If the parse |
michael@0 | 119 | * fails, pos[0] will be unchanged. |
michael@0 | 120 | * @param ch the non-whitespace character to be parsed. |
michael@0 | 121 | * @return true if 'ch' is seen preceded by zero or more |
michael@0 | 122 | * whitespace characters. |
michael@0 | 123 | */ |
michael@0 | 124 | static UBool parseChar(const UnicodeString& id, int32_t& pos, UChar ch); |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * Parse a pattern string starting at offset pos. Keywords are |
michael@0 | 128 | * matched case-insensitively. Spaces may be skipped and may be |
michael@0 | 129 | * optional or required. Integer values may be parsed, and if |
michael@0 | 130 | * they are, they will be returned in the given array. If |
michael@0 | 131 | * successful, the offset of the next non-space character is |
michael@0 | 132 | * returned. On failure, -1 is returned. |
michael@0 | 133 | * @param pattern must only contain lowercase characters, which |
michael@0 | 134 | * will match their uppercase equivalents as well. A space |
michael@0 | 135 | * character matches one or more required spaces. A '~' character |
michael@0 | 136 | * matches zero or more optional spaces. A '#' character matches |
michael@0 | 137 | * an integer and stores it in parsedInts, which the caller must |
michael@0 | 138 | * ensure has enough capacity. |
michael@0 | 139 | * @param parsedInts array to receive parsed integers. Caller |
michael@0 | 140 | * must ensure that parsedInts.length is >= the number of '#' |
michael@0 | 141 | * signs in 'pattern'. |
michael@0 | 142 | * @return the position after the last character parsed, or -1 if |
michael@0 | 143 | * the parse failed |
michael@0 | 144 | */ |
michael@0 | 145 | static int32_t parsePattern(const UnicodeString& rule, int32_t pos, int32_t limit, |
michael@0 | 146 | const UnicodeString& pattern, int32_t* parsedInts); |
michael@0 | 147 | |
michael@0 | 148 | /** |
michael@0 | 149 | * Parse a pattern string within the given Replaceable and a parsing |
michael@0 | 150 | * pattern. Characters are matched literally and case-sensitively |
michael@0 | 151 | * except for the following special characters: |
michael@0 | 152 | * |
michael@0 | 153 | * ~ zero or more Pattern_White_Space chars |
michael@0 | 154 | * |
michael@0 | 155 | * If end of pattern is reached with all matches along the way, |
michael@0 | 156 | * pos is advanced to the first unparsed index and returned. |
michael@0 | 157 | * Otherwise -1 is returned. |
michael@0 | 158 | * @param pat pattern that controls parsing |
michael@0 | 159 | * @param text text to be parsed, starting at index |
michael@0 | 160 | * @param index offset to first character to parse |
michael@0 | 161 | * @param limit offset after last character to parse |
michael@0 | 162 | * @return index after last parsed character, or -1 on parse failure. |
michael@0 | 163 | */ |
michael@0 | 164 | static int32_t parsePattern(const UnicodeString& pat, |
michael@0 | 165 | const Replaceable& text, |
michael@0 | 166 | int32_t index, |
michael@0 | 167 | int32_t limit); |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * Parse an integer at pos, either of the form \d+ or of the form |
michael@0 | 171 | * 0x[0-9A-Fa-f]+ or 0[0-7]+, that is, in standard decimal, hex, |
michael@0 | 172 | * or octal format. |
michael@0 | 173 | * @param pos INPUT-OUTPUT parameter. On input, the first |
michael@0 | 174 | * character to parse. On output, the character after the last |
michael@0 | 175 | * parsed character. |
michael@0 | 176 | */ |
michael@0 | 177 | static int32_t parseInteger(const UnicodeString& rule, int32_t& pos, int32_t limit); |
michael@0 | 178 | |
michael@0 | 179 | /** |
michael@0 | 180 | * Parse a Unicode identifier from the given string at the given |
michael@0 | 181 | * position. Return the identifier, or an empty string if there |
michael@0 | 182 | * is no identifier. |
michael@0 | 183 | * @param str the string to parse |
michael@0 | 184 | * @param pos INPUT-OUPUT parameter. On INPUT, pos is the |
michael@0 | 185 | * first character to examine. It must be less than str.length(), |
michael@0 | 186 | * and it must not point to a whitespace character. That is, must |
michael@0 | 187 | * have pos < str.length() and |
michael@0 | 188 | * !UCharacter::isWhitespace(str.char32At(pos)). On |
michael@0 | 189 | * OUTPUT, the position after the last parsed character. |
michael@0 | 190 | * @return the Unicode identifier, or an empty string if there is |
michael@0 | 191 | * no valid identifier at pos. |
michael@0 | 192 | */ |
michael@0 | 193 | static UnicodeString parseUnicodeIdentifier(const UnicodeString& str, int32_t& pos); |
michael@0 | 194 | |
michael@0 | 195 | /** |
michael@0 | 196 | * Parse an unsigned 31-bit integer at the given offset. Use |
michael@0 | 197 | * UCharacter.digit() to parse individual characters into digits. |
michael@0 | 198 | * @param text the text to be parsed |
michael@0 | 199 | * @param pos INPUT-OUTPUT parameter. On entry, pos is the |
michael@0 | 200 | * offset within text at which to start parsing; it should point |
michael@0 | 201 | * to a valid digit. On exit, pos is the offset after the last |
michael@0 | 202 | * parsed character. If the parse failed, it will be unchanged on |
michael@0 | 203 | * exit. Must be >= 0 on entry. |
michael@0 | 204 | * @param radix the radix in which to parse; must be >= 2 and <= |
michael@0 | 205 | * 36. |
michael@0 | 206 | * @return a non-negative parsed number, or -1 upon parse failure. |
michael@0 | 207 | * Parse fails if there are no digits, that is, if pos does not |
michael@0 | 208 | * point to a valid digit on entry, or if the number to be parsed |
michael@0 | 209 | * does not fit into a 31-bit unsigned integer. |
michael@0 | 210 | */ |
michael@0 | 211 | static int32_t parseNumber(const UnicodeString& text, |
michael@0 | 212 | int32_t& pos, int8_t radix); |
michael@0 | 213 | |
michael@0 | 214 | static void appendToRule(UnicodeString& rule, |
michael@0 | 215 | UChar32 c, |
michael@0 | 216 | UBool isLiteral, |
michael@0 | 217 | UBool escapeUnprintable, |
michael@0 | 218 | UnicodeString& quoteBuf); |
michael@0 | 219 | |
michael@0 | 220 | static void appendToRule(UnicodeString& rule, |
michael@0 | 221 | const UnicodeString& text, |
michael@0 | 222 | UBool isLiteral, |
michael@0 | 223 | UBool escapeUnprintable, |
michael@0 | 224 | UnicodeString& quoteBuf); |
michael@0 | 225 | |
michael@0 | 226 | static void appendToRule(UnicodeString& rule, |
michael@0 | 227 | const UnicodeMatcher* matcher, |
michael@0 | 228 | UBool escapeUnprintable, |
michael@0 | 229 | UnicodeString& quoteBuf); |
michael@0 | 230 | |
michael@0 | 231 | private: |
michael@0 | 232 | // do not instantiate |
michael@0 | 233 | ICU_Utility(); |
michael@0 | 234 | }; |
michael@0 | 235 | |
michael@0 | 236 | U_NAMESPACE_END |
michael@0 | 237 | |
michael@0 | 238 | #endif |
michael@0 | 239 | //eof |