unidecode module: change the default to: embed resource file into the application; fixes #8767

This commit is contained in:
Araq 2018-08-30 15:39:47 +02:00
commit 8e33667262

View file

@ -22,14 +22,14 @@
## strictly one-way transformation. However a human reader will probably ## strictly one-way transformation. However a human reader will probably
## still be able to guess what original string was meant from the context. ## still be able to guess what original string was meant from the context.
## ##
## This module needs the data file "unidecode.dat" to work: You can either ## This module needs the data file "unidecode.dat" to work: This file is
## ship this file with your application and initialize this module with the ## embedded as a resource into your application by default. But you an also
## `loadUnidecodeTable` proc or you can define the ``embedUnidecodeTable`` ## define the symbol ``--define:noUnidecodeTable`` during compile time and
## symbol to embed the file as a resource into your application. ## use the `loadUnidecodeTable` proc to initialize this module.
import unicode import unicode
when defined(embedUnidecodeTable): when not defined(noUnidecodeTable):
import strutils import strutils
const translationTable = splitLines(slurp"unidecode/unidecode.dat") const translationTable = splitLines(slurp"unidecode/unidecode.dat")
@ -38,11 +38,11 @@ else:
var translationTable: seq[string] var translationTable: seq[string]
proc loadUnidecodeTable*(datafile = "unidecode.dat") = proc loadUnidecodeTable*(datafile = "unidecode.dat") =
## loads the datafile that `unidecode` to work. Unless this module is ## loads the datafile that `unidecode` to work. This is only required if
## compiled with the ``embedUnidecodeTable`` symbol defined, this needs ## the module was compiled with the ``--define:noUnidecodeTable`` switch.
## to be called by the main thread before any thread can make a call ## This needs to be called by the main thread before any thread can make a
## to `unidecode`. ## call to `unidecode`.
when not defined(embedUnidecodeTable): when defined(noUnidecodeTable):
newSeq(translationTable, 0xffff) newSeq(translationTable, 0xffff)
var i = 0 var i = 0
for line in lines(datafile): for line in lines(datafile):