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;
}
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 == '_');
}
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;
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<Char> buffer_;
bool has_read_number_;
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;
}
-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) {
{
List<int>* list = new List<int>(0);
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());
+}