code: def apply_replacements(cfile, replacements):
      
      if not replacements:
          return cfile
  
      for rep in replacements:
          if not rep.get('with_extension', False):
              # By default, preserve extension
              cfile, cext = os.path.splitext(cfile)
          else:
              cfile = cfile
              cext = ''
  
          if 'is_regex' in rep and rep['is_regex']:
              cfile = re.sub(rep['match'], rep['replacement'], cfile)
          else:
              cfile = cfile.replace(rep['match'], rep['replacement'])
  
          # Rejoin extension (cext might be empty-string)
          cfile = cfile + cext
  
      return cfile
docs: Applies custom replacements.
  
      mapping(dict), where each dict contains:
          'match' - filename match pattern to check against, the filename
          replacement is applied.
  
          'replacement' - string used to replace the matched part of the filename
  
          'is_regex' - if True, the pattern is treated as a
          regex. If False, simple substring check is used (if
          'match' in filename). Default is False
  
          'with_extension' - if True, the file extension is not included in the
          pattern matching. Default is False
  
      Example replacements::
  
          {'match': ':',
           'replacement': '-',
           'is_regex': False,
           'with_extension': False,
           }
  
      :param str cfile: name of a file
      :param list replacements: mapping(dict) filename pattern matching
                                directives
      :returns: formatted filename
      :rtype: str