From ec12bbacef090c57ad5a42007911b009bef015c9 Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Sat, 27 Mar 1999 01:20:15 +0000 Subject: [PATCH] Implement new method git-svn-id: svn://10.0.0.236/trunk@25289 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsTextNode.cpp | 34 +++++++++++++++++++++++++ mozilla/layout/base/src/nsTextNode.cpp | 34 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/mozilla/content/base/src/nsTextNode.cpp b/mozilla/content/base/src/nsTextNode.cpp index 81e18734342..e5c3bd035ca 100644 --- a/mozilla/content/base/src/nsTextNode.cpp +++ b/mozilla/content/base/src/nsTextNode.cpp @@ -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; +} diff --git a/mozilla/layout/base/src/nsTextNode.cpp b/mozilla/layout/base/src/nsTextNode.cpp index 81e18734342..e5c3bd035ca 100644 --- a/mozilla/layout/base/src/nsTextNode.cpp +++ b/mozilla/layout/base/src/nsTextNode.cpp @@ -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; +}