Commit 81ac5275 by Aaron Leung

Functions for matching pathnames.

parent d235ff2d
...@@ -202,9 +202,11 @@ namespace Sass { ...@@ -202,9 +202,11 @@ namespace Sass {
// Path matching functions. // Path matching functions.
char* folder(char* src) { char* folder(char* src) {
return sequence< zero_plus< negate< exactly<'/'> > >, return sequence< zero_plus< any_char_except<'/'> >,
exactly<'/'> >(src); exactly<'/'> >(src);
} }
char* folders(char* src) {
return zero_plus< folder >(src);
}
} }
} }
\ No newline at end of file
...@@ -85,7 +85,12 @@ namespace Sass { ...@@ -85,7 +85,12 @@ namespace Sass {
} }
// Match any single character. // Match any single character.
char *any_char(char* src); char* any_char(char* src);
// Match any single character except the supplied one.
template <char c>
char* any_char_except(char* src) {
return (*src && *src != c) ? src+1 : 0;
}
// Matches zero characters (always succeeds without consuming input). // Matches zero characters (always succeeds without consuming input).
char* epsilon(char*); char* epsilon(char*);
...@@ -313,6 +318,7 @@ namespace Sass { ...@@ -313,6 +318,7 @@ namespace Sass {
// Path matching functions. // Path matching functions.
char* folder(char* src); char* folder(char* src);
char* folders(char* src);
// Utility functions for finding and counting characters in a string. // Utility functions for finding and counting characters in a string.
template<char c> template<char c>
......
...@@ -106,6 +106,8 @@ int main() { ...@@ -106,6 +106,8 @@ int main() {
check_twice(binomial, bi2, nonbi1); check_twice(binomial, bi2, nonbi1);
check_twice(folder, fld1, nonfld1); check_twice(folder, fld1, nonfld1);
check_twice(folder, fld2, nonfld1); check_twice(folder, fld2, nonfld1);
check_twice(folders, fld1, nonfld1);
check_twice(folders, fld2, nonfld1);
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