stripCmdSubst removes $(...) command substitutions (including nested ones) from s, leaving the surrounding text intact. Backtick substitutions are already handled upstream (a command never spans a backtick).
(s string)
| 165 | // from s, leaving the surrounding text intact. Backtick substitutions are |
| 166 | // already handled upstream (a command never spans a backtick). |
| 167 | func stripCmdSubst(s string) string { |
| 168 | var b strings.Builder |
| 169 | depth := 0 |
| 170 | for i := 0; i < len(s); i++ { |
| 171 | if depth == 0 && i+1 < len(s) && s[i] == '$' && s[i+1] == '(' { |
| 172 | depth = 1 |
| 173 | i++ // skip '(' |
| 174 | continue |
| 175 | } |
| 176 | if depth > 0 { |
| 177 | switch s[i] { |
| 178 | case '(': |
| 179 | depth++ |
| 180 | case ')': |
| 181 | depth-- |
| 182 | } |
| 183 | continue |
| 184 | } |
| 185 | b.WriteByte(s[i]) |
| 186 | } |
| 187 | return b.String() |
| 188 | } |
| 189 | |
| 190 | // isPlaceholderOrProse reports whether a command word is a doc placeholder |
| 191 | // (<resource>, [flags], {a|b}, +<verb>, ...) or narration (CJK / other |