Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug 692145 Separate CountNewlinesIn() to CountNewlinesInXPLength() an…

…d CountNewlinesInNativeLength() r=ehsan a=lsblakk

--HG--
extra : transplant_source : H%1DW%ED%C9%B1%DB_%0F%EB%AE%EFE%B3j%1C%0B%CF%3F%13
  • Loading branch information...
commit 1bede74e8be4f50a08a58dc1543c154a1a0f41d7 1 parent 6e23031
Masayuki Nakano masayuki-nakano authored
Showing with 28 additions and 5 deletions.
  1. +28 −5 content/events/src/nsContentEventHandler.cpp
33 content/events/src/nsContentEventHandler.cpp
View
@@ -208,16 +208,17 @@ static void AppendSubString(nsAString& aString, nsIContent* aContent,
}
#if defined(XP_WIN)
-static PRUint32 CountNewlinesIn(nsIContent* aContent, PRUint32 aMaxOffset)
+static PRUint32 CountNewlinesInXPLength(nsIContent* aContent,
+ PRUint32 aXPLength)
{
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
"aContent is not a text node!");
const nsTextFragment* text = aContent->GetText();
if (!text)
return 0;
- NS_ASSERTION(aMaxOffset == PR_UINT32_MAX || aMaxOffset <= text->GetLength(),
+ NS_ASSERTION(aXPLength == PR_UINT32_MAX || aXPLength <= text->GetLength(),
"text offset is out-of-bounds");
- const PRUint32 length = NS_MIN(aMaxOffset, text->GetLength());
+ const PRUint32 length = NS_MIN(aXPLength, text->GetLength());
PRUint32 newlines = 0;
for (PRUint32 i = 0; i < length; ++i) {
if (text->CharAt(i) == '\n') {
@@ -226,6 +227,28 @@ static PRUint32 CountNewlinesIn(nsIContent* aContent, PRUint32 aMaxOffset)
}
return newlines;
}
+
+static PRUint32 CountNewlinesInNativeLength(nsIContent* aContent,
+ PRUint32 aNativeLength)
+{
+ NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
+ "aContent is not a text node!");
+ const nsTextFragment* text = aContent->GetText();
+ if (!text) {
+ return 0;
+ }
+ const PRUint32 xpLength = text->GetLength();
+ PRUint32 newlines = 0;
+ for (PRUint32 i = 0, nativeOffset = 0;
+ i < xpLength && nativeOffset < aNativeLength;
+ ++i, ++nativeOffset) {
+ if (text->CharAt(i) == '\n') {
+ ++newlines;
+ ++nativeOffset;
+ }
+ }
+ return newlines;
+}
#endif
static PRUint32 GetNativeTextLength(nsIContent* aContent, PRUint32 aMaxLength = PR_UINT32_MAX)
@@ -240,7 +263,7 @@ static PRUint32 GetNativeTextLength(nsIContent* aContent, PRUint32 aMaxLength =
// On Windows, the length of a native newline ("\r\n") is twice the length of
// the XP newline ("\n"), so XP length is equal to the length of the native
// offset plus the number of newlines encountered in the string.
- CountNewlinesIn(aContent, aMaxLength);
+ CountNewlinesInXPLength(aContent, aMaxLength);
#else
// On other platforms, the native and XP newlines are the same.
0;
@@ -272,7 +295,7 @@ static PRUint32 ConvertToXPOffset(nsIContent* aContent, PRUint32 aNativeOffset)
// On Windows, the length of a native newline ("\r\n") is twice the length of
// the XP newline ("\n"), so XP offset is equal to the length of the native
// offset minus the number of newlines encountered in the string.
- return aNativeOffset - CountNewlinesIn(aContent, aNativeOffset);
+ return aNativeOffset - CountNewlinesInNativeLength(aContent, aNativeOffset);
#else
// On other platforms, the native and XP newlines are the same.
return aNativeOffset;
Please sign in to comment.
Something went wrong with that request. Please try again.