Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsStringIterator.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 nsStringIterator_h___
8
#define nsStringIterator_h___
9
10
#include "nsCharTraits.h"
11
#include "nsAlgorithm.h"
12
#include "nsDebug.h"
13
14
/**
15
 * @see nsTAString
16
 */
17
18
template <class CharT>
19
class nsReadingIterator
20
{
21
public:
22
  typedef nsReadingIterator<CharT>    self_type;
23
  typedef ptrdiff_t                   difference_type;
24
  typedef size_t                      size_type;
25
  typedef CharT                       value_type;
26
  typedef const CharT*                pointer;
27
  typedef const CharT&                reference;
28
29
private:
30
  friend class mozilla::detail::nsTStringRepr<CharT>;
31
32
  // unfortunately, the API for nsReadingIterator requires that the
33
  // iterator know its start and end positions.  this was needed when
34
  // we supported multi-fragment strings, but now it is really just
35
  // extra baggage.  we should remove mStart and mEnd at some point.
36
37
  const CharT* mStart;
38
  const CharT* mEnd;
39
  const CharT* mPosition;
40
41
public:
42
  nsReadingIterator()
43
    : mStart(nullptr)
44
    , mEnd(nullptr)
45
    , mPosition(nullptr)
46
19.9M
  {
47
19.9M
  }
48
  // nsReadingIterator( const nsReadingIterator<CharT>& );                    // auto-generated copy-constructor OK
49
  // nsReadingIterator<CharT>& operator=( const nsReadingIterator<CharT>& );  // auto-generated copy-assignment operator OK
50
51
  pointer get() const
52
96.6M
  {
53
96.6M
    return mPosition;
54
96.6M
  }
55
56
  CharT operator*() const
57
26.4M
  {
58
26.4M
    return *get();
59
26.4M
  }
nsReadingIterator<char>::operator*() const
Line
Count
Source
57
23.3M
  {
58
23.3M
    return *get();
59
23.3M
  }
nsReadingIterator<char16_t>::operator*() const
Line
Count
Source
57
3.09M
  {
58
3.09M
    return *get();
59
3.09M
  }
60
61
  self_type& operator++()
62
  {
63
    ++mPosition;
64
    return *this;
65
  }
66
67
  self_type operator++(int)
68
18.8M
  {
69
18.8M
    self_type result(*this);
70
18.8M
    ++mPosition;
71
18.8M
    return result;
72
18.8M
  }
nsReadingIterator<char>::operator++(int)
Line
Count
Source
68
15.7M
  {
69
15.7M
    self_type result(*this);
70
15.7M
    ++mPosition;
71
15.7M
    return result;
72
15.7M
  }
nsReadingIterator<char16_t>::operator++(int)
Line
Count
Source
68
3.09M
  {
69
3.09M
    self_type result(*this);
70
3.09M
    ++mPosition;
71
3.09M
    return result;
72
3.09M
  }
73
74
  self_type& operator--()
75
  {
76
    --mPosition;
77
    return *this;
78
  }
79
80
  self_type operator--(int)
81
0
  {
82
0
    self_type result(*this);
83
0
    --mPosition;
84
0
    return result;
85
0
  }
Unexecuted instantiation: nsReadingIterator<char16_t>::operator--(int)
Unexecuted instantiation: nsReadingIterator<char>::operator--(int)
86
87
  self_type& advance(difference_type aN)
88
  {
89
    if (aN > 0) {
90
      difference_type step = XPCOM_MIN(aN, mEnd - mPosition);
91
92
      NS_ASSERTION(step > 0,
93
                   "can't advance a reading iterator beyond the end of a string");
94
95
      mPosition += step;
96
    } else if (aN < 0) {
97
      difference_type step = XPCOM_MAX(aN, -(mPosition - mStart));
98
99
      NS_ASSERTION(step < 0,
100
                   "can't advance (backward) a reading iterator beyond the end of a string");
101
102
      mPosition += step;
103
    }
104
    return *this;
105
  }
106
107
  // We return an unsigned type here (with corresponding assert) rather than
108
  // the more usual difference_type because we want to make this class go
109
  // away in favor of mozilla::RangedPtr.  Since RangedPtr has the same
110
  // requirement we are enforcing here, the transition ought to be much
111
  // smoother.
112
  size_type operator-(const self_type& aOther) const
113
0
  {
114
0
    MOZ_ASSERT(mPosition >= aOther.mPosition);
115
0
    return mPosition - aOther.mPosition;
116
0
  }
Unexecuted instantiation: nsReadingIterator<char>::operator-(nsReadingIterator<char> const&) const
Unexecuted instantiation: nsReadingIterator<char16_t>::operator-(nsReadingIterator<char16_t> const&) const
117
};
118
119
template <class CharT>
120
inline bool
121
operator==(const nsReadingIterator<CharT>& aLhs,
122
           const nsReadingIterator<CharT>& aRhs)
123
{
124
  return aLhs.get() == aRhs.get();
125
}
126
127
template <class CharT>
128
inline bool
129
operator!=(const nsReadingIterator<CharT>& aLhs,
130
           const nsReadingIterator<CharT>& aRhs)
131
{
132
  return aLhs.get() != aRhs.get();
133
}
134
135
136
#endif /* !defined(nsStringIterator_h___) */