Beginnings of a line iterator
git-svn-id: svn://10.0.0.236/trunk@31002 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
da421fb28d
commit
f92577dd6d
@ -202,3 +202,56 @@ nsLineBox::CheckIsBlock() const
|
||||
return isBlock == IsBlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsLineBox* gDummyLines[1];
|
||||
|
||||
nsLineIterator::nsLineIterator()
|
||||
{
|
||||
mLines = nsnull;
|
||||
mNumLines = 0;
|
||||
mIndex = 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsLineIterator::Init(nsLineBox* aLines)
|
||||
{
|
||||
// Count the lines
|
||||
PRInt32 numLines = 0;
|
||||
nsLineBox* line = aLines;
|
||||
while (line) {
|
||||
numLines++;
|
||||
line = line->mNext;
|
||||
}
|
||||
if (0 == numLines) {
|
||||
// Use gDummyLines so that we don't need null pointer checks in
|
||||
// the accessor methods
|
||||
mLines = gDummyLines;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Make a linear array of the lines
|
||||
mLines = new nsLineBox*[numLines];
|
||||
if (!mLines) {
|
||||
// Use gDummyLines so that we don't need null pointer checks in
|
||||
// the accessor methods
|
||||
mLines = gDummyLines;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsLineBox** lp = mLines;
|
||||
line = aLines;
|
||||
while (line) {
|
||||
*lp++ = line;
|
||||
line = line->mNext;
|
||||
}
|
||||
mNumLines = numLines;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsLineIterator::~nsLineIterator()
|
||||
{
|
||||
if (mLines != gDummyLines) {
|
||||
delete [] mLines;
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,4 +193,46 @@ public:
|
||||
nsLineBox* mNext;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
struct nsLineIterator {
|
||||
nsLineIterator();
|
||||
~nsLineIterator();
|
||||
|
||||
nsresult Init(nsLineBox* aLines);
|
||||
|
||||
PRInt32 NumLines() const {
|
||||
return mNumLines;
|
||||
}
|
||||
|
||||
nsLineBox* CurrentLine() {
|
||||
return mLines[mIndex];
|
||||
}
|
||||
|
||||
nsLineBox* PrevLine() {
|
||||
if (0 == mIndex) {
|
||||
return nsnull;
|
||||
}
|
||||
return mLines[--mIndex];
|
||||
}
|
||||
|
||||
nsLineBox* NextLine() {
|
||||
if (mIndex >= mNumLines - 1) {
|
||||
return nsnull;
|
||||
}
|
||||
return mLines[++mIndex];
|
||||
}
|
||||
|
||||
nsLineBox* LineAt(PRInt32 aIndex) {
|
||||
if ((aIndex < 0) || (aIndex >= mNumLines)) {
|
||||
return nsnull;
|
||||
}
|
||||
return mLines[aIndex];
|
||||
}
|
||||
|
||||
nsLineBox** mLines;
|
||||
PRInt32 mIndex;
|
||||
PRInt32 mNumLines;
|
||||
};
|
||||
|
||||
#endif /* nsLineBox_h___ */
|
||||
|
||||
@ -202,3 +202,56 @@ nsLineBox::CheckIsBlock() const
|
||||
return isBlock == IsBlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsLineBox* gDummyLines[1];
|
||||
|
||||
nsLineIterator::nsLineIterator()
|
||||
{
|
||||
mLines = nsnull;
|
||||
mNumLines = 0;
|
||||
mIndex = 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsLineIterator::Init(nsLineBox* aLines)
|
||||
{
|
||||
// Count the lines
|
||||
PRInt32 numLines = 0;
|
||||
nsLineBox* line = aLines;
|
||||
while (line) {
|
||||
numLines++;
|
||||
line = line->mNext;
|
||||
}
|
||||
if (0 == numLines) {
|
||||
// Use gDummyLines so that we don't need null pointer checks in
|
||||
// the accessor methods
|
||||
mLines = gDummyLines;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Make a linear array of the lines
|
||||
mLines = new nsLineBox*[numLines];
|
||||
if (!mLines) {
|
||||
// Use gDummyLines so that we don't need null pointer checks in
|
||||
// the accessor methods
|
||||
mLines = gDummyLines;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsLineBox** lp = mLines;
|
||||
line = aLines;
|
||||
while (line) {
|
||||
*lp++ = line;
|
||||
line = line->mNext;
|
||||
}
|
||||
mNumLines = numLines;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsLineIterator::~nsLineIterator()
|
||||
{
|
||||
if (mLines != gDummyLines) {
|
||||
delete [] mLines;
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,4 +193,46 @@ public:
|
||||
nsLineBox* mNext;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
struct nsLineIterator {
|
||||
nsLineIterator();
|
||||
~nsLineIterator();
|
||||
|
||||
nsresult Init(nsLineBox* aLines);
|
||||
|
||||
PRInt32 NumLines() const {
|
||||
return mNumLines;
|
||||
}
|
||||
|
||||
nsLineBox* CurrentLine() {
|
||||
return mLines[mIndex];
|
||||
}
|
||||
|
||||
nsLineBox* PrevLine() {
|
||||
if (0 == mIndex) {
|
||||
return nsnull;
|
||||
}
|
||||
return mLines[--mIndex];
|
||||
}
|
||||
|
||||
nsLineBox* NextLine() {
|
||||
if (mIndex >= mNumLines - 1) {
|
||||
return nsnull;
|
||||
}
|
||||
return mLines[++mIndex];
|
||||
}
|
||||
|
||||
nsLineBox* LineAt(PRInt32 aIndex) {
|
||||
if ((aIndex < 0) || (aIndex >= mNumLines)) {
|
||||
return nsnull;
|
||||
}
|
||||
return mLines[aIndex];
|
||||
}
|
||||
|
||||
nsLineBox** mLines;
|
||||
PRInt32 mIndex;
|
||||
PRInt32 mNumLines;
|
||||
};
|
||||
|
||||
#endif /* nsLineBox_h___ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user