Commit d59bb82f authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Add and use AsciiAlphaToLower. Move RemoveLast test. Add Clear test. This is...

Add and use AsciiAlphaToLower.  Move RemoveLast test.  Add Clear test. This is a commit of http://codereview.chromium.org/3307003/show http://codereview.chromium.org/3312007/show and http://codereview.chromium.org/3341002/show for tfarina

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5409 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a6166065
...@@ -34,6 +34,14 @@ namespace v8 { ...@@ -34,6 +34,14 @@ namespace v8 {
namespace internal { namespace internal {
// If c is in 'A'-'Z' or 'a'-'z', return its lower-case.
// Else, return something outside of 'A'-'Z' and 'a'-'z'.
// Note: it ignores LOCALE.
inline int AsciiAlphaToLower(uc32 c) {
return c | 0x20;
}
inline bool IsCarriageReturn(uc32 c) { inline bool IsCarriageReturn(uc32 c) {
return c == 0x000D; return c == 0x000D;
} }
...@@ -59,12 +67,12 @@ inline bool IsDecimalDigit(uc32 c) { ...@@ -59,12 +67,12 @@ inline bool IsDecimalDigit(uc32 c) {
inline bool IsHexDigit(uc32 c) { inline bool IsHexDigit(uc32 c) {
// ECMA-262, 3rd, 7.6 (p 15) // ECMA-262, 3rd, 7.6 (p 15)
return IsDecimalDigit(c) || IsInRange(c | 0x20, 'a', 'f'); return IsDecimalDigit(c) || IsInRange(AsciiAlphaToLower(c), 'a', 'f');
} }
inline bool IsRegExpWord(uc16 c) { inline bool IsRegExpWord(uc16 c) {
return IsInRange(c | 0x20, 'a', 'z') return IsInRange(AsciiAlphaToLower(c), 'a', 'z')
|| IsDecimalDigit(c) || IsDecimalDigit(c)
|| (c == '_'); || (c == '_');
} }
......
...@@ -92,7 +92,7 @@ class DateParser : public AllStatic { ...@@ -92,7 +92,7 @@ class DateParser : public AllStatic {
int ReadWord(uint32_t* prefix, int prefix_size) { int ReadWord(uint32_t* prefix, int prefix_size) {
int len; int len;
for (len = 0; IsAsciiAlphaOrAbove(); Next(), len++) { for (len = 0; IsAsciiAlphaOrAbove(); Next(), len++) {
if (len < prefix_size) prefix[len] = GetAsciiAlphaLower(); if (len < prefix_size) prefix[len] = AsciiAlphaToLower(ch_);
} }
for (int i = len; i < prefix_size; i++) prefix[i] = 0; for (int i = len; i < prefix_size; i++) prefix[i] = 0;
return len; return len;
...@@ -130,10 +130,6 @@ class DateParser : public AllStatic { ...@@ -130,10 +130,6 @@ class DateParser : public AllStatic {
bool HasReadNumber() const { return has_read_number_; } bool HasReadNumber() const { return has_read_number_; }
private: private:
// If current character is in 'A'-'Z' or 'a'-'z', return its lower-case.
// Else, return something outside of 'A'-'Z' and 'a'-'z'.
uint32_t GetAsciiAlphaLower() const { return ch_ | 32; }
int index_; int index_;
Vector<Char> buffer_; Vector<Char> buffer_;
bool has_read_number_; bool has_read_number_;
......
...@@ -743,7 +743,7 @@ Token::Value Scanner::ScanJsonNumber() { ...@@ -743,7 +743,7 @@ Token::Value Scanner::ScanJsonNumber() {
AddCharAdvance(); AddCharAdvance();
} while (c0_ >= '0' && c0_ <= '9'); } while (c0_ >= '0' && c0_ <= '9');
} }
if ((c0_ | 0x20) == 'e') { if (AsciiAlphaToLower(c0_) == 'e') {
AddCharAdvance(); AddCharAdvance();
if (c0_ == '-' || c0_ == '+') AddCharAdvance(); if (c0_ == '-' || c0_ == '+') AddCharAdvance();
if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL;
......
...@@ -57,35 +57,6 @@ TEST(List) { ...@@ -57,35 +57,6 @@ TEST(List) {
} }
TEST(RemoveLast) {
List<int> list(4);
CHECK_EQ(0, list.length());
list.Add(1);
CHECK_EQ(1, list.length());
CHECK_EQ(1, list.last());
list.RemoveLast();
CHECK_EQ(0, list.length());
list.Add(2);
list.Add(3);
CHECK_EQ(2, list.length());
CHECK_EQ(3, list.last());
list.RemoveLast();
CHECK_EQ(1, list.length());
CHECK_EQ(2, list.last());
list.RemoveLast();
CHECK_EQ(0, list.length());
const int kElements = 100;
for (int i = 0; i < kElements; i++) list.Add(i);
for (int j = kElements - 1; j >= 0; j--) {
CHECK_EQ(j + 1, list.length());
CHECK_EQ(j, list.last());
list.RemoveLast();
CHECK_EQ(j, list.length());
}
}
TEST(DeleteEmpty) { TEST(DeleteEmpty) {
{ {
List<int>* list = new List<int>(0); List<int>* list = new List<int>(0);
......
...@@ -99,3 +99,42 @@ TEST(ListAddAll) { ...@@ -99,3 +99,42 @@ TEST(ListAddAll) {
CHECK_EQ(i % 3, list[i]); CHECK_EQ(i % 3, list[i]);
} }
} }
TEST(RemoveLast) {
List<int> list(4);
CHECK_EQ(0, list.length());
list.Add(1);
CHECK_EQ(1, list.length());
CHECK_EQ(1, list.last());
list.RemoveLast();
CHECK_EQ(0, list.length());
list.Add(2);
list.Add(3);
CHECK_EQ(2, list.length());
CHECK_EQ(3, list.last());
list.RemoveLast();
CHECK_EQ(1, list.length());
CHECK_EQ(2, list.last());
list.RemoveLast();
CHECK_EQ(0, list.length());
const int kElements = 100;
for (int i = 0; i < kElements; i++) list.Add(i);
for (int j = kElements - 1; j >= 0; j--) {
CHECK_EQ(j + 1, list.length());
CHECK_EQ(j, list.last());
list.RemoveLast();
CHECK_EQ(j, list.length());
}
}
TEST(Clear) {
List<int> list(4);
CHECK_EQ(0, list.length());
for (int i = 0; i < 4; ++i) list.Add(i);
CHECK_EQ(4, list.length());
list.Clear();
CHECK_EQ(0, list.length());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment