-
Notifications
You must be signed in to change notification settings - Fork 237
Closed
Labels
featurea feature request or enhancementa feature request or enhancement
Description
library(gsubfn)
library(functional)
##' Substitutions of questionable characters with a hacker-joke to
##' boot.
substitutions=c(
`!`='bang',
`"`='quote',
`#`='hash',
`$`='cash', # sigil
`%`='grapes',
`&`='and',
`'`='single-quote',
`(`='open-paren',
`)`='close-paren',
`*`='star',
`+`='plus',
`,`='comma',
`-`='dash',
`.`='dot',
`/`='slash',
`:`='colon',
`;`='semi-colon',
`<`='less-than',
`=`='equals',
`>`='greater-than',
`?`='p',
`@`='asperand',
`[`='open-brace',
`\\`='backslash',
`]`='close-brace',
`^`='hat',
`_`='sub',
'`'='backtick', # let's add another ` to
# rectify syntax highlighting
# in emacs; thanks.
`{`='open-curly',
`|`='pipe',
`}`='close',
`~`='not'
)
##' \code{NULL} if empty-string.
##' @param string string to check
##' @return \code{NULL} or identity
nil_if_lambda <- function(string)
if (nchar(string)) string else NULL
##' Translate file-system-questionable characters (i.e. punctuation
##' within ASCII).
##' @param filename the filename to translate
##' @return the translated filename
translate_questionable_characters <- function(filename)
do.call(Curry(paste, collapse="-"),
strapply(filename,
pattern='([[:punct:]]|)([^[:punct:]]*|)',
function(punctuation, letters)
c(substitutions[nil_if_lambda(punctuation)],
nil_if_lambda(letters))))
translate_questionable_characters('%||%')
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancement