Re: [PATCH] Add .trim method
On 2009 Jan 12, at 15:17, Ovid wrote: בָּרוּךְ שֵׁם כְּבוֹד מַלְכוּתוֹ לְעוֹלָם וָעֶד. If you can't see that in your client, that's Hebrew from http://www.i18nguy.com/unicode/shma.html and means Hear O Israel, the Lord is our God, the Lord is One. Actually that's the response: blessed be the name of the glory of His kingdom for ever and ever (and your guess is as good as anyone else's as to the actual meaning of that :) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH
Re: [PATCH] Add .trim method
- Original Message From: Ovid publiustemp-perl6interna...@yahoo.com This patch implements the .trim() method for strings. Now that I'm reading S29, I see there is no .trim() method there. I got that because it was referenced in pugs in the cookbook (not in tests, though) and I was trying to get the examples to run. Bummer :( Sorry for constant spamming, but now that I've put disparate pieces together, I see what's going on here. I'll stop soon, but I am *sick* of rewriting the trim() function over and over :) There are no tests because it's not in the spec. If there's a spec, I know where to write the tests and will happily commit tests for them to Pugs and I'll submit a new patch against any-str.pir and t/spectest.data to get them to pass. http://tinyurl.com/4xjnh, a mailing list thread where Larry wrote: : (Replying to p6l instead of p6c as requested.) : : On Mon, Apr 04, 2005 at 10:39:16AM -0700, Larry Wall wrote: : (Now that builtins are just functions out in * space, we can probably : afford to throw a few more convenience functions out there for common : operations like word splitting and whitespace trimming. (Specific : proposals to p6l please.)) So even though it's not in the spec, it seems like something Larry is not entirely opposed to (or wasn't back in 2005). So here's my proposal (copied to p6l): =item trim our Str multi Str::trim ( Str $string ) Removes leading and trailing whitespace from a string. =cut I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Setting leading or trailing to false (they default to true) would result in either leading or trailing whitespace not being trimmed. Setting both to false would be a no-op. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
Ovid (): =item trim our Str multi Str::trim ( Str $string ) Removes leading and trailing whitespace from a string. =cut I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Setting leading or trailing to false (they default to true) would result in either leading or trailing whitespace not being trimmed. Setting both to false would be a no-op. Unless someone protests loudly, I can add this to S29, and I (or someone else with tuits) can implement it in Rakudo. // Carl
Re: [PATCH] Add .trim method
- Original Message =item trim our Str multi Str::trim ( Str $string ) Removes leading and trailing whitespace from a string. =cut I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Setting leading or trailing to false (they default to true) would result in either leading or trailing whitespace not being trimmed. Setting both to false would be a no-op. Unless someone protests loudly, I can add this to S29, and I (or someone else with tuits) can implement it in Rakudo. I've already submitted a patch for Rakudo which implements this for the trivial $string.trim and trim($string) case. The optional :leading and :trailing parameters aren't there. I'm happy to finish the work according to whatever spec is agreed upon. I want this badly enough that it's important to me :) Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
- Original Message I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). If you need to dynamically determine what you're going to trim, you'd couldn't just set variables to do it, though. You'd have to figure out which methods to call. Or all could be allowed and $string.trim(:leading0) could all $string.rtrim internally. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
* Ovid publiustemp-perl6langua...@yahoo.com [2009-01-12 16:05]: Or all could be allowed and $string.trim(:leading0) could all $string.rtrim internally. ++ Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: [PATCH] Add .trim method
Aristotle Pagaltzis wrote: * Ovid publiustemp-perl6langua...@yahoo.com [2009-01-12 16:05]: Or all could be allowed and $string.trim(:leading0) could all $string.rtrim internally. ++ Note you can write it :!leading too. :-) Jonathan
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 05:04:50AM -0800, Ovid wrote: : ...the trivial $string.trim and trim($string) case. Hmm, I'd think .trim should work like .chomp, and return the trimmed string without changing the original. You'd use $str.=trim to do it in place. Can't say I really like the negated options though. They smell funny. Larry
Re: [PATCH] Add .trim method
Ovid wrote: - Original Message In the pir, doesn't the s = self line copy self, thus ensuring that I'm changing s and not self? No, it's binding. Or do I need s = clone self (or however it's written). Yeah, but also note that substr would return a copy... Can't say I really like the negated options though. They smell funny. Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. Suggestions welcome as I can't think of anything better. The .Net framework calls 'em TrimStart and TrimEnd (and has a Trim that does both). So maybe trim_start and trim_end if we wanted to take that lead... Jonathan
Re: [PATCH] Add .trim method
Jonathan (), Ovid (), Larry (): Can't say I really like the negated options though. They smell funny. Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. Suggestions welcome as I can't think of anything better. The .Net framework calls 'em TrimStart and TrimEnd (and has a Trim that does both). So maybe trim_start and trim_end if we wanted to take that lead... How about .trim(:start) and .trim(:end)? // Carl
Re: [PATCH] Add .trim method
On Mon, 2009-01-12 at 07:01 -0800, Ovid wrote: - Original Message I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). If you need to dynamically determine what you're going to trim, you'd couldn't just set variables to do it, though. You'd have to figure out which methods to call. Or all could be allowed and $string.trim(:leading0) could all $string.rtrim internally. When I saw your proposed syntax above, instead of reading don't trim leading/trailing whitespace, I read change the definition of 'whitespace' to 'codepoint 0' for leading/trailing. That of course raises the question of how one *would* properly override trim's concept of whitespace -'f
Re: [PATCH] Add .trim method
- Original Message Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. Suggestions welcome as I can't think of anything better. The .Net framework calls 'em TrimStart and TrimEnd (and has a Trim that does both). So maybe trim_start and trim_end if we wanted to take that lead... How about .trim(:start) and .trim(:end)? So if: 1. No params, trim all 2. :start or :end, only trim that bit (not a negated option :) 3. If both, goto 1 Sound good? Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
- Original Message From: Geoffrey Broadwell ge...@broadwell.org When I saw your proposed syntax above, instead of reading don't trim leading/trailing whitespace, I read change the definition of 'whitespace' to 'codepoint 0' for leading/trailing. That of course raises the question of how one *would* properly override trim's concept of whitespace Change your locale to one with a different concept of whitespace (are there any?) Otherwise, would this be trying to stuff too much into one function? Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 09:33:32AM -0800, Geoffrey Broadwell wrote: : That of course raises the question of how one *would* properly override : trim's concept of whitespace Well, given that .trim is essentially just .comb(/\S.*\S/), which in turn is really just m:g/(\S.*\S)/, I don't see much need for alternate trimmings. Larry
Re: [PATCH] Add .trim method
Larry Wall wrote: On Mon, Jan 12, 2009 at 05:04:50AM -0800, Ovid wrote: : ...the trivial $string.trim and trim($string) case. Hmm, I'd think .trim should work like .chomp, and return the trimmed string without changing the original. You'd use $str.=trim to do it in place. Can't say I really like the negated options though. They smell funny. Larry I'm +1 on adding a trim, I do a lot of csv import (with trimming) in perl 5. On a side note, between modifying the original and returning a fixed string, which one would we expect to be faster? And I assume either would be faster than the regex method of trimming? -Andy
Re: [PATCH] Add .trim method
* Ovid publiustemp-perl6langua...@yahoo.com [2009-01-12 18:40]: 1. No params, trim all 2. :start or :end, only trim that bit (not a negated option :) 3. If both, goto 1 Also `:!start` to imply `:end` unless `:!end` (which in turn implies `:start` unless `:!end`)? I’d like not to have to type `.trim(:start)` when I could just do `.ltrim` though. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 2:50 PM, Aristotle Pagaltzis pagalt...@gmx.de wrote: I'd like not to have to type `.trim(:start)` when I could just do `.ltrim` though. As long as we gloss .ltrim as leading trim rather than left trim. Then the other end could be .ttrim for trailing? We really ought to avoid using left and right to refer to the beginning and end of text strings. -- Mark J. Reed markjr...@gmail.com
Re: [PATCH] Add .trim method
- Original Message Also `:!start` to imply `:end` unless `:!end` (which in turn implies `:start` unless `:!end`)? I’d like not to have to type `.trim(:start)` when I could just do `.ltrim` though. So what would .ltrim do with this? בָּרוּךְ שֵׁם כְּבוֹד מַלְכוּתוֹ לְעוֹלָם וָעֶד. If you can't see that in your client, that's Hebrew from http://www.i18nguy.com/unicode/shma.html and means Hear O Israel, the Lord is our God, the Lord is One. Since that's RTL (Right To Left) text, should ltrim remove the leading or trailing whitespace? I like Jonathan's trim_start and trim_end. Side note: I'm implementing the tests now, but only for bog-standard .trim. I won't do the rest until we settle this. So far I only have one failing test: is_deeply(trim(()), (), trim on empty list); Results in: not ok 10 - trim on empty list # have: # want: [] Note that this output is from my locally hacked version of Test.pm which is kind enough to tell you what the failure is. I'll submit a patch for that later. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
* Aristotle Pagaltzis pagalt...@gmx.de [2009-01-12 20:55]: Also `:!start` to imply `:end` unless `:!end` (which in turn implies `:start` unless `:!end`)? Ugh, forget this, I was having a blank moment. Actually that makes me wonder now whether it’s actually a good idea at all to make the function parametrisable at all. Even `.ltrim.rtrim` is shorter and easier than `.trim(:start,:end)`! Plus if there are separate `.ltrim` and `.rtrim` functions it would be better to implement `.trim` by calling them rather than vice versa, so it wouldn’t even be less efficient two make two calls rather than a parametrised one. And if anyone really needs to be able to decide the trimming based on flags, they can do that themselves with `.ltrim`/ `.rtrim` with rather little code anyway. So I question the usefulness of parametrisation here. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: [PATCH] Add .trim method
* Ovid publiustemp-perl6langua...@yahoo.com [2009-01-12 21:20]: Since that's RTL (Right To Left) text, should ltrim remove the leading or trailing whitespace? I like Jonathan's trim_start and trim_end. Let me ask you first: does a string that runs Right-to-Left start at the left and end at the right or start at the right and end at the left? Now to answer your question, *I* know where the *left* side is in a string that runs from right to left: it’s at the *left*, same as if the string ran from the left to the right, because left is at the *left*. :-) I mean, if the the meaning of “left” was inverted by “right-to-left”, in which it is contained, then what does the latter even mean? (OK, we’re on a Perl 6 list so I guess the answer is it’s a juction… :-) ) Clearly one of us has an inversed sense of which pair of terms is ambiguous, and I don’t think it’s me… ;-) Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 09:18:03PM +0100, Aristotle Pagaltzis wrote: : Plus if there are separate `.ltrim` and `.rtrim` functions it : would be better to implement `.trim` by calling them rather than : vice versa, so it wouldn’t even be less efficient two make two : calls rather than a parametrised one. Depends on your string implementation if they're non-destructive, since they potentially have to copy the middle of the string twice if your implementation can't support one string pointing into the middle of another. And again, I think .trim should be non-destructive, and .=trim should be the destructive version. Larry
Re: [PATCH] Add .trim method
Aristotle Pagaltzis wrote: Actually that makes me wonder now whether it’s actually a good idea at all to make the function parametrisable at all. Even `.ltrim.rtrim` is shorter and easier than `.trim(:start,:end)`! How about .trim(:l, :r) with both as the default? And if the rtl crowd makes a furor, we can add :a/:o or :ת/:א or something. So I question the usefulness of parametrisation here. Useful for doing infrequent things. IMO, left and right trimming are infrequent compared to the frequency of basic input editing. =Austin
Re: [PATCH] Add .trim method
- Original Message From: Aristotle Pagaltzis pagalt...@gmx.de I like Jonathan's trim_start and trim_end. Let me ask you first: does a string that runs Right-to-Left start at the left and end at the right or start at the right and end at the left? Now to answer your question, *I* know where the *left* side is in a string that runs from right to left: it’s at the *left*, same as if the string ran from the left to the right, because left is at the *left*. :-) I see your point, but it complicates the internals of the trim method because then I have to detect if a string is RTL and reverse it, then unreverse it when done (or something conceptually similar). I'd rather not toss in said complications for a problem space I don't know very well. On the other hand, this is a core feature, not a quick CPAN jobbie, so it's important to get it RIGHT or it will be LEFT out. (I kill me. I really do :) Beers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
* Larry Wall la...@wall.org [2009-01-12 21:55]: * Aristotle Pagaltzis pagalt...@gmx.de [2009-01-12 21:20]: Plus if there are separate `.ltrim` and `.rtrim` functions it would be better to implement `.trim` by calling them rather than vice versa, so it wouldn’t even be less efficient two make two calls rather than a parametrised one. Depends on your string implementation if they're non-destructive, since they potentially have to copy the middle of the string twice if your implementation can't support one string pointing into the middle of another. And again, I think .trim should be non-destructive, and .=trim should be the destructive version. Sure, but that doesn’t affect my point: if `.trim` is implemented as calling `.ltrim` + `.rtrim`, as I assumed, then all ways of trimming a string at both ends will be equally efficient or inefficient depending on whether or not the implementation supports offsetted strings. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: [PATCH] Add .trim method
* Ovid publiustemp-perl6langua...@yahoo.com [2009-01-12 22:05]: I see your point And now I see yours. I was visualising the memory layout of a string, wherein a right-to-left string gets displayed from the right end of it’s in-memory representation so “left” and “right” are absolutes in that picture. But of course RTL reverses the relation of left/right in memory and left/right on screen. I think a week’s worth of wolf sleep is catching up to me, sorry. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: [PATCH] Add .trim method
* Austin Hastings austin_hasti...@yahoo.com [2009-01-12 22:00]: How about .trim(:l, :r) with both as the default? Liveable. And if the rtl crowd makes a furor, we can add :a/:o or :ת/:א or something. *grin* Maybe :h and :t (head/tail). Useful for doing infrequent things. IMO, left and right trimming are infrequent compared to the frequency of basic input editing. Good point, rings true. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: [PATCH] Add .trim method
- Original Message From: Aristotle Pagaltzis pagalt...@gmx.de * Austin Hastings [2009-01-12 22:00]: How about .trim(:l, :r) with both as the default? Liveable. I've just committed the pugs tests for trim. However, it's just 'trim' with no left/right, leading/trailing, Catholic/Protestant implementation. I'll submit a patch for trim with the spectest data updated and work on the rest after the dust settles. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
- Original Message From: jesse je...@fsck.com On Mon, Jan 12, 2009 at 07:01:25AM -0800, Ovid wrote: I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). 'left' and 'right' are probably not the right names for functions which trim leading and/or trailing space, since their meanings get somewhat ambiguous if a language renders right-to-left instead of left-to-right or vice-versa Um, er. Damn. Now I'm wondering how my leading and trailing trimming works with Hebrew. How are the strings implemented internally? And then there are languages such as Manchu and Uygher which can be written vertically. http://www.omniglot.com/writing/direction.htm Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
On 2009-01-12 Ovid publiustemp-perl6interna...@yahoo.com wrote: Um, er. Damn. Now I'm wondering how my leading and trailing trimming works with Hebrew. How are the strings implemented internally? RTL (and bidi) languages are written in strings so that the character order is the logical, reading, order. That is, the character nearer to the beginning of the string is the first one to be read by a human reader (so, such character would be displayed on the right for a RTL language, on the left for a LTR language, at the top for a TTB language) Short answer: your implementation is right :) -- Dakkar - Mobilis in mobile GPG public key fingerprint = A071 E618 DD2C 5901 9574 6FE2 40EA 9883 7519 3F88 key id = 0x75193F88 You possess a mind not merely twisted, but actually sprained. signature.asc Description: PGP signature
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 9:01 AM, Ovid publiustemp-perl6langua...@yahoo.comwrote: - Original Message I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). If you need to dynamically determine what you're going to trim, you'd couldn't just set variables to do it, though. You'd have to figure out which methods to call. Or all could be allowed and $string.trim(:leading0) could all $string.rtrim internally. If I were going to have ltrim() and rtrim(), I'd implement them in terms of trim() rather than the other way around. -Scott -- Jonathan Scott Duff perlpi...@gmail.com
Re: [PATCH] Add .trim method
- Original Message From: Larry Wall la...@wall.org On Mon, Jan 12, 2009 at 05:04:50AM -0800, Ovid wrote: : ...the trivial $string.trim and trim($string) case. Hmm, I'd think .trim should work like .chomp, and return the trimmed string without changing the original. You'd use $str.=trim to do it in place. In the pir, doesn't the s = self line copy self, thus ensuring that I'm changing s and not self? Or do I need s = clone self (or however it's written). Can't say I really like the negated options though. They smell funny. Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. Suggestions welcome as I can't think of anything better. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
Ovid wrote: $string.trim(:leading0); $string.trim(:trailing0); Setting leading or trailing to false (they default to true) would result in either leading or trailing whitespace not being trimmed Alternatively, those could be ltrim() and rtrim(). If you need to dynamically determine what you're going to trim, you'd couldn't just set variables to do it, though. You'd have to figure out which methods to call. Or all could be allowed and $string.trim(:leading0) could all $string.rtrim internally. I like having the options, I think. If the default value of :trailing was /ws*/, then someone could change it to /ws*\#\N*/ to chomp trailing line comments. (Assuming they don't simply redefine the ws token)
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 07:01:25AM -0800, Ovid wrote: I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). 'left' and 'right' are probably not the right names for functions which trim leading and/or trailing space, since their meanings get somewhat ambiguous if a language renders right-to-left instead of left-to-right or vice-versa -jesse
Re: [PATCH] Add .trim method
On Jan 12, 2009, at 11:27 AM, Carl Mäsak wrote: How about .trim(:start) and .trim(:end)? And .trim(:both) for orthogonality. -- Andy Lester = a...@petdance.com = www.petdance.com = AIM:petdance
Re: [PATCH] Add .trim method
Carl Mäsak wrote: Jonathan (), Ovid (), Larry (): Can't say I really like the negated options though. They smell funny. Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. Suggestions welcome as I can't think of anything better. The .Net framework calls 'em TrimStart and TrimEnd (and has a Trim that does both). So maybe trim_start and trim_end if we wanted to take that lead... How about .trim(:start) and .trim(:end)? That would be my favourite: our Str multi method trim (Str $string:, :start = True, :end = True) So $str.=trim would trim both start and end, and if you want only one, you can say $str.=trim(:!end);. Cheers, Moritz
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 06:36:55PM +0100, Moritz Lenz wrote: : Carl Mäsak wrote: : Jonathan (), Ovid (), Larry (): : Can't say I really like the negated options though. They smell funny. : : Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. : Suggestions welcome as I can't think of anything better. : : The .Net framework calls 'em TrimStart and TrimEnd (and has a Trim that does : both). So maybe trim_start and trim_end if we wanted to take that lead... : : How about .trim(:start) and .trim(:end)? : : That would be my favourite: : : our Str multi method trim (Str $string:, :start = True, :end = True) Er, that would make .trim(:start) also default :end to True... Well, except it won't parse either. For at least two reasons. :) : So $str.=trim would trim both start and end, and if you want only one, : you can say $str.=trim(:!end);. HEY! Don't ignore my nose. At least, not this time. :) Switches should almost never default to true. It's more like: our Str multi method trim (Str $string: :$start = False, :$end = False, :$both = not $start || $end) or really, since start/end really mean startonly/endonly: our Str multi method trim (Str $string: :start($start_only) = False, :end($end_only) = False) { my $do_start = not $end_only; my $do_end = not $start_only; ... } I really shouldn't be participating in the bikeshedding though... Larry
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 9:07 AM, jesse je...@fsck.com wrote: 'left' and 'right' are probably not the right names for functions which trim leading and/or trailing space, since their meanings get somewhat ambiguous if a language renders right-to-left instead of left-to-right or vice-versa I'm in favor of using the proposed syntax, but I will agree with lwall that it seems like overkill to have the specialized trims. .trim should be non-destructive and .=trim should be destructive (these seems intuitive). Some languages run in the direction of left-to-right, some in the direction right-to-left (some even top-to-bottom). No matter what language you speak or which direction your native language reads, left is the same for everyone as well as right. If we wanted to simplify matters, use :left, :right and :both. Those have the same meaning everywhere. If we wanted language dependent version, use :leading, :trailing, and :both. That will require each implementation properly handle the language variations. By the way, good work on this. Everyone loves useful string functions. -Jason s1n Switzer
Trimming; left or start? (was: Re: [PATCH] Add .trim method)
Can I make a suggestion? From my point of view, it'd be nice if the trim method supported: - left/right (leftmost/rightmost part of the string; language-independent) - start/end (start and end of string; could be leading/trailing instead) - both How would that work? :) - | Name: Tim Nelson | Because the Creator is,| | E-mail: wayl...@wayland.id.au| I am | - BEGIN GEEK CODE BLOCK Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+++ PGP-+++ R(+) !tv b++ DI D G+ e++ h! y- -END GEEK CODE BLOCK-
Re: [PATCH] Add .trim method
- Original Message From: jason switzer jswit...@gmail.com If we wanted language dependent version, use :leading, :trailing, and :both. That will require each implementation properly handle the language variations. I think :start and :end are my favorites. Huffman++ (maybe :begin and :end for consistency?). Still raises the question of what to do with arrays of hashes of arrays with @array .= trim; I can't trim keys of pairs because they're used as unique identifiers in hashes and conflicts will occur. So recursive trimming needs have a special case for keys or it needs to not be allowed (and thus fail with AoHoA and similar complex data structures). By the way, good work on this. Everyone loves useful string functions. Thanks. It's been lots of fun :) Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: [PATCH] Add .trim method
On Mon, Jan 12, 2009 at 6:26 PM, Ovid publiustemp-perl6langua...@yahoo.comwrote: - Original Message From: jason switzer jswit...@gmail.com If we wanted language dependent version, use :leading, :trailing, and :both. That will require each implementation properly handle the language variations. I think :start and :end are my favorites. Huffman++ (maybe :begin and :end for consistency?). My best advise is to keep it consistant. .chomp makes references to chomping from the end, not the trailing. .substr makes reference to start. I think that's better to just find terminology that has already been agreed upon and keep abusing it.