Permalink
Browse files
Make a note about ${s#prefix} ${s%suffix} and unicode.
- Loading branch information...
Showing
with
9 additions
and
3 deletions.
-
+8
−1
core/libstr.py
-
+1
−2
spec/var-op-strip.test.sh
|
|
@@ -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