Automate whitespace removal

The downloaded Unicode files contain trailing whitespace. This will now be removed immediately after downloading the files.
This commit is contained in:
utelle 2023-04-19 15:41:25 +02:00
parent 79cd7d034e
commit 7465f72544
No known key found for this signature in database
GPG key ID: 0B721BF7BBC62016
4 changed files with 39 additions and 2 deletions

View file

@ -12,3 +12,6 @@ bitsadmin /transfer wxDownloadJob /download /priority normal https://www.unicode
rem Download ISO 3166 (list of territories)
bitsadmin /transfer wxDownloadJob /download /priority normal https://github.com/unicode-org/cldr/raw/main/tools/cldr-code/src/main/resources/org/unicode/cldr/util/data/territory_codes.txt %workdir%\unicode\territory_codes.txt
luashell removewhitespace.lua unicode/iso15924.txt
luashell removewhitespace.lua unicode/territory_codes.txt

View file

@ -0,0 +1,35 @@
-- Assign script arguments and check validity
fileName = arg[1]
assert(fileName ~= nil, "Filename parameter missing!")
fileNameTemp = fileName .. ".tmp"
function trim(s)
return s:match'^%s*(.*%S)' or ''
end
-- Remove whitespace from file
lastline = nil
prevlen = 0
fo2 = io.open(fileNameTemp,'wb')
for line in io.lines(fileName) do
newline = trim(line)
if lastline ~= nil then
lastlen = string.len(lastline)
if lastlen ~= 0 then
fo2:write(lastline .. "\n")
elseif prevlen ~=0 and lastlen == 0 then
fo2:write("\n")
end
prevlen = lastlen
end
lastline = newline
end
if string.len(lastline) > 0 then
fo2:write(lastline .. "\n")
end
fo2:close()
-- Remove original and replace it by the file with whitespace removed
os.remove(fileName)
os.rename(fileNameTemp, fileName)

View file

@ -1,7 +1,7 @@
#
# ISO 15924 - Codes for the representation of names of scripts
# Codes pour la représentation des noms décritures
# Format:
# Format:
# Code;N°;English Name;Nom français;PVA;Unicode Version;Date
#

View file

@ -328,4 +328,3 @@ IC - - - - # Canary Islands
UN - UNO - - # United Nations
#end