diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-01-11 18:04:52 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-01-11 18:04:52 -0500 |
commit | 4eb2a196fa24d52462f3f325d73952fe2d1c12cd (patch) | |
tree | 5e3b768a97aef4741f8ba13b7b6d80490fe39b12 | |
parent | 138f64b8f02f05e6073f61b1db2c3d5e805b75c0 (diff) |
Some more string parsing functions; naughtyDebug
-rw-r--r-- | include/urweb.h | 1 | ||||
-rw-r--r-- | lib/ur/basis.urs | 1 | ||||
-rw-r--r-- | lib/ur/string.ur | 18 | ||||
-rw-r--r-- | lib/ur/string.urs | 4 | ||||
-rw-r--r-- | src/c/urweb.c | 7 | ||||
-rw-r--r-- | src/settings.sml | 1 |
6 files changed, 29 insertions, 3 deletions
diff --git a/include/urweb.h b/include/urweb.h index 49281ac1..6fceeb50 100644 --- a/include/urweb.h +++ b/include/urweb.h @@ -291,6 +291,7 @@ void uw_set_deadline(uw_context, int); void uw_check_deadline(uw_context); uw_Basis_unit uw_Basis_debug(uw_context, uw_Basis_string); +uw_Basis_int uw_Basis_naughtyDebug(uw_context, uw_Basis_string); void uw_set_client_data(uw_context, void *); diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index 727f2e39..0b22544f 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -857,5 +857,6 @@ val mayUpdate : fs ::: {Type} -> tables ::: {{Type}} -> [[Old, New] ~ tables] val also : sql_policy -> sql_policy -> sql_policy val debug : string -> transaction unit +val naughtyDebug : string -> int val rand : transaction int diff --git a/lib/ur/string.ur b/lib/ur/string.ur index 235e5939..a93f7a57 100644 --- a/lib/ur/string.ur +++ b/lib/ur/string.ur @@ -24,17 +24,31 @@ fun mindex {Haystack = s, Needle = chs} = fun substring s {Start = start, Len = len} = Basis.substring s start len +fun seek s ch = + case index s ch of + None => None + | Some i => Some (suffix s (i + 1)) +fun mseek {Haystack = s, Needle = chs} = + case mindex {Haystack = s, Needle = chs} of + None => None + | Some i => Some (sub s i, suffix s (i + 1)) + fun split s ch = case index s ch of None => None | Some i => Some (substring s {Start = 0, Len = i}, - substring s {Start = i + 1, Len = length s - i - 1}) + suffix s (i + 1)) +fun split' s ch = + case index s ch of + None => None + | Some i => Some (substring s {Start = 0, Len = i}, + suffix s i) fun msplit {Haystack = s, Needle = chs} = case mindex {Haystack = s, Needle = chs} of None => None | Some i => Some (substring s {Start = 0, Len = i}, sub s i, - substring s {Start = i + 1, Len = length s - i - 1}) + suffix s (i + 1)) fun all f s = let diff --git a/lib/ur/string.urs b/lib/ur/string.urs index 52aa27b6..55133578 100644 --- a/lib/ur/string.urs +++ b/lib/ur/string.urs @@ -17,7 +17,11 @@ val mindex : {Haystack : t, Needle : t} -> option int val substring : t -> {Start : int, Len : int} -> string +val seek : t -> char -> option string +val mseek : {Haystack : t, Needle : t} -> option (char * string) + val split : t -> char -> option (string * string) +val split' : t -> char -> option (string * string) (* The matched character is kept at the beginning of the suffix. *) val msplit : {Haystack : t, Needle : t} -> option (string * char * string) val all : (char -> bool) -> string -> bool diff --git a/src/c/urweb.c b/src/c/urweb.c index 0b4054e9..7e62d571 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1176,7 +1176,7 @@ static void uw_buffer_check_ctx(uw_context ctx, const char *kind, uw_buffer *b, if (new_heap != b->start) { b->start = new_heap; - uw_error(ctx, UNLIMITED_RETRY, "Couldn't allocate new %s contiguously", desc); + uw_error(ctx, UNLIMITED_RETRY, "Couldn't allocate new %s contiguously; increasing size to %llu", desc, (unsigned long long)next); } b->start = new_heap; @@ -3602,6 +3602,11 @@ void uw_check_deadline(uw_context ctx) { size_t uw_database_max = SIZE_MAX; +uw_Basis_int uw_Basis_naughtyDebug(uw_context ctx, uw_Basis_string s) { + fprintf(stderr, "%s\n", s); + return 0; +} + uw_Basis_unit uw_Basis_debug(uw_context ctx, uw_Basis_string s) { if (ctx->log_debug) ctx->log_debug(ctx->logger_data, "%s\n", s); diff --git a/src/settings.sml b/src/settings.sml index 29bbb1d8..ec0f582d 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -138,6 +138,7 @@ val benignBase = basis ["get_cookie", "onServerError", "kc", "debug", + "naughtyDebug", "rand"] val benign = ref benignBase |