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-2012, 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 | * 05/19/2010 markus Rewritten from scratch |
michael@0 | 9 | ********************************************************************** |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | #ifndef CHARSTRING_H |
michael@0 | 13 | #define CHARSTRING_H |
michael@0 | 14 | |
michael@0 | 15 | #include "unicode/utypes.h" |
michael@0 | 16 | #include "unicode/unistr.h" |
michael@0 | 17 | #include "unicode/uobject.h" |
michael@0 | 18 | #include "cmemory.h" |
michael@0 | 19 | |
michael@0 | 20 | U_NAMESPACE_BEGIN |
michael@0 | 21 | |
michael@0 | 22 | // Windows needs us to DLL-export the MaybeStackArray template specialization, |
michael@0 | 23 | // but MacOS X cannot handle it. Same as in digitlst.h. |
michael@0 | 24 | #if !U_PLATFORM_IS_DARWIN_BASED |
michael@0 | 25 | template class U_COMMON_API MaybeStackArray<char, 40>; |
michael@0 | 26 | #endif |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * ICU-internal char * string class. |
michael@0 | 30 | * This class does not assume or enforce any particular character encoding. |
michael@0 | 31 | * Raw bytes can be stored. The string object owns its characters. |
michael@0 | 32 | * A terminating NUL is stored, but the class does not prevent embedded NUL characters. |
michael@0 | 33 | * |
michael@0 | 34 | * This class wants to be convenient but is also deliberately minimalist. |
michael@0 | 35 | * Please do not add methods if they only add minor convenience. |
michael@0 | 36 | * For example: |
michael@0 | 37 | * cs.data()[5]='a'; // no need for setCharAt(5, 'a') |
michael@0 | 38 | */ |
michael@0 | 39 | class U_COMMON_API CharString : public UMemory { |
michael@0 | 40 | public: |
michael@0 | 41 | CharString() : len(0) { buffer[0]=0; } |
michael@0 | 42 | CharString(const StringPiece &s, UErrorCode &errorCode) : len(0) { |
michael@0 | 43 | buffer[0]=0; |
michael@0 | 44 | append(s, errorCode); |
michael@0 | 45 | } |
michael@0 | 46 | CharString(const CharString &s, UErrorCode &errorCode) : len(0) { |
michael@0 | 47 | buffer[0]=0; |
michael@0 | 48 | append(s, errorCode); |
michael@0 | 49 | } |
michael@0 | 50 | CharString(const char *s, int32_t sLength, UErrorCode &errorCode) : len(0) { |
michael@0 | 51 | buffer[0]=0; |
michael@0 | 52 | append(s, sLength, errorCode); |
michael@0 | 53 | } |
michael@0 | 54 | ~CharString() {} |
michael@0 | 55 | |
michael@0 | 56 | /** |
michael@0 | 57 | * Replaces this string's contents with the other string's contents. |
michael@0 | 58 | * CharString does not support the standard copy constructor nor |
michael@0 | 59 | * the assignment operator, to make copies explicit and to |
michael@0 | 60 | * use a UErrorCode where memory allocations might be needed. |
michael@0 | 61 | */ |
michael@0 | 62 | CharString ©From(const CharString &other, UErrorCode &errorCode); |
michael@0 | 63 | |
michael@0 | 64 | UBool isEmpty() const { return len==0; } |
michael@0 | 65 | int32_t length() const { return len; } |
michael@0 | 66 | char operator[](int32_t index) const { return buffer[index]; } |
michael@0 | 67 | StringPiece toStringPiece() const { return StringPiece(buffer.getAlias(), len); } |
michael@0 | 68 | |
michael@0 | 69 | const char *data() const { return buffer.getAlias(); } |
michael@0 | 70 | char *data() { return buffer.getAlias(); } |
michael@0 | 71 | |
michael@0 | 72 | CharString &clear() { len=0; buffer[0]=0; return *this; } |
michael@0 | 73 | CharString &truncate(int32_t newLength); |
michael@0 | 74 | |
michael@0 | 75 | CharString &append(char c, UErrorCode &errorCode); |
michael@0 | 76 | CharString &append(const StringPiece &s, UErrorCode &errorCode) { |
michael@0 | 77 | return append(s.data(), s.length(), errorCode); |
michael@0 | 78 | } |
michael@0 | 79 | CharString &append(const CharString &s, UErrorCode &errorCode) { |
michael@0 | 80 | return append(s.data(), s.length(), errorCode); |
michael@0 | 81 | } |
michael@0 | 82 | CharString &append(const char *s, int32_t sLength, UErrorCode &status); |
michael@0 | 83 | /** |
michael@0 | 84 | * Returns a writable buffer for appending and writes the buffer's capacity to |
michael@0 | 85 | * resultCapacity. Guarantees resultCapacity>=minCapacity if U_SUCCESS(). |
michael@0 | 86 | * There will additionally be space for a terminating NUL right at resultCapacity. |
michael@0 | 87 | * (This function is similar to ByteSink.GetAppendBuffer().) |
michael@0 | 88 | * |
michael@0 | 89 | * The returned buffer is only valid until the next write operation |
michael@0 | 90 | * on this string. |
michael@0 | 91 | * |
michael@0 | 92 | * After writing at most resultCapacity bytes, call append() with the |
michael@0 | 93 | * pointer returned from this function and the number of bytes written. |
michael@0 | 94 | * |
michael@0 | 95 | * @param minCapacity required minimum capacity of the returned buffer; |
michael@0 | 96 | * must be non-negative |
michael@0 | 97 | * @param desiredCapacityHint desired capacity of the returned buffer; |
michael@0 | 98 | * must be non-negative |
michael@0 | 99 | * @param resultCapacity will be set to the capacity of the returned buffer |
michael@0 | 100 | * @param errorCode in/out error code |
michael@0 | 101 | * @return a buffer with resultCapacity>=min_capacity |
michael@0 | 102 | */ |
michael@0 | 103 | char *getAppendBuffer(int32_t minCapacity, |
michael@0 | 104 | int32_t desiredCapacityHint, |
michael@0 | 105 | int32_t &resultCapacity, |
michael@0 | 106 | UErrorCode &errorCode); |
michael@0 | 107 | |
michael@0 | 108 | CharString &appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode); |
michael@0 | 109 | |
michael@0 | 110 | /** |
michael@0 | 111 | * Appends a filename/path part, e.g., a directory name. |
michael@0 | 112 | * First appends a U_FILE_SEP_CHAR if necessary. |
michael@0 | 113 | * Does nothing if s is empty. |
michael@0 | 114 | */ |
michael@0 | 115 | CharString &appendPathPart(const StringPiece &s, UErrorCode &errorCode); |
michael@0 | 116 | |
michael@0 | 117 | private: |
michael@0 | 118 | MaybeStackArray<char, 40> buffer; |
michael@0 | 119 | int32_t len; |
michael@0 | 120 | |
michael@0 | 121 | UBool ensureCapacity(int32_t capacity, int32_t desiredCapacityHint, UErrorCode &errorCode); |
michael@0 | 122 | |
michael@0 | 123 | CharString(const CharString &other); // forbid copying of this class |
michael@0 | 124 | CharString &operator=(const CharString &other); // forbid copying of this class |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | U_NAMESPACE_END |
michael@0 | 128 | |
michael@0 | 129 | #endif |
michael@0 | 130 | //eof |