R/create_extractor.R

Defines functions create_extractor

create_extractor <- function(x) {
  if (is.null(x)) return(function(x) TRUE)
  if (is.function(x)) return(x)
  if (is.character(x)) return(function(section) {
    if (x %in% c("APP", "SOF")) {
      (!is.null(section$section) && startsWith(section$section,x))
    } else {
      (!is.null(section$section) && section$section==x) ||
        (!is.null(section$id) && section$id==x)
    }
  })
  if (is.numeric(x)) return(function(section) {
    return (!is.null(section$marker) && section$marker == x)
  })
  stop(paste0("Unable to create extractor from object of class '",
              toString(class(x)),
              "'. Expecting integer, character, or function"))
}
MrFlick/readexif documentation built on Dec. 17, 2021, 4:22 a.m.