TextDocument: Added Length()

This commit is contained in:
Stephan Aßmus 2013-12-06 23:16:00 +01:00
parent a681c327ed
commit 586ec1c10b
2 changed files with 20 additions and 0 deletions

View File

@ -165,6 +165,8 @@ TextDocument::ParagraphStyleAt(int32 textOffset) const
const Paragraph&
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;
paragraphOffset = 0;
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;
}

View File

@ -62,6 +62,9 @@ public:
bool Append(const Paragraph& paragraph);
// Query information
int32 Length() const;
private:
ParagraphList fParagraphs;
Paragraph fEmptyLastParagraph;