Open DaveBenham opened 4 years ago
- Always use single quotes whenever a string of characters is required. Escape single quote literal as
''
, For example!undefined;'This is Dave''s idea'!
Escaping is on the cards (need a way to get colon), but atm it's not supported, hence the three string types. Doubling up the quote will work with all types, so I see no reason to restrict it to one.
- Ditch the 0 padding construct and allow specification of any pad string for both left and right alignment. Default to spaces for padding. So
!var;05!
would now be written as!var;5'0'
.
Not a fan of the syntax, looks more like 5 zeroes, not length of 5, pad with zero.
A little more verbose, but now you can do something like
set "TOC=Chapter 1" & echo !TOC;-30' .'!
yieldingChapter 1. . . . . . . . . . .
I was thinking of something like the Perl/Python-style *
operator: echo Chapter one!30* .!
(if the variable starts with a number followed by a star, repeat the rest that many times).
- Consider abbreviating filter function names: length -> len, upper -> up, lower -> low, capital -> cap. [...] Using the
'string'
syntax,!var;trim[xy]!
would become!var;trim'xy'!
.
Heh, this goes against Carlos' new filters; I'm content how they are. I chose square brackets as that's what Take Command uses (not that I actually use it). Your syntax looks like it will trim the string xy
, not the characters x
and y
.
- Implement case sensitive find/replace as
!var;'search'='replace'!
. In addition to providing case sensitive support, it would allow searching for=
and*
. [...]
I do want something like that, but again, not sure of your syntax. I was thinking more of a sed-style s/search/replace/options
(where /
could be any non-alphanumeric).
Lastly, I'm not sure if this is a bug or a feature request, but I would expect something like zero pad and right align to be chainable. For example,
set n=1 & echo !n;03;5!
should yield--001
, but I am getting----1
(I substituted dash for space). Note that with my proposed new syntax, the code would be written as!n;3'0';5!
.
ATM padding and length are delayed and applied after all the other modifiers, so 03;5
is set a length of 3, padding with zeroes, then set the length to 5. That's indeed what I get: 00005
. I guess I could apply it immediately, allowing what you want.
. . . hence the three string types. Doubling up the quote will work with all types, so I see no reason to restrict it to one.
I didn't realize you could also quote with backtick or double quote when specifying a default.
Is there any built in help for anything other than called @extensions
? Help for filters and all new behaviors would be great. Or is that another existing feature that I am missing?
I was thinking of something like the Perl/Python-style operator: echo Chapter one!30 .! (if the variable starts with a number followed by a star, repeat the rest that many times).
Not quite the same, though perhaps also useful. I was looking for a way of choosing the character (or string) used to pad a value to a particular length - a generalized form of zero padding that allows padding on either side, and with any string value.
Is there any built in help for anything other than called
@extensions
?
Not at the moment, but eventually.
Not quite the same, though perhaps also useful. I was looking for a way of choosing the character (or string) used to pad a value to a particular length - a generalized form of zero padding that allows padding on either side, and with any string value.
Oh, yes. How about a more explicit lpad[string]
and rpad[string]
, similar to trim? The length would remain separate: rpad[. ];30
.
That would be good, except I don't like separating the length from the pad string. They are part of the same operation, and chaining makes more sense when they are together.
So any of the following make sense to me:
rpad[30,string]
rpad(30,string)
rpad(30,'string')
rpad(30'string')
rpad30'string'
In all cases, the string is optional, with a default value of spaces. If this were implemented, then there is no need for the numeric left and right justification filter. My original suggestion was an attempt to preserve the terseness of the original syntax with augmented capability.
I think I prefer the first (rather not use parentheses, as they might require escaping), having quotes optional (as a way to add ']'; the character-based options have it first, so escaping isn't required). Thus rpad[30,string]
and rpad[30,'string']
are equivalent. There could also be rpad[30,$var]
, which pads to the expansion of $var
(that exists now, but as text substitution; I'd have to tweak it a bit). I don't see why we can't keep the existing number style and have these modifiers.
Some suggestions:
''
, For example!undefined;'This is Dave''s idea'!
!var;05!
would now be written as!var;5'0'
.A little more verbose, but now you can do something like
set "TOC=Chapter 1" & echo !TOC;-30' .'!
yieldingChapter 1. . . . . . . . . . .
'string'
syntax,!var;trim[xy]!
would become!var;trim'xy'!
.!var;'search'='replace'!
. In addition to providing case sensitive support, it would allow searching for=
and*
. Additional related extensions to consider!var;'search'i='replace'!
- case insensitive search, still useful because allows=
and*
'!var;'search'3='replace'!
- only replace the 3rd occurrence!var;'search'-1='replace'!
- only replace the last occurrence!var;*'search'='replace'!
- replace everything from beginning through 1st occurrence of search.!var;*'search'-1='replace'!
would replace from beginning through last occurrence, etc. No occurrence, occurrence of 0, and occurrence of 1 would all be equivalent.*
after 'search' to replace from search to end of string. For example!var;'search'*-1='replace'!
would replace from the last occurrence of search to the end of string.Lastly, I'm not sure if this is a bug or a feature request, but I would expect something like zero pad and right align to be chainable. For example,
set n=1 & echo !n;03;5!
should yield--001
, but I am getting----1
(I substituted dash for space). Note that with my proposed new syntax, the code would be written as!n;3'0';5!
.