Implement new method

This commit is contained in:
kipp%netscape.com 1999-03-27 01:20:15 +00:00
parent a0ef7d0fd6
commit 0c1b82b05a
2 changed files with 68 additions and 0 deletions

View File

@ -73,6 +73,8 @@ public:
PRInt32 aLength,
PRBool aNotify);
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult);
protected:
nsGenericDOMDataNode mInner;
};
@ -298,3 +300,35 @@ nsTextNode::SetText(const char* aBuffer, PRInt32 aLength,
}
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::IsOnlyWhitespace(PRBool* aResult)
{
nsTextFragment& frag = mInner.mText;
if (frag.Is2b()) {
const PRUnichar* cp = frag.Get2b();
const PRUnichar* end = cp + frag.GetLength();
while (cp < end) {
PRUnichar ch = *cp++;
if (!XP_IS_SPACE(ch)) {
*aResult = PR_FALSE;
return NS_OK;
}
}
}
else {
const char* cp = frag.Get1b();
const char* end = cp + frag.GetLength();
while (cp < end) {
PRUnichar ch = PRUnichar(*(unsigned char*)cp);
cp++;
if (!XP_IS_SPACE(ch)) {
*aResult = PR_FALSE;
return NS_OK;
}
}
}
*aResult = PR_TRUE;
return NS_OK;
}

View File

@ -73,6 +73,8 @@ public:
PRInt32 aLength,
PRBool aNotify);
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult);
protected:
nsGenericDOMDataNode mInner;
};
@ -298,3 +300,35 @@ nsTextNode::SetText(const char* aBuffer, PRInt32 aLength,
}
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::IsOnlyWhitespace(PRBool* aResult)
{
nsTextFragment& frag = mInner.mText;
if (frag.Is2b()) {
const PRUnichar* cp = frag.Get2b();
const PRUnichar* end = cp + frag.GetLength();
while (cp < end) {
PRUnichar ch = *cp++;
if (!XP_IS_SPACE(ch)) {
*aResult = PR_FALSE;
return NS_OK;
}
}
}
else {
const char* cp = frag.Get1b();
const char* end = cp + frag.GetLength();
while (cp < end) {
PRUnichar ch = PRUnichar(*(unsigned char*)cp);
cp++;
if (!XP_IS_SPACE(ch)) {
*aResult = PR_FALSE;
return NS_OK;
}
}
}
*aResult = PR_TRUE;
return NS_OK;
}