Add ingo#str#trcd() variant of ingo#str#trd()

This commit is contained in:
Ingo Karkat
2020-03-01 13:03:51 +01:00
parent 99b59c8db4
commit 9abc06ae08
3 changed files with 22 additions and 1 deletions
+1
View File
@@ -159,6 +159,7 @@ HISTORY
- Add optional a:Predicate argument to ingo#area#frompattern#Get() and
ingo#text#frompattern#Get(). Additionally, the a:isOnlyFirstMatch and
a:isUnique arguments are optional now, too.
- Add ingo#str#trcd() variant of ingo#str#trd().
##### 1.040 31-Oct-2019
- Add ingo#str#TrimTrailing() variant of ingo#str#Trim().
+20 -1
View File
@@ -5,7 +5,7 @@
" - ingo/regexp/virtcols.vim autoload script
" - ingo/str/list.vim autoload script
"
" Copyright: (C) 2013-2019 Ingo Karkat
" Copyright: (C) 2013-2020 Ingo Karkat
" The VIM LICENSE applies to this script; see ':help copyright'.
"
" Maintainer: Ingo Karkat <ingo@karkat.de>
@@ -141,6 +141,25 @@ function! ingo#str#trd( src, fromstr )
return substitute(a:src, '\C' . ingo#regexp#collection#LiteralToRegexp(a:fromstr), '', 'g')
endfunction
function! ingo#str#trcd( src, fromstr )
"******************************************************************************
"* PURPOSE:
" Keep only characters in a:fromstr in a copy of a:src. Like tr -cd, but the
" built-in tr() doesn't support this.
"* ASSUMPTIONS / PRECONDITIONS:
" None.
"* EFFECTS / POSTCONDITIONS:
" None.
"* INPUTS:
" a:src Source string.
" a:fromstr Characters that will each be kept in a:src.
"* RETURN VALUES:
" Copy of a:src that has all instances of the complement of the characters in
" a:fromstr removed.
"******************************************************************************
return substitute(a:src, '\C[^' . ingo#regexp#collection#LiteralToRegexp(a:fromstr)[1:], '', 'g')
endfunction
function! ingo#str#Wrap( string, commonOrPrefix, ... ) abort
"******************************************************************************
"* PURPOSE:
+1
View File
@@ -174,6 +174,7 @@ HISTORY *ingo-library-history*
- Add optional a:Predicate argument to ingo#area#frompattern#Get() and
ingo#text#frompattern#Get(). Additionally, the a:isOnlyFirstMatch and
a:isUnique arguments are optional now, too.
- Add ingo#str#trcd() variant of ingo#str#trd().
1.040 31-Oct-2019
- Add ingo#str#TrimTrailing() variant of ingo#str#Trim().