Title: [101152] trunk/Source/_javascript_Core
- Revision
- 101152
- Author
- msab...@apple.com
- Date
- 2011-11-24 22:55:34 -0800 (Thu, 24 Nov 2011)
Log Message
UString methods are not character size aware
https://bugs.webkit.org/show_bug.cgi?id=72975
Changed the UString number constructors to build 8 bit strings.
Modified the other methods to check string bitness and process
with 8 bits wherre appropriate.
* runtime/UString.cpp:
(JSC::UString::number):
(JSC::operator==):
(JSC::operator<):
(JSC::UString::ascii):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (101151 => 101152)
--- trunk/Source/_javascript_Core/ChangeLog 2011-11-25 06:47:48 UTC (rev 101151)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-11-25 06:55:34 UTC (rev 101152)
@@ -1,5 +1,20 @@
2011-11-24 Michael Saboff <msab...@apple.com>
+ UString methods are not character size aware
+ https://bugs.webkit.org/show_bug.cgi?id=72975
+
+ Changed the UString number constructors to build 8 bit strings.
+ Modified the other methods to check string bitness and process
+ with 8 bits wherre appropriate.
+
+ * runtime/UString.cpp:
+ (JSC::UString::number):
+ (JSC::operator==):
+ (JSC::operator<):
+ (JSC::UString::ascii):
+
+2011-11-24 Michael Saboff <msab...@apple.com>
+
_javascript_ string to number conversion functions use characters()
https://bugs.webkit.org/show_bug.cgi?id=72974
Modified: trunk/Source/_javascript_Core/runtime/UString.cpp (101151 => 101152)
--- trunk/Source/_javascript_Core/runtime/UString.cpp 2011-11-25 06:47:48 UTC (rev 101151)
+++ trunk/Source/_javascript_Core/runtime/UString.cpp 2011-11-25 06:55:34 UTC (rev 101152)
@@ -96,9 +96,9 @@
UString UString::number(int i)
{
- UChar buf[1 + sizeof(i) * 3];
- UChar* end = buf + WTF_ARRAY_LENGTH(buf);
- UChar* p = end;
+ LChar buf[1 + sizeof(i) * 3];
+ LChar* end = buf + WTF_ARRAY_LENGTH(buf);
+ LChar* p = end;
if (i == 0)
*--p = '0';
@@ -125,9 +125,9 @@
UString UString::number(long long i)
{
- UChar buf[1 + sizeof(i) * 3];
- UChar* end = buf + WTF_ARRAY_LENGTH(buf);
- UChar* p = end;
+ LChar buf[1 + sizeof(i) * 3];
+ LChar* end = buf + WTF_ARRAY_LENGTH(buf);
+ LChar* p = end;
if (i == 0)
*--p = '0';
@@ -158,9 +158,9 @@
UString UString::number(unsigned u)
{
- UChar buf[sizeof(u) * 3];
- UChar* end = buf + WTF_ARRAY_LENGTH(buf);
- UChar* p = end;
+ LChar buf[sizeof(u) * 3];
+ LChar* end = buf + WTF_ARRAY_LENGTH(buf);
+ LChar* p = end;
if (u == 0)
*--p = '0';
@@ -176,9 +176,9 @@
UString UString::number(long l)
{
- UChar buf[1 + sizeof(l) * 3];
- UChar* end = buf + WTF_ARRAY_LENGTH(buf);
- UChar* p = end;
+ LChar buf[1 + sizeof(l) * 3];
+ LChar* end = buf + WTF_ARRAY_LENGTH(buf);
+ LChar* p = end;
if (l == 0)
*--p = '0';
@@ -224,19 +224,10 @@
bool operator==(const UString& s1, const char *s2)
{
- if (s2 == 0)
- return s1.isEmpty();
+ if (s1.isEmpty())
+ return !s2;
- const UChar* u = s1.characters();
- const UChar* uend = u + s1.length();
- while (u != uend && *s2) {
- if (u[0] != (unsigned char)*s2)
- return false;
- s2++;
- u++;
- }
-
- return u == uend && *s2 == 0;
+ return equal(s1.impl(), s2);
}
// This method assumes that all simple checks have been performed by
@@ -315,15 +306,29 @@
const unsigned l1 = s1.length();
const unsigned l2 = s2.length();
const unsigned lmin = l1 < l2 ? l1 : l2;
+ if (s1.is8Bit() && s2.is8Bit()) {
+ const LChar* c1 = s1.characters8();
+ const LChar* c2 = s2.characters8();
+ unsigned length = 0;
+ while (length < lmin && *c1 == *c2) {
+ c1++;
+ c2++;
+ length++;
+ }
+ if (length < lmin)
+ return (c1[0] < c2[0]);
+
+ return (l1 < l2);
+ }
const UChar* c1 = s1.characters();
const UChar* c2 = s2.characters();
- unsigned l = 0;
- while (l < lmin && *c1 == *c2) {
+ unsigned length = 0;
+ while (length < lmin && *c1 == *c2) {
c1++;
c2++;
- l++;
+ length++;
}
- if (l < lmin)
+ if (length < lmin)
return (c1[0] < c2[0]);
return (l1 < l2);
@@ -354,8 +359,23 @@
// preserved, characters outside of this range are converted to '?'.
unsigned length = this->length();
- const UChar* characters = this->characters();
+ if (this->is8Bit()) {
+ const LChar* characters = this->characters8();
+
+ char* characterBuffer;
+ CString result = CString::newUninitialized(length, characterBuffer);
+
+ for (unsigned i = 0; i < length; ++i) {
+ LChar ch = characters[i];
+ characterBuffer[i] = ch && (ch < 0x20 || ch > 0x7f) ? '?' : ch;
+ }
+
+ return result;
+ }
+
+ const UChar* characters = this->characters16();
+
char* characterBuffer;
CString result = CString::newUninitialized(length, characterBuffer);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes