File: update_mime.R

package info (click to toggle)
r-cran-httpuv 1.6.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,292 kB
  • sloc: ansic: 6,499; cpp: 5,501; makefile: 103; sh: 56
file content (41 lines) | stat: -rw-r--r-- 830 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

library(rprojroot)

dest_file <- rprojroot::find_package_root_file("src", "mime.cpp")

mime_map_text <- mapply(
  function(ext, mime_type) {
    sprintf('  {"%s", "%s"}', ext, mime_type);
  },
  names(mime::mimemap),
  mime::mimemap,
  SIMPLIFY = TRUE,
  USE.NAMES = FALSE
)
mime_map_text <- paste(mime_map_text, collapse = ",\n")


output <- glue(.open = "[", .close = "]", '
// Do not edit.
// Generated by ../tools/update_mime.R using R package mime [packageVersion("mime")]

#include <map>
#include <string>

const std::map<std::string, std::string> mime_map = {
[mime_map_text]
};

std::string find_mime_type(const std::string& ext) {
  std::map<std::string, std::string>::const_iterator it = mime_map.find(ext);
  if (it == mime_map.end()) {
    return "";
  }
  
  return it->second;
}

'
)

cat(output, file = dest_file)