Add utils MustGetFileAsString and GetNumberOfLeftSpaces.
This commit is contained in:
@@ -2,9 +2,11 @@ package editorconfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var filePathSeparatorRegex = regexp.QuoteMeta(string(filepath.Separator))
|
||||
@@ -54,3 +56,16 @@ func GetErrorWithLineBreaksVisible(s string) string {
|
||||
s = crlfRegexp.ReplaceAllString(s, `\r\n`)
|
||||
return s
|
||||
}
|
||||
|
||||
func MustGetFileAsString(path string) string {
|
||||
inBytes, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
ExitBecauseOfInternalError("Could not read file: " + path)
|
||||
}
|
||||
|
||||
return string(inBytes)
|
||||
}
|
||||
|
||||
func GetNumberOfLeftSpaces(s string) int {
|
||||
return len(s) - len(strings.TrimLeft(s, " "))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user