Title: [135805] trunk/Source/WebCore
- Revision
- 135805
- Author
- msab...@apple.com
- Date
- 2012-11-26 19:51:30 -0800 (Mon, 26 Nov 2012)
Log Message
Grapheme cluster functions can be simplified for 8 bit Strings
https://bugs.webkit.org/show_bug.cgi?id=102996
Reviewed by Alexey Proskuryakov.
For 8 bit strings, check for the uncommon CR-LF by looking for any CR. If there aren't any CR characters,
the number of Extended Grapheme Clusters is equal to the string length. If we need to handle Tailored
Graheme Clusters, then this will need to change.
No new tests. No change in functionality.
* platform/text/TextBreakIterator.cpp:
(WebCore::numGraphemeClusters):
(WebCore::numCharactersInGraphemeClusters):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (135804 => 135805)
--- trunk/Source/WebCore/ChangeLog 2012-11-27 03:40:59 UTC (rev 135804)
+++ trunk/Source/WebCore/ChangeLog 2012-11-27 03:51:30 UTC (rev 135805)
@@ -1,3 +1,20 @@
+2012-11-26 Michael Saboff <msab...@apple.com>
+
+ Grapheme cluster functions can be simplified for 8 bit Strings
+ https://bugs.webkit.org/show_bug.cgi?id=102996
+
+ Reviewed by Alexey Proskuryakov.
+
+ For 8 bit strings, check for the uncommon CR-LF by looking for any CR. If there aren't any CR characters,
+ the number of Extended Grapheme Clusters is equal to the string length. If we need to handle Tailored
+ Graheme Clusters, then this will need to change.
+
+ No new tests. No change in functionality.
+
+ * platform/text/TextBreakIterator.cpp:
+ (WebCore::numGraphemeClusters):
+ (WebCore::numCharactersInGraphemeClusters):
+
2012-11-26 Istiaque Ahmed <lazy...@chromium.org>
Check for empty perContextData while creating NP V8 Object.
Modified: trunk/Source/WebCore/platform/text/TextBreakIterator.cpp (135804 => 135805)
--- trunk/Source/WebCore/platform/text/TextBreakIterator.cpp 2012-11-27 03:40:59 UTC (rev 135804)
+++ trunk/Source/WebCore/platform/text/TextBreakIterator.cpp 2012-11-27 03:51:30 UTC (rev 135805)
@@ -26,9 +26,18 @@
unsigned numGraphemeClusters(const String& s)
{
- NonSharedCharacterBreakIterator it(s.characters(), s.length());
+ unsigned stringLength = s.length();
+
+ if (!stringLength)
+ return 0;
+
+ // The only Latin-1 Extended Grapheme Cluster is CR LF
+ if (s.is8Bit() && !s.contains('\r'))
+ return stringLength;
+
+ NonSharedCharacterBreakIterator it(s.characters(), stringLength);
if (!it)
- return s.length();
+ return stringLength;
unsigned num = 0;
while (textBreakNext(it) != TextBreakDone)
@@ -38,13 +47,22 @@
unsigned numCharactersInGraphemeClusters(const String& s, unsigned numGraphemeClusters)
{
- NonSharedCharacterBreakIterator it(s.characters(), s.length());
+ unsigned stringLength = s.length();
+
+ if (!stringLength)
+ return 0;
+
+ // The only Latin-1 Extended Grapheme Cluster is CR LF
+ if (s.is8Bit() && !s.contains('\r'))
+ return std::min(stringLength, numGraphemeClusters);
+
+ NonSharedCharacterBreakIterator it(s.characters(), stringLength);
if (!it)
- return std::min(s.length(), numGraphemeClusters);
+ return std::min(stringLength, numGraphemeClusters);
for (unsigned i = 0; i < numGraphemeClusters; ++i) {
if (textBreakNext(it) == TextBreakDone)
- return s.length();
+ return stringLength;
}
return textBreakCurrent(it);
}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes