diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ellinika/elmorph.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/ellinika/elmorph.c b/src/ellinika/elmorph.c index faeeb49..5785f8d 100644 --- a/src/ellinika/elmorph.c +++ b/src/ellinika/elmorph.c @@ -596,12 +596,14 @@ SCM_DEFINE_PUBLIC(scm_elstr_char_prop_bitmask, "elstr-char-prop-bitmask", #define FUNC_NAME s_scm_elstr_char_prop_bitmask { struct elstr *elstr; - unsigned num; + int num; SCM_ASSERT(scm_is_elstr(el), el, SCM_ARG1, FUNC_NAME); SCM_ASSERT(scm_is_integer(n), n, SCM_ARG2, FUNC_NAME); elstr = (struct elstr*) SCM_CDR(el); - num = scm_to_uint(n); + num = scm_to_int(n); + if (num < 0) + num += elstr->len; if (num >= elstr->len) scm_misc_error(FUNC_NAME, "cannot get character #~S: not enough characters: ~S", @@ -812,6 +814,51 @@ SCM_DEFINE_PUBLIC(scm_elstr_index, "elstr-index", } #undef FUNC_NAME +static int +_suffix_matches(struct elstr *elstr, SCM suffix, int arg, const char *func_name) +{ + struct elstr *ep; + + if (scm_is_elstr(suffix)) { + ep = (struct elstr*) SCM_CDR(suffix); + } else { + SCM scm; + char *str; + + SCM_ASSERT(scm_is_string(suffix), suffix, arg, func_name); + str = scm_to_locale_string(suffix); + scm = _elstr_alloc(str, 0); + free(str); + ep = (struct elstr*) SCM_CDR(scm); + } + return (ep->len < elstr->len && + memcmp(elstr->str + elstr->len - ep->len, + ep->str, + ep->len * sizeof(elstr->str[0])) == 0); +} + +SCM_DEFINE_PUBLIC(scm_elstr_suffix_p, "elstr-suffix?", + 2, 0, 1, + (SCM word, SCM suffix, SCM rest), +"Return #t if WORDS ends with SUFFIX") +#define FUNC_NAME s_scm_elstr_suffix_p +{ + struct elstr *elstr; + + SCM_ASSERT(scm_is_elstr(word), word, SCM_ARG1, FUNC_NAME); + elstr = (struct elstr*) SCM_CDR(word); + if (_suffix_matches(elstr, suffix, SCM_ARG2, FUNC_NAME)) + return suffix; + + for (; !scm_is_null(rest); rest = SCM_CDR(rest)) { + SCM val = SCM_CAR(rest); + if (_suffix_matches(elstr, val, SCM_ARGn, FUNC_NAME)) + return val; + } + return SCM_BOOL_F; +} +#undef FUNC_NAME + SCM_DEFINE_PUBLIC(scm_elstr_append, "elstr-append", 0, 0, 1, (SCM rest), |