     for pair in @_languageDetectionCache
       return pair[1] if baseName.match pair[0]
 
-  # Map a list of file paths to relative target paths by stripping prefixes off of them.
+  # Map a list of file paths to relative target paths by stripping prefixes.
   mapFiles: (resolveRoot, files, stripPrefixes) ->
-    # Ensure that we're dealing with absolute paths across the board
+    # Ensure that we're dealing with absolute paths across the board.
     files = files.map (f) -> path.resolve resolveRoot, f
-    # And that the strip prefixes all end with a /, to avoid a target path being absolute.
-    stripPrefixes = stripPrefixes.map (p) -> path.join( "#{path.resolve resolveRoot, p}#{CompatibilityHelpers.pathSep}" )
-
-    # Prefixes are stripped in order of most specific to least (# of directories deep)
+
+    # And that the strip prefixes all end with a /, avoids absolute target path.
+    stripPrefixes = stripPrefixes.map (p) ->
+      path.join "#{path.resolve resolveRoot, p}#{CompatibilityHelpers.pathSep}"
+
+    # Prefixes are stripped in the order of most specific to least
+    # (# of directories deep)
     prefixes = stripPrefixes.sort (a,b) => @pathDepth(b) - @pathDepth(a)
 
     result = {}


      result.push arg if arg.slice(-1) == CompatibilityHelpers.pathSep

    # For now, we try to avoid ambiguous situations by guessing the FIRST directory given.  The
    # assumption is that you don't want merged paths, but probably did specify the most important
    # source directory first.
    result = _(result).uniq()[...1]

  # How many directories deep is a given path?



module.exports = Utils =

  # Code from <http://zetafleet.com/>
  # via <http://blog.simonwillison.net/post/57956816139/escape>
  regexpEscapePattern : /[-[\]{}()*+?.,\\^$|#\s]/g
  regexpEscapeReplace : '\\$&'

  # Escape regular expression characters in a String, an Array of Strings or
  # any Object having a proper toString-method
  regexpEscape: (obj) ->
    if _.isArray obj
      _.invoke(obj, 'replace', @regexpEscapePattern, @regexpEscapeReplace)
    else if _.isString obj
      obj.replace(@regexpEscapePattern, @regexpEscapeReplace)
    else
      @regexpEscape "#{obj}"

  # Detect and return the language that a given file is written in.
  #
  # The language is also annotated with a name property, matching the language's
  # key in LANGUAGES.
  getLanguage: (filePath, languageDefinitions = './languages') ->
    unless @_languageDetectionCache?
      @_languageDetectionCache = []
