* Truncate without padding
@ 2005-10-31 11:27 DervishD
2005-10-31 15:35 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: DervishD @ 2005-10-31 11:27 UTC (permalink / raw)
To: Zsh Users
Hi all :)
I would like to print a string truncated *but* without padding,
so I cannot use the "l" and "r" parameter expansion flags. Of course,
I could use the "%" parameter expansion flag and use %>STRING>, but I
don't want the string to be prompt-expanded.
I know I can use "printf" or "zformat" for that, but I was
wondering if this can be done using "print" and some form of
expansion. I need to use "print" because sometimes I have to do
translation of echo escape sequences and sometimes not, and I've
implemented that using optionally the "-r" option to "print". I can
switch to printf and do any translation before, but I would like to
use the current code and not switch to printf or zformat.
Thanks a lot in advance :)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Truncate without padding
2005-10-31 11:27 Truncate without padding DervishD
@ 2005-10-31 15:35 ` Bart Schaefer
2005-10-31 17:21 ` DervishD
2005-10-31 23:56 ` DervishD
0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2005-10-31 15:35 UTC (permalink / raw)
To: Zsh Users
On Oct 31, 12:27pm, DervishD wrote:
}
} I would like to print a string truncated *but* without padding
Just truncate it first with padding, and then strip the padding.
${${(pl:WIDTH::::\0:)string}#*$'\0'}
${${(pr:WIDTH::::\0:)string}%$'\0'*}
You can pick some other character than NUL if you know that character
doesn't appear in the string, in which case you don't need the (p) flag.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Truncate without padding
2005-10-31 15:35 ` Bart Schaefer
@ 2005-10-31 17:21 ` DervishD
2005-10-31 23:56 ` DervishD
1 sibling, 0 replies; 4+ messages in thread
From: DervishD @ 2005-10-31 17:21 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh Users
Hi Bart :)
* Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Oct 31, 12:27pm, DervishD wrote:
> }
> } I would like to print a string truncated *but* without padding
>
> Just truncate it first with padding, and then strip the padding.
Sorry, I didn't mention that it has to be done in one step
(namely in the print command) and the "string" to be printed is $*.
I think I could save "$*" in a parameter (it won't be splitted
nor any other thing except printed) and apply your solution :)
Anyway, is there a way of doing all in one step, with the
restrictions I mention above?
> You can pick some other character than NUL if you know that
> character doesn't appear in the string, in which case you don't
> need the (p) flag.
It's OK to use '\0' if I apply this solution, althoug it is not
needed because ALL pad characters will be " " and ALL pad characters
will be added by the pad flags. The string won't have trailing or
leading spaces (well, it is not supossed to...) Thanks :)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Truncate without padding
2005-10-31 15:35 ` Bart Schaefer
2005-10-31 17:21 ` DervishD
@ 2005-10-31 23:56 ` DervishD
1 sibling, 0 replies; 4+ messages in thread
From: DervishD @ 2005-10-31 23:56 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh Users
Hi Bart :)
* Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Oct 31, 12:27pm, DervishD wrote:
> }
> } I would like to print a string truncated *but* without padding
>
> Just truncate it first with padding, and then strip the padding.
>
> ${${(pl:WIDTH::::\0:)string}#*$'\0'}
> ${${(pr:WIDTH::::\0:)string}%$'\0'*}
I finally modified the shell function to do all string processing
first. After that, I just do "print $_rawmode -n -- $_string". So I
can do the printing in one step and the string processing in two (one
is the truncation+padding, the second is the optional padding
removal).
I'm afraid I was misreading your suggestion: both things were done
in just one step and I thought the first expansion was the truncation
and padding and the second the padding removal. Sorry for the noise
and thanks a lot, as always, for your kind help.
When I test the function I will probably post it here just in
case the code can be improved or anyone is interested in using it.
Thanks again :)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-10-31 23:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-31 11:27 Truncate without padding DervishD
2005-10-31 15:35 ` Bart Schaefer
2005-10-31 17:21 ` DervishD
2005-10-31 23:56 ` DervishD
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).