・・・・
type iScanner interface {
Err() error
Scan() bool
Text() string
}
func ifuncNewScanner(r io.Reader) iScanner {
return bufio.NewScanner(r)
}
type hookBufio struct {
NewScanner func(r io.Reader) iScanner
}
type iFile interface {
Close() error
WriteString(s string) (n int, err error)
Read(p []byte) (n int, err error)
}
func ifuncOpen(name string) (iFile, error) {
return os.Open(name)
}
func ifuncCreate(name string) (iFile, error) {
return os.Create(name)
}
type hookOs struct {
Open func(name string) (iFile, error)
Create func(name string) (iFile, error)
}
type hook struct {
bufio *hookBufio
os *hookOs
}
// textLines はテキストを格納します。
// [TODO] 文字エンコーディング関係機能
type textLines struct {
// 文字列スライス
lines []string
// フック
hook *hook
}
・・・・
func (t *textLines) LoadFrom(filename string) error {
f, err := t.hook.os.Open(filename)
if err != nil {
return fmt.Errorf("os.Open(%s) return %v", filename, err)
}
defer f.Close()
s := t.hook.bufio.NewScanner(f)
for s.Scan() {
t.lines = append(t.lines, s.Text())
}
err = s.Err()
if err != nil {
return fmt.Errorf("scanner.Scan(%s) return %v", filename, err)
}
return err
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}