Commit d8419f01 by Aaron Leung

Added function for matching hex literals.

parent d3b2584d
...@@ -107,6 +107,11 @@ namespace Sass { ...@@ -107,6 +107,11 @@ namespace Sass {
char* dimension(char* src) { char* dimension(char* src) {
return sequence<number, identifier>(src); return sequence<number, identifier>(src);
} }
char* hex(char* src) {
char* p = sequence< exactly<'#'>, one_plus<xdigit> >(src);
int len = p - src;
return (len != 4 && len != 7) ? 0 : p;
}
// Match CSS uri specifiers. // Match CSS uri specifiers.
extern const char url_call[] = "url("; extern const char url_call[] = "url(";
char* uri(char* src) { char* uri(char* src) {
......
...@@ -228,6 +228,7 @@ namespace Sass { ...@@ -228,6 +228,7 @@ namespace Sass {
char* number(char* src); char* number(char* src);
char* percentage(char* src); char* percentage(char* src);
char* dimension(char* src); char* dimension(char* src);
char* hex(char* src);
// Match CSS uri specifiers. // Match CSS uri specifiers.
char* uri(char* src); char* uri(char* src);
// Match CSS function call openers. // Match CSS function call openers.
......
...@@ -43,6 +43,10 @@ char pre1[] = "^='hux'] { ... }"; ...@@ -43,6 +43,10 @@ char pre1[] = "^='hux'] { ... }";
char suf1[] = "$='baz'] { ... }"; char suf1[] = "$='baz'] { ... }";
char sub1[] = "*='bum'] { ... }"; char sub1[] = "*='bum'] { ... }";
char ws1[] = " /* hello */\t\n//blah\n /*blah*/ significant"; char ws1[] = " /* hello */\t\n//blah\n /*blah*/ significant";
char hex1[] = "#1a2b3c#f1ab";
char hex2[] = "#abc-zippo";
char nonhex1[] = "#ab blah";
char nonhex2[] = "#abc123blah";
extern const char slash_star[] = "/*"; extern const char slash_star[] = "/*";
...@@ -82,6 +86,8 @@ int main() { ...@@ -82,6 +86,8 @@ int main() {
check_twice(suffix_match, suf1, pre1); check_twice(suffix_match, suf1, pre1);
check_twice(substring_match, sub1, suf1); check_twice(substring_match, sub1, suf1);
check_twice(spaces_and_comments, ws1, num1); check_twice(spaces_and_comments, ws1, num1);
check_twice(hex, hex1, nonhex1);
check_twice(hex, hex2, nonhex2);
cout << count_interval<'\n'>(ws1, spaces_and_comments(ws1)) << endl; cout << count_interval<'\n'>(ws1, spaces_and_comments(ws1)) << endl;
cout << count_interval<'*'>(ws1, spaces_and_comments(ws1)) << endl; cout << count_interval<'*'>(ws1, spaces_and_comments(ws1)) << endl;
cout << count_interval<exactly<slash_star> >(ws1, spaces_and_comments(ws1)) << endl; cout << count_interval<exactly<slash_star> >(ws1, spaces_and_comments(ws1)) << endl;
......
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