diff options
author | 2011-01-11 14:03:54 -0500 | |
---|---|---|
committer | 2011-01-11 14:03:54 -0500 | |
commit | 138f64b8f02f05e6073f61b1db2c3d5e805b75c0 (patch) | |
tree | 07c262b05b9acf20fbb9aaaef74b8a2b300ad330 /src/c/urweb.c | |
parent | d6cee9f01237ec6c6ebb2843a33eda0da89fd5bb (diff) |
String processing optimizations
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r-- | src/c/urweb.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 17e4bed2..0b4054e9 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -2133,23 +2133,48 @@ uw_unit uw_Basis_htmlifyTime_w(uw_context ctx, uw_Basis_time t) { } uw_Basis_char uw_Basis_strsub(uw_context ctx, uw_Basis_string s, uw_Basis_int n) { - if (n >= 0 && n < strlen(s)) - return s[n]; - else - uw_error(ctx, FATAL, "Out-of-bounds strsub"); + while (n >= 0) { + if (*s == 0) + uw_error(ctx, FATAL, "Out-of-bounds strsub"); + + if (n == 0) + return *s; + + --n; + ++s; + } + + uw_error(ctx, FATAL, "Negative strsub bound"); } uw_Basis_string uw_Basis_strsuffix(uw_context ctx, uw_Basis_string s, uw_Basis_int n) { - if (n >= 0 && n < strlen(s)) - return &s[n]; - else - uw_error(ctx, FATAL, "Out-of-bounds strsuffix"); + while (n >= 0) { + if (*s == 0 || n == 0) + return s; + + --n; + ++s; + } + + uw_error(ctx, FATAL, "Negative strsuffix bound"); } uw_Basis_int uw_Basis_strlen(uw_context ctx, uw_Basis_string s) { return strlen(s); } +uw_Basis_bool uw_Basis_strlenGe(uw_context ctx, uw_Basis_string s, uw_Basis_int n) { + while (n > 0) { + if (*s == 0) + return uw_Basis_False; + + --n; + ++s; + } + + return uw_Basis_True; +} + uw_Basis_string uw_Basis_strchr(uw_context ctx, uw_Basis_string s, uw_Basis_char ch) { return strchr(s, ch); } |