// If in == nil, the source is the contents of the file with the given filename.
320867
func processFile(filename string, in io.Reader, out io.Writer, stdin bool, opts Options) error {
	if in == nil {
		f, err := os.Open(filename)
		if err != nil {
			return err
		}
		defer f.Close()
		in = f
	}

	src, err := ioutil.ReadAll(in)
	if err != nil {
		return err
	}

	res, err := printer.Format(src)
	if err != nil {
		return fmt.Errorf("In %s: %s", filename, err)
	}

	if !bytes.Equal(src, res) {
		// formatting has changed
		if opts.List {
			fmt.Fprintln(out, filename)
		}
		if opts.Write {
			err = ioutil.WriteFile(filename, res, 0644)
			if err != nil {
				return err
			}
		}
		if opts.Diff {
			data, err := diff(src, res)
			if err != nil {
				return fmt.Errorf("computing diff: %s", err)
			}
			fmt.Fprintf(out, "diff a/%s b/%s\n", filename, filename)
			out.Write(data)
		}
	}

	if !opts.List && !opts.Write && !opts.Diff {
		_, err = out.Write(res)
	}

	return err
}
687853
func (s SourceFilesystems) IsI18n(filename string) bool {
	return s.I18n.Contains(filename)
}
623644
func (f *File) Lookup(name string) (*File, error) {
	var bino uint32
	bname := []byte(name)
	err := f.walkDir(func(name []byte, ino uint32) bool {
		if bytes.Equal(bname, name) {
			bino = ino
			return false
		}
		return true
	})
	if err != nil {
		return nil, err
	}
	if bino == 0 {
		return nil, fmt.Errorf("file not found")
	}
	return f.fs.File(bino)
}
1089709
func (r *Response) FileName() string {
	_, params, err := mime.ParseMediaType(r.Headers.Get("Content-Disposition"))
	if fName, ok := params["filename"]; ok && err == nil {
		return SanitizeFileName(fName)
	}
	if r.Request.URL.RawQuery != "" {
		return SanitizeFileName(fmt.Sprintf("%s_%s", r.Request.URL.Path, r.Request.URL.RawQuery))
	}
	return SanitizeFileName(strings.TrimPrefix(r.Request.URL.Path, "/"))
}
322546
func (u Uint16) If(fn func(uint16)) {
	if u.Present() {
		fn(*u.value)
	}
}
915660
func (f *file) lintIncDec() {
	f.walk(func(n ast.Node) bool {
		as, ok := n.(*ast.AssignStmt)
		if !ok {
			return true
		}
		if len(as.Lhs) != 1 {
			return true
		}
		if !isOne(as.Rhs[0]) {
			return true
		}
		var suffix string
		switch as.Tok {
		case token.ADD_ASSIGN:
			suffix = "++"
		case token.SUB_ASSIGN:
			suffix = "--"
		default:
			return true
		}
		f.errorf(as, 0.8, category("unary-op"), "should replace %s with %s%s", f.render(as), f.render(as.Lhs[0]), suffix)
		return true
	})
}
662213
func (s SourceFilesystems) IsData(filename string) bool {
	return s.Data.Contains(filename)
}
21678
func (fn *RandomFunction) Source() (interface{}, error) {
	source := make(map[string]interface{})
	if fn.field != "" {
		source["field"] = fn.field
	}
	if fn.seed != nil {
		source["seed"] = fn.seed
	}
	// Notice that the weight has to be serialized in FunctionScoreQuery.
	return source, nil
}
808554
func Load(filename string) (*ClosestMatch, error) {
	cm := new(ClosestMatch)

	f, err := os.Open(filename)
	defer f.Close()
	if err != nil {
		return cm, err
	}

	w, err := gzip.NewReader(f)
	if err != nil {
		return cm, err
	}

	err = json.NewDecoder(w).Decode(&cm)
	return cm, err
}
138624
func parseFile(fname string, source io.Reader) (ast.Node, error) {
	f, err := parser.ParseFile(token.NewFileSet(), fname, source, parser.DeclarationErrors)
	if err != nil {
		return nil, err
	}
	return f, nil
}
25147
func strPtrIsNilOrContentIsEqual(l, r *string) bool {
	if l == nil && r != nil {
		return false
	}
	if l != nil && r == nil {
		return false
	}
	if l == nil && r == nil {
		return true
	}
	return *l == *r
}
1316544
func (loc *Location) Filename() string {
	nmr := loc.Namer()
	if loc.filename == "" && nmr == nil {
		log.Fatal("[F] No filename or namer set")
	}

	if loc.filename == "" {
		loc.filename = nmr.String()

		if !loc.opts.compress {
			newName := reGzip.ReplaceAllString(loc.filename, "")
			loc.filename = newName
		}
	}
	return loc.filename
}
1317112
func ParseFile(filename string) (string, error) {
	bs, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", err
	}
	return Parse(filepath.Base(filename), bs)
}
1049928
func (po *Po) ParseFile(f string) {
	// Check if file exists
	info, err := os.Stat(f)
	if err != nil {
		return
	}

	// Check that isn't a directory
	if info.IsDir() {
		return
	}

	// Parse file content
	data, err := ioutil.ReadFile(f)
	if err != nil {
		return
	}

	po.Parse(data)
}
814756
func FnOr(name string, input interface{}, template interface{}) interface{} {
	// "Fn::Or": [{condition}, ...]

	// Check the input is an array
	if arr, ok := input.([]interface{}); ok {
		if len(arr) < 2 || len(arr) > 10 {
			return nil
		}

		for _, c := range arr {
			if value, ok := retrieveCondition(c, template); ok {
				if value {
					return true
				}
			} else {
				return nil
			}
		}

		return false
	}

	return nil
}
769532
func (d *SourceFilesystem) Contains(filename string) bool {
	for _, dir := range d.Dirnames {
		if strings.HasPrefix(filename, dir) {
			return true
		}
	}
	return false
}
1064216
func readSource(filename string, src interface{}) ([]byte, error) {
	if src == nil {
		return ioutil.ReadFile(filename)
	}
	switch s := src.(type) {
	case string:
		return []byte(s), nil
	}
	return nil, errors.New("invalid source type")
}