From: erik.corry@gmail.com Date: Fri, 3 Sep 2010 12:59:52 +0000 (+0000) Subject: Add and use AsciiAlphaToLower. Move RemoveLast test. Add Clear test. This is a... X-Git-Tag: upstream/4.7.83~21243 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d59bb82f1f5a25a3b796598979c39f29758267a6;p=platform%2Fupstream%2Fv8.git Add and use AsciiAlphaToLower. Move RemoveLast test. Add Clear test. This is a commit of 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 --- diff --git a/src/char-predicates-inl.h b/src/char-predicates-inl.h index fadbc9a..0dfc80d 100644 --- a/src/char-predicates-inl.h +++ b/src/char-predicates-inl.h @@ -34,6 +34,14 @@ namespace v8 { 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) { return c == 0x000D; } @@ -59,12 +67,12 @@ inline bool IsDecimalDigit(uc32 c) { inline bool IsHexDigit(uc32 c) { // 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) { - return IsInRange(c | 0x20, 'a', 'z') + return IsInRange(AsciiAlphaToLower(c), 'a', 'z') || IsDecimalDigit(c) || (c == '_'); } diff --git a/src/dateparser.h b/src/dateparser.h index d999d9c..cae9b08 100644 --- a/src/dateparser.h +++ b/src/dateparser.h @@ -92,7 +92,7 @@ class DateParser : public AllStatic { int ReadWord(uint32_t* prefix, int prefix_size) { int 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; return len; @@ -130,10 +130,6 @@ class DateParser : public AllStatic { bool HasReadNumber() const { return has_read_number_; } 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_; Vector buffer_; bool has_read_number_; diff --git a/src/scanner.cc b/src/scanner.cc index 334aff9..15b1d44 100755 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -743,7 +743,7 @@ Token::Value Scanner::ScanJsonNumber() { AddCharAdvance(); } while (c0_ >= '0' && c0_ <= '9'); } - if ((c0_ | 0x20) == 'e') { + if (AsciiAlphaToLower(c0_) == 'e') { AddCharAdvance(); if (c0_ == '-' || c0_ == '+') AddCharAdvance(); if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; diff --git a/test/cctest/test-ast.cc b/test/cctest/test-ast.cc index 9931f56..9c292bc 100644 --- a/test/cctest/test-ast.cc +++ b/test/cctest/test-ast.cc @@ -57,35 +57,6 @@ TEST(List) { } -TEST(RemoveLast) { - List 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) { { List* list = new List(0); diff --git a/test/cctest/test-list.cc b/test/cctest/test-list.cc index 624b6e9..e20ee8a 100644 --- a/test/cctest/test-list.cc +++ b/test/cctest/test-list.cc @@ -99,3 +99,42 @@ TEST(ListAddAll) { CHECK_EQ(i % 3, list[i]); } } + + +TEST(RemoveLast) { + List 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 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()); +}