Permalink
Browse files

Make a note about ${s#prefix} ${s%suffix} and unicode.

  • Loading branch information...
Andy Chu
Andy Chu committed Aug 25, 2018
1 parent 2c205f0 commit 7a1947fa24a10718b2b34c260013a4a21ed3f1bb
Showing with 9 additions and 3 deletions.
  1. +8 −1 core/libstr.py
  2. +1 −2 spec/var-op-strip.test.sh
View
@@ -191,13 +191,20 @@ def DoUnarySuffixOp(s, op, arg):
# For patterns, do fnmatch() in a loop.
#
# TODO: Check another fast path first?
# TODO: The loop needs to iterate over code points, not bytes!
# - The forward case can probably be handled in a similar manner.
# - The backward case might be handled by pre-calculating an array of start
# positions with _NextUtf8Char.
#
# TODO: Another potential fast path:
#
# v=aabbccdd
# echo ${v#*b} # strip shortest prefix
#
# If the whole thing doesn't match '*b*', then no test can succeed. So we
# can fail early. Conversely echo ${v%%c*} and '*c*'.
#
# (Although honestly this whole construct is nuts and should be deprecated.)
n = len(s)
if op.op_id == Id.VOp1_Pound: # shortest prefix
@@ -60,8 +60,7 @@ echo ${v%[[:alpha:]]}
## N-I mksh stdout: abc
#### Strip unicode prefix
# NOTE: LANG is set to utf-8. Problem: there is no way to represent the
# invalid character! Instead of stdout-json, how about stdout-bytes?
# NOTE: LANG is set to utf-8.
v='μ-'
echo ${v#?} # ? is a glob that stands for one character
## stdout: -

0 comments on commit 7a1947f

Please sign in to comment.