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>
This commit is contained in:
parent
2ec52faae5
commit
429b128632
2 changed files with 5 additions and 3 deletions
|
|
@ -26,12 +26,12 @@ runnableExamples:
|
||||||
doAssert m.getMimetype("fakext") == "text/fakelang"
|
doAssert m.getMimetype("fakext") == "text/fakelang"
|
||||||
doAssert m.getMimetype("FaKeXT") == "text/fakelang"
|
doAssert m.getMimetype("FaKeXT") == "text/fakelang"
|
||||||
|
|
||||||
import strtabs
|
import tables
|
||||||
from strutils import startsWith, toLowerAscii, strip
|
from strutils import startsWith, toLowerAscii, strip
|
||||||
|
|
||||||
type
|
type
|
||||||
MimeDB* = object
|
MimeDB* = object
|
||||||
mimes: StringTableRef
|
mimes: OrderedTableRef[string, string]
|
||||||
|
|
||||||
const mimes* = {
|
const mimes* = {
|
||||||
"123": "application/vnd.lotus-1-2-3",
|
"123": "application/vnd.lotus-1-2-3",
|
||||||
|
|
@ -1903,7 +1903,8 @@ const mimes* = {
|
||||||
func newMimetypes*(): MimeDB =
|
func newMimetypes*(): MimeDB =
|
||||||
## Creates a new Mimetypes database. The database will contain the most
|
## Creates a new Mimetypes database. The database will contain the most
|
||||||
## common mimetypes.
|
## common mimetypes.
|
||||||
result.mimes = mimes.newStringTable()
|
{.cast(noSideEffect).}:
|
||||||
|
result.mimes = mimes.newOrderedTable()
|
||||||
|
|
||||||
func getMimetype*(mimedb: MimeDB, ext: string, default = "text/plain"): string =
|
func getMimetype*(mimedb: MimeDB, ext: string, default = "text/plain"): string =
|
||||||
## Gets mimetype which corresponds to `ext`. Returns `default` if `ext`
|
## Gets mimetype which corresponds to `ext`. Returns `default` if `ext`
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import std/mimetypes
|
||||||
template main() =
|
template main() =
|
||||||
var m = newMimetypes()
|
var m = newMimetypes()
|
||||||
doAssert m.getMimetype("mp4") == "video/mp4"
|
doAssert m.getMimetype("mp4") == "video/mp4"
|
||||||
|
doAssert m.getExt("application/json") == "json"
|
||||||
# see also `runnableExamples`.
|
# see also `runnableExamples`.
|
||||||
# xxx we should have a way to avoid duplicating code between runnableExamples and tests
|
# xxx we should have a way to avoid duplicating code between runnableExamples and tests
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue