Skip to content

Commit af157db

Browse files
author
Yorick Peterse
committedApr 29, 2015
Fix detecting of constants with Unicode
There's no need to check the characters that follow the initial one, instead we can assert that a constant simply starts with a capital latin letter. Fixes #3382
1 parent 2482b09 commit af157db

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed
 

Diff for: ‎vm/symbol_table.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ namespace rubinius {
1616
SymbolTable::Kind SymbolTable::detect_kind(const char* str, size_t size) {
1717
const char one = str[0];
1818

19-
// A constant begins with an uppercase letter.
20-
if(one >= 'A' && one <= 'Z') {
21-
// Make sure that the rest of it is only alphanumerics
22-
for(size_t i = 1; i < size; i++) {
23-
if((isalnum(str[i]) || str[i] == '_') == false)
24-
return SymbolTable::Normal;
25-
}
19+
// Constants start with A-Z
20+
if(isupper(one)) {
2621
return SymbolTable::Constant;
2722
}
2823

Diff for: ‎vm/test/test_symbol_table.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ class TestSymbolTable : public CxxTest::TestSuite, public VMTest {
2222
destroy();
2323
}
2424

25+
void test_detect_kind_with_constant() {
26+
const char *input = "Pettson";
27+
28+
SymbolTable::Kind kind = symbols->detect_kind(input, strlen(input));
29+
30+
TS_ASSERT_EQUALS(kind, SymbolTable::Constant);
31+
}
32+
33+
void test_detect_kind_with_unicode_constant() {
34+
const char *input = "Pettsonλ";
35+
36+
SymbolTable::Kind kind = symbols->detect_kind(input, strlen(input));
37+
38+
TS_ASSERT_EQUALS(kind, SymbolTable::Constant);
39+
}
40+
2541
void test_lookup_with_c_str() {
2642
Object* sym = symbols->lookup(state, std::string("unique"));
2743
TS_ASSERT(sym->symbol_p());

0 commit comments

Comments
 (0)
Please sign in to comment.