2004-02-19 05:44:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
#ifndef nsScannerString_h___
|
|
|
|
#define nsScannerString_h___
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsUnicharUtils.h" // for nsCaseInsensitiveStringComparator
|
2013-07-31 19:35:25 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NOTE: nsScannerString (and the other classes defined in this file) are
|
|
|
|
* not related to nsAString or any of the other xpcom/string classes.
|
|
|
|
*
|
|
|
|
* nsScannerString is based on the nsSlidingString implementation that used
|
|
|
|
* to live in xpcom/string. Now that nsAString is limited to representing
|
|
|
|
* only single fragment strings, nsSlidingString can no longer be used.
|
|
|
|
*
|
2017-10-26 17:50:26 +03:00
|
|
|
* An advantage to this design is that it does not employ any virtual
|
2004-02-19 05:44:03 +03:00
|
|
|
* functions.
|
|
|
|
*
|
|
|
|
* This file uses SCC-style indenting in deference to the nsSlidingString
|
|
|
|
* code from which this code is derived ;-)
|
|
|
|
*/
|
|
|
|
|
|
|
|
class nsScannerIterator;
|
|
|
|
class nsScannerSubstring;
|
|
|
|
class nsScannerString;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsScannerBufferList
|
|
|
|
*
|
|
|
|
* This class maintains a list of heap-allocated Buffer objects. The buffers
|
|
|
|
* are maintained in a circular linked list. Each buffer has a usage count
|
|
|
|
* that is decremented by the owning nsScannerSubstring.
|
|
|
|
*
|
|
|
|
* The buffer list itself is reference counted. This allows the buffer list
|
|
|
|
* to be shared by multiple nsScannerSubstring objects. The reference
|
|
|
|
* counting is not threadsafe, which is not at all a requirement.
|
|
|
|
*
|
|
|
|
* When a nsScannerSubstring releases its reference to a buffer list, it
|
|
|
|
* decrements the usage count of the first buffer in the buffer list that it
|
|
|
|
* was referencing. It informs the buffer list that it can discard buffers
|
|
|
|
* starting at that prefix. The buffer list will do so if the usage count of
|
|
|
|
* that buffer is 0 and if it is the first buffer in the list. It will
|
|
|
|
* continue to prune buffers starting from the front of the buffer list until
|
|
|
|
* it finds a buffer that has a usage count that is non-zero.
|
|
|
|
*/
|
|
|
|
class nsScannerBufferList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Buffer objects are directly followed by a data segment. The start
|
|
|
|
* of the data segment is determined by increment the |this| pointer
|
|
|
|
* by 1 unit.
|
|
|
|
*/
|
2013-07-31 19:35:25 +04:00
|
|
|
class Buffer : public mozilla::LinkedListElement<Buffer>
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void IncrementUsageCount() { ++mUsageCount; }
|
|
|
|
void DecrementUsageCount() { --mUsageCount; }
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInUse() const { return mUsageCount != 0; }
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* DataStart() const { return (const char16_t*) (this+1); }
|
|
|
|
char16_t* DataStart() { return ( char16_t*) (this+1); }
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* DataEnd() const { return mDataEnd; }
|
|
|
|
char16_t* DataEnd() { return mDataEnd; }
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2013-07-31 19:35:25 +04:00
|
|
|
const Buffer* Next() const { return getNext(); }
|
|
|
|
Buffer* Next() { return getNext(); }
|
2012-10-31 20:31:36 +04:00
|
|
|
|
2013-07-31 19:35:25 +04:00
|
|
|
const Buffer* Prev() const { return getPrevious(); }
|
|
|
|
Buffer* Prev() { return getPrevious(); }
|
2012-10-31 20:31:36 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t DataLength() const { return mDataEnd - DataStart(); }
|
|
|
|
void SetDataLength(uint32_t len) { mDataEnd = DataStart() + len; }
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
friend class nsScannerBufferList;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mUsageCount;
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* mDataEnd;
|
2004-02-19 05:44:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Position objects serve as lightweight pointers into a buffer list.
|
|
|
|
* The mPosition member must be contained with mBuffer->DataStart()
|
|
|
|
* and mBuffer->DataEnd().
|
|
|
|
*/
|
|
|
|
class Position
|
|
|
|
{
|
|
|
|
public:
|
2018-06-14 00:08:27 +03:00
|
|
|
Position()
|
|
|
|
: mBuffer(nullptr)
|
|
|
|
, mPosition(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2017-10-26 17:50:26 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
Position( Buffer* buffer, char16_t* position )
|
2004-02-19 05:44:03 +03:00
|
|
|
: mBuffer(buffer)
|
|
|
|
, mPosition(position)
|
|
|
|
{}
|
2017-10-26 17:50:26 +03:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
inline
|
2014-09-02 02:04:52 +04:00
|
|
|
explicit Position( const nsScannerIterator& aIter );
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
inline
|
|
|
|
Position& operator=( const nsScannerIterator& aIter );
|
|
|
|
|
|
|
|
static size_t Distance( const Position& p1, const Position& p2 );
|
|
|
|
|
|
|
|
Buffer* mBuffer;
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* mPosition;
|
2004-02-19 05:44:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static Buffer* AllocBufferFromString( const nsAString& );
|
2012-08-22 19:56:38 +04:00
|
|
|
static Buffer* AllocBuffer( uint32_t capacity ); // capacity = number of chars
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-09-02 02:04:52 +04:00
|
|
|
explicit nsScannerBufferList( Buffer* buf )
|
2004-02-19 05:44:03 +03:00
|
|
|
: mRefCnt(0)
|
|
|
|
{
|
2013-07-31 19:35:25 +04:00
|
|
|
mBuffers.insertBack(buf);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddRef() { ++mRefCnt; }
|
|
|
|
void Release() { if (--mRefCnt == 0) delete this; }
|
|
|
|
|
2017-10-26 17:50:26 +03:00
|
|
|
void Append( Buffer* buf ) { mBuffers.insertBack(buf); }
|
2013-07-31 19:35:25 +04:00
|
|
|
void InsertAfter( Buffer* buf, Buffer* prev ) { prev->setNext(buf); }
|
2004-02-19 05:44:03 +03:00
|
|
|
void SplitBuffer( const Position& );
|
|
|
|
void DiscardUnreferencedPrefix( Buffer* );
|
|
|
|
|
2013-07-31 19:35:25 +04:00
|
|
|
Buffer* Head() { return mBuffers.getFirst(); }
|
|
|
|
const Buffer* Head() const { return mBuffers.getFirst(); }
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2013-07-31 19:35:25 +04:00
|
|
|
Buffer* Tail() { return mBuffers.getLast(); }
|
|
|
|
const Buffer* Tail() const { return mBuffers.getLast(); }
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
friend class nsScannerSubstring;
|
|
|
|
|
|
|
|
~nsScannerBufferList() { ReleaseAll(); }
|
|
|
|
void ReleaseAll();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mRefCnt;
|
2013-07-31 19:35:25 +04:00
|
|
|
mozilla::LinkedList<Buffer> mBuffers;
|
2004-02-19 05:44:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsScannerFragment represents a "slice" of a Buffer object.
|
|
|
|
*/
|
|
|
|
struct nsScannerFragment
|
|
|
|
{
|
|
|
|
typedef nsScannerBufferList::Buffer Buffer;
|
|
|
|
|
|
|
|
const Buffer* mBuffer;
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* mFragmentStart;
|
|
|
|
const char16_t* mFragmentEnd;
|
2004-02-19 05:44:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsScannerSubstring is the base class for nsScannerString. It provides
|
|
|
|
* access to iterators and methods to bind the substring to another
|
|
|
|
* substring or nsAString instance.
|
|
|
|
*
|
|
|
|
* This class owns the buffer list.
|
|
|
|
*/
|
|
|
|
class nsScannerSubstring
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef nsScannerBufferList::Buffer Buffer;
|
|
|
|
typedef nsScannerBufferList::Position Position;
|
2012-08-22 19:56:38 +04:00
|
|
|
typedef uint32_t size_type;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
nsScannerSubstring();
|
2014-09-02 02:04:52 +04:00
|
|
|
explicit nsScannerSubstring( const nsAString& s );
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
~nsScannerSubstring();
|
|
|
|
|
|
|
|
nsScannerIterator& BeginReading( nsScannerIterator& iter ) const;
|
|
|
|
nsScannerIterator& EndReading( nsScannerIterator& iter ) const;
|
|
|
|
|
|
|
|
size_type Length() const { return mLength; }
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
int32_t CountChar( char16_t ) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
void Rebind( const nsScannerSubstring&, const nsScannerIterator&, const nsScannerIterator& );
|
|
|
|
void Rebind( const nsAString& );
|
|
|
|
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& AsString() const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetNextFragment( nsScannerFragment& ) const;
|
|
|
|
bool GetPrevFragment( nsScannerFragment& ) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
static inline Buffer* AllocBufferFromString( const nsAString& aStr ) { return nsScannerBufferList::AllocBufferFromString(aStr); }
|
|
|
|
static inline Buffer* AllocBuffer( size_type aCapacity ) { return nsScannerBufferList::AllocBuffer(aCapacity); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void acquire_ownership_of_buffer_list() const
|
|
|
|
{
|
|
|
|
mBufferList->AddRef();
|
|
|
|
mStart.mBuffer->IncrementUsageCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_ownership_of_buffer_list()
|
|
|
|
{
|
|
|
|
if (mBufferList)
|
|
|
|
{
|
|
|
|
mStart.mBuffer->DecrementUsageCount();
|
|
|
|
mBufferList->DiscardUnreferencedPrefix(mStart.mBuffer);
|
|
|
|
mBufferList->Release();
|
|
|
|
}
|
|
|
|
}
|
2017-10-26 17:50:26 +03:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
void init_range_from_buffer_list()
|
|
|
|
{
|
|
|
|
mStart.mBuffer = mBufferList->Head();
|
|
|
|
mStart.mPosition = mStart.mBuffer->DataStart();
|
|
|
|
|
|
|
|
mEnd.mBuffer = mBufferList->Tail();
|
|
|
|
mEnd.mPosition = mEnd.mBuffer->DataEnd();
|
|
|
|
|
|
|
|
mLength = Position::Distance(mStart, mEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
Position mStart;
|
|
|
|
Position mEnd;
|
|
|
|
nsScannerBufferList *mBufferList;
|
|
|
|
size_type mLength;
|
|
|
|
|
|
|
|
// these fields are used to implement AsString
|
2004-11-25 10:03:20 +03:00
|
|
|
nsDependentSubstring mFlattenedRep;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsDirty;
|
2004-11-25 10:03:20 +03:00
|
|
|
|
|
|
|
friend class nsScannerSharedSubstring;
|
2004-02-19 05:44:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsScannerString provides methods to grow and modify a buffer list.
|
|
|
|
*/
|
|
|
|
class nsScannerString : public nsScannerSubstring
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-09-02 02:04:52 +04:00
|
|
|
explicit nsScannerString( Buffer* );
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
// you are giving ownership to the string, it takes and keeps your
|
|
|
|
// buffer, deleting it when done.
|
|
|
|
// Use AllocBuffer or AllocBufferFromString to create a Buffer object
|
|
|
|
// for use with this function.
|
|
|
|
void AppendBuffer( Buffer* );
|
|
|
|
|
|
|
|
void DiscardPrefix( const nsScannerIterator& );
|
|
|
|
// any other way you want to do this?
|
|
|
|
|
|
|
|
void UngetReadable(const nsAString& aReadable, const nsScannerIterator& aCurrentPosition);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-11-25 10:03:20 +03:00
|
|
|
/**
|
|
|
|
* nsScannerSharedSubstring implements copy-on-write semantics for
|
|
|
|
* nsScannerSubstring. When you call .writable(), it will copy the data
|
|
|
|
* and return a mutable string object. This class also manages releasing
|
|
|
|
* the reference to the scanner buffer when it is no longer needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class nsScannerSharedSubstring
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsScannerSharedSubstring()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mBuffer(nullptr), mBufferList(nullptr) { }
|
2004-11-25 10:03:20 +03:00
|
|
|
|
|
|
|
~nsScannerSharedSubstring()
|
|
|
|
{
|
|
|
|
if (mBufferList)
|
|
|
|
ReleaseBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Acquire a copy-on-write reference to the given substring.
|
2014-06-02 16:08:21 +04:00
|
|
|
void Rebind(const nsScannerIterator& aStart,
|
2004-11-25 10:03:20 +03:00
|
|
|
const nsScannerIterator& aEnd);
|
|
|
|
|
|
|
|
// Get a mutable reference to this string
|
2017-06-20 12:19:52 +03:00
|
|
|
nsAString& writable()
|
2004-11-25 10:03:20 +03:00
|
|
|
{
|
|
|
|
if (mBufferList)
|
|
|
|
MakeMutable();
|
|
|
|
|
|
|
|
return mString;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a const reference to this string
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& str() const { return mString; }
|
2004-11-25 10:03:20 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef nsScannerBufferList::Buffer Buffer;
|
|
|
|
|
2014-06-02 16:08:21 +04:00
|
|
|
void ReleaseBuffer();
|
|
|
|
void MakeMutable();
|
2004-11-25 10:03:20 +03:00
|
|
|
|
|
|
|
nsDependentSubstring mString;
|
|
|
|
Buffer *mBuffer;
|
|
|
|
nsScannerBufferList *mBufferList;
|
|
|
|
};
|
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
/**
|
|
|
|
* nsScannerIterator works just like nsReadingIterator<CharT> except that
|
|
|
|
* it knows how to iterate over a list of scanner buffers.
|
|
|
|
*/
|
|
|
|
class nsScannerIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef nsScannerIterator self_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
2014-01-04 19:02:17 +04:00
|
|
|
typedef char16_t value_type;
|
|
|
|
typedef const char16_t* pointer;
|
|
|
|
typedef const char16_t& reference;
|
2004-02-19 05:44:03 +03:00
|
|
|
typedef nsScannerSubstring::Buffer Buffer;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
nsScannerFragment mFragment;
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* mPosition;
|
2004-02-19 05:44:03 +03:00
|
|
|
const nsScannerSubstring* mOwner;
|
|
|
|
|
|
|
|
friend class nsScannerSubstring;
|
2004-11-25 10:03:20 +03:00
|
|
|
friend class nsScannerSharedSubstring;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
public:
|
2017-10-26 17:50:26 +03:00
|
|
|
// nsScannerIterator(); // auto-generate default constructor is OK
|
2004-02-19 05:44:03 +03:00
|
|
|
// nsScannerIterator( const nsScannerIterator& ); // auto-generated copy-constructor OK
|
|
|
|
// nsScannerIterator& operator=( const nsScannerIterator& ); // auto-generated copy-assignment operator OK
|
|
|
|
|
|
|
|
inline void normalize_forward();
|
|
|
|
inline void normalize_backward();
|
|
|
|
|
|
|
|
pointer get() const
|
|
|
|
{
|
|
|
|
return mPosition;
|
|
|
|
}
|
2017-10-26 17:50:26 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t operator*() const
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
|
|
|
return *get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsScannerFragment& fragment() const
|
|
|
|
{
|
|
|
|
return mFragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Buffer* buffer() const
|
|
|
|
{
|
|
|
|
return mFragment.mBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
self_type& operator++()
|
|
|
|
{
|
|
|
|
++mPosition;
|
|
|
|
normalize_forward();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
self_type operator++( int )
|
|
|
|
{
|
|
|
|
self_type result(*this);
|
|
|
|
++mPosition;
|
|
|
|
normalize_forward();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
self_type& operator--()
|
|
|
|
{
|
|
|
|
normalize_backward();
|
|
|
|
--mPosition;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
self_type operator--( int )
|
|
|
|
{
|
|
|
|
self_type result(*this);
|
|
|
|
normalize_backward();
|
|
|
|
--mPosition;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
difference_type size_forward() const
|
|
|
|
{
|
|
|
|
return mFragment.mFragmentEnd - mPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
difference_type size_backward() const
|
|
|
|
{
|
|
|
|
return mPosition - mFragment.mFragmentStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
self_type& advance( difference_type n )
|
|
|
|
{
|
|
|
|
while ( n > 0 )
|
|
|
|
{
|
2013-01-15 16:22:03 +04:00
|
|
|
difference_type one_hop = std::min(n, size_forward());
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a reading iterator beyond the end of a string");
|
|
|
|
// perhaps I should |break| if |!one_hop|?
|
|
|
|
|
|
|
|
mPosition += one_hop;
|
|
|
|
normalize_forward();
|
|
|
|
n -= one_hop;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( n < 0 )
|
|
|
|
{
|
|
|
|
normalize_backward();
|
2013-01-15 16:22:03 +04:00
|
|
|
difference_type one_hop = std::max(n, -size_backward());
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a reading iterator beyond the end of a string");
|
|
|
|
// perhaps I should |break| if |!one_hop|?
|
|
|
|
|
|
|
|
mPosition += one_hop;
|
|
|
|
n -= one_hop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
SameFragment( const nsScannerIterator& a, const nsScannerIterator& b )
|
|
|
|
{
|
|
|
|
return a.fragment().mFragmentStart == b.fragment().mFragmentStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this class is needed in order to make use of the methods in nsAlgorithm.h
|
|
|
|
*/
|
2011-12-13 18:17:59 +04:00
|
|
|
template <>
|
2004-02-19 05:44:03 +03:00
|
|
|
struct nsCharSourceTraits<nsScannerIterator>
|
|
|
|
{
|
|
|
|
typedef nsScannerIterator::difference_type difference_type;
|
|
|
|
|
|
|
|
static
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2004-02-19 05:44:03 +03:00
|
|
|
readable_distance( const nsScannerIterator& first, const nsScannerIterator& last )
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
return uint32_t(SameFragment(first, last) ? last.get() - first.get() : first.size_forward());
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
const nsScannerIterator::value_type*
|
|
|
|
read( const nsScannerIterator& iter )
|
|
|
|
{
|
|
|
|
return iter.get();
|
|
|
|
}
|
2017-10-26 17:50:26 +03:00
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
static
|
|
|
|
void
|
|
|
|
advance( nsScannerIterator& s, difference_type n )
|
|
|
|
{
|
|
|
|
s.advance(n);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* inline methods follow
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline
|
|
|
|
void
|
|
|
|
nsScannerIterator::normalize_forward()
|
|
|
|
{
|
|
|
|
while (mPosition == mFragment.mFragmentEnd && mOwner->GetNextFragment(mFragment))
|
|
|
|
mPosition = mFragment.mFragmentStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void
|
|
|
|
nsScannerIterator::normalize_backward()
|
|
|
|
{
|
|
|
|
while (mPosition == mFragment.mFragmentStart && mOwner->GetPrevFragment(mFragment))
|
|
|
|
mPosition = mFragment.mFragmentEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
operator==( const nsScannerIterator& lhs, const nsScannerIterator& rhs )
|
|
|
|
{
|
|
|
|
return lhs.get() == rhs.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
operator!=( const nsScannerIterator& lhs, const nsScannerIterator& rhs )
|
|
|
|
{
|
|
|
|
return lhs.get() != rhs.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
nsScannerBufferList::Position::Position(const nsScannerIterator& aIter)
|
2007-07-08 11:08:04 +04:00
|
|
|
: mBuffer(const_cast<Buffer*>(aIter.buffer()))
|
2014-01-04 19:02:17 +04:00
|
|
|
, mPosition(const_cast<char16_t*>(aIter.get()))
|
2004-02-19 05:44:03 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
inline
|
|
|
|
nsScannerBufferList::Position&
|
|
|
|
nsScannerBufferList::Position::operator=(const nsScannerIterator& aIter)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
mBuffer = const_cast<Buffer*>(aIter.buffer());
|
2014-01-04 19:02:17 +04:00
|
|
|
mPosition = const_cast<char16_t*>(aIter.get());
|
2004-02-19 05:44:03 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scanner string utils
|
|
|
|
*
|
|
|
|
* These methods mimic the API provided by nsReadableUtils in xpcom/string.
|
|
|
|
* Here we provide only the methods that the htmlparser module needs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline
|
|
|
|
size_t
|
|
|
|
Distance( const nsScannerIterator& aStart, const nsScannerIterator& aEnd )
|
|
|
|
{
|
|
|
|
typedef nsScannerBufferList::Position Position;
|
|
|
|
return Position::Distance(Position(aStart), Position(aEnd));
|
|
|
|
}
|
|
|
|
|
2016-02-09 13:45:59 +03:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
CopyUnicodeTo( const nsScannerIterator& aSrcStart,
|
|
|
|
const nsScannerIterator& aSrcEnd,
|
|
|
|
nsAString& aDest );
|
|
|
|
|
|
|
|
inline
|
2016-02-09 13:45:59 +03:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
CopyUnicodeTo( const nsScannerSubstring& aSrc, nsAString& aDest )
|
|
|
|
{
|
|
|
|
nsScannerIterator begin, end;
|
2016-02-09 13:45:59 +03:00
|
|
|
return CopyUnicodeTo(aSrc.BeginReading(begin), aSrc.EndReading(end), aDest);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2016-02-09 13:45:59 +03:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
AppendUnicodeTo( const nsScannerIterator& aSrcStart,
|
|
|
|
const nsScannerIterator& aSrcEnd,
|
|
|
|
nsAString& aDest );
|
|
|
|
|
|
|
|
inline
|
2016-02-09 13:45:59 +03:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
AppendUnicodeTo( const nsScannerSubstring& aSrc, nsAString& aDest )
|
|
|
|
{
|
|
|
|
nsScannerIterator begin, end;
|
2016-02-09 13:45:59 +03:00
|
|
|
return AppendUnicodeTo(aSrc.BeginReading(begin), aSrc.EndReading(end), aDest);
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
|
|
|
|
2016-02-09 13:45:59 +03:00
|
|
|
bool
|
2004-11-25 10:03:20 +03:00
|
|
|
AppendUnicodeTo( const nsScannerIterator& aSrcStart,
|
|
|
|
const nsScannerIterator& aSrcEnd,
|
|
|
|
nsScannerSharedSubstring& aDest );
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-01-04 19:02:17 +04:00
|
|
|
FindCharInReadable( char16_t aChar,
|
2004-02-19 05:44:03 +03:00
|
|
|
nsScannerIterator& aStart,
|
|
|
|
const nsScannerIterator& aEnd );
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
FindInReadable( const nsAString& aPattern,
|
|
|
|
nsScannerIterator& aStart,
|
|
|
|
nsScannerIterator& aEnd,
|
|
|
|
const nsStringComparator& = nsDefaultStringComparator() );
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-02-19 05:44:03 +03:00
|
|
|
RFindInReadable( const nsAString& aPattern,
|
|
|
|
nsScannerIterator& aStart,
|
|
|
|
nsScannerIterator& aEnd,
|
|
|
|
const nsStringComparator& = nsDefaultStringComparator() );
|
|
|
|
|
|
|
|
inline
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-10-26 17:50:26 +03:00
|
|
|
CaseInsensitiveFindInReadable( const nsAString& aPattern,
|
2004-02-19 05:44:03 +03:00
|
|
|
nsScannerIterator& aStart,
|
|
|
|
nsScannerIterator& aEnd )
|
|
|
|
{
|
|
|
|
return FindInReadable(aPattern, aStart, aEnd,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(nsScannerString_h___)
|