Skip to content

Commit

Permalink
0.0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed May 13, 2024
1 parent 67d4280 commit 29802ac
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Revision history for String-Utils

{{$NEXT}}

0.0.23 2024-05-13T12:59:15+02:00
- Add support for "nomark"
- Update copyright year

0.0.22 2023-07-04T21:31:56+02:00
- Add support for "is-uppercase"
- Add support for "is-lowercase"
Expand Down
5 changes: 3 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"STEM",
"NGRAM",
"NAUGHTY",
"WORD"
"WORD",
"MARKS"
],
"test-depends": [
],
"version": "0.0.22"
"version": "0.0.23"
}
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ say letters("//foo:bar"); # foobar

Returns all of the alphanumeric characters in the given string as a string.

nomark
------

```raku
say nomark("élève"); # eleve
```

Returns the given string with any diacritcs removed.

has-marks
---------

Expand Down Expand Up @@ -341,7 +350,7 @@ If you like this module, or what I’m doing more generally, committing to a [sm
COPYRIGHT AND LICENSE
=====================

Copyright 2022, 2023 Elizabeth Mattijsen
Copyright 2022, 2023, 2024 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

61 changes: 60 additions & 1 deletion lib/String/Utils.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,55 @@ my sub letters(str $string) {
nqp::join('',$found)
}

my constant $gcprop = nqp::unipropcode("General_Category");
my constant $empty = nqp::create(array[uint32]);
my sub nomark(str $string) {

# At least 1 char in the string
if nqp::chars($string) -> int $c {
my $codes := nqp::strtocodes(
$string,
nqp::const::NORMALIZE_NFD,
nqp::create(array[uint32])
);
my int $m = nqp::elems($codes);

# No codepoints that decomposed
if $m == $c {
$string
}

# At least one codepoint that decomposed
else {
my $cleaned := nqp::setelems(
nqp::setelems(nqp::create(array[uint32]), $c),
0
);

my int $i = -1;
nqp::while(
++$i < $m,
nqp::if(
nqp::isne_i(
nqp::getuniprop_int(
nqp::atpos_i($codes, $i),
$gcprop
),
6 # mark
),
nqp::push_i($cleaned, nqp::atpos_i($codes, $i))
)
);
nqp::strfromcodes($cleaned);
}
}

# Nothing to work with
else {
$string
}
}

my sub has-marks(str $string) {
my str $letters = letters($string);
nqp::strtocodes($letters, nqp::const::NORMALIZE_NFD, my int32 @ords);
Expand Down Expand Up @@ -651,6 +700,16 @@ say letters("//foo:bar"); # foobar
Returns all of the alphanumeric characters in the given string as a
string.
=head2 nomark
=begin code :lang<raku>
say nomark("élève"); # eleve
=end code
Returns the given string with any diacritcs removed.
=head2 has-marks
=begin code :lang<raku>
Expand Down Expand Up @@ -766,7 +825,7 @@ deal to me!
=head1 COPYRIGHT AND LICENSE
Copyright 2022, 2023 Elizabeth Mattijsen
Copyright 2022, 2023, 2024 Elizabeth Mattijsen
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
Expand Down
5 changes: 4 additions & 1 deletion t/01-basic.rakutest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use Test;
use String::Utils;

plan 68;
plan 71;

is after("foobar","foo"), "bar", 'after(foo) ok?';
is "foobar".&after("foo"), "bar", '.&after(foo) ok?';
Expand Down Expand Up @@ -101,5 +101,8 @@ is-deeply all-same("aaaaaa"), "a", 'all-same ok';
is-deeply all-same("aaaaba"), Nil, 'all-same NOT ok';
is-deeply all-same(""), Nil, 'all-same empty NOT ok';

is-deeply nomark("élève"), "eleve", 'nomark with marks ok';
is-deeply nomark("eleve"), "eleve", 'nomark without marks ok';
is-deeply nomark(""), "", 'nomark empty ok';

# vim: expandtab shiftwidth=4
File renamed without changes.

0 comments on commit 29802ac

Please sign in to comment.