id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
138,800
beego/mux
params.go
Params
func Params(r *http.Request) map[string]string { v := r.Context().Value(routeParamsID) if v == nil { return map[string]string{} } if v, ok := v.(map[string]string); ok { return v } return map[string]string{} }
go
func Params(r *http.Request) map[string]string { v := r.Context().Value(routeParamsID) if v == nil { return map[string]string{} } if v, ok := v.(map[string]string); ok { return v } return map[string]string{} }
[ "func", "Params", "(", "r", "*", "http", ".", "Request", ")", "map", "[", "string", "]", "string", "{", "v", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "routeParamsID", ")", "\n", "if", "v", "==", "nil", "{", "return", "map", "[", ...
// Params return the router params
[ "Params", "return", "the", "router", "params" ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/params.go#L15-L24
138,801
beego/mux
params.go
Param
func Param(r *http.Request, key string) string { p := Params(r) if v, ok := p[key]; ok { return v } return "" }
go
func Param(r *http.Request, key string) string { p := Params(r) if v, ok := p[key]; ok { return v } return "" }
[ "func", "Param", "(", "r", "*", "http", ".", "Request", ",", "key", "string", ")", "string", "{", "p", ":=", "Params", "(", "r", ")", "\n", "if", "v", ",", "ok", ":=", "p", "[", "key", "]", ";", "ok", "{", "return", "v", "\n", "}", "\n", "r...
// Param return the router param based on the key
[ "Param", "return", "the", "router", "param", "based", "on", "the", "key" ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/params.go#L27-L33
138,802
beego/mux
mux.go
Get
func (m *Mux) Get(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodGet, pattern, handler) }
go
func (m *Mux) Get(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodGet, pattern, handler) }
[ "func", "(", "m", "*", "Mux", ")", "Get", "(", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "m", ".", "Handle", "(", "http", ".", "MethodGet", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Get registers a new GET route for a path with matching handler in the Mux.
[ "Get", "registers", "a", "new", "GET", "route", "for", "a", "path", "with", "matching", "handler", "in", "the", "Mux", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L23-L25
138,803
beego/mux
mux.go
Head
func (m *Mux) Head(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodHead, pattern, handler) }
go
func (m *Mux) Head(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodHead, pattern, handler) }
[ "func", "(", "m", "*", "Mux", ")", "Head", "(", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "m", ".", "Handle", "(", "http", ".", "MethodHead", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Head registers a new HEAD route for a path with matching handler in the Mux.
[ "Head", "registers", "a", "new", "HEAD", "route", "for", "a", "path", "with", "matching", "handler", "in", "the", "Mux", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L28-L30
138,804
beego/mux
mux.go
Post
func (m *Mux) Post(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodPost, pattern, handler) }
go
func (m *Mux) Post(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodPost, pattern, handler) }
[ "func", "(", "m", "*", "Mux", ")", "Post", "(", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "m", ".", "Handle", "(", "http", ".", "MethodPost", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Post registers a new POST route for a path with matching handler in the Mux.
[ "Post", "registers", "a", "new", "POST", "route", "for", "a", "path", "with", "matching", "handler", "in", "the", "Mux", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L33-L35
138,805
beego/mux
mux.go
Put
func (m *Mux) Put(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodPut, pattern, handler) }
go
func (m *Mux) Put(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodPut, pattern, handler) }
[ "func", "(", "m", "*", "Mux", ")", "Put", "(", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "m", ".", "Handle", "(", "http", ".", "MethodPut", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Put registers a new PUT route for a path with matching handler in the Mux.
[ "Put", "registers", "a", "new", "PUT", "route", "for", "a", "path", "with", "matching", "handler", "in", "the", "Mux", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L38-L40
138,806
beego/mux
mux.go
Patch
func (m *Mux) Patch(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodPatch, pattern, handler) }
go
func (m *Mux) Patch(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodPatch, pattern, handler) }
[ "func", "(", "m", "*", "Mux", ")", "Patch", "(", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "m", ".", "Handle", "(", "http", ".", "MethodPatch", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Patch registers a new PATCH route for a path with matching handler in the Mux.
[ "Patch", "registers", "a", "new", "PATCH", "route", "for", "a", "path", "with", "matching", "handler", "in", "the", "Mux", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L43-L45
138,807
beego/mux
mux.go
Delete
func (m *Mux) Delete(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodDelete, pattern, handler) }
go
func (m *Mux) Delete(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodDelete, pattern, handler) }
[ "func", "(", "m", "*", "Mux", ")", "Delete", "(", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "m", ".", "Handle", "(", "http", ".", "MethodDelete", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Delete registers a new DELETE route for a path with matching handler in the Mux.
[ "Delete", "registers", "a", "new", "DELETE", "route", "for", "a", "path", "with", "matching", "handler", "in", "the", "Mux", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L48-L50
138,808
beego/mux
mux.go
Options
func (m *Mux) Options(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodOptions, pattern, handler) }
go
func (m *Mux) Options(pattern string, handler http.HandlerFunc) { m.Handle(http.MethodOptions, pattern, handler) }
[ "func", "(", "m", "*", "Mux", ")", "Options", "(", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "m", ".", "Handle", "(", "http", ".", "MethodOptions", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Options registers a new OPTIONS route for a path with matching handler in the Mux.
[ "Options", "registers", "a", "new", "OPTIONS", "route", "for", "a", "path", "with", "matching", "handler", "in", "the", "Mux", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L53-L55
138,809
beego/mux
mux.go
Handle
func (m *Mux) Handle(method, pattern string, handler http.HandlerFunc) { if method == "" { panic(fmt.Errorf("invalid method")) } m.trie.Parse(pattern).Handle(strings.ToUpper(method), handler) }
go
func (m *Mux) Handle(method, pattern string, handler http.HandlerFunc) { if method == "" { panic(fmt.Errorf("invalid method")) } m.trie.Parse(pattern).Handle(strings.ToUpper(method), handler) }
[ "func", "(", "m", "*", "Mux", ")", "Handle", "(", "method", ",", "pattern", "string", ",", "handler", "http", ".", "HandlerFunc", ")", "{", "if", "method", "==", "\"", "\"", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n"...
// Handle registers a new handler with method and path in the Mux. // For GET, POST, PUT, PATCH and DELETE requests the respective shortcut // functions can be used.
[ "Handle", "registers", "a", "new", "handler", "with", "method", "and", "path", "in", "the", "Mux", ".", "For", "GET", "POST", "PUT", "PATCH", "and", "DELETE", "requests", "the", "respective", "shortcut", "functions", "can", "be", "used", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L66-L71
138,810
beego/mux
mux.go
Handler
func (m *Mux) Handler(method, path string, handler http.Handler) { m.Handle(method, path, func(w http.ResponseWriter, req *http.Request) { handler.ServeHTTP(w, req) }) }
go
func (m *Mux) Handler(method, path string, handler http.Handler) { m.Handle(method, path, func(w http.ResponseWriter, req *http.Request) { handler.ServeHTTP(w, req) }) }
[ "func", "(", "m", "*", "Mux", ")", "Handler", "(", "method", ",", "path", "string", ",", "handler", "http", ".", "Handler", ")", "{", "m", ".", "Handle", "(", "method", ",", "path", ",", "func", "(", "w", "http", ".", "ResponseWriter", ",", "req", ...
// Handler is an adapter which allows the usage of an http.Handler as a // request handle.
[ "Handler", "is", "an", "adapter", "which", "allows", "the", "usage", "of", "an", "http", ".", "Handler", "as", "a", "request", "handle", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L75-L79
138,811
beego/mux
mux.go
ServeHTTP
func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request) { var handler http.HandlerFunc path := req.URL.Path method := req.Method match, err := m.trie.Match(path) if err != nil { http.Error(w, fmt.Sprintf(`"Access %s: %s"`, path, err), http.StatusNotImplemented) return } if match.Node == nil { // ...
go
func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request) { var handler http.HandlerFunc path := req.URL.Path method := req.Method match, err := m.trie.Match(path) if err != nil { http.Error(w, fmt.Sprintf(`"Access %s: %s"`, path, err), http.StatusNotImplemented) return } if match.Node == nil { // ...
[ "func", "(", "m", "*", "Mux", ")", "ServeHTTP", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "var", "handler", "http", ".", "HandlerFunc", "\n", "path", ":=", "req", ".", "URL", ".", "Path", "\n", "met...
// ServeHTTP implemented http.Handler interface
[ "ServeHTTP", "implemented", "http", ".", "Handler", "interface" ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L82-L132
138,812
beego/mux
tree.go
getChild
func (n *Node) getChild(key string) *Node { if strings.Contains(key, "::") { key = strings.Replace(key, "::", ":", -1) } if v, ok := n.children[key]; ok { return v } for _, c := range n.segChildren { if c.segment == key { return c } } for _, c := range n.optionChildren { if c.segment == key { ret...
go
func (n *Node) getChild(key string) *Node { if strings.Contains(key, "::") { key = strings.Replace(key, "::", ":", -1) } if v, ok := n.children[key]; ok { return v } for _, c := range n.segChildren { if c.segment == key { return c } } for _, c := range n.optionChildren { if c.segment == key { ret...
[ "func", "(", "n", "*", "Node", ")", "getChild", "(", "key", "string", ")", "*", "Node", "{", "if", "strings", ".", "Contains", "(", "key", ",", "\"", "\"", ")", "{", "key", "=", "strings", ".", "Replace", "(", "key", ",", "\"", "\"", ",", "\"",...
// getChild return the static key
[ "getChild", "return", "the", "static", "key" ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L279-L302
138,813
beego/mux
tree.go
Name
func (n *Node) Name(name string) *Node { if n.getRootNode().namedRoutes == nil { n.getRootNode().namedRoutes = map[string]*Node{name: n} } else { if _, ok := n.getRootNode().namedRoutes[name]; ok { panic(fmt.Errorf("mux: route already has name %q, can't set", name)) } n.getRootNode().namedRoutes[name] = n ...
go
func (n *Node) Name(name string) *Node { if n.getRootNode().namedRoutes == nil { n.getRootNode().namedRoutes = map[string]*Node{name: n} } else { if _, ok := n.getRootNode().namedRoutes[name]; ok { panic(fmt.Errorf("mux: route already has name %q, can't set", name)) } n.getRootNode().namedRoutes[name] = n ...
[ "func", "(", "n", "*", "Node", ")", "Name", "(", "name", "string", ")", "*", "Node", "{", "if", "n", ".", "getRootNode", "(", ")", ".", "namedRoutes", "==", "nil", "{", "n", ".", "getRootNode", "(", ")", ".", "namedRoutes", "=", "map", "[", "stri...
// Name sets the name for the route, used to build URLs.
[ "Name", "sets", "the", "name", "for", "the", "route", "used", "to", "build", "URLs", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L305-L315
138,814
beego/mux
tree.go
GetName
func (n *Node) GetName(name string) *Node { if n.getRootNode().namedRoutes != nil { return n.getRootNode().namedRoutes[name] } return nil }
go
func (n *Node) GetName(name string) *Node { if n.getRootNode().namedRoutes != nil { return n.getRootNode().namedRoutes[name] } return nil }
[ "func", "(", "n", "*", "Node", ")", "GetName", "(", "name", "string", ")", "*", "Node", "{", "if", "n", ".", "getRootNode", "(", ")", ".", "namedRoutes", "!=", "nil", "{", "return", "n", ".", "getRootNode", "(", ")", ".", "namedRoutes", "[", "name"...
// GetName returns the name for the route, if any.
[ "GetName", "returns", "the", "name", "for", "the", "route", "if", "any", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L318-L323
138,815
beego/mux
tree.go
getRootNode
func (n *Node) getRootNode() *Node { if n.parent == nil { return n } return n.parent.getRootNode() }
go
func (n *Node) getRootNode() *Node { if n.parent == nil { return n } return n.parent.getRootNode() }
[ "func", "(", "n", "*", "Node", ")", "getRootNode", "(", ")", "*", "Node", "{", "if", "n", ".", "parent", "==", "nil", "{", "return", "n", "\n", "}", "\n", "return", "n", ".", "parent", ".", "getRootNode", "(", ")", "\n", "}" ]
// getRootNode will return the Node whose parent is nil
[ "getRootNode", "will", "return", "the", "Node", "whose", "parent", "is", "nil" ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L326-L331
138,816
beego/mux
tree.go
BuildURL
func (n *Node) BuildURL(pairs ...string) (*url.URL, error) { if len(pairs)%2 != 0 { return nil, fmt.Errorf("pairs expect even number key/val, but get %d", len(pairs)) } params := make(map[string]string) var key string for k, v := range pairs { if k%2 == 0 { key = v } else { params[key] = v } } path...
go
func (n *Node) BuildURL(pairs ...string) (*url.URL, error) { if len(pairs)%2 != 0 { return nil, fmt.Errorf("pairs expect even number key/val, but get %d", len(pairs)) } params := make(map[string]string) var key string for k, v := range pairs { if k%2 == 0 { key = v } else { params[key] = v } } path...
[ "func", "(", "n", "*", "Node", ")", "BuildURL", "(", "pairs", "...", "string", ")", "(", "*", "url", ".", "URL", ",", "error", ")", "{", "if", "len", "(", "pairs", ")", "%", "2", "!=", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "("...
// BuildURL will builds a URL for the pattern.
[ "BuildURL", "will", "builds", "a", "URL", "for", "the", "pattern", "." ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L334-L354
138,817
beego/mux
tree.go
parsePattern
func parsePattern(parent *Node, segments []string) *Node { segment := segments[0] segments = segments[1:] child := parseSegment(parent, segment) if len(segments) == 0 { child.endpoint = true return child } return parsePattern(child, segments) }
go
func parsePattern(parent *Node, segments []string) *Node { segment := segments[0] segments = segments[1:] child := parseSegment(parent, segment) if len(segments) == 0 { child.endpoint = true return child } return parsePattern(child, segments) }
[ "func", "parsePattern", "(", "parent", "*", "Node", ",", "segments", "[", "]", "string", ")", "*", "Node", "{", "segment", ":=", "segments", "[", "0", "]", "\n", "segments", "=", "segments", "[", "1", ":", "]", "\n", "child", ":=", "parseSegment", "(...
// parsePattern support multi pattern
[ "parsePattern", "support", "multi", "pattern" ]
6660b4b5accbb383fac89498e57d3250d5e907ac
https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L460-L469
138,818
notnil/chess
game.go
PGN
func PGN(r io.Reader) (func(*Game), error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } game, err := decodePGN(string(b)) if err != nil { return nil, err } return func(g *Game) { g.copy(game) }, nil }
go
func PGN(r io.Reader) (func(*Game), error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } game, err := decodePGN(string(b)) if err != nil { return nil, err } return func(g *Game) { g.copy(game) }, nil }
[ "func", "PGN", "(", "r", "io", ".", "Reader", ")", "(", "func", "(", "*", "Game", ")", ",", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", ...
// PGN takes a reader and returns a function that updates // the game to reflect the PGN data. The PGN can use any // move notation supported by this package. The returned // function is designed to be used in the NewGame constructor. // An error is returned if there is a problem parsing the PGN data.
[ "PGN", "takes", "a", "reader", "and", "returns", "a", "function", "that", "updates", "the", "game", "to", "reflect", "the", "PGN", "data", ".", "The", "PGN", "can", "use", "any", "move", "notation", "supported", "by", "this", "package", ".", "The", "retu...
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L87-L99
138,819
notnil/chess
game.go
FEN
func FEN(fen string) (func(*Game), error) { pos, err := decodeFEN(fen) if err != nil { return nil, err } return func(g *Game) { g.pos = pos g.positions = []*Position{pos} g.updatePosition() }, nil }
go
func FEN(fen string) (func(*Game), error) { pos, err := decodeFEN(fen) if err != nil { return nil, err } return func(g *Game) { g.pos = pos g.positions = []*Position{pos} g.updatePosition() }, nil }
[ "func", "FEN", "(", "fen", "string", ")", "(", "func", "(", "*", "Game", ")", ",", "error", ")", "{", "pos", ",", "err", ":=", "decodeFEN", "(", "fen", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "r...
// FEN takes a string and returns a function that updates // the game to reflect the FEN data. Since FEN doesn't encode // prior moves, the move list will be empty. The returned // function is designed to be used in the NewGame constructor. // An error is returned if there is a problem parsing the FEN data.
[ "FEN", "takes", "a", "string", "and", "returns", "a", "function", "that", "updates", "the", "game", "to", "reflect", "the", "FEN", "data", ".", "Since", "FEN", "doesn", "t", "encode", "prior", "moves", "the", "move", "list", "will", "be", "empty", ".", ...
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L106-L116
138,820
notnil/chess
game.go
TagPairs
func TagPairs(tagPairs []*TagPair) func(*Game) { return func(g *Game) { g.tagPairs = append([]*TagPair(nil), tagPairs...) } }
go
func TagPairs(tagPairs []*TagPair) func(*Game) { return func(g *Game) { g.tagPairs = append([]*TagPair(nil), tagPairs...) } }
[ "func", "TagPairs", "(", "tagPairs", "[", "]", "*", "TagPair", ")", "func", "(", "*", "Game", ")", "{", "return", "func", "(", "g", "*", "Game", ")", "{", "g", ".", "tagPairs", "=", "append", "(", "[", "]", "*", "TagPair", "(", "nil", ")", ",",...
// TagPairs returns a function that sets the tag pairs // to the given value. The returned function is designed // to be used in the NewGame constructor.
[ "TagPairs", "returns", "a", "function", "that", "sets", "the", "tag", "pairs", "to", "the", "given", "value", ".", "The", "returned", "function", "is", "designed", "to", "be", "used", "in", "the", "NewGame", "constructor", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L121-L125
138,821
notnil/chess
game.go
NewGame
func NewGame(options ...func(*Game)) *Game { pos, _ := decodeFEN(startFEN) game := &Game{ notation: AlgebraicNotation{}, moves: []*Move{}, pos: pos, positions: []*Position{pos}, outcome: NoOutcome, method: NoMethod, } for _, f := range options { if f != nil { f(game) } } return ...
go
func NewGame(options ...func(*Game)) *Game { pos, _ := decodeFEN(startFEN) game := &Game{ notation: AlgebraicNotation{}, moves: []*Move{}, pos: pos, positions: []*Position{pos}, outcome: NoOutcome, method: NoMethod, } for _, f := range options { if f != nil { f(game) } } return ...
[ "func", "NewGame", "(", "options", "...", "func", "(", "*", "Game", ")", ")", "*", "Game", "{", "pos", ",", "_", ":=", "decodeFEN", "(", "startFEN", ")", "\n", "game", ":=", "&", "Game", "{", "notation", ":", "AlgebraicNotation", "{", "}", ",", "mo...
// NewGame defaults to returning a game in the standard // opening position. Options can be given to configure // the game's initial state.
[ "NewGame", "defaults", "to", "returning", "a", "game", "in", "the", "standard", "opening", "position", ".", "Options", "can", "be", "given", "to", "configure", "the", "game", "s", "initial", "state", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L141-L157
138,822
notnil/chess
game.go
Move
func (g *Game) Move(m *Move) error { valid := moveSlice(g.ValidMoves()).find(m) if valid == nil { return fmt.Errorf("chess: invalid move %s", m) } g.moves = append(g.moves, valid) g.pos = g.pos.Update(valid) g.positions = append(g.positions, g.pos) g.updatePosition() return nil }
go
func (g *Game) Move(m *Move) error { valid := moveSlice(g.ValidMoves()).find(m) if valid == nil { return fmt.Errorf("chess: invalid move %s", m) } g.moves = append(g.moves, valid) g.pos = g.pos.Update(valid) g.positions = append(g.positions, g.pos) g.updatePosition() return nil }
[ "func", "(", "g", "*", "Game", ")", "Move", "(", "m", "*", "Move", ")", "error", "{", "valid", ":=", "moveSlice", "(", "g", ".", "ValidMoves", "(", ")", ")", ".", "find", "(", "m", ")", "\n", "if", "valid", "==", "nil", "{", "return", "fmt", ...
// Move updates the game with the given move. An error is returned // if the move is invalid or the game has already been completed.
[ "Move", "updates", "the", "game", "with", "the", "given", "move", ".", "An", "error", "is", "returned", "if", "the", "move", "is", "invalid", "or", "the", "game", "has", "already", "been", "completed", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L161-L171
138,823
notnil/chess
game.go
MoveStr
func (g *Game) MoveStr(s string) error { m, err := g.notation.Decode(g.pos, s) if err != nil { return err } return g.Move(m) }
go
func (g *Game) MoveStr(s string) error { m, err := g.notation.Decode(g.pos, s) if err != nil { return err } return g.Move(m) }
[ "func", "(", "g", "*", "Game", ")", "MoveStr", "(", "s", "string", ")", "error", "{", "m", ",", "err", ":=", "g", ".", "notation", ".", "Decode", "(", "g", ".", "pos", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n",...
// MoveStr decodes the given string in game's notation // and calls the Move function. An error is returned if // the move can't be decoded or the move is invalid.
[ "MoveStr", "decodes", "the", "given", "string", "in", "game", "s", "notation", "and", "calls", "the", "Move", "function", ".", "An", "error", "is", "returned", "if", "the", "move", "can", "t", "be", "decoded", "or", "the", "move", "is", "invalid", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L176-L182
138,824
notnil/chess
game.go
MarshalText
func (g *Game) MarshalText() (text []byte, err error) { return []byte(encodePGN(g)), nil }
go
func (g *Game) MarshalText() (text []byte, err error) { return []byte(encodePGN(g)), nil }
[ "func", "(", "g", "*", "Game", ")", "MarshalText", "(", ")", "(", "text", "[", "]", "byte", ",", "err", "error", ")", "{", "return", "[", "]", "byte", "(", "encodePGN", "(", "g", ")", ")", ",", "nil", "\n", "}" ]
// MarshalText implements the encoding.TextMarshaler interface and // encodes the game's PGN.
[ "MarshalText", "implements", "the", "encoding", ".", "TextMarshaler", "interface", "and", "encodes", "the", "game", "s", "PGN", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L233-L235
138,825
notnil/chess
game.go
UnmarshalText
func (g *Game) UnmarshalText(text []byte) error { game, err := decodePGN(string(text)) if err != nil { return err } g.copy(game) return nil }
go
func (g *Game) UnmarshalText(text []byte) error { game, err := decodePGN(string(text)) if err != nil { return err } g.copy(game) return nil }
[ "func", "(", "g", "*", "Game", ")", "UnmarshalText", "(", "text", "[", "]", "byte", ")", "error", "{", "game", ",", "err", ":=", "decodePGN", "(", "string", "(", "text", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", ...
// UnmarshalText implements the encoding.TextUnarshaler interface and // assumes the data is in the PGN format.
[ "UnmarshalText", "implements", "the", "encoding", ".", "TextUnarshaler", "interface", "and", "assumes", "the", "data", "is", "in", "the", "PGN", "format", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L239-L246
138,826
notnil/chess
game.go
Draw
func (g *Game) Draw(method Method) error { switch method { case ThreefoldRepetition: if g.numOfRepitions() < 3 { return errors.New("chess: draw by ThreefoldRepetition requires at least three repetitions of the current board state") } case FiftyMoveRule: if g.pos.halfMoveClock < 100 { return fmt.Errorf("c...
go
func (g *Game) Draw(method Method) error { switch method { case ThreefoldRepetition: if g.numOfRepitions() < 3 { return errors.New("chess: draw by ThreefoldRepetition requires at least three repetitions of the current board state") } case FiftyMoveRule: if g.pos.halfMoveClock < 100 { return fmt.Errorf("c...
[ "func", "(", "g", "*", "Game", ")", "Draw", "(", "method", "Method", ")", "error", "{", "switch", "method", "{", "case", "ThreefoldRepetition", ":", "if", "g", ".", "numOfRepitions", "(", ")", "<", "3", "{", "return", "errors", ".", "New", "(", "\"",...
// Draw attempts to draw the game by the given method. If the // method is valid, then the game is updated to a draw by that // method. If the method isn't valid then an error is returned.
[ "Draw", "attempts", "to", "draw", "the", "game", "by", "the", "given", "method", ".", "If", "the", "method", "is", "valid", "then", "the", "game", "is", "updated", "to", "a", "draw", "by", "that", "method", ".", "If", "the", "method", "isn", "t", "va...
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L251-L268
138,827
notnil/chess
game.go
Resign
func (g *Game) Resign(color Color) { if g.outcome != NoOutcome || color == NoColor { return } if color == White { g.outcome = BlackWon } else { g.outcome = WhiteWon } g.method = Resignation }
go
func (g *Game) Resign(color Color) { if g.outcome != NoOutcome || color == NoColor { return } if color == White { g.outcome = BlackWon } else { g.outcome = WhiteWon } g.method = Resignation }
[ "func", "(", "g", "*", "Game", ")", "Resign", "(", "color", "Color", ")", "{", "if", "g", ".", "outcome", "!=", "NoOutcome", "||", "color", "==", "NoColor", "{", "return", "\n", "}", "\n", "if", "color", "==", "White", "{", "g", ".", "outcome", "...
// Resign resigns the game for the given color. If the game has // already been completed then the game is not updated.
[ "Resign", "resigns", "the", "game", "for", "the", "given", "color", ".", "If", "the", "game", "has", "already", "been", "completed", "then", "the", "game", "is", "not", "updated", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L272-L282
138,828
notnil/chess
game.go
AddTagPair
func (g *Game) AddTagPair(k, v string) bool { for i, tag := range g.tagPairs { if tag.Key == k { g.tagPairs[i].Value = v return true } } g.tagPairs = append(g.tagPairs, &TagPair{Key: k, Value: v}) return false }
go
func (g *Game) AddTagPair(k, v string) bool { for i, tag := range g.tagPairs { if tag.Key == k { g.tagPairs[i].Value = v return true } } g.tagPairs = append(g.tagPairs, &TagPair{Key: k, Value: v}) return false }
[ "func", "(", "g", "*", "Game", ")", "AddTagPair", "(", "k", ",", "v", "string", ")", "bool", "{", "for", "i", ",", "tag", ":=", "range", "g", ".", "tagPairs", "{", "if", "tag", ".", "Key", "==", "k", "{", "g", ".", "tagPairs", "[", "i", "]", ...
// AddTagPair adds or updates a tag pair with the given key and // value and returns true if the value is overwritten.
[ "AddTagPair", "adds", "or", "updates", "a", "tag", "pair", "with", "the", "given", "key", "and", "value", "and", "returns", "true", "if", "the", "value", "is", "overwritten", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L298-L307
138,829
notnil/chess
game.go
GetTagPair
func (g *Game) GetTagPair(k string) *TagPair { for _, tag := range g.tagPairs { if tag.Key == k { return tag } } return nil }
go
func (g *Game) GetTagPair(k string) *TagPair { for _, tag := range g.tagPairs { if tag.Key == k { return tag } } return nil }
[ "func", "(", "g", "*", "Game", ")", "GetTagPair", "(", "k", "string", ")", "*", "TagPair", "{", "for", "_", ",", "tag", ":=", "range", "g", ".", "tagPairs", "{", "if", "tag", ".", "Key", "==", "k", "{", "return", "tag", "\n", "}", "\n", "}", ...
// GetTagPair returns the tag pair for the given key or nil // if it is not present.
[ "GetTagPair", "returns", "the", "tag", "pair", "for", "the", "given", "key", "or", "nil", "if", "it", "is", "not", "present", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L311-L318
138,830
notnil/chess
game.go
RemoveTagPair
func (g *Game) RemoveTagPair(k string) bool { cp := []*TagPair{} found := false for _, tag := range g.tagPairs { if tag.Key == k { found = true } else { cp = append(cp, tag) } } g.tagPairs = cp return found }
go
func (g *Game) RemoveTagPair(k string) bool { cp := []*TagPair{} found := false for _, tag := range g.tagPairs { if tag.Key == k { found = true } else { cp = append(cp, tag) } } g.tagPairs = cp return found }
[ "func", "(", "g", "*", "Game", ")", "RemoveTagPair", "(", "k", "string", ")", "bool", "{", "cp", ":=", "[", "]", "*", "TagPair", "{", "}", "\n", "found", ":=", "false", "\n", "for", "_", ",", "tag", ":=", "range", "g", ".", "tagPairs", "{", "if...
// RemoveTagPair removes the tag pair for the given key and // returns true if a tag pair was removed.
[ "RemoveTagPair", "removes", "the", "tag", "pair", "for", "the", "given", "key", "and", "returns", "true", "if", "a", "tag", "pair", "was", "removed", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/game.go#L322-L334
138,831
notnil/chess
move.go
String
func (m *Move) String() string { return m.s1.String() + m.s2.String() + m.promo.String() }
go
func (m *Move) String() string { return m.s1.String() + m.s2.String() + m.promo.String() }
[ "func", "(", "m", "*", "Move", ")", "String", "(", ")", "string", "{", "return", "m", ".", "s1", ".", "String", "(", ")", "+", "m", ".", "s2", ".", "String", "(", ")", "+", "m", ".", "promo", ".", "String", "(", ")", "\n", "}" ]
// String returns a string useful for debugging. String doesn't return // algebraic notation.
[ "String", "returns", "a", "string", "useful", "for", "debugging", ".", "String", "doesn", "t", "return", "algebraic", "notation", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/move.go#L32-L34
138,832
notnil/chess
board.go
SquareMap
func (b *Board) SquareMap() map[Square]Piece { m := map[Square]Piece{} for sq := 0; sq < numOfSquaresInBoard; sq++ { p := b.Piece(Square(sq)) if p != NoPiece { m[Square(sq)] = p } } return m }
go
func (b *Board) SquareMap() map[Square]Piece { m := map[Square]Piece{} for sq := 0; sq < numOfSquaresInBoard; sq++ { p := b.Piece(Square(sq)) if p != NoPiece { m[Square(sq)] = p } } return m }
[ "func", "(", "b", "*", "Board", ")", "SquareMap", "(", ")", "map", "[", "Square", "]", "Piece", "{", "m", ":=", "map", "[", "Square", "]", "Piece", "{", "}", "\n", "for", "sq", ":=", "0", ";", "sq", "<", "numOfSquaresInBoard", ";", "sq", "++", ...
// SquareMap returns a mapping of squares to pieces. A square is only added to the map if it is occupied.
[ "SquareMap", "returns", "a", "mapping", "of", "squares", "to", "pieces", ".", "A", "square", "is", "only", "added", "to", "the", "map", "if", "it", "is", "occupied", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/board.go#L33-L42
138,833
notnil/chess
board.go
Draw
func (b *Board) Draw() string { s := "\n A B C D E F G H\n" for r := 7; r >= 0; r-- { s += Rank(r).String() for f := 0; f < numOfSquaresInRow; f++ { p := b.Piece(getSquare(File(f), Rank(r))) if p == NoPiece { s += "-" } else { s += p.String() } s += " " } s += "\n" } return s }
go
func (b *Board) Draw() string { s := "\n A B C D E F G H\n" for r := 7; r >= 0; r-- { s += Rank(r).String() for f := 0; f < numOfSquaresInRow; f++ { p := b.Piece(getSquare(File(f), Rank(r))) if p == NoPiece { s += "-" } else { s += p.String() } s += " " } s += "\n" } return s }
[ "func", "(", "b", "*", "Board", ")", "Draw", "(", ")", "string", "{", "s", ":=", "\"", "\\n", "\\n", "\"", "\n", "for", "r", ":=", "7", ";", "r", ">=", "0", ";", "r", "--", "{", "s", "+=", "Rank", "(", "r", ")", ".", "String", "(", ")", ...
// Draw returns visual representation of the board useful for debugging.
[ "Draw", "returns", "visual", "representation", "of", "the", "board", "useful", "for", "debugging", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/board.go#L45-L61
138,834
notnil/chess
board.go
Piece
func (b *Board) Piece(sq Square) Piece { for _, p := range allPieces { bb := b.bbForPiece(p) if bb.Occupied(sq) { return p } } return NoPiece }
go
func (b *Board) Piece(sq Square) Piece { for _, p := range allPieces { bb := b.bbForPiece(p) if bb.Occupied(sq) { return p } } return NoPiece }
[ "func", "(", "b", "*", "Board", ")", "Piece", "(", "sq", "Square", ")", "Piece", "{", "for", "_", ",", "p", ":=", "range", "allPieces", "{", "bb", ":=", "b", ".", "bbForPiece", "(", "p", ")", "\n", "if", "bb", ".", "Occupied", "(", "sq", ")", ...
// Piece returns the piece for the given square.
[ "Piece", "returns", "the", "piece", "for", "the", "given", "square", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/board.go#L90-L98
138,835
notnil/chess
pgn.go
GamesFromPGN
func GamesFromPGN(r io.Reader) ([]*Game, error) { games := []*Game{} current := "" count := 0 totalCount := 0 br := bufio.NewReader(r) for { line, err := br.ReadString('\n') if err == io.EOF { break } else if err != nil { return nil, err } if strings.TrimSpace(line) == "" { count++ } else { ...
go
func GamesFromPGN(r io.Reader) ([]*Game, error) { games := []*Game{} current := "" count := 0 totalCount := 0 br := bufio.NewReader(r) for { line, err := br.ReadString('\n') if err == io.EOF { break } else if err != nil { return nil, err } if strings.TrimSpace(line) == "" { count++ } else { ...
[ "func", "GamesFromPGN", "(", "r", "io", ".", "Reader", ")", "(", "[", "]", "*", "Game", ",", "error", ")", "{", "games", ":=", "[", "]", "*", "Game", "{", "}", "\n", "current", ":=", "\"", "\"", "\n", "count", ":=", "0", "\n", "totalCount", ":=...
// GamesFromPGN returns all PGN decoding games from the // reader. It is designed to be used decoding multiple PGNs // in the same file. An error is returned if there is an // issue parsing the PGNs.
[ "GamesFromPGN", "returns", "all", "PGN", "decoding", "games", "from", "the", "reader", ".", "It", "is", "designed", "to", "be", "used", "decoding", "multiple", "PGNs", "in", "the", "same", "file", ".", "An", "error", "is", "returned", "if", "there", "is", ...
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/pgn.go#L16-L47
138,836
notnil/chess
piece.go
Other
func (c Color) Other() Color { switch c { case White: return Black case Black: return White } return NoColor }
go
func (c Color) Other() Color { switch c { case White: return Black case Black: return White } return NoColor }
[ "func", "(", "c", "Color", ")", "Other", "(", ")", "Color", "{", "switch", "c", "{", "case", "White", ":", "return", "Black", "\n", "case", "Black", ":", "return", "White", "\n", "}", "\n", "return", "NoColor", "\n", "}" ]
// Other returns the opposie color of the receiver.
[ "Other", "returns", "the", "opposie", "color", "of", "the", "receiver", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/piece.go#L16-L24
138,837
notnil/chess
piece.go
Type
func (p Piece) Type() PieceType { switch p { case WhiteKing, BlackKing: return King case WhiteQueen, BlackQueen: return Queen case WhiteRook, BlackRook: return Rook case WhiteBishop, BlackBishop: return Bishop case WhiteKnight, BlackKnight: return Knight case WhitePawn, BlackPawn: return Pawn } ret...
go
func (p Piece) Type() PieceType { switch p { case WhiteKing, BlackKing: return King case WhiteQueen, BlackQueen: return Queen case WhiteRook, BlackRook: return Rook case WhiteBishop, BlackBishop: return Bishop case WhiteKnight, BlackKnight: return Knight case WhitePawn, BlackPawn: return Pawn } ret...
[ "func", "(", "p", "Piece", ")", "Type", "(", ")", "PieceType", "{", "switch", "p", "{", "case", "WhiteKing", ",", "BlackKing", ":", "return", "King", "\n", "case", "WhiteQueen", ",", "BlackQueen", ":", "return", "Queen", "\n", "case", "WhiteRook", ",", ...
// Type returns the type of the piece.
[ "Type", "returns", "the", "type", "of", "the", "piece", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/piece.go#L147-L163
138,838
notnil/chess
piece.go
Color
func (p Piece) Color() Color { switch p { case WhiteKing, WhiteQueen, WhiteRook, WhiteBishop, WhiteKnight, WhitePawn: return White case BlackKing, BlackQueen, BlackRook, BlackBishop, BlackKnight, BlackPawn: return Black } return NoColor }
go
func (p Piece) Color() Color { switch p { case WhiteKing, WhiteQueen, WhiteRook, WhiteBishop, WhiteKnight, WhitePawn: return White case BlackKing, BlackQueen, BlackRook, BlackBishop, BlackKnight, BlackPawn: return Black } return NoColor }
[ "func", "(", "p", "Piece", ")", "Color", "(", ")", "Color", "{", "switch", "p", "{", "case", "WhiteKing", ",", "WhiteQueen", ",", "WhiteRook", ",", "WhiteBishop", ",", "WhiteKnight", ",", "WhitePawn", ":", "return", "White", "\n", "case", "BlackKing", ",...
// Color returns the color of the piece.
[ "Color", "returns", "the", "color", "of", "the", "piece", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/piece.go#L166-L174
138,839
notnil/chess
bitboard.go
Occupied
func (b bitboard) Occupied(sq Square) bool { return (uint64(b) >> uint64(63-sq) & 1) == 1 }
go
func (b bitboard) Occupied(sq Square) bool { return (uint64(b) >> uint64(63-sq) & 1) == 1 }
[ "func", "(", "b", "bitboard", ")", "Occupied", "(", "sq", "Square", ")", "bool", "{", "return", "(", "uint64", "(", "b", ")", ">>", "uint64", "(", "63", "-", "sq", ")", "&", "1", ")", "==", "1", "\n", "}" ]
// Occupied returns true if the square's bitboard position is 1.
[ "Occupied", "returns", "true", "if", "the", "square", "s", "bitboard", "position", "is", "1", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/bitboard.go#L39-L41
138,840
notnil/chess
bitboard.go
String
func (b bitboard) String() string { s := strconv.FormatUint(uint64(b), 2) return strings.Repeat("0", numOfSquaresInBoard-len(s)) + s }
go
func (b bitboard) String() string { s := strconv.FormatUint(uint64(b), 2) return strings.Repeat("0", numOfSquaresInBoard-len(s)) + s }
[ "func", "(", "b", "bitboard", ")", "String", "(", ")", "string", "{", "s", ":=", "strconv", ".", "FormatUint", "(", "uint64", "(", "b", ")", ",", "2", ")", "\n", "return", "strings", ".", "Repeat", "(", "\"", "\"", ",", "numOfSquaresInBoard", "-", ...
// String returns a 64 character string of 1s and 0s starting with the most significant bit.
[ "String", "returns", "a", "64", "character", "string", "of", "1s", "and", "0s", "starting", "with", "the", "most", "significant", "bit", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/bitboard.go#L44-L47
138,841
notnil/chess
bitboard.go
Draw
func (b bitboard) Draw() string { s := "\n A B C D E F G H\n" for r := 7; r >= 0; r-- { s += Rank(r).String() for f := 0; f < numOfSquaresInRow; f++ { sq := getSquare(File(f), Rank(r)) if b.Occupied(sq) { s += "1" } else { s += "0" } s += " " } s += "\n" } return s }
go
func (b bitboard) Draw() string { s := "\n A B C D E F G H\n" for r := 7; r >= 0; r-- { s += Rank(r).String() for f := 0; f < numOfSquaresInRow; f++ { sq := getSquare(File(f), Rank(r)) if b.Occupied(sq) { s += "1" } else { s += "0" } s += " " } s += "\n" } return s }
[ "func", "(", "b", "bitboard", ")", "Draw", "(", ")", "string", "{", "s", ":=", "\"", "\\n", "\\n", "\"", "\n", "for", "r", ":=", "7", ";", "r", ">=", "0", ";", "r", "--", "{", "s", "+=", "Rank", "(", "r", ")", ".", "String", "(", ")", "\n...
// Draw returns visual representation of the bitboard useful for debugging.
[ "Draw", "returns", "visual", "representation", "of", "the", "bitboard", "useful", "for", "debugging", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/bitboard.go#L82-L98
138,842
notnil/chess
position.go
CanCastle
func (cr CastleRights) CanCastle(c Color, side Side) bool { char := "k" if side == QueenSide { char = "q" } if c == White { char = strings.ToUpper(char) } return strings.Contains(string(cr), char) }
go
func (cr CastleRights) CanCastle(c Color, side Side) bool { char := "k" if side == QueenSide { char = "q" } if c == White { char = strings.ToUpper(char) } return strings.Contains(string(cr), char) }
[ "func", "(", "cr", "CastleRights", ")", "CanCastle", "(", "c", "Color", ",", "side", "Side", ")", "bool", "{", "char", ":=", "\"", "\"", "\n", "if", "side", "==", "QueenSide", "{", "char", "=", "\"", "\"", "\n", "}", "\n", "if", "c", "==", "White...
// CanCastle returns true if the given color and side combination // can castle, otherwise returns false.
[ "CanCastle", "returns", "true", "if", "the", "given", "color", "and", "side", "combination", "can", "castle", "otherwise", "returns", "false", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/position.go#L25-L34
138,843
notnil/chess
position.go
Update
func (pos *Position) Update(m *Move) *Position { moveCount := pos.moveCount if pos.turn == Black { moveCount++ } cr := pos.CastleRights() ncr := pos.updateCastleRights(m) p := pos.board.Piece(m.s1) halfMove := pos.halfMoveClock if p.Type() == Pawn || m.HasTag(Capture) || cr != ncr { halfMove = 0 } else { ...
go
func (pos *Position) Update(m *Move) *Position { moveCount := pos.moveCount if pos.turn == Black { moveCount++ } cr := pos.CastleRights() ncr := pos.updateCastleRights(m) p := pos.board.Piece(m.s1) halfMove := pos.halfMoveClock if p.Type() == Pawn || m.HasTag(Capture) || cr != ncr { halfMove = 0 } else { ...
[ "func", "(", "pos", "*", "Position", ")", "Update", "(", "m", "*", "Move", ")", "*", "Position", "{", "moveCount", ":=", "pos", ".", "moveCount", "\n", "if", "pos", ".", "turn", "==", "Black", "{", "moveCount", "++", "\n", "}", "\n", "cr", ":=", ...
// Update returns a new position resulting from the given move. // The move itself isn't validated, if validation is needed use // Game's Move method. This method is more performant for bots that // rely on the ValidMoves because it skips redundant validation.
[ "Update", "returns", "a", "new", "position", "resulting", "from", "the", "given", "move", ".", "The", "move", "itself", "isn", "t", "validated", "if", "validation", "is", "needed", "use", "Game", "s", "Move", "method", ".", "This", "method", "is", "more", ...
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/position.go#L59-L84
138,844
notnil/chess
position.go
ValidMoves
func (pos *Position) ValidMoves() []*Move { if pos.validMoves != nil { return append([]*Move(nil), pos.validMoves...) } pos.validMoves = engine{}.CalcMoves(pos, false) return append([]*Move(nil), pos.validMoves...) }
go
func (pos *Position) ValidMoves() []*Move { if pos.validMoves != nil { return append([]*Move(nil), pos.validMoves...) } pos.validMoves = engine{}.CalcMoves(pos, false) return append([]*Move(nil), pos.validMoves...) }
[ "func", "(", "pos", "*", "Position", ")", "ValidMoves", "(", ")", "[", "]", "*", "Move", "{", "if", "pos", ".", "validMoves", "!=", "nil", "{", "return", "append", "(", "[", "]", "*", "Move", "(", "nil", ")", ",", "pos", ".", "validMoves", "...",...
// ValidMoves returns a list of valid moves for the position.
[ "ValidMoves", "returns", "a", "list", "of", "valid", "moves", "for", "the", "position", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/position.go#L87-L93
138,845
notnil/chess
position.go
Hash
func (pos *Position) Hash() [16]byte { sq := "-" if pos.enPassantSquare != NoSquare { sq = pos.enPassantSquare.String() } s := pos.turn.String() + ":" + pos.castleRights.String() + ":" + sq for _, p := range allPieces { bb := pos.board.bbForPiece(p) s += ":" + strconv.FormatUint(uint64(bb), 16) } return md...
go
func (pos *Position) Hash() [16]byte { sq := "-" if pos.enPassantSquare != NoSquare { sq = pos.enPassantSquare.String() } s := pos.turn.String() + ":" + pos.castleRights.String() + ":" + sq for _, p := range allPieces { bb := pos.board.bbForPiece(p) s += ":" + strconv.FormatUint(uint64(bb), 16) } return md...
[ "func", "(", "pos", "*", "Position", ")", "Hash", "(", ")", "[", "16", "]", "byte", "{", "sq", ":=", "\"", "\"", "\n", "if", "pos", ".", "enPassantSquare", "!=", "NoSquare", "{", "sq", "=", "pos", ".", "enPassantSquare", ".", "String", "(", ")", ...
// Hash returns a unique hash of the position
[ "Hash", "returns", "a", "unique", "hash", "of", "the", "position" ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/position.go#L130-L141
138,846
notnil/chess
position.go
MarshalText
func (pos *Position) MarshalText() (text []byte, err error) { return []byte(pos.String()), nil }
go
func (pos *Position) MarshalText() (text []byte, err error) { return []byte(pos.String()), nil }
[ "func", "(", "pos", "*", "Position", ")", "MarshalText", "(", ")", "(", "text", "[", "]", "byte", ",", "err", "error", ")", "{", "return", "[", "]", "byte", "(", "pos", ".", "String", "(", ")", ")", ",", "nil", "\n", "}" ]
// MarshalText implements the encoding.TextMarshaler interface and // encodes the position's FEN.
[ "MarshalText", "implements", "the", "encoding", ".", "TextMarshaler", "interface", "and", "encodes", "the", "position", "s", "FEN", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/position.go#L145-L147
138,847
notnil/chess
position.go
UnmarshalText
func (pos *Position) UnmarshalText(text []byte) error { cp, err := decodeFEN(string(text)) if err != nil { return err } pos.board = cp.board pos.turn = cp.turn pos.castleRights = cp.castleRights pos.enPassantSquare = cp.enPassantSquare pos.halfMoveClock = cp.halfMoveClock pos.moveCount = cp.moveCount pos.in...
go
func (pos *Position) UnmarshalText(text []byte) error { cp, err := decodeFEN(string(text)) if err != nil { return err } pos.board = cp.board pos.turn = cp.turn pos.castleRights = cp.castleRights pos.enPassantSquare = cp.enPassantSquare pos.halfMoveClock = cp.halfMoveClock pos.moveCount = cp.moveCount pos.in...
[ "func", "(", "pos", "*", "Position", ")", "UnmarshalText", "(", "text", "[", "]", "byte", ")", "error", "{", "cp", ",", "err", ":=", "decodeFEN", "(", "string", "(", "text", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}...
// UnmarshalText implements the encoding.TextUnarshaler interface and // assumes the data is in the FEN format.
[ "UnmarshalText", "implements", "the", "encoding", ".", "TextUnarshaler", "interface", "and", "assumes", "the", "data", "is", "in", "the", "FEN", "format", "." ]
2ad5c7f990b6eb99cfd6a5d3187c899c75053b89
https://github.com/notnil/chess/blob/2ad5c7f990b6eb99cfd6a5d3187c899c75053b89/position.go#L151-L164
138,848
vulcand/predicate
lib.go
GetFieldByTag
func GetFieldByTag(ival interface{}, tagName string, fieldNames []string) (interface{}, error) { if len(fieldNames) == 0 { return nil, trace.BadParameter("missing field names") } val := reflect.ValueOf(ival) if val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr { val = val.Elem() } if val.Kind() != ...
go
func GetFieldByTag(ival interface{}, tagName string, fieldNames []string) (interface{}, error) { if len(fieldNames) == 0 { return nil, trace.BadParameter("missing field names") } val := reflect.ValueOf(ival) if val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr { val = val.Elem() } if val.Kind() != ...
[ "func", "GetFieldByTag", "(", "ival", "interface", "{", "}", ",", "tagName", "string", ",", "fieldNames", "[", "]", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "len", "(", "fieldNames", ")", "==", "0", "{", "return", "nil...
// GetFieldByTag returns a field from the object based on the tag
[ "GetFieldByTag", "returns", "a", "field", "from", "the", "object", "based", "on", "the", "tag" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/lib.go#L131-L158
138,849
vulcand/predicate
builder/builder.go
Equals
func Equals(left, right Expr) EqualsExpr { return EqualsExpr{Left: left, Right: right} }
go
func Equals(left, right Expr) EqualsExpr { return EqualsExpr{Left: left, Right: right} }
[ "func", "Equals", "(", "left", ",", "right", "Expr", ")", "EqualsExpr", "{", "return", "EqualsExpr", "{", "Left", ":", "left", ",", "Right", ":", "right", "}", "\n", "}" ]
// Equals returns equals expression
[ "Equals", "returns", "equals", "expression" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/builder/builder.go#L72-L74
138,850
vulcand/predicate
builder/builder.go
String
func (i EqualsExpr) String() string { return fmt.Sprintf("equals(%v, %v)", i.Left, i.Right) }
go
func (i EqualsExpr) String() string { return fmt.Sprintf("equals(%v, %v)", i.Left, i.Right) }
[ "func", "(", "i", "EqualsExpr", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ".", "Left", ",", "i", ".", "Right", ")", "\n", "}" ]
// String returns function call expression used in rules
[ "String", "returns", "function", "call", "expression", "used", "in", "rules" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/builder/builder.go#L87-L89
138,851
vulcand/predicate
builder/builder.go
Contains
func Contains(a, b Expr) ContainsExpr { return ContainsExpr{Left: a, Right: b} }
go
func Contains(a, b Expr) ContainsExpr { return ContainsExpr{Left: a, Right: b} }
[ "func", "Contains", "(", "a", ",", "b", "Expr", ")", "ContainsExpr", "{", "return", "ContainsExpr", "{", "Left", ":", "a", ",", "Right", ":", "b", "}", "\n", "}" ]
// Contains returns contains function call expression
[ "Contains", "returns", "contains", "function", "call", "expression" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/builder/builder.go#L110-L112
138,852
vulcand/predicate
builder/builder.go
String
func (i ContainsExpr) String() string { return fmt.Sprintf("contains(%v, %v)", i.Left, i.Right) }
go
func (i ContainsExpr) String() string { return fmt.Sprintf("contains(%v, %v)", i.Left, i.Right) }
[ "func", "(", "i", "ContainsExpr", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ".", "Left", ",", "i", ".", "Right", ")", "\n", "}" ]
// String rturns function call expression used in rules
[ "String", "rturns", "function", "call", "expression", "used", "in", "rules" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/builder/builder.go#L125-L127
138,853
vulcand/predicate
builder/builder.go
And
func And(left, right Expr) AndExpr { return AndExpr{ Left: left, Right: right, } }
go
func And(left, right Expr) AndExpr { return AndExpr{ Left: left, Right: right, } }
[ "func", "And", "(", "left", ",", "right", "Expr", ")", "AndExpr", "{", "return", "AndExpr", "{", "Left", ":", "left", ",", "Right", ":", "right", ",", "}", "\n", "}" ]
// And returns && expression
[ "And", "returns", "&&", "expression" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/builder/builder.go#L130-L135
138,854
vulcand/predicate
builder/builder.go
Or
func Or(left, right Expr) OrExpr { return OrExpr{ Left: left, Right: right, } }
go
func Or(left, right Expr) OrExpr { return OrExpr{ Left: left, Right: right, } }
[ "func", "Or", "(", "left", ",", "right", "Expr", ")", "OrExpr", "{", "return", "OrExpr", "{", "Left", ":", "left", ",", "Right", ":", "right", ",", "}", "\n", "}" ]
// Or returns || expression
[ "Or", "returns", "||", "expression" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/builder/builder.go#L151-L156
138,855
vulcand/predicate
parse.go
evaluateSelector
func evaluateSelector(sel *ast.SelectorExpr, fields []string) ([]string, error) { fields = append([]string{sel.Sel.Name}, fields...) switch l := sel.X.(type) { case *ast.SelectorExpr: return evaluateSelector(l, fields) case *ast.Ident: fields = append([]string{l.Name}, fields...) return fields, nil default: ...
go
func evaluateSelector(sel *ast.SelectorExpr, fields []string) ([]string, error) { fields = append([]string{sel.Sel.Name}, fields...) switch l := sel.X.(type) { case *ast.SelectorExpr: return evaluateSelector(l, fields) case *ast.Ident: fields = append([]string{l.Name}, fields...) return fields, nil default: ...
[ "func", "evaluateSelector", "(", "sel", "*", "ast", ".", "SelectorExpr", ",", "fields", "[", "]", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "fields", "=", "append", "(", "[", "]", "string", "{", "sel", ".", "Sel", ".", "Name",...
// evaluateSelector recursively evaluates the selector field and returns a list // of properties at the end
[ "evaluateSelector", "recursively", "evaluates", "the", "selector", "field", "and", "returns", "a", "list", "of", "properties", "at", "the", "end" ]
8fbfb3ab0e94276b6b58bec378600829adc7a203
https://github.com/vulcand/predicate/blob/8fbfb3ab0e94276b6b58bec378600829adc7a203/parse.go#L156-L167
138,856
Unknwon/cae
zip/write.go
packFile
func packFile(srcFile string, recPath string, zw *zip.Writer, fi os.FileInfo) error { if fi.IsDir() { fh, err := zip.FileInfoHeader(fi) if err != nil { return err } fh.Name = recPath + "/" if _, err = zw.CreateHeader(fh); err != nil { return err } } else { fh, err := zip.FileInfoHeader(fi) if er...
go
func packFile(srcFile string, recPath string, zw *zip.Writer, fi os.FileInfo) error { if fi.IsDir() { fh, err := zip.FileInfoHeader(fi) if err != nil { return err } fh.Name = recPath + "/" if _, err = zw.CreateHeader(fh); err != nil { return err } } else { fh, err := zip.FileInfoHeader(fi) if er...
[ "func", "packFile", "(", "srcFile", "string", ",", "recPath", "string", ",", "zw", "*", "zip", ".", "Writer", ",", "fi", "os", ".", "FileInfo", ")", "error", "{", "if", "fi", ".", "IsDir", "(", ")", "{", "fh", ",", "err", ":=", "zip", ".", "FileI...
// packFile packs a file or directory to zip.Writer.
[ "packFile", "packs", "a", "file", "or", "directory", "to", "zip", ".", "Writer", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/zip/write.go#L197-L241
138,857
Unknwon/cae
tz/stream.go
NewStreamArachive
func NewStreamArachive(w io.Writer) *StreamArchive { s := &StreamArchive{} s.gw = gzip.NewWriter(w) s.Writer = tar.NewWriter(s.gw) return s }
go
func NewStreamArachive(w io.Writer) *StreamArchive { s := &StreamArchive{} s.gw = gzip.NewWriter(w) s.Writer = tar.NewWriter(s.gw) return s }
[ "func", "NewStreamArachive", "(", "w", "io", ".", "Writer", ")", "*", "StreamArchive", "{", "s", ":=", "&", "StreamArchive", "{", "}", "\n", "s", ".", "gw", "=", "gzip", ".", "NewWriter", "(", "w", ")", "\n", "s", ".", "Writer", "=", "tar", ".", ...
// NewStreamArachive returns a new streamable archive with given io.Writer. // It's caller's responsibility to close io.Writer and streamer after operation.
[ "NewStreamArachive", "returns", "a", "new", "streamable", "archive", "with", "given", "io", ".", "Writer", ".", "It", "s", "caller", "s", "responsibility", "to", "close", "io", ".", "Writer", "and", "streamer", "after", "operation", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/stream.go#L40-L45
138,858
Unknwon/cae
tz/stream.go
StreamReader
func (s *StreamArchive) StreamReader(relPath string, fi os.FileInfo, r io.Reader) (err error) { fh, err := tar.FileInfoHeader(fi, "") if err != nil { return err } fh.Name = filepath.Join(relPath, fi.Name()) if err = s.Writer.WriteHeader(fh); err != nil { return err } _, err = io.Copy(s.Writer, r) return err...
go
func (s *StreamArchive) StreamReader(relPath string, fi os.FileInfo, r io.Reader) (err error) { fh, err := tar.FileInfoHeader(fi, "") if err != nil { return err } fh.Name = filepath.Join(relPath, fi.Name()) if err = s.Writer.WriteHeader(fh); err != nil { return err } _, err = io.Copy(s.Writer, r) return err...
[ "func", "(", "s", "*", "StreamArchive", ")", "StreamReader", "(", "relPath", "string", ",", "fi", "os", ".", "FileInfo", ",", "r", "io", ".", "Reader", ")", "(", "err", "error", ")", "{", "fh", ",", "err", ":=", "tar", ".", "FileInfoHeader", "(", "...
// StreamReader streams data from io.Reader to StreamArchive.
[ "StreamReader", "streams", "data", "from", "io", ".", "Reader", "to", "StreamArchive", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/stream.go#L81-L92
138,859
Unknwon/cae
tz/write.go
ExtractToFunc
func (tz *TzArchive) ExtractToFunc(destPath string, fn cae.HookFunc, entries ...string) (err error) { destPath = strings.Replace(destPath, "\\", "/", -1) isHasEntry := len(entries) > 0 if Verbose { fmt.Println("Extracting " + tz.FileName + "...") } os.MkdirAll(destPath, os.ModePerm) // Copy post-added files. ...
go
func (tz *TzArchive) ExtractToFunc(destPath string, fn cae.HookFunc, entries ...string) (err error) { destPath = strings.Replace(destPath, "\\", "/", -1) isHasEntry := len(entries) > 0 if Verbose { fmt.Println("Extracting " + tz.FileName + "...") } os.MkdirAll(destPath, os.ModePerm) // Copy post-added files. ...
[ "func", "(", "tz", "*", "TzArchive", ")", "ExtractToFunc", "(", "destPath", "string", ",", "fn", "cae", ".", "HookFunc", ",", "entries", "...", "string", ")", "(", "err", "error", ")", "{", "destPath", "=", "strings", ".", "Replace", "(", "destPath", "...
// ExtractTo extracts the whole archive or the given files to the // specified destination. // It accepts a function as a middleware for custom operations.
[ "ExtractTo", "extracts", "the", "whole", "archive", "or", "the", "given", "files", "to", "the", "specified", "destination", ".", "It", "accepts", "a", "function", "as", "a", "middleware", "for", "custom", "operations", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/write.go#L71-L145
138,860
Unknwon/cae
tz/write.go
extractFile
func (tz *TzArchive) extractFile(f *File, tr *tar.Reader) error { if !tz.isHasWriter { for _, h := range tz.ReadCloser.File { if f.Name == h.Name { return extractFile(h, tr, f.absPath) } } } return cae.Copy(f.Name, f.absPath) }
go
func (tz *TzArchive) extractFile(f *File, tr *tar.Reader) error { if !tz.isHasWriter { for _, h := range tz.ReadCloser.File { if f.Name == h.Name { return extractFile(h, tr, f.absPath) } } } return cae.Copy(f.Name, f.absPath) }
[ "func", "(", "tz", "*", "TzArchive", ")", "extractFile", "(", "f", "*", "File", ",", "tr", "*", "tar", ".", "Reader", ")", "error", "{", "if", "!", "tz", ".", "isHasWriter", "{", "for", "_", ",", "h", ":=", "range", "tz", ".", "ReadCloser", ".", ...
// extractFile extracts file from TzArchive to file system.
[ "extractFile", "extracts", "file", "from", "TzArchive", "to", "file", "system", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/write.go#L166-L176
138,861
Unknwon/cae
tz/write.go
packFile
func packFile(srcFile string, recPath string, tw *tar.Writer, fi os.FileInfo) (err error) { if fi.IsDir() { h, err := tar.FileInfoHeader(fi, "") if err != nil { return err } h.Name = recPath + "/" if err = tw.WriteHeader(h); err != nil { return err } } else { target := "" if fi.Mode()&os.ModeSy...
go
func packFile(srcFile string, recPath string, tw *tar.Writer, fi os.FileInfo) (err error) { if fi.IsDir() { h, err := tar.FileInfoHeader(fi, "") if err != nil { return err } h.Name = recPath + "/" if err = tw.WriteHeader(h); err != nil { return err } } else { target := "" if fi.Mode()&os.ModeSy...
[ "func", "packFile", "(", "srcFile", "string", ",", "recPath", "string", ",", "tw", "*", "tar", ".", "Writer", ",", "fi", "os", ".", "FileInfo", ")", "(", "err", "error", ")", "{", "if", "fi", ".", "IsDir", "(", ")", "{", "h", ",", "err", ":=", ...
// packFile packs a file or directory to tar.Writer.
[ "packFile", "packs", "a", "file", "or", "directory", "to", "tar", ".", "Writer", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/write.go#L256-L297
138,862
Unknwon/cae
tz/write.go
PackToFunc
func PackToFunc(srcPath, destPath string, fn func(fullName string, fi os.FileInfo) error, includeDir ...bool) error { isIncludeDir := false if len(includeDir) > 0 && includeDir[0] { isIncludeDir = true } return packTo(srcPath, destPath, fn, isIncludeDir) }
go
func PackToFunc(srcPath, destPath string, fn func(fullName string, fi os.FileInfo) error, includeDir ...bool) error { isIncludeDir := false if len(includeDir) > 0 && includeDir[0] { isIncludeDir = true } return packTo(srcPath, destPath, fn, isIncludeDir) }
[ "func", "PackToFunc", "(", "srcPath", ",", "destPath", "string", ",", "fn", "func", "(", "fullName", "string", ",", "fi", "os", ".", "FileInfo", ")", "error", ",", "includeDir", "...", "bool", ")", "error", "{", "isIncludeDir", ":=", "false", "\n", "if",...
// PackToFunc packs the complete archive to the specified destination. // It accepts a function as a middleware for custom operations.
[ "PackToFunc", "packs", "the", "complete", "archive", "to", "the", "specified", "destination", ".", "It", "accepts", "a", "function", "as", "a", "middleware", "for", "custom", "operations", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/write.go#L388-L395
138,863
Unknwon/cae
tz/tz.go
List
func (tz *TzArchive) List(prefixes ...string) []string { isHasPrefix := len(prefixes) > 0 names := make([]string, 0, tz.NumFiles) for _, f := range tz.files { if isHasPrefix && !cae.HasPrefix(f.Name, prefixes) { continue } names = append(names, f.Name) } return names }
go
func (tz *TzArchive) List(prefixes ...string) []string { isHasPrefix := len(prefixes) > 0 names := make([]string, 0, tz.NumFiles) for _, f := range tz.files { if isHasPrefix && !cae.HasPrefix(f.Name, prefixes) { continue } names = append(names, f.Name) } return names }
[ "func", "(", "tz", "*", "TzArchive", ")", "List", "(", "prefixes", "...", "string", ")", "[", "]", "string", "{", "isHasPrefix", ":=", "len", "(", "prefixes", ")", ">", "0", "\n", "names", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "tz...
// List returns a string slice of files' name in TzArchive. // Specify prefixes will be used as filters.
[ "List", "returns", "a", "string", "slice", "of", "files", "name", "in", "TzArchive", ".", "Specify", "prefixes", "will", "be", "used", "as", "filters", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/tz.go#L92-L102
138,864
Unknwon/cae
tz/tz.go
AddEmptyDir
func (tz *TzArchive) AddEmptyDir(dirPath string) bool { if !strings.HasSuffix(dirPath, "/") { dirPath += "/" } for _, f := range tz.files { if dirPath == f.Name { return false } } dirPath = strings.TrimSuffix(dirPath, "/") if strings.Contains(dirPath, "/") { // Auto add all upper level directories. ...
go
func (tz *TzArchive) AddEmptyDir(dirPath string) bool { if !strings.HasSuffix(dirPath, "/") { dirPath += "/" } for _, f := range tz.files { if dirPath == f.Name { return false } } dirPath = strings.TrimSuffix(dirPath, "/") if strings.Contains(dirPath, "/") { // Auto add all upper level directories. ...
[ "func", "(", "tz", "*", "TzArchive", ")", "AddEmptyDir", "(", "dirPath", "string", ")", "bool", "{", "if", "!", "strings", ".", "HasSuffix", "(", "dirPath", ",", "\"", "\"", ")", "{", "dirPath", "+=", "\"", "\"", "\n", "}", "\n\n", "for", "_", ",",...
// AddEmptyDir adds a raw directory entry to TzArchive, // it returns false if same directory enry already existed.
[ "AddEmptyDir", "adds", "a", "raw", "directory", "entry", "to", "TzArchive", "it", "returns", "false", "if", "same", "directory", "enry", "already", "existed", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/tz.go#L106-L129
138,865
Unknwon/cae
tz/tz.go
AddDir
func (tz *TzArchive) AddDir(dirPath, absPath string) error { dir, err := os.Open(absPath) if err != nil { return err } defer dir.Close() tz.AddEmptyDir(dirPath) fis, err := dir.Readdir(0) if err != nil { return err } for _, fi := range fis { curPath := strings.Replace(absPath+"/"+fi.Name(), "\\", "/", ...
go
func (tz *TzArchive) AddDir(dirPath, absPath string) error { dir, err := os.Open(absPath) if err != nil { return err } defer dir.Close() tz.AddEmptyDir(dirPath) fis, err := dir.Readdir(0) if err != nil { return err } for _, fi := range fis { curPath := strings.Replace(absPath+"/"+fi.Name(), "\\", "/", ...
[ "func", "(", "tz", "*", "TzArchive", ")", "AddDir", "(", "dirPath", ",", "absPath", "string", ")", "error", "{", "dir", ",", "err", ":=", "os", ".", "Open", "(", "absPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n...
// AddDir adds a directory and subdirectories entries to TzArchive.
[ "AddDir", "adds", "a", "directory", "and", "subdirectories", "entries", "to", "TzArchive", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/tz.go#L132-L159
138,866
Unknwon/cae
tz/tz.go
AddFile
func (tz *TzArchive) AddFile(fileName, absPath string) error { if cae.IsFilter(absPath) { return nil } si, err := os.Lstat(absPath) if err != nil { return err } target := "" if si.Mode()&os.ModeSymlink != 0 { target, err = os.Readlink(absPath) if err != nil { return err } } file := new(File) f...
go
func (tz *TzArchive) AddFile(fileName, absPath string) error { if cae.IsFilter(absPath) { return nil } si, err := os.Lstat(absPath) if err != nil { return err } target := "" if si.Mode()&os.ModeSymlink != 0 { target, err = os.Readlink(absPath) if err != nil { return err } } file := new(File) f...
[ "func", "(", "tz", "*", "TzArchive", ")", "AddFile", "(", "fileName", ",", "absPath", "string", ")", "error", "{", "if", "cae", ".", "IsFilter", "(", "absPath", ")", "{", "return", "nil", "\n", "}", "\n\n", "si", ",", "err", ":=", "os", ".", "Lstat...
// AddFile adds a file entry to TzArchive.
[ "AddFile", "adds", "a", "file", "entry", "to", "TzArchive", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/tz.go#L168-L210
138,867
Unknwon/cae
tz/read.go
openFile
func openFile(name string) (*tar.Reader, *os.File, error) { f, err := os.Open(name) if err != nil { return nil, nil, err } gr, err := gzip.NewReader(f) if err != nil { f.Close() return nil, nil, err } return tar.NewReader(gr), f, nil }
go
func openFile(name string) (*tar.Reader, *os.File, error) { f, err := os.Open(name) if err != nil { return nil, nil, err } gr, err := gzip.NewReader(f) if err != nil { f.Close() return nil, nil, err } return tar.NewReader(gr), f, nil }
[ "func", "openFile", "(", "name", "string", ")", "(", "*", "tar", ".", "Reader", ",", "*", "os", ".", "File", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "n...
// openFile opens a tar.gz file with gzip and tar decoders.
[ "openFile", "opens", "a", "tar", ".", "gz", "file", "with", "gzip", "and", "tar", "decoders", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/read.go#L37-L50
138,868
Unknwon/cae
tz/read.go
openReader
func openReader(name string) (*ReadCloser, error) { tr, f, err := openFile(name) if err != nil { return nil, err } r := new(ReadCloser) if err := r.init(tr); err != nil { return nil, err } r.f = f return r, nil }
go
func openReader(name string) (*ReadCloser, error) { tr, f, err := openFile(name) if err != nil { return nil, err } r := new(ReadCloser) if err := r.init(tr); err != nil { return nil, err } r.f = f return r, nil }
[ "func", "openReader", "(", "name", "string", ")", "(", "*", "ReadCloser", ",", "error", ")", "{", "tr", ",", "f", ",", "err", ":=", "openFile", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n",...
// openReader opens the tar.gz file specified by name and return a tar.Reader.
[ "openReader", "opens", "the", "tar", ".", "gz", "file", "specified", "by", "name", "and", "return", "a", "tar", ".", "Reader", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/read.go#L53-L65
138,869
Unknwon/cae
tz/read.go
init
func (rc *ReadCloser) init(r *tar.Reader) error { defer rc.Close() rc.File = make([]*tar.Header, 0, 10) for { h, err := r.Next() if err == io.EOF { break } else if err != nil { return err } rc.File = append(rc.File, h) } return nil }
go
func (rc *ReadCloser) init(r *tar.Reader) error { defer rc.Close() rc.File = make([]*tar.Header, 0, 10) for { h, err := r.Next() if err == io.EOF { break } else if err != nil { return err } rc.File = append(rc.File, h) } return nil }
[ "func", "(", "rc", "*", "ReadCloser", ")", "init", "(", "r", "*", "tar", ".", "Reader", ")", "error", "{", "defer", "rc", ".", "Close", "(", ")", "\n\n", "rc", ".", "File", "=", "make", "(", "[", "]", "*", "tar", ".", "Header", ",", "0", ",",...
// init initializes a new ReadCloser.
[ "init", "initializes", "a", "new", "ReadCloser", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/read.go#L68-L83
138,870
Unknwon/cae
tz/read.go
syncFiles
func (tz *TzArchive) syncFiles() { tz.files = make([]*File, tz.NumFiles) for i, f := range tz.File { tz.files[i] = &File{} tz.files[i].Header = f tz.files[i].Name = strings.Replace(f.Name, "\\", "/", -1) if f.FileInfo().IsDir() && !strings.HasSuffix(tz.files[i].Name, "/") { tz.files[i].Name += "/" } } }
go
func (tz *TzArchive) syncFiles() { tz.files = make([]*File, tz.NumFiles) for i, f := range tz.File { tz.files[i] = &File{} tz.files[i].Header = f tz.files[i].Name = strings.Replace(f.Name, "\\", "/", -1) if f.FileInfo().IsDir() && !strings.HasSuffix(tz.files[i].Name, "/") { tz.files[i].Name += "/" } } }
[ "func", "(", "tz", "*", "TzArchive", ")", "syncFiles", "(", ")", "{", "tz", ".", "files", "=", "make", "(", "[", "]", "*", "File", ",", "tz", ".", "NumFiles", ")", "\n", "for", "i", ",", "f", ":=", "range", "tz", ".", "File", "{", "tz", ".", ...
// syncFiles syncs file information from file system to memroy object.
[ "syncFiles", "syncs", "file", "information", "from", "file", "system", "to", "memroy", "object", "." ]
c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c
https://github.com/Unknwon/cae/blob/c6aac99ea2cae2ebaf23f26f76b04fe3fcfc9f8c/tz/read.go#L86-L96
138,871
gowww/router
node.go
countChildren
func (n *node) countChildren() (i int) { for _, n := range n.children { i++ i += n.countChildren() } return }
go
func (n *node) countChildren() (i int) { for _, n := range n.children { i++ i += n.countChildren() } return }
[ "func", "(", "n", "*", "node", ")", "countChildren", "(", ")", "(", "i", "int", ")", "{", "for", "_", ",", "n", ":=", "range", "n", ".", "children", "{", "i", "++", "\n", "i", "+=", "n", ".", "countChildren", "(", ")", "\n", "}", "\n", "retur...
// countChildren returns the number of children + grandchildren in node.
[ "countChildren", "returns", "the", "number", "of", "children", "+", "grandchildren", "in", "node", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/node.go#L52-L58
138,872
gowww/router
node.go
makeChild
func (n *node) makeChild(path string, params map[string]uint16, re *regexp.Regexp, handler http.Handler, isRoot bool) { defer n.sortChildren() NodesLoop: for _, child := range n.children { minlen := len(child.s) if len(path) < minlen { minlen = len(path) } for i := 0; i < minlen; i++ { if child.s[i] == ...
go
func (n *node) makeChild(path string, params map[string]uint16, re *regexp.Regexp, handler http.Handler, isRoot bool) { defer n.sortChildren() NodesLoop: for _, child := range n.children { minlen := len(child.s) if len(path) < minlen { minlen = len(path) } for i := 0; i < minlen; i++ { if child.s[i] == ...
[ "func", "(", "n", "*", "node", ")", "makeChild", "(", "path", "string", ",", "params", "map", "[", "string", "]", "uint16", ",", "re", "*", "regexp", ".", "Regexp", ",", "handler", "http", ".", "Handler", ",", "isRoot", "bool", ")", "{", "defer", "...
// makeChild adds a node to the tree.
[ "makeChild", "adds", "a", "node", "to", "the", "tree", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/node.go#L61-L120
138,873
gowww/router
node.go
findChild
func (n *node) findChild(path string) *node { for _, n = range n.children { if n.isParameter() { paramEnd := strings.IndexByte(path, '/') if paramEnd == -1 { // Path ends with the parameter. if n.re != nil && !n.re.MatchString(path) { continue } return n } if n.re != nil && !n.re.MatchSt...
go
func (n *node) findChild(path string) *node { for _, n = range n.children { if n.isParameter() { paramEnd := strings.IndexByte(path, '/') if paramEnd == -1 { // Path ends with the parameter. if n.re != nil && !n.re.MatchString(path) { continue } return n } if n.re != nil && !n.re.MatchSt...
[ "func", "(", "n", "*", "node", ")", "findChild", "(", "path", "string", ")", "*", "node", "{", "for", "_", ",", "n", "=", "range", "n", ".", "children", "{", "if", "n", ".", "isParameter", "(", ")", "{", "paramEnd", ":=", "strings", ".", "IndexBy...
// findChild returns the deepest node matching path.
[ "findChild", "returns", "the", "deepest", "node", "matching", "path", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/node.go#L123-L154
138,874
gowww/router
node.go
sortChildren
func (n *node) sortChildren() { sort.Slice(n.children, func(i, j int) bool { a := n.children[i] b := n.children[j] return a.isParameter() && b.isParameter() && a.re != nil || !a.isParameter() && b.isParameter() || a.countChildren() > b.countChildren() }) }
go
func (n *node) sortChildren() { sort.Slice(n.children, func(i, j int) bool { a := n.children[i] b := n.children[j] return a.isParameter() && b.isParameter() && a.re != nil || !a.isParameter() && b.isParameter() || a.countChildren() > b.countChildren() }) }
[ "func", "(", "n", "*", "node", ")", "sortChildren", "(", ")", "{", "sort", ".", "Slice", "(", "n", ".", "children", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "a", ":=", "n", ".", "children", "[", "i", "]", "\n", "b", ":=", "...
// sortChildren puts children with most subnodes on top, plain strings before parameters, and parameters with regular expressions before the parameter without.
[ "sortChildren", "puts", "children", "with", "most", "subnodes", "on", "top", "plain", "strings", "before", "parameters", "and", "parameters", "with", "regular", "expressions", "before", "the", "parameter", "without", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/node.go#L157-L165
138,875
gowww/router
router.go
Handle
func (rt *Router) Handle(method, path string, handler http.Handler) { if len(path) == 0 || path[0] != '/' { panic(fmt.Errorf("router: path %q must begin with %q", path, "/")) } // Get (or set) tree for method. n := rt.trees[method] if n == nil { n = new(node) rt.trees[method] = n } // Put parameters in t...
go
func (rt *Router) Handle(method, path string, handler http.Handler) { if len(path) == 0 || path[0] != '/' { panic(fmt.Errorf("router: path %q must begin with %q", path, "/")) } // Get (or set) tree for method. n := rt.trees[method] if n == nil { n = new(node) rt.trees[method] = n } // Put parameters in t...
[ "func", "(", "rt", "*", "Router", ")", "Handle", "(", "method", ",", "path", "string", ",", "handler", "http", ".", "Handler", ")", "{", "if", "len", "(", "path", ")", "==", "0", "||", "path", "[", "0", "]", "!=", "'/'", "{", "panic", "(", "fmt...
// Handle adds a route with method, path and handler.
[ "Handle", "adds", "a", "route", "with", "method", "path", "and", "handler", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/router.go#L44-L108
138,876
gowww/router
router.go
Get
func (rt *Router) Get(path string, handler http.Handler) { rt.Handle(http.MethodGet, path, handler) }
go
func (rt *Router) Get(path string, handler http.Handler) { rt.Handle(http.MethodGet, path, handler) }
[ "func", "(", "rt", "*", "Router", ")", "Get", "(", "path", "string", ",", "handler", "http", ".", "Handler", ")", "{", "rt", ".", "Handle", "(", "http", ".", "MethodGet", ",", "path", ",", "handler", ")", "\n", "}" ]
// Get makes a route for GET method.
[ "Get", "makes", "a", "route", "for", "GET", "method", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/router.go#L111-L113
138,877
gowww/router
router.go
Post
func (rt *Router) Post(path string, handler http.Handler) { rt.Handle(http.MethodPost, path, handler) }
go
func (rt *Router) Post(path string, handler http.Handler) { rt.Handle(http.MethodPost, path, handler) }
[ "func", "(", "rt", "*", "Router", ")", "Post", "(", "path", "string", ",", "handler", "http", ".", "Handler", ")", "{", "rt", ".", "Handle", "(", "http", ".", "MethodPost", ",", "path", ",", "handler", ")", "\n", "}" ]
// Post makes a route for POST method.
[ "Post", "makes", "a", "route", "for", "POST", "method", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/router.go#L116-L118
138,878
gowww/router
router.go
Put
func (rt *Router) Put(path string, handler http.Handler) { rt.Handle(http.MethodPut, path, handler) }
go
func (rt *Router) Put(path string, handler http.Handler) { rt.Handle(http.MethodPut, path, handler) }
[ "func", "(", "rt", "*", "Router", ")", "Put", "(", "path", "string", ",", "handler", "http", ".", "Handler", ")", "{", "rt", ".", "Handle", "(", "http", ".", "MethodPut", ",", "path", ",", "handler", ")", "\n", "}" ]
// Put makes a route for PUT method.
[ "Put", "makes", "a", "route", "for", "PUT", "method", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/router.go#L121-L123
138,879
gowww/router
router.go
Patch
func (rt *Router) Patch(path string, handler http.Handler) { rt.Handle(http.MethodPatch, path, handler) }
go
func (rt *Router) Patch(path string, handler http.Handler) { rt.Handle(http.MethodPatch, path, handler) }
[ "func", "(", "rt", "*", "Router", ")", "Patch", "(", "path", "string", ",", "handler", "http", ".", "Handler", ")", "{", "rt", ".", "Handle", "(", "http", ".", "MethodPatch", ",", "path", ",", "handler", ")", "\n", "}" ]
// Patch makes a route for PATCH method.
[ "Patch", "makes", "a", "route", "for", "PATCH", "method", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/router.go#L126-L128
138,880
gowww/router
router.go
Delete
func (rt *Router) Delete(path string, handler http.Handler) { rt.Handle(http.MethodDelete, path, handler) }
go
func (rt *Router) Delete(path string, handler http.Handler) { rt.Handle(http.MethodDelete, path, handler) }
[ "func", "(", "rt", "*", "Router", ")", "Delete", "(", "path", "string", ",", "handler", "http", ".", "Handler", ")", "{", "rt", ".", "Handle", "(", "http", ".", "MethodDelete", ",", "path", ",", "handler", ")", "\n", "}" ]
// Delete makes a route for DELETE method.
[ "Delete", "makes", "a", "route", "for", "DELETE", "method", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/router.go#L131-L133
138,881
gowww/router
router.go
Parameter
func Parameter(r *http.Request, key string) string { params, ok := r.Context().Value(contextKeyParams).(map[string]string) if ok { // Parameters already parsed. return params[key] } paramsIdx, ok := r.Context().Value(contextKeyParamsIdx).(map[string]uint16) if !ok { return "" } params = make(map[string]strin...
go
func Parameter(r *http.Request, key string) string { params, ok := r.Context().Value(contextKeyParams).(map[string]string) if ok { // Parameters already parsed. return params[key] } paramsIdx, ok := r.Context().Value(contextKeyParamsIdx).(map[string]uint16) if !ok { return "" } params = make(map[string]strin...
[ "func", "Parameter", "(", "r", "*", "http", ".", "Request", ",", "key", "string", ")", "string", "{", "params", ",", "ok", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "contextKeyParams", ")", ".", "(", "map", "[", "string", "]", "string...
// Parameter returns the value of path parameter. // Result is empty if parameter doesn't exist.
[ "Parameter", "returns", "the", "value", "of", "path", "parameter", ".", "Result", "is", "empty", "if", "parameter", "doesn", "t", "exist", "." ]
5f9c626ef61940c38ace97f795658c6f2b759afa
https://github.com/gowww/router/blob/5f9c626ef61940c38ace97f795658c6f2b759afa/router.go#L166-L193
138,882
denormal/go-gitignore
position.go
String
func (p Position) String() string { _prefix := "" if p.File != "" { _prefix = p.File + ": " } if p.Line == 0 { return fmt.Sprintf("%s+%d", _prefix, p.Offset) } else if p.Column == 0 { return fmt.Sprintf("%s%d", _prefix, p.Line) } else { return fmt.Sprintf("%s%d:%d", _prefix, p.Line, p.Column) } }
go
func (p Position) String() string { _prefix := "" if p.File != "" { _prefix = p.File + ": " } if p.Line == 0 { return fmt.Sprintf("%s+%d", _prefix, p.Offset) } else if p.Column == 0 { return fmt.Sprintf("%s%d", _prefix, p.Line) } else { return fmt.Sprintf("%s%d:%d", _prefix, p.Line, p.Column) } }
[ "func", "(", "p", "Position", ")", "String", "(", ")", "string", "{", "_prefix", ":=", "\"", "\"", "\n", "if", "p", ".", "File", "!=", "\"", "\"", "{", "_prefix", "=", "p", ".", "File", "+", "\"", "\"", "\n", "}", "\n\n", "if", "p", ".", "Lin...
// String returns a string representation of the current position.
[ "String", "returns", "a", "string", "representation", "of", "the", "current", "position", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/position.go#L17-L30
138,883
denormal/go-gitignore
position.go
Zero
func (p Position) Zero() bool { return p.Line+p.Column+p.Offset == 0 }
go
func (p Position) Zero() bool { return p.Line+p.Column+p.Offset == 0 }
[ "func", "(", "p", "Position", ")", "Zero", "(", ")", "bool", "{", "return", "p", ".", "Line", "+", "p", ".", "Column", "+", "p", ".", "Offset", "==", "0", "\n", "}" ]
// Zero returns true if the Position represents the zero Position
[ "Zero", "returns", "true", "if", "the", "Position", "represents", "the", "zero", "Position" ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/position.go#L33-L35
138,884
denormal/go-gitignore
tokentype.go
String
func (t TokenType) String() string { switch t { case ILLEGAL: return "ILLEGAL" case EOF: return "EOF" case EOL: return "EOL" case WHITESPACE: return "WHITESPACE" case COMMENT: return "COMMENT" case SEPARATOR: return "SEPARATOR" case NEGATION: return "NEGATION" case PATTERN: return "PATTERN" ca...
go
func (t TokenType) String() string { switch t { case ILLEGAL: return "ILLEGAL" case EOF: return "EOF" case EOL: return "EOL" case WHITESPACE: return "WHITESPACE" case COMMENT: return "COMMENT" case SEPARATOR: return "SEPARATOR" case NEGATION: return "NEGATION" case PATTERN: return "PATTERN" ca...
[ "func", "(", "t", "TokenType", ")", "String", "(", ")", "string", "{", "switch", "t", "{", "case", "ILLEGAL", ":", "return", "\"", "\"", "\n", "case", "EOF", ":", "return", "\"", "\"", "\n", "case", "EOL", ":", "return", "\"", "\"", "\n", "case", ...
// String returns a string representation of the Token type.
[ "String", "returns", "a", "string", "representation", "of", "the", "Token", "type", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/tokentype.go#L19-L42
138,885
denormal/go-gitignore
error.go
NewError
func NewError(e error, p Position) Error { return &err{error: e, _position: p} }
go
func NewError(e error, p Position) Error { return &err{error: e, _position: p} }
[ "func", "NewError", "(", "e", "error", ",", "p", "Position", ")", "Error", "{", "return", "&", "err", "{", "error", ":", "e", ",", "_position", ":", "p", "}", "\n", "}" ]
// NewError returns a new Error instance for the given error e and position p.
[ "NewError", "returns", "a", "new", "Error", "instance", "for", "the", "given", "error", "e", "and", "position", "p", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/error.go#L21-L23
138,886
denormal/go-gitignore
cache.go
Set
func (c *cache) Set(path string, ignore GitIgnore) { if ignore == nil { return } // ensure the map is defined if c._i == nil { c._i = make(map[string]GitIgnore) } // set the cache item c._lock.Lock() c._i[path] = ignore c._lock.Unlock() }
go
func (c *cache) Set(path string, ignore GitIgnore) { if ignore == nil { return } // ensure the map is defined if c._i == nil { c._i = make(map[string]GitIgnore) } // set the cache item c._lock.Lock() c._i[path] = ignore c._lock.Unlock() }
[ "func", "(", "c", "*", "cache", ")", "Set", "(", "path", "string", ",", "ignore", "GitIgnore", ")", "{", "if", "ignore", "==", "nil", "{", "return", "\n", "}", "\n\n", "// ensure the map is defined", "if", "c", ".", "_i", "==", "nil", "{", "c", ".", ...
// Set stores the GitIgnore ignore against its path.
[ "Set", "stores", "the", "GitIgnore", "ignore", "against", "its", "path", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/cache.go#L30-L44
138,887
denormal/go-gitignore
cache.go
Get
func (c *cache) Get(path string) GitIgnore { c._lock.Lock() _ignore, _ok := c._i[path] c._lock.Unlock() if _ok { return _ignore } else { return nil } }
go
func (c *cache) Get(path string) GitIgnore { c._lock.Lock() _ignore, _ok := c._i[path] c._lock.Unlock() if _ok { return _ignore } else { return nil } }
[ "func", "(", "c", "*", "cache", ")", "Get", "(", "path", "string", ")", "GitIgnore", "{", "c", ".", "_lock", ".", "Lock", "(", ")", "\n", "_ignore", ",", "_ok", ":=", "c", ".", "_i", "[", "path", "]", "\n", "c", ".", "_lock", ".", "Unlock", "...
// Get attempts to retrieve an GitIgnore instance associated with the given // path. If the path is not known nil is returned.
[ "Get", "attempts", "to", "retrieve", "an", "GitIgnore", "instance", "associated", "with", "the", "given", "path", ".", "If", "the", "path", "is", "not", "known", "nil", "is", "returned", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/cache.go#L48-L57
138,888
denormal/go-gitignore
repository.go
Absolute
func (r *repository) Absolute(path string, isdir bool) Match { // does the file share the same directory as this ignore file? if !strings.HasPrefix(path, r.Base()) { return nil } // extract the relative path of this file _prefix := len(r.Base()) + 1 _rel := string(path[_prefix:]) return r.Relative(_rel, isdir...
go
func (r *repository) Absolute(path string, isdir bool) Match { // does the file share the same directory as this ignore file? if !strings.HasPrefix(path, r.Base()) { return nil } // extract the relative path of this file _prefix := len(r.Base()) + 1 _rel := string(path[_prefix:]) return r.Relative(_rel, isdir...
[ "func", "(", "r", "*", "repository", ")", "Absolute", "(", "path", "string", ",", "isdir", "bool", ")", "Match", "{", "// does the file share the same directory as this ignore file?", "if", "!", "strings", ".", "HasPrefix", "(", "path", ",", "r", ".", "Base", ...
// Absolute attempts to match an absolute path against this repository. If the // path is not located under the base directory of this repository, or is not // matched by this repository, nil is returned.
[ "Absolute", "attempts", "to", "match", "an", "absolute", "path", "against", "this", "repository", ".", "If", "the", "path", "is", "not", "located", "under", "the", "base", "directory", "of", "this", "repository", "or", "is", "not", "matched", "by", "this", ...
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/repository.go#L197-L207
138,889
denormal/go-gitignore
repository.go
Relative
func (r *repository) Relative(path string, isdir bool) Match { // if there's no path, then there's nothing to match _path := filepath.Clean(path) if _path == "." { return nil } // repository matching: // - a child path cannot be considered if its parent is ignored // - a .gitignore in a lower directory over...
go
func (r *repository) Relative(path string, isdir bool) Match { // if there's no path, then there's nothing to match _path := filepath.Clean(path) if _path == "." { return nil } // repository matching: // - a child path cannot be considered if its parent is ignored // - a .gitignore in a lower directory over...
[ "func", "(", "r", "*", "repository", ")", "Relative", "(", "path", "string", ",", "isdir", "bool", ")", "Match", "{", "// if there's no path, then there's nothing to match", "_path", ":=", "filepath", ".", "Clean", "(", "path", ")", "\n", "if", "_path", "==", ...
// Relative attempts to match a path relative to the repository base directory. // If the path is not matched by the repository, nil is returned.
[ "Relative", "attempts", "to", "match", "a", "path", "relative", "to", "the", "repository", "base", "directory", ".", "If", "the", "path", "is", "not", "matched", "by", "the", "repository", "nil", "is", "returned", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/repository.go#L211-L271
138,890
denormal/go-gitignore
token.go
NewToken
func NewToken(t TokenType, word []rune, pos Position) *Token { // ensure the type is valid if t < ILLEGAL || t > BAD { t = BAD } // return the token return &Token{Type: t, Word: word, Position: pos} }
go
func NewToken(t TokenType, word []rune, pos Position) *Token { // ensure the type is valid if t < ILLEGAL || t > BAD { t = BAD } // return the token return &Token{Type: t, Word: word, Position: pos} }
[ "func", "NewToken", "(", "t", "TokenType", ",", "word", "[", "]", "rune", ",", "pos", "Position", ")", "*", "Token", "{", "// ensure the type is valid", "if", "t", "<", "ILLEGAL", "||", "t", ">", "BAD", "{", "t", "=", "BAD", "\n", "}", "\n\n", "// re...
// NewToken returns a Token instance of the given t, represented by the // word runes, at the stream position pos. If the token type is not know, the // returned instance will have type BAD.
[ "NewToken", "returns", "a", "Token", "instance", "of", "the", "given", "t", "represented", "by", "the", "word", "runes", "at", "the", "stream", "position", "pos", ".", "If", "the", "token", "type", "is", "not", "know", "the", "returned", "instance", "will"...
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/token.go#L19-L27
138,891
denormal/go-gitignore
gitignore.go
NewFromFile
func NewFromFile(file string) (GitIgnore, error) { // define an error handler to catch any file access errors // - record the first encountered error var _error Error _errors := func(e Error) bool { if _error == nil { _error = e } return true } // attempt to retrieve the GitIgnore represented by this f...
go
func NewFromFile(file string) (GitIgnore, error) { // define an error handler to catch any file access errors // - record the first encountered error var _error Error _errors := func(e Error) bool { if _error == nil { _error = e } return true } // attempt to retrieve the GitIgnore represented by this f...
[ "func", "NewFromFile", "(", "file", "string", ")", "(", "GitIgnore", ",", "error", ")", "{", "// define an error handler to catch any file access errors", "//\t\t- record the first encountered error", "var", "_error", "Error", "\n", "_errors", ":=", "func", "(", "e", "E...
// NewFromFile creates a GitIgnore instance from the given file. An error // will be returned if file cannot be opened or its absolute path determined.
[ "NewFromFile", "creates", "a", "GitIgnore", "instance", "from", "the", "given", "file", ".", "An", "error", "will", "be", "returned", "if", "file", "cannot", "be", "opened", "or", "its", "absolute", "path", "determined", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/gitignore.go#L80-L105
138,892
denormal/go-gitignore
gitignore.go
Absolute
func (i *ignore) Absolute(path string, isdir bool) Match { // does the file share the same directory as this ignore file? if !strings.HasPrefix(path, i._base) { return nil } // extract the relative path of this file _prefix := len(i._base) + 1 _rel := string(path[_prefix:]) return i.Relative(_rel, isdir) }
go
func (i *ignore) Absolute(path string, isdir bool) Match { // does the file share the same directory as this ignore file? if !strings.HasPrefix(path, i._base) { return nil } // extract the relative path of this file _prefix := len(i._base) + 1 _rel := string(path[_prefix:]) return i.Relative(_rel, isdir) }
[ "func", "(", "i", "*", "ignore", ")", "Absolute", "(", "path", "string", ",", "isdir", "bool", ")", "Match", "{", "// does the file share the same directory as this ignore file?", "if", "!", "strings", ".", "HasPrefix", "(", "path", ",", "i", ".", "_base", ")"...
// Absolute attempts to match an absolute path against this GitIgnore. If // the path is not located under the base directory of this GitIgnore, or // is not matched by this GitIgnore, nil is returned.
[ "Absolute", "attempts", "to", "match", "an", "absolute", "path", "against", "this", "GitIgnore", ".", "If", "the", "path", "is", "not", "located", "under", "the", "base", "directory", "of", "this", "GitIgnore", "or", "is", "not", "matched", "by", "this", "...
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/gitignore.go#L244-L254
138,893
denormal/go-gitignore
gitignore.go
Relative
func (i *ignore) Relative(path string, isdir bool) Match { // if we are on Windows, then translate the path to Unix form _rel := path if runtime.GOOS == "windows" { _rel = filepath.ToSlash(_rel) } // iterate over the patterns for this ignore file // - iterate in reverse, since later patterns overwrite ear...
go
func (i *ignore) Relative(path string, isdir bool) Match { // if we are on Windows, then translate the path to Unix form _rel := path if runtime.GOOS == "windows" { _rel = filepath.ToSlash(_rel) } // iterate over the patterns for this ignore file // - iterate in reverse, since later patterns overwrite ear...
[ "func", "(", "i", "*", "ignore", ")", "Relative", "(", "path", "string", ",", "isdir", "bool", ")", "Match", "{", "// if we are on Windows, then translate the path to Unix form", "_rel", ":=", "path", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", ...
// Relative attempts to match a path relative to the GitIgnore base // directory. isdir is used to indicate whether the path represents a file // or a directory. If the path is not matched by the GitIgnore, nil is // returned.
[ "Relative", "attempts", "to", "match", "a", "path", "relative", "to", "the", "GitIgnore", "base", "directory", ".", "isdir", "is", "used", "to", "indicate", "whether", "the", "path", "represents", "a", "file", "or", "a", "directory", ".", "If", "the", "pat...
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/gitignore.go#L260-L278
138,894
denormal/go-gitignore
lexer.go
NewLexer
func NewLexer(r io.Reader) Lexer { return &lexer{_r: bufio.NewReader(r), _line: 1, _column: 1} }
go
func NewLexer(r io.Reader) Lexer { return &lexer{_r: bufio.NewReader(r), _line: 1, _column: 1} }
[ "func", "NewLexer", "(", "r", "io", ".", "Reader", ")", "Lexer", "{", "return", "&", "lexer", "{", "_r", ":", "bufio", ".", "NewReader", "(", "r", ")", ",", "_line", ":", "1", ",", "_column", ":", "1", "}", "\n", "}" ]
// NewLexer returns a Lexer instance for the io.Reader r.
[ "NewLexer", "returns", "a", "Lexer", "instance", "for", "the", "io", ".", "Reader", "r", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/lexer.go#L38-L40
138,895
denormal/go-gitignore
lexer.go
Next
func (l *lexer) Next() (*Token, Error) { // are we at the beginning of the line? _beginning := l.beginning() // read the next rune _r, _err := l.read() if _err != nil { return nil, _err } switch _r { // end of file case _EOF: return l.token(EOF, nil, nil) // whitespace ' ', '\t' case _SPACE: fallthr...
go
func (l *lexer) Next() (*Token, Error) { // are we at the beginning of the line? _beginning := l.beginning() // read the next rune _r, _err := l.read() if _err != nil { return nil, _err } switch _r { // end of file case _EOF: return l.token(EOF, nil, nil) // whitespace ' ', '\t' case _SPACE: fallthr...
[ "func", "(", "l", "*", "lexer", ")", "Next", "(", ")", "(", "*", "Token", ",", "Error", ")", "{", "// are we at the beginning of the line?", "_beginning", ":=", "l", ".", "beginning", "(", ")", "\n\n", "// read the next rune", "_r", ",", "_err", ":=", "l",...
// Next returns the next Token from the Lexer reader. If an error is // encountered, it will be returned as an Error instance, detailing the error // and its position within the stream.
[ "Next", "returns", "the", "next", "Token", "from", "the", "Lexer", "reader", ".", "If", "an", "error", "is", "encountered", "it", "will", "be", "returned", "as", "an", "Error", "instance", "detailing", "the", "error", "and", "its", "position", "within", "t...
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/lexer.go#L45-L125
138,896
denormal/go-gitignore
lexer.go
Position
func (l *lexer) Position() Position { return Position{"", l._line, l._column, l._offset} }
go
func (l *lexer) Position() Position { return Position{"", l._line, l._column, l._offset} }
[ "func", "(", "l", "*", "lexer", ")", "Position", "(", ")", "Position", "{", "return", "Position", "{", "\"", "\"", ",", "l", ".", "_line", ",", "l", ".", "_column", ",", "l", ".", "_offset", "}", "\n", "}" ]
// Position returns the current position of the Lexer.
[ "Position", "returns", "the", "current", "position", "of", "the", "Lexer", "." ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/lexer.go#L128-L130
138,897
denormal/go-gitignore
lexer.go
read
func (l *lexer) read() (rune, Error) { var _r rune var _err error // do we have any unread runes to read? _length := len(l._unread) if _length > 0 { _r = l._unread[_length-1] l._unread = l._unread[:_length-1] // otherwise, attempt to read a new rune } else { _r, _, _err = l._r.ReadRune() if _err == io...
go
func (l *lexer) read() (rune, Error) { var _r rune var _err error // do we have any unread runes to read? _length := len(l._unread) if _length > 0 { _r = l._unread[_length-1] l._unread = l._unread[:_length-1] // otherwise, attempt to read a new rune } else { _r, _, _err = l._r.ReadRune() if _err == io...
[ "func", "(", "l", "*", "lexer", ")", "read", "(", ")", "(", "rune", ",", "Error", ")", "{", "var", "_r", "rune", "\n", "var", "_err", "error", "\n\n", "// do we have any unread runes to read?", "_length", ":=", "len", "(", "l", ".", "_unread", ")", "\n...
// // private methods // // read the next rune from the stream. Return an Error if there is a problem // reading from the stream. If the end of stream is reached, return the EOF // Token.
[ "private", "methods", "read", "the", "next", "rune", "from", "the", "stream", ".", "Return", "an", "Error", "if", "there", "is", "a", "problem", "reading", "from", "the", "stream", ".", "If", "the", "end", "of", "stream", "is", "reached", "return", "the"...
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/lexer.go#L145-L168
138,898
denormal/go-gitignore
lexer.go
unread
func (l *lexer) unread(r ...rune) { // ignore EOF runes _r := make([]rune, 0) for _, _rune := range r { if _rune != _EOF { _r = append(_r, _rune) } } // initialise the unread rune list if necessary if l._unread == nil { l._unread = make([]rune, 0) } if len(_r) != 0 { l._unread = append(l._unread, _r...
go
func (l *lexer) unread(r ...rune) { // ignore EOF runes _r := make([]rune, 0) for _, _rune := range r { if _rune != _EOF { _r = append(_r, _rune) } } // initialise the unread rune list if necessary if l._unread == nil { l._unread = make([]rune, 0) } if len(_r) != 0 { l._unread = append(l._unread, _r...
[ "func", "(", "l", "*", "lexer", ")", "unread", "(", "r", "...", "rune", ")", "{", "// ignore EOF runes", "_r", ":=", "make", "(", "[", "]", "rune", ",", "0", ")", "\n", "for", "_", ",", "_rune", ":=", "range", "r", "{", "if", "_rune", "!=", "_E...
// unread returns the given runes to the stream, making them eligible to be // read again. The runes are returned in the order given, so the last rune // specified will be the next rune read from the stream.
[ "unread", "returns", "the", "given", "runes", "to", "the", "stream", "making", "them", "eligible", "to", "be", "read", "again", ".", "The", "runes", "are", "returned", "in", "the", "order", "given", "so", "the", "last", "rune", "specified", "will", "be", ...
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/lexer.go#L173-L207
138,899
denormal/go-gitignore
lexer.go
newline
func (l *lexer) newline() { // adjust the counters for the new line if l._previous == nil { l._previous = make([]int, 0) } l._previous = append(l._previous, l._column) l._column = 1 l._line++ }
go
func (l *lexer) newline() { // adjust the counters for the new line if l._previous == nil { l._previous = make([]int, 0) } l._previous = append(l._previous, l._column) l._column = 1 l._line++ }
[ "func", "(", "l", "*", "lexer", ")", "newline", "(", ")", "{", "// adjust the counters for the new line", "if", "l", ".", "_previous", "==", "nil", "{", "l", ".", "_previous", "=", "make", "(", "[", "]", "int", ",", "0", ")", "\n", "}", "\n", "l", ...
// newline adjusts the positional counters when an end of line is reached
[ "newline", "adjusts", "the", "positional", "counters", "when", "an", "end", "of", "line", "is", "reached" ]
ae8ad1d07817b3d3b49cabb21559a3f493a357a3
https://github.com/denormal/go-gitignore/blob/ae8ad1d07817b3d3b49cabb21559a3f493a357a3/lexer.go#L225-L233