TextDocument: Added Length()
This commit is contained in:
@@ -165,6 +165,8 @@ TextDocument::ParagraphStyleAt(int32 textOffset) const
|
|||||||
const Paragraph&
|
const Paragraph&
|
||||||
TextDocument::ParagraphAt(int32 textOffset, int32& paragraphOffset) const
|
TextDocument::ParagraphAt(int32 textOffset, int32& paragraphOffset) const
|
||||||
{
|
{
|
||||||
|
// TODO: Could binary search the Paragraphs if they were wrapped in classes
|
||||||
|
// that knew there text offset in the document.
|
||||||
int32 textLength = 0;
|
int32 textLength = 0;
|
||||||
paragraphOffset = 0;
|
paragraphOffset = 0;
|
||||||
int32 count = fParagraphs.CountItems();
|
int32 count = fParagraphs.CountItems();
|
||||||
@@ -194,3 +196,18 @@ TextDocument::Append(const Paragraph& paragraph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
TextDocument::Length() const
|
||||||
|
{
|
||||||
|
// TODO: Could be O(1) if the Paragraphs were wrapped in classes that
|
||||||
|
// knew there text offset in the document.
|
||||||
|
int32 textLength = 0;
|
||||||
|
int32 count = fParagraphs.CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
const Paragraph& paragraph = fParagraphs.ItemAtFast(i);
|
||||||
|
textLength += paragraph.Length();
|
||||||
|
}
|
||||||
|
return textLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ public:
|
|||||||
|
|
||||||
bool Append(const Paragraph& paragraph);
|
bool Append(const Paragraph& paragraph);
|
||||||
|
|
||||||
|
// Query information
|
||||||
|
int32 Length() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParagraphList fParagraphs;
|
ParagraphList fParagraphs;
|
||||||
Paragraph fEmptyLastParagraph;
|
Paragraph fEmptyLastParagraph;
|
||||||
|
|||||||
Reference in New Issue
Block a user