New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move capitalize from builtins to setting #816
Comments
From @clintongormleyThe attached patch moves capitalize from builtins/any-str.pir to |
From @clintongormleycapitalize_move_to_setting.patchdiff --git a/src/builtins/any-str.pir b/src/builtins/any-str.pir
index 0369a40..066ff56 100644
--- a/src/builtins/any-str.pir
+++ b/src/builtins/any-str.pir
@@ -23,7 +23,7 @@ the size of that file down and to emphasize their generic,
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
- '!EXPORT'('capitalize,chomp,chars,:d,:e,:f,index,rindex,ord,substr,trim', 'from'=>$P0)
+ '!EXPORT'('chomp,chars,:d,:e,:f,index,rindex,ord,substr,trim', 'from'=>$P0)
.end
@@ -33,48 +33,6 @@ the size of that file down and to emphasize their generic,
.namespace ['Any']
-=item capitalize
-
- our Str multi Str::capitalize ( Str $string )
-
-Has the effect of first doing an C<lc> on the entire string, then performing a
-C<s:g/(\w+)/{ucfirst $1}/> on it.
-
-=cut
-
-.sub 'capitalize' :method :multi(_)
- .local string tmps
- .local pmc retv
- .local int len
-
- retv = new 'Str'
- tmps = self
-
- len = length tmps
- if len == 0 goto done
-
- downcase tmps
-
- .local int pos
- .local string s1
- pos = 0
- next_word:
- pos = find_cclass .CCLASS_LOWERCASE, tmps, pos, len
- s1 = substr tmps, pos, 1
- upcase s1
- substr tmps, pos, 1, s1
- len = length tmps
- pos+=1
- if pos == len goto done
- pos = find_not_cclass .CCLASS_LOWERCASE, tmps, pos, len
- if pos == len goto done
- goto next_word
-
- done:
- retv = tmps
- .return (retv)
-.end
-
.sub 'chars' :method :multi(_)
$S0 = self
$I0 = length $S0
diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm
index bbf28a3..49855d1 100644
--- a/src/setting/Any-str.pm
+++ b/src/setting/Any-str.pm
@@ -19,6 +19,38 @@ class Any is also {
self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! ""
}
+ our Str multi method capitalize is export {
+ return Q:PIR {
+ $S0 = self
+ .local int len
+
+ len = length $S0
+ if len == 0 goto done
+
+ downcase $S0
+
+ .local int pos
+ .local string s1
+ pos = 0
+
+ next_word:
+ pos = find_cclass .CCLASS_LOWERCASE, $S0, pos, len
+ s1 = substr $S0, pos, 1
+ upcase s1
+ substr $S0, pos, 1, s1
+ pos+=1
+ if pos == len goto done
+
+ pos = find_not_cclass .CCLASS_LOWERCASE, $S0, pos, len
+ if pos == len goto done
+ goto next_word
+
+ done:
+ %r = box $S0
+ }
+
+ }
+
our List multi method split(Code $delimiter, $limit = *) {
my $s = ~self;
my $l = $limit ~~ Whatever ?? Inf !! $limit;
|
From @pmichaudI'm declining this patch in favor of a slightly shorter version our Str multi method capitalize() is export { Just for reference (and for consideration in other upcoming patches) -- (1) The synopsis says that the conversion takes place on word (2) Methods that don't accept additional positional parameters really (3) Case conversions on a string *can* cause its length to change -- in Thanks for the patch! Pm |
1 similar comment
From @pmichaudI'm declining this patch in favor of a slightly shorter version our Str multi method capitalize() is export { Just for reference (and for consideration in other upcoming patches) -- (1) The synopsis says that the conversion takes place on word (2) Methods that don't accept additional positional parameters really (3) Case conversions on a string *can* cause its length to change -- in Thanks for the patch! Pm |
@pmichaud - Status changed from 'new' to 'resolved' |
From @moritzPatrick R. Michaud via RT wrote:
How can you doubt, when a German hacker takes care of the test suite? It's in t/spec/S32-str/uc.t, line 45, for regexes this is tested in Actually there might be codepoints that turn into multiple codepoints on Cheers, |
1 similar comment
From @moritzPatrick R. Michaud via RT wrote:
How can you doubt, when a German hacker takes care of the test suite? It's in t/spec/S32-str/uc.t, line 45, for regexes this is tested in Actually there might be codepoints that turn into multiple codepoints on Cheers, |
Migrated from rt.perl.org#64060 (status was 'resolved')
Searchable as RT64060$
The text was updated successfully, but these errors were encountered: