summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-05-06 16:08:48 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-05-06 16:08:48 -0400
commitb9634e3475a851640db7ddf93bb29e7778bc9e34 (patch)
treea956507879ff7df344774dc30dabdc5438d4cb63 /src/c
parente1ea17cb21e3193a99cfd93d7e264ba0176f66f5 (diff)
Run-time CSS style validation
Diffstat (limited to 'src/c')
-rw-r--r--src/c/urweb.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 93635fd1..2e16743c 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -4021,3 +4021,46 @@ uw_Basis_int uw_Basis_trunc(uw_context ctx, uw_Basis_float n) {
uw_Basis_int uw_Basis_round(uw_context ctx, uw_Basis_float n) {
return round(n);
}
+
+uw_Basis_string uw_Basis_atom(uw_context ctx, uw_Basis_string s) {
+ char *p;
+
+ for (p = s; *p; ++p) {
+ char c = *p;
+ if (!isalnum(c) && c != '+' && c != '-' && c != '.' && c != '%' && c != '#')
+ uw_error(ctx, FATAL, "Disallowed character in CSS atom");
+ }
+
+ return s;
+}
+
+uw_Basis_string uw_Basis_css_url(uw_context ctx, uw_Basis_string s) {
+ char *p;
+
+ for (p = s; *p; ++p) {
+ char c = *p;
+ if (!isalnum(c) && c != ':' && c != '/' && c != '.' && c != '_' && c != '+'
+ && c != '-' && c != '%' && c != '?' && c != '&' && c != '=' && c != '#')
+ uw_error(ctx, FATAL, "Disallowed character in CSS URL");
+ }
+
+ return s;
+}
+
+uw_Basis_string uw_Basis_property(uw_context ctx, uw_Basis_string s) {
+ char *p;
+
+ if (!*s)
+ uw_error(ctx, FATAL, "Empty CSS property");
+
+ if (!islower(s[0]) && s[0] != '_')
+ uw_error(ctx, FATAL, "Bad initial character in CSS property");
+
+ for (p = s; *p; ++p) {
+ char c = *p;
+ if (!islower(c) && !isdigit(c) && c != '_' && c != '-')
+ uw_error(ctx, FATAL, "Disallowed character in CSS property");
+ }
+
+ return s;
+}