Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • v1.6.3
  • v1.6.2
  • v1.6.1
  • v1.6.0
  • v1.5.0
  • v1.4.1
  • v1.4.0
  • v1.3.9
  • v1.3.8
  • v1.3.7
  • v1.3.6
  • v1.3.5
  • v1.3.4
  • v1.3.3
  • v1.3.2
  • v1.3.1
  • v1.3.0
  • v1.2.23
  • v1.2.22
  • v1.2.21
21 results

globals.go

globals.go 834 B
package file

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"path/filepath"
)

//var regAllDashes = regexp.MustCompile("^[-]+$")

func newBlankFile() *File {
	return &File{
		multiComments: map[int]*MultiLineComment{},
		commentLines:  map[int]string{},
	}
}

func FromReader(rd io.Reader, s score) (f *File) {
	f = newBlankFile()
	f.Score = s
	f.Input = bufio.NewScanner(rd)
	return f
}

func New(fpath string, s score) (f *File, err error) {
	fpath, err = filepath.Abs(fpath)
	if err != nil {
		return nil, err
	}

	fi, err := os.Stat(fpath)
	if err != nil {
		return nil, err
	}

	if fi.IsDir() {
		return nil, fmt.Errorf("%q is a directory", fpath)
	}

	file, err := os.Open(fpath)
	if err != nil {
		return nil, err
	}

	f = FromReader(file, s)
	f.file = file
	f.dir = filepath.Dir(fpath)
	f.name = filepath.Base(fpath)
	return f, nil
}