Timeline for Get the display width of a string of characters
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 23, 2020 at 18:20 | comment | added | Stéphane Chazelas |
@AdamKatz, on FreeBSD 12.1-RELEASE-p6 and in a UTF-8 locale, I get 0 for printf $'\xe2\x80\xa6' |wc -L and printf abc | wc -L (I suppose those don't contain any line), but I get 3 for both printf $'\xe2\x80\xa6\n' |wc -L and printf 'abc\n' | wc -L, so still the number of bytes in the (properly delimited) line with the most bytes.
|
|
| Dec 5, 2019 at 15:59 | comment | added | Adam Katz |
@StéphaneChazelas – I get 0 out of printf $'\xe2\x80\xa6' |wc -L on FreeBSD 11.2 vs 1 with GNU coreutils 8.30 on Debian Testing (11, Bullseye). That prints a horizontal ellipsis (U+2026 …) which is one character wide in a fixed-width font.
|
|
| Jun 24, 2019 at 20:51 | comment | added | Stéphane Chazelas | @G-Man, I was refering to the FreeBSD implementation, which in FreeBSD 12.0 and a UTF-8 locale still seems to be counting bytes. Note that é can be written using one U+00E9 character or a U+0065 (e) character followed by U+0301 (combining acute accent), the latter being the one showed in the question. | |
| Jun 24, 2019 at 20:41 | comment | added | G-Man Says 'Reinstate Monica' |
@StéphaneChazelas: Are you still having the issue that this returns the number of bytes rather than the number of characters? I tested it on your data and get the results you wanted: wc -L <<< 'unix' → 8, wc -L <<< 'Stéphane' → 8, and wc -L <<< 'もで 諤奯ゞ' → 11. P.S. You consider “Stéphane” to be nine characters, one of which is zero-width? It looks to me like eight characters, one of which is multi-byte.
|
|
| Apr 19, 2016 at 18:11 | comment | added | Stéphane Chazelas | Actually, for more-than-one-line strings, I would say it also does exactly what I'm looking for, as in it handles the LF control characters properly. | |
| Jan 29, 2016 at 16:22 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
typo sorry
|
| Jan 29, 2016 at 15:53 | comment | added | Stéphane Chazelas |
It seems to handle tab as well (assumes tab stops every 8 columns).
|
|
| Jan 29, 2016 at 15:49 | comment | added | Stéphane Chazelas | Thanks. I had no idea it would return the display width. Note that the FreeBSD implementation also has a -L option, the doc says it returns the number of characters in the longest line, but my test seems to indicate it's a number of bytes instead (not the display width in anycase). OS/X has no -L even though I'd have expected it to derive from FreeBSD's. | |
| Jan 29, 2016 at 15:47 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
--max-line-length is GNU only. FreeBSD also have a -L but docs says it returns number of characters, and my tests show number of bytes.
|
| Jan 29, 2016 at 14:48 | history | answered | egmont | CC BY-SA 3.0 |