xpcom/ds/nsWhitespaceTokenizer.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 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef __nsWhitespaceTokenizer_h
michael@0 7 #define __nsWhitespaceTokenizer_h
michael@0 8
michael@0 9 #include "mozilla/RangedPtr.h"
michael@0 10 #include "nsDependentSubstring.h"
michael@0 11 #include "nsCRT.h"
michael@0 12
michael@0 13 template<bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace>
michael@0 14 class nsWhitespaceTokenizerTemplate
michael@0 15 {
michael@0 16 public:
michael@0 17 nsWhitespaceTokenizerTemplate(const nsSubstring& aSource)
michael@0 18 : mIter(aSource.Data(), aSource.Length()),
michael@0 19 mEnd(aSource.Data() + aSource.Length(), aSource.Data(),
michael@0 20 aSource.Length()),
michael@0 21 mWhitespaceBeforeFirstToken(false),
michael@0 22 mWhitespaceAfterCurrentToken(false)
michael@0 23 {
michael@0 24 while (mIter < mEnd && IsWhitespace(*mIter)) {
michael@0 25 mWhitespaceBeforeFirstToken = true;
michael@0 26 ++mIter;
michael@0 27 }
michael@0 28 }
michael@0 29
michael@0 30 /**
michael@0 31 * Checks if any more tokens are available.
michael@0 32 */
michael@0 33 bool hasMoreTokens() const
michael@0 34 {
michael@0 35 return mIter < mEnd;
michael@0 36 }
michael@0 37
michael@0 38 /*
michael@0 39 * Returns true if there is whitespace prior to the first token.
michael@0 40 */
michael@0 41 bool whitespaceBeforeFirstToken() const
michael@0 42 {
michael@0 43 return mWhitespaceBeforeFirstToken;
michael@0 44 }
michael@0 45
michael@0 46 /*
michael@0 47 * Returns true if there is any whitespace after the current token.
michael@0 48 * This is always true unless we're reading the last token.
michael@0 49 */
michael@0 50 bool whitespaceAfterCurrentToken() const
michael@0 51 {
michael@0 52 return mWhitespaceAfterCurrentToken;
michael@0 53 }
michael@0 54
michael@0 55 /**
michael@0 56 * Returns the next token.
michael@0 57 */
michael@0 58 const nsDependentSubstring nextToken()
michael@0 59 {
michael@0 60 const mozilla::RangedPtr<const char16_t> tokenStart = mIter;
michael@0 61 while (mIter < mEnd && !IsWhitespace(*mIter)) {
michael@0 62 ++mIter;
michael@0 63 }
michael@0 64 const mozilla::RangedPtr<const char16_t> tokenEnd = mIter;
michael@0 65 mWhitespaceAfterCurrentToken = false;
michael@0 66 while (mIter < mEnd && IsWhitespace(*mIter)) {
michael@0 67 mWhitespaceAfterCurrentToken = true;
michael@0 68 ++mIter;
michael@0 69 }
michael@0 70 return Substring(tokenStart.get(), tokenEnd.get());
michael@0 71 }
michael@0 72
michael@0 73 private:
michael@0 74 mozilla::RangedPtr<const char16_t> mIter;
michael@0 75 const mozilla::RangedPtr<const char16_t> mEnd;
michael@0 76 bool mWhitespaceBeforeFirstToken;
michael@0 77 bool mWhitespaceAfterCurrentToken;
michael@0 78 };
michael@0 79
michael@0 80 class nsWhitespaceTokenizer: public nsWhitespaceTokenizerTemplate<>
michael@0 81 {
michael@0 82 public:
michael@0 83 nsWhitespaceTokenizer(const nsSubstring& aSource)
michael@0 84 : nsWhitespaceTokenizerTemplate<>(aSource)
michael@0 85 {
michael@0 86 }
michael@0 87 };
michael@0 88
michael@0 89 template<bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace>
michael@0 90 class nsCWhitespaceTokenizerTemplate
michael@0 91 {
michael@0 92 public:
michael@0 93 nsCWhitespaceTokenizerTemplate(const nsCSubstring& aSource)
michael@0 94 : mIter(aSource.Data(), aSource.Length()),
michael@0 95 mEnd(aSource.Data() + aSource.Length(), aSource.Data(),
michael@0 96 aSource.Length()),
michael@0 97 mWhitespaceBeforeFirstToken(false),
michael@0 98 mWhitespaceAfterCurrentToken(false)
michael@0 99 {
michael@0 100 while (mIter < mEnd && IsWhitespace(*mIter)) {
michael@0 101 mWhitespaceBeforeFirstToken = true;
michael@0 102 ++mIter;
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 /**
michael@0 107 * Checks if any more tokens are available.
michael@0 108 */
michael@0 109 bool hasMoreTokens() const
michael@0 110 {
michael@0 111 return mIter < mEnd;
michael@0 112 }
michael@0 113
michael@0 114 /*
michael@0 115 * Returns true if there is whitespace prior to the first token.
michael@0 116 */
michael@0 117 bool whitespaceBeforeFirstToken() const
michael@0 118 {
michael@0 119 return mWhitespaceBeforeFirstToken;
michael@0 120 }
michael@0 121
michael@0 122 /*
michael@0 123 * Returns true if there is any whitespace after the current token.
michael@0 124 * This is always true unless we're reading the last token.
michael@0 125 */
michael@0 126 bool whitespaceAfterCurrentToken() const
michael@0 127 {
michael@0 128 return mWhitespaceAfterCurrentToken;
michael@0 129 }
michael@0 130
michael@0 131 /**
michael@0 132 * Returns the next token.
michael@0 133 */
michael@0 134 const nsDependentCSubstring nextToken()
michael@0 135 {
michael@0 136 const mozilla::RangedPtr<const char> tokenStart = mIter;
michael@0 137 while (mIter < mEnd && !IsWhitespace(*mIter)) {
michael@0 138 ++mIter;
michael@0 139 }
michael@0 140 const mozilla::RangedPtr<const char> tokenEnd = mIter;
michael@0 141 mWhitespaceAfterCurrentToken = false;
michael@0 142 while (mIter < mEnd && IsWhitespace(*mIter)) {
michael@0 143 mWhitespaceAfterCurrentToken = true;
michael@0 144 ++mIter;
michael@0 145 }
michael@0 146 return Substring(tokenStart.get(), tokenEnd.get());
michael@0 147 }
michael@0 148
michael@0 149 private:
michael@0 150 mozilla::RangedPtr<const char> mIter;
michael@0 151 const mozilla::RangedPtr<const char> mEnd;
michael@0 152 bool mWhitespaceBeforeFirstToken;
michael@0 153 bool mWhitespaceAfterCurrentToken;
michael@0 154 };
michael@0 155
michael@0 156 class nsCWhitespaceTokenizer: public nsCWhitespaceTokenizerTemplate<>
michael@0 157 {
michael@0 158 public:
michael@0 159 nsCWhitespaceTokenizer(const nsCSubstring& aSource)
michael@0 160 : nsCWhitespaceTokenizerTemplate<>(aSource)
michael@0 161 {
michael@0 162 }
michael@0 163 };
michael@0 164
michael@0 165 #endif /* __nsWhitespaceTokenizer_h */

mercurial