truncating
This commit is contained in:
23
download.sh
23
download.sh
@ -170,9 +170,30 @@ get_items() {
|
||||
# Expecting a single line: ["<filename>","<download_url>"]
|
||||
JSON_PAIR_RE='^\["([^"]*)","([^"]*)"\]$'
|
||||
|
||||
#sanitize_filename() {
|
||||
# local in=$1
|
||||
# local truncated=${in:0:80}
|
||||
# # replace anything not alnum, underscore, dot or dash with underscore
|
||||
# printf '%s' "$truncated" | sed 's/[^A-Za-z0-9_.-]/_/g'
|
||||
#}
|
||||
|
||||
sanitize_filename() {
|
||||
local in=$1
|
||||
local truncated=${in:0:80}
|
||||
local truncated
|
||||
# find cutoff at first space after 80th character
|
||||
if (( ${#in} > 80 )); then
|
||||
local prefix=${in:0:80}
|
||||
local remainder=${in:80}
|
||||
if [[ $remainder == *' '* ]]; then
|
||||
local next_space_pos
|
||||
next_space_pos=$(expr index "$remainder" ' ')
|
||||
truncated="${prefix}${remainder:0:next_space_pos}"
|
||||
else
|
||||
truncated=$in
|
||||
fi
|
||||
else
|
||||
truncated=$in
|
||||
fi
|
||||
# replace anything not alnum, underscore, dot or dash with underscore
|
||||
printf '%s' "$truncated" | sed 's/[^A-Za-z0-9_.-]/_/g'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user