Skip to content

Commit

Permalink
Add Parrot_str_foldcase to the string subsystem API.
Browse files Browse the repository at this point in the history
Expose this through a new foldcase op.
  • Loading branch information
Whiteknight authored and Reini Urban committed Feb 16, 2016
1 parent d36915e commit 7cbbd4e
Show file tree
Hide file tree
Showing 7 changed files with 1,021 additions and 931 deletions.
2 changes: 2 additions & 0 deletions include/parrot/oplib/core_ops.h
Expand Up @@ -917,6 +917,8 @@ op_lib_t *PARROT_CORE_OPLIB_INIT(PARROT_INTERP, long init);
opcode_t * Parrot_downcase_s_sc(opcode_t *, PARROT_INTERP);
opcode_t * Parrot_titlecase_s_s(opcode_t *, PARROT_INTERP);
opcode_t * Parrot_titlecase_s_sc(opcode_t *, PARROT_INTERP);
opcode_t * Parrot_foldcase_s_s(opcode_t *, PARROT_INTERP);
opcode_t * Parrot_foldcase_s_sc(opcode_t *, PARROT_INTERP);
opcode_t * Parrot_join_s_s_p(opcode_t *, PARROT_INTERP);
opcode_t * Parrot_join_s_sc_p(opcode_t *, PARROT_INTERP);
opcode_t * Parrot_split_p_s_s(opcode_t *, PARROT_INTERP);
Expand Down
466 changes: 234 additions & 232 deletions include/parrot/oplib/ops.h

Large diffs are not rendered by default.

466 changes: 234 additions & 232 deletions include/parrot/opsenum.h

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions include/parrot/string_funcs.h
Expand Up @@ -180,6 +180,12 @@ PARROT_EXPORT
void Parrot_str_finish(PARROT_INTERP)
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
STRING * Parrot_str_foldcase(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_str_format_data(PARROT_INTERP,
Expand Down Expand Up @@ -557,6 +563,8 @@ STRING * Parrot_str_new_from_cstring(PARROT_INTERP,
, PARROT_ASSERT_ARG(search))
#define ASSERT_ARGS_Parrot_str_finish __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_foldcase __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_format_data __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(format))
Expand Down
972 changes: 505 additions & 467 deletions src/ops/core_ops.c

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/ops/string.ops
Expand Up @@ -441,6 +441,16 @@ inline op titlecase(out STR, in STR) {
$1 = Parrot_str_titlecase(interp, $2);
}

=item B<foldcase>(out STR, in STR)

Foldcase $2 and put the result in $1

=cut

inline op foldcase(out STR, in STR) {
$1 = Parrot_str_foldcase(interp, $2);
}


=item B<join>(out STR, in STR, invar PMC)

Expand Down
28 changes: 28 additions & 0 deletions src/string/api.c
Expand Up @@ -2974,6 +2974,34 @@ Parrot_str_titlecase(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
}
}

/*
=item C<STRING * Parrot_str_foldcase(PARROT_INTERP, const STRING *s)>
Returns a copy of the specified Parrot string case-folded. Non caseable
characters are left unchanged. The encoding of the string may be modified.
=cut
*/

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
STRING *
Parrot_str_foldcase(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
{
ASSERT_ARGS(Parrot_str_foldcase)

if (STRING_IS_NULL(s))
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
"Can't foldcase NULL string");
else {
STRING * const res = STRING_foldcase(interp, s);
res->hashval = 0;
return res;
}
}

/*
Expand Down

0 comments on commit 7cbbd4e

Please sign in to comment.