diff options
author | Bung <crc32@qq.com> | 2021-06-07 19:57:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 13:57:42 +0200 |
commit | 429b1286325e7b6cf86ed4e29cea3e11a8c0e2df (patch) | |
tree | 9f172ae3507d1dbc204b583c038d6e2ce7f3d7db | |
parent | 2ec52faae5ba5c233f977a8a4b997734c4ad83e7 (diff) | |
download | Nim-429b1286325e7b6cf86ed4e29cea3e11a8c0e2df.tar.gz |
change mimedb stroe stringtable to orderedtable (#18065)
* change mimedb stroe stringtable to orderedtable * Update lib/pure/mimetypes.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r-- | lib/pure/mimetypes.nim | 7 | ||||
-rw-r--r-- | tests/stdlib/tmimetypes.nim | 1 |
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/pure/mimetypes.nim b/lib/pure/mimetypes.nim index c10739fec..6ae63a0ae 100644 --- a/lib/pure/mimetypes.nim +++ b/lib/pure/mimetypes.nim @@ -26,12 +26,12 @@ runnableExamples: doAssert m.getMimetype("fakext") == "text/fakelang" doAssert m.getMimetype("FaKeXT") == "text/fakelang" -import strtabs +import tables from strutils import startsWith, toLowerAscii, strip type MimeDB* = object - mimes: StringTableRef + mimes: OrderedTableRef[string, string] const mimes* = { "123": "application/vnd.lotus-1-2-3", @@ -1903,7 +1903,8 @@ const mimes* = { func newMimetypes*(): MimeDB = ## Creates a new Mimetypes database. The database will contain the most ## common mimetypes. - result.mimes = mimes.newStringTable() + {.cast(noSideEffect).}: + result.mimes = mimes.newOrderedTable() func getMimetype*(mimedb: MimeDB, ext: string, default = "text/plain"): string = ## Gets mimetype which corresponds to `ext`. Returns `default` if `ext` diff --git a/tests/stdlib/tmimetypes.nim b/tests/stdlib/tmimetypes.nim index cd41e614b..93c20d4a3 100644 --- a/tests/stdlib/tmimetypes.nim +++ b/tests/stdlib/tmimetypes.nim @@ -6,6 +6,7 @@ import std/mimetypes template main() = var m = newMimetypes() doAssert m.getMimetype("mp4") == "video/mp4" + doAssert m.getExt("application/json") == "json" # see also `runnableExamples`. # xxx we should have a way to avoid duplicating code between runnableExamples and tests |