/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:set ts=2 sw=2 sts=2 et cindent: */ /* 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/. */
#include"nsString.h" #include"nsUnicharUtils.h"// for nsCaseInsensitiveStringComparator #include"mozilla/LinkedList.h" #include <algorithm>
/** * 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. * * An advantage to this design is that it does not employ any virtual * 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.
*/ class Buffer : public mozilla::LinkedListElement<Buffer> { public: void IncrementUsageCount() { ++mUsageCount; } void DecrementUsageCount() { --mUsageCount; }
/** * 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:
Position() : mBuffer(nullptr), mPosition(nullptr) {}
/** * 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; typedef uint32_t size_type;
Position mStart;
Position mEnd;
nsScannerBufferList* mBufferList;
size_type mLength;
friendclass nsScannerSharedSubstring;
};
/** * nsScannerString provides methods to grow and modify a buffer list.
*/ class nsScannerString : public nsScannerSubstring { public: explicit nsScannerString(Buffer*);
// 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?
/** * nsScannerSharedSubstring implements copy-on-write semantics for * nsScannerSubstring. This class also manages releasing * the reference to the scanner buffer when it is no longer needed.
*/
class nsScannerSharedSubstring { public:
nsScannerSharedSubstring() : mBuffer(nullptr), mBufferList(nullptr) {}
~nsScannerSharedSubstring() { if (mBufferList) ReleaseBuffer();
}
// Acquire a copy-on-write reference to the given substring. void Rebind(const nsScannerIterator& aStart, const nsScannerIterator& aEnd);
// Get a const reference to this string const nsAString& str() const { return mString; }
/** * 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; typedef char16_t value_type; typedefconst char16_t* pointer; typedefconst char16_t& reference; typedef nsScannerSubstring::Buffer Buffer;
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;
}
};
inlinebool SameFragment(const nsScannerIterator& a, const nsScannerIterator& b) { return a.fragment().mFragmentStart == b.fragment().mFragmentStart;
}
/** * 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.
*/
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.20Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.