/work/obj-fuzz/dist/include/nsWhitespaceTokenizer.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef __nsWhitespaceTokenizer_h |
8 | | #define __nsWhitespaceTokenizer_h |
9 | | |
10 | | #include "mozilla/RangedPtr.h" |
11 | | #include "nsDependentSubstring.h" |
12 | | #include "nsCRT.h" |
13 | | |
14 | | template<typename DependentSubstringType, bool IsWhitespace(char16_t)> |
15 | | class nsTWhitespaceTokenizer |
16 | | { |
17 | | typedef typename DependentSubstringType::char_type CharType; |
18 | | typedef typename DependentSubstringType::substring_type SubstringType; |
19 | | |
20 | | public: |
21 | | explicit nsTWhitespaceTokenizer(const SubstringType& aSource) |
22 | | : mIter(aSource.Data(), aSource.Length()) |
23 | | , mEnd(aSource.Data() + aSource.Length(), aSource.Data(), |
24 | | aSource.Length()) |
25 | | , mWhitespaceBeforeFirstToken(false) |
26 | | , mWhitespaceAfterCurrentToken(false) |
27 | 0 | { |
28 | 0 | while (mIter < mEnd && IsWhitespace(*mIter)) { |
29 | 0 | mWhitespaceBeforeFirstToken = true; |
30 | 0 | ++mIter; |
31 | 0 | } |
32 | 0 | } Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char>, &(NS_IsAsciiWhitespace(char16_t))>::nsTWhitespaceTokenizer(nsTSubstring<char> const&) Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char16_t>, &nsContentUtils::IsHTMLWhitespace>::nsTWhitespaceTokenizer(nsTSubstring<char16_t> const&) Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char16_t>, &(NS_IsAsciiWhitespace(char16_t))>::nsTWhitespaceTokenizer(nsTSubstring<char16_t> const&) Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char>, &(IsNewLine(char16_t))>::nsTWhitespaceTokenizer(nsTSubstring<char> const&) |
33 | | |
34 | | /** |
35 | | * Checks if any more tokens are available. |
36 | | */ |
37 | | bool hasMoreTokens() const |
38 | 0 | { |
39 | 0 | return mIter < mEnd; |
40 | 0 | } Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char>, &(NS_IsAsciiWhitespace(char16_t))>::hasMoreTokens() const Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char16_t>, &nsContentUtils::IsHTMLWhitespace>::hasMoreTokens() const Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char16_t>, &(NS_IsAsciiWhitespace(char16_t))>::hasMoreTokens() const Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char>, &(IsNewLine(char16_t))>::hasMoreTokens() const |
41 | | |
42 | | /* |
43 | | * Returns true if there is whitespace prior to the first token. |
44 | | */ |
45 | | bool whitespaceBeforeFirstToken() const |
46 | 0 | { |
47 | 0 | return mWhitespaceBeforeFirstToken; |
48 | 0 | } |
49 | | |
50 | | /* |
51 | | * Returns true if there is any whitespace after the current token. |
52 | | * This is always true unless we're reading the last token. |
53 | | */ |
54 | | bool whitespaceAfterCurrentToken() const |
55 | 0 | { |
56 | 0 | return mWhitespaceAfterCurrentToken; |
57 | 0 | } |
58 | | |
59 | | /** |
60 | | * Returns the next token. |
61 | | */ |
62 | | const DependentSubstringType nextToken() |
63 | 0 | { |
64 | 0 | const mozilla::RangedPtr<const CharType> tokenStart = mIter; |
65 | 0 | while (mIter < mEnd && !IsWhitespace(*mIter)) { |
66 | 0 | ++mIter; |
67 | 0 | } |
68 | 0 | const mozilla::RangedPtr<const CharType> tokenEnd = mIter; |
69 | 0 | mWhitespaceAfterCurrentToken = false; |
70 | 0 | while (mIter < mEnd && IsWhitespace(*mIter)) { |
71 | 0 | mWhitespaceAfterCurrentToken = true; |
72 | 0 | ++mIter; |
73 | 0 | } |
74 | 0 | return Substring(tokenStart.get(), tokenEnd.get()); |
75 | 0 | } Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char>, &(NS_IsAsciiWhitespace(char16_t))>::nextToken() Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char16_t>, &nsContentUtils::IsHTMLWhitespace>::nextToken() Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char16_t>, &(NS_IsAsciiWhitespace(char16_t))>::nextToken() Unexecuted instantiation: nsTWhitespaceTokenizer<nsTDependentSubstring<char>, &(IsNewLine(char16_t))>::nextToken() |
76 | | |
77 | | private: |
78 | | mozilla::RangedPtr<const CharType> mIter; |
79 | | const mozilla::RangedPtr<const CharType> mEnd; |
80 | | bool mWhitespaceBeforeFirstToken; |
81 | | bool mWhitespaceAfterCurrentToken; |
82 | | }; |
83 | | |
84 | | template<bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace> |
85 | | class nsWhitespaceTokenizerTemplate |
86 | | : public nsTWhitespaceTokenizer<nsDependentSubstring, IsWhitespace> |
87 | | { |
88 | | public: |
89 | | explicit nsWhitespaceTokenizerTemplate(const nsAString& aSource) |
90 | | : nsTWhitespaceTokenizer<nsDependentSubstring, IsWhitespace>(aSource) |
91 | 0 | { |
92 | 0 | } Unexecuted instantiation: nsWhitespaceTokenizerTemplate<&nsContentUtils::IsHTMLWhitespace>::nsWhitespaceTokenizerTemplate(nsTSubstring<char16_t> const&) Unexecuted instantiation: nsWhitespaceTokenizerTemplate<&(NS_IsAsciiWhitespace(char16_t))>::nsWhitespaceTokenizerTemplate(nsTSubstring<char16_t> const&) |
93 | | }; |
94 | | |
95 | | typedef nsWhitespaceTokenizerTemplate<> nsWhitespaceTokenizer; |
96 | | |
97 | | template<bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace> |
98 | | class nsCWhitespaceTokenizerTemplate |
99 | | : public nsTWhitespaceTokenizer<nsDependentCSubstring, IsWhitespace> |
100 | | { |
101 | | public: |
102 | | explicit nsCWhitespaceTokenizerTemplate(const nsACString& aSource) |
103 | | : nsTWhitespaceTokenizer<nsDependentCSubstring, IsWhitespace>(aSource) |
104 | 0 | { |
105 | 0 | } Unexecuted instantiation: nsCWhitespaceTokenizerTemplate<&(NS_IsAsciiWhitespace(char16_t))>::nsCWhitespaceTokenizerTemplate(nsTSubstring<char> const&) Unexecuted instantiation: nsCWhitespaceTokenizerTemplate<&(IsNewLine(char16_t))>::nsCWhitespaceTokenizerTemplate(nsTSubstring<char> const&) |
106 | | }; |
107 | | |
108 | | typedef nsCWhitespaceTokenizerTemplate<> nsCWhitespaceTokenizer; |
109 | | |
110 | | #endif /* __nsWhitespaceTokenizer_h */ |