repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
mailru/easyjson
jwriter/writer.go
Base64Bytes
func (w *Writer) Base64Bytes(data []byte) { if data == nil { w.Buffer.AppendString("null") return } w.Buffer.AppendByte('"') w.base64(data) w.Buffer.AppendByte('"') }
go
func (w *Writer) Base64Bytes(data []byte) { if data == nil { w.Buffer.AppendString("null") return } w.Buffer.AppendByte('"') w.base64(data) w.Buffer.AppendByte('"') }
[ "func", "(", "w", "*", "Writer", ")", "Base64Bytes", "(", "data", "[", "]", "byte", ")", "{", "if", "data", "==", "nil", "{", "w", ".", "Buffer", ".", "AppendString", "(", "\"null\"", ")", "\n", "return", "\n", "}", "\n", "w", ".", "Buffer", ".", "AppendByte", "(", "'\"'", ")", "\n", "w", ".", "base64", "(", "data", ")", "\n", "w", ".", "Buffer", ".", "AppendByte", "(", "'\"'", ")", "\n", "}" ]
// Base64Bytes appends data to the buffer after base64 encoding it
[ "Base64Bytes", "appends", "data", "to", "the", "buffer", "after", "base64", "encoding", "it" ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jwriter/writer.go#L101-L109
train
mailru/easyjson
parser/pkgpath.go
goModPath
func goModPath(fname string, isDir bool) (string, error) { root := fname if !isDir { root = filepath.Dir(fname) } goModPathCache.RLock() goModPath, ok := goModPathCache.paths[root] goModPathCache.RUnlock() if ok { return goModPath, nil } defer func() { goModPathCache.Lock() goModPathCache.paths[root] = goModPath goModPathCache.Unlock() }() cmd := exec.Command("go", "env", "GOMOD") cmd.Dir = root stdout, err := cmd.Output() if err != nil { return "", err } goModPath = string(bytes.TrimSpace(stdout)) return goModPath, nil }
go
func goModPath(fname string, isDir bool) (string, error) { root := fname if !isDir { root = filepath.Dir(fname) } goModPathCache.RLock() goModPath, ok := goModPathCache.paths[root] goModPathCache.RUnlock() if ok { return goModPath, nil } defer func() { goModPathCache.Lock() goModPathCache.paths[root] = goModPath goModPathCache.Unlock() }() cmd := exec.Command("go", "env", "GOMOD") cmd.Dir = root stdout, err := cmd.Output() if err != nil { return "", err } goModPath = string(bytes.TrimSpace(stdout)) return goModPath, nil }
[ "func", "goModPath", "(", "fname", "string", ",", "isDir", "bool", ")", "(", "string", ",", "error", ")", "{", "root", ":=", "fname", "\n", "if", "!", "isDir", "{", "root", "=", "filepath", ".", "Dir", "(", "fname", ")", "\n", "}", "\n", "goModPathCache", ".", "RLock", "(", ")", "\n", "goModPath", ",", "ok", ":=", "goModPathCache", ".", "paths", "[", "root", "]", "\n", "goModPathCache", ".", "RUnlock", "(", ")", "\n", "if", "ok", "{", "return", "goModPath", ",", "nil", "\n", "}", "\n", "defer", "func", "(", ")", "{", "goModPathCache", ".", "Lock", "(", ")", "\n", "goModPathCache", ".", "paths", "[", "root", "]", "=", "goModPath", "\n", "goModPathCache", ".", "Unlock", "(", ")", "\n", "}", "(", ")", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"go\"", ",", "\"env\"", ",", "\"GOMOD\"", ")", "\n", "cmd", ".", "Dir", "=", "root", "\n", "stdout", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "goModPath", "=", "string", "(", "bytes", ".", "TrimSpace", "(", "stdout", ")", ")", "\n", "return", "goModPath", ",", "nil", "\n", "}" ]
// empty if no go.mod, GO111MODULE=off or go without go modules support
[ "empty", "if", "no", "go", ".", "mod", "GO111MODULE", "=", "off", "or", "go", "without", "go", "modules", "support" ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/parser/pkgpath.go#L46-L76
train
mailru/easyjson
buffer/pool.go
putBuf
func putBuf(buf []byte) { size := cap(buf) if size < config.PooledSize { return } if c := buffers[size]; c != nil { c.Put(buf[:0]) } }
go
func putBuf(buf []byte) { size := cap(buf) if size < config.PooledSize { return } if c := buffers[size]; c != nil { c.Put(buf[:0]) } }
[ "func", "putBuf", "(", "buf", "[", "]", "byte", ")", "{", "size", ":=", "cap", "(", "buf", ")", "\n", "if", "size", "<", "config", ".", "PooledSize", "{", "return", "\n", "}", "\n", "if", "c", ":=", "buffers", "[", "size", "]", ";", "c", "!=", "nil", "{", "c", ".", "Put", "(", "buf", "[", ":", "0", "]", ")", "\n", "}", "\n", "}" ]
// putBuf puts a chunk to reuse pool if it can be reused.
[ "putBuf", "puts", "a", "chunk", "to", "reuse", "pool", "if", "it", "can", "be", "reused", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L43-L51
train
mailru/easyjson
buffer/pool.go
getBuf
func getBuf(size int) []byte { if size < config.PooledSize { return make([]byte, 0, size) } if c := buffers[size]; c != nil { v := c.Get() if v != nil { return v.([]byte) } } return make([]byte, 0, size) }
go
func getBuf(size int) []byte { if size < config.PooledSize { return make([]byte, 0, size) } if c := buffers[size]; c != nil { v := c.Get() if v != nil { return v.([]byte) } } return make([]byte, 0, size) }
[ "func", "getBuf", "(", "size", "int", ")", "[", "]", "byte", "{", "if", "size", "<", "config", ".", "PooledSize", "{", "return", "make", "(", "[", "]", "byte", ",", "0", ",", "size", ")", "\n", "}", "\n", "if", "c", ":=", "buffers", "[", "size", "]", ";", "c", "!=", "nil", "{", "v", ":=", "c", ".", "Get", "(", ")", "\n", "if", "v", "!=", "nil", "{", "return", "v", ".", "(", "[", "]", "byte", ")", "\n", "}", "\n", "}", "\n", "return", "make", "(", "[", "]", "byte", ",", "0", ",", "size", ")", "\n", "}" ]
// getBuf gets a chunk from reuse pool or creates a new one if reuse failed.
[ "getBuf", "gets", "a", "chunk", "from", "reuse", "pool", "or", "creates", "a", "new", "one", "if", "reuse", "failed", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L54-L66
train
mailru/easyjson
buffer/pool.go
EnsureSpace
func (b *Buffer) EnsureSpace(s int) { if cap(b.Buf)-len(b.Buf) >= s { return } l := len(b.Buf) if l > 0 { if cap(b.toPool) != cap(b.Buf) { // Chunk was reallocated, toPool can be pooled. putBuf(b.toPool) } if cap(b.bufs) == 0 { b.bufs = make([][]byte, 0, 8) } b.bufs = append(b.bufs, b.Buf) l = cap(b.toPool) * 2 } else { l = config.StartSize } if l > config.MaxSize { l = config.MaxSize } b.Buf = getBuf(l) b.toPool = b.Buf }
go
func (b *Buffer) EnsureSpace(s int) { if cap(b.Buf)-len(b.Buf) >= s { return } l := len(b.Buf) if l > 0 { if cap(b.toPool) != cap(b.Buf) { // Chunk was reallocated, toPool can be pooled. putBuf(b.toPool) } if cap(b.bufs) == 0 { b.bufs = make([][]byte, 0, 8) } b.bufs = append(b.bufs, b.Buf) l = cap(b.toPool) * 2 } else { l = config.StartSize } if l > config.MaxSize { l = config.MaxSize } b.Buf = getBuf(l) b.toPool = b.Buf }
[ "func", "(", "b", "*", "Buffer", ")", "EnsureSpace", "(", "s", "int", ")", "{", "if", "cap", "(", "b", ".", "Buf", ")", "-", "len", "(", "b", ".", "Buf", ")", ">=", "s", "{", "return", "\n", "}", "\n", "l", ":=", "len", "(", "b", ".", "Buf", ")", "\n", "if", "l", ">", "0", "{", "if", "cap", "(", "b", ".", "toPool", ")", "!=", "cap", "(", "b", ".", "Buf", ")", "{", "putBuf", "(", "b", ".", "toPool", ")", "\n", "}", "\n", "if", "cap", "(", "b", ".", "bufs", ")", "==", "0", "{", "b", ".", "bufs", "=", "make", "(", "[", "]", "[", "]", "byte", ",", "0", ",", "8", ")", "\n", "}", "\n", "b", ".", "bufs", "=", "append", "(", "b", ".", "bufs", ",", "b", ".", "Buf", ")", "\n", "l", "=", "cap", "(", "b", ".", "toPool", ")", "*", "2", "\n", "}", "else", "{", "l", "=", "config", ".", "StartSize", "\n", "}", "\n", "if", "l", ">", "config", ".", "MaxSize", "{", "l", "=", "config", ".", "MaxSize", "\n", "}", "\n", "b", ".", "Buf", "=", "getBuf", "(", "l", ")", "\n", "b", ".", "toPool", "=", "b", ".", "Buf", "\n", "}" ]
// EnsureSpace makes sure that the current chunk contains at least s free bytes, // possibly creating a new chunk.
[ "EnsureSpace", "makes", "sure", "that", "the", "current", "chunk", "contains", "at", "least", "s", "free", "bytes", "possibly", "creating", "a", "new", "chunk", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L80-L104
train
mailru/easyjson
buffer/pool.go
AppendByte
func (b *Buffer) AppendByte(data byte) { if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined. b.EnsureSpace(1) } b.Buf = append(b.Buf, data) }
go
func (b *Buffer) AppendByte(data byte) { if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined. b.EnsureSpace(1) } b.Buf = append(b.Buf, data) }
[ "func", "(", "b", "*", "Buffer", ")", "AppendByte", "(", "data", "byte", ")", "{", "if", "cap", "(", "b", ".", "Buf", ")", "==", "len", "(", "b", ".", "Buf", ")", "{", "b", ".", "EnsureSpace", "(", "1", ")", "\n", "}", "\n", "b", ".", "Buf", "=", "append", "(", "b", ".", "Buf", ",", "data", ")", "\n", "}" ]
// AppendByte appends a single byte to buffer.
[ "AppendByte", "appends", "a", "single", "byte", "to", "buffer", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L107-L112
train
mailru/easyjson
buffer/pool.go
AppendBytes
func (b *Buffer) AppendBytes(data []byte) { for len(data) > 0 { if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined. b.EnsureSpace(1) } sz := cap(b.Buf) - len(b.Buf) if sz > len(data) { sz = len(data) } b.Buf = append(b.Buf, data[:sz]...) data = data[sz:] } }
go
func (b *Buffer) AppendBytes(data []byte) { for len(data) > 0 { if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined. b.EnsureSpace(1) } sz := cap(b.Buf) - len(b.Buf) if sz > len(data) { sz = len(data) } b.Buf = append(b.Buf, data[:sz]...) data = data[sz:] } }
[ "func", "(", "b", "*", "Buffer", ")", "AppendBytes", "(", "data", "[", "]", "byte", ")", "{", "for", "len", "(", "data", ")", ">", "0", "{", "if", "cap", "(", "b", ".", "Buf", ")", "==", "len", "(", "b", ".", "Buf", ")", "{", "b", ".", "EnsureSpace", "(", "1", ")", "\n", "}", "\n", "sz", ":=", "cap", "(", "b", ".", "Buf", ")", "-", "len", "(", "b", ".", "Buf", ")", "\n", "if", "sz", ">", "len", "(", "data", ")", "{", "sz", "=", "len", "(", "data", ")", "\n", "}", "\n", "b", ".", "Buf", "=", "append", "(", "b", ".", "Buf", ",", "data", "[", ":", "sz", "]", "...", ")", "\n", "data", "=", "data", "[", "sz", ":", "]", "\n", "}", "\n", "}" ]
// AppendBytes appends a byte slice to buffer.
[ "AppendBytes", "appends", "a", "byte", "slice", "to", "buffer", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L115-L129
train
mailru/easyjson
buffer/pool.go
AppendString
func (b *Buffer) AppendString(data string) { for len(data) > 0 { if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined. b.EnsureSpace(1) } sz := cap(b.Buf) - len(b.Buf) if sz > len(data) { sz = len(data) } b.Buf = append(b.Buf, data[:sz]...) data = data[sz:] } }
go
func (b *Buffer) AppendString(data string) { for len(data) > 0 { if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined. b.EnsureSpace(1) } sz := cap(b.Buf) - len(b.Buf) if sz > len(data) { sz = len(data) } b.Buf = append(b.Buf, data[:sz]...) data = data[sz:] } }
[ "func", "(", "b", "*", "Buffer", ")", "AppendString", "(", "data", "string", ")", "{", "for", "len", "(", "data", ")", ">", "0", "{", "if", "cap", "(", "b", ".", "Buf", ")", "==", "len", "(", "b", ".", "Buf", ")", "{", "b", ".", "EnsureSpace", "(", "1", ")", "\n", "}", "\n", "sz", ":=", "cap", "(", "b", ".", "Buf", ")", "-", "len", "(", "b", ".", "Buf", ")", "\n", "if", "sz", ">", "len", "(", "data", ")", "{", "sz", "=", "len", "(", "data", ")", "\n", "}", "\n", "b", ".", "Buf", "=", "append", "(", "b", ".", "Buf", ",", "data", "[", ":", "sz", "]", "...", ")", "\n", "data", "=", "data", "[", "sz", ":", "]", "\n", "}", "\n", "}" ]
// AppendBytes appends a string to buffer.
[ "AppendBytes", "appends", "a", "string", "to", "buffer", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L132-L146
train
mailru/easyjson
buffer/pool.go
Size
func (b *Buffer) Size() int { size := len(b.Buf) for _, buf := range b.bufs { size += len(buf) } return size }
go
func (b *Buffer) Size() int { size := len(b.Buf) for _, buf := range b.bufs { size += len(buf) } return size }
[ "func", "(", "b", "*", "Buffer", ")", "Size", "(", ")", "int", "{", "size", ":=", "len", "(", "b", ".", "Buf", ")", "\n", "for", "_", ",", "buf", ":=", "range", "b", ".", "bufs", "{", "size", "+=", "len", "(", "buf", ")", "\n", "}", "\n", "return", "size", "\n", "}" ]
// Size computes the size of a buffer by adding sizes of every chunk.
[ "Size", "computes", "the", "size", "of", "a", "buffer", "by", "adding", "sizes", "of", "every", "chunk", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L149-L155
train
mailru/easyjson
buffer/pool.go
DumpTo
func (b *Buffer) DumpTo(w io.Writer) (written int, err error) { var n int for _, buf := range b.bufs { if err == nil { n, err = w.Write(buf) written += n } putBuf(buf) } if err == nil { n, err = w.Write(b.Buf) written += n } putBuf(b.toPool) b.bufs = nil b.Buf = nil b.toPool = nil return }
go
func (b *Buffer) DumpTo(w io.Writer) (written int, err error) { var n int for _, buf := range b.bufs { if err == nil { n, err = w.Write(buf) written += n } putBuf(buf) } if err == nil { n, err = w.Write(b.Buf) written += n } putBuf(b.toPool) b.bufs = nil b.Buf = nil b.toPool = nil return }
[ "func", "(", "b", "*", "Buffer", ")", "DumpTo", "(", "w", "io", ".", "Writer", ")", "(", "written", "int", ",", "err", "error", ")", "{", "var", "n", "int", "\n", "for", "_", ",", "buf", ":=", "range", "b", ".", "bufs", "{", "if", "err", "==", "nil", "{", "n", ",", "err", "=", "w", ".", "Write", "(", "buf", ")", "\n", "written", "+=", "n", "\n", "}", "\n", "putBuf", "(", "buf", ")", "\n", "}", "\n", "if", "err", "==", "nil", "{", "n", ",", "err", "=", "w", ".", "Write", "(", "b", ".", "Buf", ")", "\n", "written", "+=", "n", "\n", "}", "\n", "putBuf", "(", "b", ".", "toPool", ")", "\n", "b", ".", "bufs", "=", "nil", "\n", "b", ".", "Buf", "=", "nil", "\n", "b", ".", "toPool", "=", "nil", "\n", "return", "\n", "}" ]
// DumpTo outputs the contents of a buffer to a writer and resets the buffer.
[ "DumpTo", "outputs", "the", "contents", "of", "a", "buffer", "to", "a", "writer", "and", "resets", "the", "buffer", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L158-L179
train
mailru/easyjson
buffer/pool.go
BuildBytes
func (b *Buffer) BuildBytes(reuse ...[]byte) []byte { if len(b.bufs) == 0 { ret := b.Buf b.toPool = nil b.Buf = nil return ret } var ret []byte size := b.Size() // If we got a buffer as argument and it is big enought, reuse it. if len(reuse) == 1 && cap(reuse[0]) >= size { ret = reuse[0][:0] } else { ret = make([]byte, 0, size) } for _, buf := range b.bufs { ret = append(ret, buf...) putBuf(buf) } ret = append(ret, b.Buf...) putBuf(b.toPool) b.bufs = nil b.toPool = nil b.Buf = nil return ret }
go
func (b *Buffer) BuildBytes(reuse ...[]byte) []byte { if len(b.bufs) == 0 { ret := b.Buf b.toPool = nil b.Buf = nil return ret } var ret []byte size := b.Size() // If we got a buffer as argument and it is big enought, reuse it. if len(reuse) == 1 && cap(reuse[0]) >= size { ret = reuse[0][:0] } else { ret = make([]byte, 0, size) } for _, buf := range b.bufs { ret = append(ret, buf...) putBuf(buf) } ret = append(ret, b.Buf...) putBuf(b.toPool) b.bufs = nil b.toPool = nil b.Buf = nil return ret }
[ "func", "(", "b", "*", "Buffer", ")", "BuildBytes", "(", "reuse", "...", "[", "]", "byte", ")", "[", "]", "byte", "{", "if", "len", "(", "b", ".", "bufs", ")", "==", "0", "{", "ret", ":=", "b", ".", "Buf", "\n", "b", ".", "toPool", "=", "nil", "\n", "b", ".", "Buf", "=", "nil", "\n", "return", "ret", "\n", "}", "\n", "var", "ret", "[", "]", "byte", "\n", "size", ":=", "b", ".", "Size", "(", ")", "\n", "if", "len", "(", "reuse", ")", "==", "1", "&&", "cap", "(", "reuse", "[", "0", "]", ")", ">=", "size", "{", "ret", "=", "reuse", "[", "0", "]", "[", ":", "0", "]", "\n", "}", "else", "{", "ret", "=", "make", "(", "[", "]", "byte", ",", "0", ",", "size", ")", "\n", "}", "\n", "for", "_", ",", "buf", ":=", "range", "b", ".", "bufs", "{", "ret", "=", "append", "(", "ret", ",", "buf", "...", ")", "\n", "putBuf", "(", "buf", ")", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "b", ".", "Buf", "...", ")", "\n", "putBuf", "(", "b", ".", "toPool", ")", "\n", "b", ".", "bufs", "=", "nil", "\n", "b", ".", "toPool", "=", "nil", "\n", "b", ".", "Buf", "=", "nil", "\n", "return", "ret", "\n", "}" ]
// BuildBytes creates a single byte slice with all the contents of the buffer. Data is // copied if it does not fit in a single chunk. You can optionally provide one byte // slice as argument that it will try to reuse.
[ "BuildBytes", "creates", "a", "single", "byte", "slice", "with", "all", "the", "contents", "of", "the", "buffer", ".", "Data", "is", "copied", "if", "it", "does", "not", "fit", "in", "a", "single", "chunk", ".", "You", "can", "optionally", "provide", "one", "byte", "slice", "as", "argument", "that", "it", "will", "try", "to", "reuse", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L184-L214
train
mailru/easyjson
buffer/pool.go
ReadCloser
func (b *Buffer) ReadCloser() io.ReadCloser { ret := &readCloser{0, append(b.bufs, b.Buf)} b.bufs = nil b.toPool = nil b.Buf = nil return ret }
go
func (b *Buffer) ReadCloser() io.ReadCloser { ret := &readCloser{0, append(b.bufs, b.Buf)} b.bufs = nil b.toPool = nil b.Buf = nil return ret }
[ "func", "(", "b", "*", "Buffer", ")", "ReadCloser", "(", ")", "io", ".", "ReadCloser", "{", "ret", ":=", "&", "readCloser", "{", "0", ",", "append", "(", "b", ".", "bufs", ",", "b", ".", "Buf", ")", "}", "\n", "b", ".", "bufs", "=", "nil", "\n", "b", ".", "toPool", "=", "nil", "\n", "b", ".", "Buf", "=", "nil", "\n", "return", "ret", "\n", "}" ]
// ReadCloser creates an io.ReadCloser with all the contents of the buffer.
[ "ReadCloser", "creates", "an", "io", ".", "ReadCloser", "with", "all", "the", "contents", "of", "the", "buffer", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L262-L270
train
mailru/easyjson
jlexer/lexer.go
FetchToken
func (r *Lexer) FetchToken() { r.token.kind = tokenUndef r.start = r.pos // Check if r.Data has r.pos element // If it doesn't, it mean corrupted input data if len(r.Data) < r.pos { r.errParse("Unexpected end of data") return } // Determine the type of a token by skipping whitespace and reading the // first character. for _, c := range r.Data[r.pos:] { switch c { case ':', ',': if r.wantSep == c { r.pos++ r.start++ r.wantSep = 0 } else { r.errSyntax() } case ' ', '\t', '\r', '\n': r.pos++ r.start++ case '"': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenString r.fetchString() return case '{', '[': if r.wantSep != 0 { r.errSyntax() } r.firstElement = true r.token.kind = tokenDelim r.token.delimValue = r.Data[r.pos] r.pos++ return case '}', ']': if !r.firstElement && (r.wantSep != ',') { r.errSyntax() } r.wantSep = 0 r.token.kind = tokenDelim r.token.delimValue = r.Data[r.pos] r.pos++ return case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenNumber r.fetchNumber() return case 'n': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenNull r.fetchNull() return case 't': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenBool r.token.boolValue = true r.fetchTrue() return case 'f': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenBool r.token.boolValue = false r.fetchFalse() return default: r.errSyntax() return } } r.fatalError = io.EOF return }
go
func (r *Lexer) FetchToken() { r.token.kind = tokenUndef r.start = r.pos // Check if r.Data has r.pos element // If it doesn't, it mean corrupted input data if len(r.Data) < r.pos { r.errParse("Unexpected end of data") return } // Determine the type of a token by skipping whitespace and reading the // first character. for _, c := range r.Data[r.pos:] { switch c { case ':', ',': if r.wantSep == c { r.pos++ r.start++ r.wantSep = 0 } else { r.errSyntax() } case ' ', '\t', '\r', '\n': r.pos++ r.start++ case '"': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenString r.fetchString() return case '{', '[': if r.wantSep != 0 { r.errSyntax() } r.firstElement = true r.token.kind = tokenDelim r.token.delimValue = r.Data[r.pos] r.pos++ return case '}', ']': if !r.firstElement && (r.wantSep != ',') { r.errSyntax() } r.wantSep = 0 r.token.kind = tokenDelim r.token.delimValue = r.Data[r.pos] r.pos++ return case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenNumber r.fetchNumber() return case 'n': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenNull r.fetchNull() return case 't': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenBool r.token.boolValue = true r.fetchTrue() return case 'f': if r.wantSep != 0 { r.errSyntax() } r.token.kind = tokenBool r.token.boolValue = false r.fetchFalse() return default: r.errSyntax() return } } r.fatalError = io.EOF return }
[ "func", "(", "r", "*", "Lexer", ")", "FetchToken", "(", ")", "{", "r", ".", "token", ".", "kind", "=", "tokenUndef", "\n", "r", ".", "start", "=", "r", ".", "pos", "\n", "if", "len", "(", "r", ".", "Data", ")", "<", "r", ".", "pos", "{", "r", ".", "errParse", "(", "\"Unexpected end of data\"", ")", "\n", "return", "\n", "}", "\n", "for", "_", ",", "c", ":=", "range", "r", ".", "Data", "[", "r", ".", "pos", ":", "]", "{", "switch", "c", "{", "case", "':'", ",", "','", ":", "if", "r", ".", "wantSep", "==", "c", "{", "r", ".", "pos", "++", "\n", "r", ".", "start", "++", "\n", "r", ".", "wantSep", "=", "0", "\n", "}", "else", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "case", "' '", ",", "'\\t'", ",", "'\\r'", ",", "'\\n'", ":", "r", ".", "pos", "++", "\n", "r", ".", "start", "++", "\n", "case", "'\"'", ":", "if", "r", ".", "wantSep", "!=", "0", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "r", ".", "token", ".", "kind", "=", "tokenString", "\n", "r", ".", "fetchString", "(", ")", "\n", "return", "\n", "case", "'{'", ",", "'['", ":", "if", "r", ".", "wantSep", "!=", "0", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "r", ".", "firstElement", "=", "true", "\n", "r", ".", "token", ".", "kind", "=", "tokenDelim", "\n", "r", ".", "token", ".", "delimValue", "=", "r", ".", "Data", "[", "r", ".", "pos", "]", "\n", "r", ".", "pos", "++", "\n", "return", "\n", "case", "'}'", ",", "']'", ":", "if", "!", "r", ".", "firstElement", "&&", "(", "r", ".", "wantSep", "!=", "','", ")", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "r", ".", "wantSep", "=", "0", "\n", "r", ".", "token", ".", "kind", "=", "tokenDelim", "\n", "r", ".", "token", ".", "delimValue", "=", "r", ".", "Data", "[", "r", ".", "pos", "]", "\n", "r", ".", "pos", "++", "\n", "return", "\n", "case", "'0'", ",", "'1'", ",", "'2'", ",", "'3'", ",", "'4'", ",", "'5'", ",", "'6'", ",", "'7'", ",", "'8'", ",", "'9'", ",", "'-'", ":", "if", "r", ".", "wantSep", "!=", "0", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "r", ".", "token", ".", "kind", "=", "tokenNumber", "\n", "r", ".", "fetchNumber", "(", ")", "\n", "return", "\n", "case", "'n'", ":", "if", "r", ".", "wantSep", "!=", "0", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "r", ".", "token", ".", "kind", "=", "tokenNull", "\n", "r", ".", "fetchNull", "(", ")", "\n", "return", "\n", "case", "'t'", ":", "if", "r", ".", "wantSep", "!=", "0", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "r", ".", "token", ".", "kind", "=", "tokenBool", "\n", "r", ".", "token", ".", "boolValue", "=", "true", "\n", "r", ".", "fetchTrue", "(", ")", "\n", "return", "\n", "case", "'f'", ":", "if", "r", ".", "wantSep", "!=", "0", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "r", ".", "token", ".", "kind", "=", "tokenBool", "\n", "r", ".", "token", ".", "boolValue", "=", "false", "\n", "r", ".", "fetchFalse", "(", ")", "\n", "return", "\n", "default", ":", "r", ".", "errSyntax", "(", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "r", ".", "fatalError", "=", "io", ".", "EOF", "\n", "return", "\n", "}" ]
// FetchToken scans the input for the next token.
[ "FetchToken", "scans", "the", "input", "for", "the", "next", "token", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L57-L157
train
mailru/easyjson
jlexer/lexer.go
isTokenEnd
func isTokenEnd(c byte) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '[' || c == ']' || c == '{' || c == '}' || c == ',' || c == ':' }
go
func isTokenEnd(c byte) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '[' || c == ']' || c == '{' || c == '}' || c == ',' || c == ':' }
[ "func", "isTokenEnd", "(", "c", "byte", ")", "bool", "{", "return", "c", "==", "' '", "||", "c", "==", "'\\t'", "||", "c", "==", "'\\r'", "||", "c", "==", "'\\n'", "||", "c", "==", "'['", "||", "c", "==", "']'", "||", "c", "==", "'{'", "||", "c", "==", "'}'", "||", "c", "==", "','", "||", "c", "==", "':'", "\n", "}" ]
// isTokenEnd returns true if the char can follow a non-delimiter token
[ "isTokenEnd", "returns", "true", "if", "the", "char", "can", "follow", "a", "non", "-", "delimiter", "token" ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L160-L162
train
mailru/easyjson
jlexer/lexer.go
fetchNull
func (r *Lexer) fetchNull() { r.pos += 4 if r.pos > len(r.Data) || r.Data[r.pos-3] != 'u' || r.Data[r.pos-2] != 'l' || r.Data[r.pos-1] != 'l' || (r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) { r.pos -= 4 r.errSyntax() } }
go
func (r *Lexer) fetchNull() { r.pos += 4 if r.pos > len(r.Data) || r.Data[r.pos-3] != 'u' || r.Data[r.pos-2] != 'l' || r.Data[r.pos-1] != 'l' || (r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) { r.pos -= 4 r.errSyntax() } }
[ "func", "(", "r", "*", "Lexer", ")", "fetchNull", "(", ")", "{", "r", ".", "pos", "+=", "4", "\n", "if", "r", ".", "pos", ">", "len", "(", "r", ".", "Data", ")", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "3", "]", "!=", "'u'", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "2", "]", "!=", "'l'", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "1", "]", "!=", "'l'", "||", "(", "r", ".", "pos", "!=", "len", "(", "r", ".", "Data", ")", "&&", "!", "isTokenEnd", "(", "r", ".", "Data", "[", "r", ".", "pos", "]", ")", ")", "{", "r", ".", "pos", "-=", "4", "\n", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "}" ]
// fetchNull fetches and checks remaining bytes of null keyword.
[ "fetchNull", "fetches", "and", "checks", "remaining", "bytes", "of", "null", "keyword", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L165-L176
train
mailru/easyjson
jlexer/lexer.go
fetchTrue
func (r *Lexer) fetchTrue() { r.pos += 4 if r.pos > len(r.Data) || r.Data[r.pos-3] != 'r' || r.Data[r.pos-2] != 'u' || r.Data[r.pos-1] != 'e' || (r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) { r.pos -= 4 r.errSyntax() } }
go
func (r *Lexer) fetchTrue() { r.pos += 4 if r.pos > len(r.Data) || r.Data[r.pos-3] != 'r' || r.Data[r.pos-2] != 'u' || r.Data[r.pos-1] != 'e' || (r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) { r.pos -= 4 r.errSyntax() } }
[ "func", "(", "r", "*", "Lexer", ")", "fetchTrue", "(", ")", "{", "r", ".", "pos", "+=", "4", "\n", "if", "r", ".", "pos", ">", "len", "(", "r", ".", "Data", ")", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "3", "]", "!=", "'r'", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "2", "]", "!=", "'u'", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "1", "]", "!=", "'e'", "||", "(", "r", ".", "pos", "!=", "len", "(", "r", ".", "Data", ")", "&&", "!", "isTokenEnd", "(", "r", ".", "Data", "[", "r", ".", "pos", "]", ")", ")", "{", "r", ".", "pos", "-=", "4", "\n", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "}" ]
// fetchTrue fetches and checks remaining bytes of true keyword.
[ "fetchTrue", "fetches", "and", "checks", "remaining", "bytes", "of", "true", "keyword", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L179-L190
train
mailru/easyjson
jlexer/lexer.go
fetchFalse
func (r *Lexer) fetchFalse() { r.pos += 5 if r.pos > len(r.Data) || r.Data[r.pos-4] != 'a' || r.Data[r.pos-3] != 'l' || r.Data[r.pos-2] != 's' || r.Data[r.pos-1] != 'e' || (r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) { r.pos -= 5 r.errSyntax() } }
go
func (r *Lexer) fetchFalse() { r.pos += 5 if r.pos > len(r.Data) || r.Data[r.pos-4] != 'a' || r.Data[r.pos-3] != 'l' || r.Data[r.pos-2] != 's' || r.Data[r.pos-1] != 'e' || (r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) { r.pos -= 5 r.errSyntax() } }
[ "func", "(", "r", "*", "Lexer", ")", "fetchFalse", "(", ")", "{", "r", ".", "pos", "+=", "5", "\n", "if", "r", ".", "pos", ">", "len", "(", "r", ".", "Data", ")", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "4", "]", "!=", "'a'", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "3", "]", "!=", "'l'", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "2", "]", "!=", "'s'", "||", "r", ".", "Data", "[", "r", ".", "pos", "-", "1", "]", "!=", "'e'", "||", "(", "r", ".", "pos", "!=", "len", "(", "r", ".", "Data", ")", "&&", "!", "isTokenEnd", "(", "r", ".", "Data", "[", "r", ".", "pos", "]", ")", ")", "{", "r", ".", "pos", "-=", "5", "\n", "r", ".", "errSyntax", "(", ")", "\n", "}", "\n", "}" ]
// fetchFalse fetches and checks remaining bytes of false keyword.
[ "fetchFalse", "fetches", "and", "checks", "remaining", "bytes", "of", "false", "keyword", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L193-L205
train
mailru/easyjson
jlexer/lexer.go
fetchNumber
func (r *Lexer) fetchNumber() { hasE := false afterE := false hasDot := false r.pos++ for i, c := range r.Data[r.pos:] { switch { case c >= '0' && c <= '9': afterE = false case c == '.' && !hasDot: hasDot = true case (c == 'e' || c == 'E') && !hasE: hasE = true hasDot = true afterE = true case (c == '+' || c == '-') && afterE: afterE = false default: r.pos += i if !isTokenEnd(c) { r.errSyntax() } else { r.token.byteValue = r.Data[r.start:r.pos] } return } } r.pos = len(r.Data) r.token.byteValue = r.Data[r.start:] }
go
func (r *Lexer) fetchNumber() { hasE := false afterE := false hasDot := false r.pos++ for i, c := range r.Data[r.pos:] { switch { case c >= '0' && c <= '9': afterE = false case c == '.' && !hasDot: hasDot = true case (c == 'e' || c == 'E') && !hasE: hasE = true hasDot = true afterE = true case (c == '+' || c == '-') && afterE: afterE = false default: r.pos += i if !isTokenEnd(c) { r.errSyntax() } else { r.token.byteValue = r.Data[r.start:r.pos] } return } } r.pos = len(r.Data) r.token.byteValue = r.Data[r.start:] }
[ "func", "(", "r", "*", "Lexer", ")", "fetchNumber", "(", ")", "{", "hasE", ":=", "false", "\n", "afterE", ":=", "false", "\n", "hasDot", ":=", "false", "\n", "r", ".", "pos", "++", "\n", "for", "i", ",", "c", ":=", "range", "r", ".", "Data", "[", "r", ".", "pos", ":", "]", "{", "switch", "{", "case", "c", ">=", "'0'", "&&", "c", "<=", "'9'", ":", "afterE", "=", "false", "\n", "case", "c", "==", "'.'", "&&", "!", "hasDot", ":", "hasDot", "=", "true", "\n", "case", "(", "c", "==", "'e'", "||", "c", "==", "'E'", ")", "&&", "!", "hasE", ":", "hasE", "=", "true", "\n", "hasDot", "=", "true", "\n", "afterE", "=", "true", "\n", "case", "(", "c", "==", "'+'", "||", "c", "==", "'-'", ")", "&&", "afterE", ":", "afterE", "=", "false", "\n", "default", ":", "r", ".", "pos", "+=", "i", "\n", "if", "!", "isTokenEnd", "(", "c", ")", "{", "r", ".", "errSyntax", "(", ")", "\n", "}", "else", "{", "r", ".", "token", ".", "byteValue", "=", "r", ".", "Data", "[", "r", ".", "start", ":", "r", ".", "pos", "]", "\n", "}", "\n", "return", "\n", "}", "\n", "}", "\n", "r", ".", "pos", "=", "len", "(", "r", ".", "Data", ")", "\n", "r", ".", "token", ".", "byteValue", "=", "r", ".", "Data", "[", "r", ".", "start", ":", "]", "\n", "}" ]
// fetchNumber scans a number literal token.
[ "fetchNumber", "scans", "a", "number", "literal", "token", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L208-L239
train
mailru/easyjson
jlexer/lexer.go
findStringLen
func findStringLen(data []byte) (isValid, hasEscapes bool, length int) { delta := 0 for i := 0; i < len(data); i++ { switch data[i] { case '\\': i++ delta++ if i < len(data) && data[i] == 'u' { delta++ } case '"': return true, (delta > 0), (i - delta) } } return false, false, len(data) }
go
func findStringLen(data []byte) (isValid, hasEscapes bool, length int) { delta := 0 for i := 0; i < len(data); i++ { switch data[i] { case '\\': i++ delta++ if i < len(data) && data[i] == 'u' { delta++ } case '"': return true, (delta > 0), (i - delta) } } return false, false, len(data) }
[ "func", "findStringLen", "(", "data", "[", "]", "byte", ")", "(", "isValid", ",", "hasEscapes", "bool", ",", "length", "int", ")", "{", "delta", ":=", "0", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "data", ")", ";", "i", "++", "{", "switch", "data", "[", "i", "]", "{", "case", "'\\\\'", ":", "i", "++", "\n", "delta", "++", "\n", "if", "i", "<", "len", "(", "data", ")", "&&", "data", "[", "i", "]", "==", "'u'", "{", "delta", "++", "\n", "}", "\n", "case", "'\"'", ":", "return", "true", ",", "(", "delta", ">", "0", ")", ",", "(", "i", "-", "delta", ")", "\n", "}", "\n", "}", "\n", "return", "false", ",", "false", ",", "len", "(", "data", ")", "\n", "}" ]
// findStringLen tries to scan into the string literal for ending quote char to determine required size. // The size will be exact if no escapes are present and may be inexact if there are escaped chars.
[ "findStringLen", "tries", "to", "scan", "into", "the", "string", "literal", "for", "ending", "quote", "char", "to", "determine", "required", "size", ".", "The", "size", "will", "be", "exact", "if", "no", "escapes", "are", "present", "and", "may", "be", "inexact", "if", "there", "are", "escaped", "chars", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L243-L260
train
mailru/easyjson
jlexer/lexer.go
processEscape
func (r *Lexer) processEscape(data []byte) (int, error) { if len(data) < 2 { return 0, fmt.Errorf("syntax error at %v", string(data)) } c := data[1] switch c { case '"', '/', '\\': r.token.byteValue = append(r.token.byteValue, c) return 2, nil case 'b': r.token.byteValue = append(r.token.byteValue, '\b') return 2, nil case 'f': r.token.byteValue = append(r.token.byteValue, '\f') return 2, nil case 'n': r.token.byteValue = append(r.token.byteValue, '\n') return 2, nil case 'r': r.token.byteValue = append(r.token.byteValue, '\r') return 2, nil case 't': r.token.byteValue = append(r.token.byteValue, '\t') return 2, nil case 'u': rr := getu4(data) if rr < 0 { return 0, errors.New("syntax error") } read := 6 if utf16.IsSurrogate(rr) { rr1 := getu4(data[read:]) if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar { read += 6 rr = dec } else { rr = unicode.ReplacementChar } } var d [4]byte s := utf8.EncodeRune(d[:], rr) r.token.byteValue = append(r.token.byteValue, d[:s]...) return read, nil } return 0, errors.New("syntax error") }
go
func (r *Lexer) processEscape(data []byte) (int, error) { if len(data) < 2 { return 0, fmt.Errorf("syntax error at %v", string(data)) } c := data[1] switch c { case '"', '/', '\\': r.token.byteValue = append(r.token.byteValue, c) return 2, nil case 'b': r.token.byteValue = append(r.token.byteValue, '\b') return 2, nil case 'f': r.token.byteValue = append(r.token.byteValue, '\f') return 2, nil case 'n': r.token.byteValue = append(r.token.byteValue, '\n') return 2, nil case 'r': r.token.byteValue = append(r.token.byteValue, '\r') return 2, nil case 't': r.token.byteValue = append(r.token.byteValue, '\t') return 2, nil case 'u': rr := getu4(data) if rr < 0 { return 0, errors.New("syntax error") } read := 6 if utf16.IsSurrogate(rr) { rr1 := getu4(data[read:]) if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar { read += 6 rr = dec } else { rr = unicode.ReplacementChar } } var d [4]byte s := utf8.EncodeRune(d[:], rr) r.token.byteValue = append(r.token.byteValue, d[:s]...) return read, nil } return 0, errors.New("syntax error") }
[ "func", "(", "r", "*", "Lexer", ")", "processEscape", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "data", ")", "<", "2", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"syntax error at %v\"", ",", "string", "(", "data", ")", ")", "\n", "}", "\n", "c", ":=", "data", "[", "1", "]", "\n", "switch", "c", "{", "case", "'\"'", ",", "'/'", ",", "'\\\\'", ":", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "c", ")", "\n", "return", "2", ",", "nil", "\n", "case", "'b'", ":", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "'\\b'", ")", "\n", "return", "2", ",", "nil", "\n", "case", "'f'", ":", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "'\\f'", ")", "\n", "return", "2", ",", "nil", "\n", "case", "'n'", ":", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "'\\n'", ")", "\n", "return", "2", ",", "nil", "\n", "case", "'r'", ":", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "'\\r'", ")", "\n", "return", "2", ",", "nil", "\n", "case", "'t'", ":", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "'\\t'", ")", "\n", "return", "2", ",", "nil", "\n", "case", "'u'", ":", "rr", ":=", "getu4", "(", "data", ")", "\n", "if", "rr", "<", "0", "{", "return", "0", ",", "errors", ".", "New", "(", "\"syntax error\"", ")", "\n", "}", "\n", "read", ":=", "6", "\n", "if", "utf16", ".", "IsSurrogate", "(", "rr", ")", "{", "rr1", ":=", "getu4", "(", "data", "[", "read", ":", "]", ")", "\n", "if", "dec", ":=", "utf16", ".", "DecodeRune", "(", "rr", ",", "rr1", ")", ";", "dec", "!=", "unicode", ".", "ReplacementChar", "{", "read", "+=", "6", "\n", "rr", "=", "dec", "\n", "}", "else", "{", "rr", "=", "unicode", ".", "ReplacementChar", "\n", "}", "\n", "}", "\n", "var", "d", "[", "4", "]", "byte", "\n", "s", ":=", "utf8", ".", "EncodeRune", "(", "d", "[", ":", "]", ",", "rr", ")", "\n", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "d", "[", ":", "s", "]", "...", ")", "\n", "return", "read", ",", "nil", "\n", "}", "\n", "return", "0", ",", "errors", ".", "New", "(", "\"syntax error\"", ")", "\n", "}" ]
// processEscape processes a single escape sequence and returns number of bytes processed.
[ "processEscape", "processes", "a", "single", "escape", "sequence", "and", "returns", "number", "of", "bytes", "processed", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L290-L338
train
mailru/easyjson
jlexer/lexer.go
fetchString
func (r *Lexer) fetchString() { r.pos++ data := r.Data[r.pos:] isValid, hasEscapes, length := findStringLen(data) if !isValid { r.pos += length r.errParse("unterminated string literal") return } if !hasEscapes { r.token.byteValue = data[:length] r.pos += length + 1 return } r.token.byteValue = make([]byte, 0, length) p := 0 for i := 0; i < len(data); { switch data[i] { case '"': r.pos += i + 1 r.token.byteValue = append(r.token.byteValue, data[p:i]...) i++ return case '\\': r.token.byteValue = append(r.token.byteValue, data[p:i]...) off, err := r.processEscape(data[i:]) if err != nil { r.errParse(err.Error()) return } i += off p = i default: i++ } } r.errParse("unterminated string literal") }
go
func (r *Lexer) fetchString() { r.pos++ data := r.Data[r.pos:] isValid, hasEscapes, length := findStringLen(data) if !isValid { r.pos += length r.errParse("unterminated string literal") return } if !hasEscapes { r.token.byteValue = data[:length] r.pos += length + 1 return } r.token.byteValue = make([]byte, 0, length) p := 0 for i := 0; i < len(data); { switch data[i] { case '"': r.pos += i + 1 r.token.byteValue = append(r.token.byteValue, data[p:i]...) i++ return case '\\': r.token.byteValue = append(r.token.byteValue, data[p:i]...) off, err := r.processEscape(data[i:]) if err != nil { r.errParse(err.Error()) return } i += off p = i default: i++ } } r.errParse("unterminated string literal") }
[ "func", "(", "r", "*", "Lexer", ")", "fetchString", "(", ")", "{", "r", ".", "pos", "++", "\n", "data", ":=", "r", ".", "Data", "[", "r", ".", "pos", ":", "]", "\n", "isValid", ",", "hasEscapes", ",", "length", ":=", "findStringLen", "(", "data", ")", "\n", "if", "!", "isValid", "{", "r", ".", "pos", "+=", "length", "\n", "r", ".", "errParse", "(", "\"unterminated string literal\"", ")", "\n", "return", "\n", "}", "\n", "if", "!", "hasEscapes", "{", "r", ".", "token", ".", "byteValue", "=", "data", "[", ":", "length", "]", "\n", "r", ".", "pos", "+=", "length", "+", "1", "\n", "return", "\n", "}", "\n", "r", ".", "token", ".", "byteValue", "=", "make", "(", "[", "]", "byte", ",", "0", ",", "length", ")", "\n", "p", ":=", "0", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "data", ")", ";", "{", "switch", "data", "[", "i", "]", "{", "case", "'\"'", ":", "r", ".", "pos", "+=", "i", "+", "1", "\n", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "data", "[", "p", ":", "i", "]", "...", ")", "\n", "i", "++", "\n", "return", "\n", "case", "'\\\\'", ":", "r", ".", "token", ".", "byteValue", "=", "append", "(", "r", ".", "token", ".", "byteValue", ",", "data", "[", "p", ":", "i", "]", "...", ")", "\n", "off", ",", "err", ":=", "r", ".", "processEscape", "(", "data", "[", "i", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "r", ".", "errParse", "(", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "i", "+=", "off", "\n", "p", "=", "i", "\n", "default", ":", "i", "++", "\n", "}", "\n", "}", "\n", "r", ".", "errParse", "(", "\"unterminated string literal\"", ")", "\n", "}" ]
// fetchString scans a string literal token.
[ "fetchString", "scans", "a", "string", "literal", "token", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L341-L382
train
mailru/easyjson
jlexer/lexer.go
scanToken
func (r *Lexer) scanToken() { if r.token.kind != tokenUndef || r.fatalError != nil { return } r.FetchToken() }
go
func (r *Lexer) scanToken() { if r.token.kind != tokenUndef || r.fatalError != nil { return } r.FetchToken() }
[ "func", "(", "r", "*", "Lexer", ")", "scanToken", "(", ")", "{", "if", "r", ".", "token", ".", "kind", "!=", "tokenUndef", "||", "r", ".", "fatalError", "!=", "nil", "{", "return", "\n", "}", "\n", "r", ".", "FetchToken", "(", ")", "\n", "}" ]
// scanToken scans the next token if no token is currently available in the lexer.
[ "scanToken", "scans", "the", "next", "token", "if", "no", "token", "is", "currently", "available", "in", "the", "lexer", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L385-L391
train
mailru/easyjson
jlexer/lexer.go
consume
func (r *Lexer) consume() { r.token.kind = tokenUndef r.token.delimValue = 0 }
go
func (r *Lexer) consume() { r.token.kind = tokenUndef r.token.delimValue = 0 }
[ "func", "(", "r", "*", "Lexer", ")", "consume", "(", ")", "{", "r", ".", "token", ".", "kind", "=", "tokenUndef", "\n", "r", ".", "token", ".", "delimValue", "=", "0", "\n", "}" ]
// consume resets the current token to allow scanning the next one.
[ "consume", "resets", "the", "current", "token", "to", "allow", "scanning", "the", "next", "one", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L394-L397
train
mailru/easyjson
jlexer/lexer.go
Delim
func (r *Lexer) Delim(c byte) { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.delimValue != c { r.consume() // errInvalidToken can change token if UseMultipleErrors is enabled. r.errInvalidToken(string([]byte{c})) } else { r.consume() } }
go
func (r *Lexer) Delim(c byte) { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.delimValue != c { r.consume() // errInvalidToken can change token if UseMultipleErrors is enabled. r.errInvalidToken(string([]byte{c})) } else { r.consume() } }
[ "func", "(", "r", "*", "Lexer", ")", "Delim", "(", "c", "byte", ")", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "if", "!", "r", ".", "Ok", "(", ")", "||", "r", ".", "token", ".", "delimValue", "!=", "c", "{", "r", ".", "consume", "(", ")", "\n", "r", ".", "errInvalidToken", "(", "string", "(", "[", "]", "byte", "{", "c", "}", ")", ")", "\n", "}", "else", "{", "r", ".", "consume", "(", ")", "\n", "}", "\n", "}" ]
// Delim consumes a token and verifies that it is the given delimiter.
[ "Delim", "consumes", "a", "token", "and", "verifies", "that", "it", "is", "the", "given", "delimiter", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L468-L479
train
mailru/easyjson
jlexer/lexer.go
IsDelim
func (r *Lexer) IsDelim(c byte) bool { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } return !r.Ok() || r.token.delimValue == c }
go
func (r *Lexer) IsDelim(c byte) bool { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } return !r.Ok() || r.token.delimValue == c }
[ "func", "(", "r", "*", "Lexer", ")", "IsDelim", "(", "c", "byte", ")", "bool", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "return", "!", "r", ".", "Ok", "(", ")", "||", "r", ".", "token", ".", "delimValue", "==", "c", "\n", "}" ]
// IsDelim returns true if there was no scanning error and next token is the given delimiter.
[ "IsDelim", "returns", "true", "if", "there", "was", "no", "scanning", "error", "and", "next", "token", "is", "the", "given", "delimiter", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L482-L487
train
mailru/easyjson
jlexer/lexer.go
Null
func (r *Lexer) Null() { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenNull { r.errInvalidToken("null") } r.consume() }
go
func (r *Lexer) Null() { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenNull { r.errInvalidToken("null") } r.consume() }
[ "func", "(", "r", "*", "Lexer", ")", "Null", "(", ")", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "if", "!", "r", ".", "Ok", "(", ")", "||", "r", ".", "token", ".", "kind", "!=", "tokenNull", "{", "r", ".", "errInvalidToken", "(", "\"null\"", ")", "\n", "}", "\n", "r", ".", "consume", "(", ")", "\n", "}" ]
// Null verifies that the next token is null and consumes it.
[ "Null", "verifies", "that", "the", "next", "token", "is", "null", "and", "consumes", "it", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L490-L498
train
mailru/easyjson
jlexer/lexer.go
IsNull
func (r *Lexer) IsNull() bool { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } return r.Ok() && r.token.kind == tokenNull }
go
func (r *Lexer) IsNull() bool { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } return r.Ok() && r.token.kind == tokenNull }
[ "func", "(", "r", "*", "Lexer", ")", "IsNull", "(", ")", "bool", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "return", "r", ".", "Ok", "(", ")", "&&", "r", ".", "token", ".", "kind", "==", "tokenNull", "\n", "}" ]
// IsNull returns true if the next token is a null keyword.
[ "IsNull", "returns", "true", "if", "the", "next", "token", "is", "a", "null", "keyword", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L501-L506
train
mailru/easyjson
jlexer/lexer.go
Skip
func (r *Lexer) Skip() { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } r.consume() }
go
func (r *Lexer) Skip() { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } r.consume() }
[ "func", "(", "r", "*", "Lexer", ")", "Skip", "(", ")", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "r", ".", "consume", "(", ")", "\n", "}" ]
// Skip skips a single token.
[ "Skip", "skips", "a", "single", "token", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L509-L514
train
mailru/easyjson
jlexer/lexer.go
Raw
func (r *Lexer) Raw() []byte { r.SkipRecursive() if !r.Ok() { return nil } return r.Data[r.start:r.pos] }
go
func (r *Lexer) Raw() []byte { r.SkipRecursive() if !r.Ok() { return nil } return r.Data[r.start:r.pos] }
[ "func", "(", "r", "*", "Lexer", ")", "Raw", "(", ")", "[", "]", "byte", "{", "r", ".", "SkipRecursive", "(", ")", "\n", "if", "!", "r", ".", "Ok", "(", ")", "{", "return", "nil", "\n", "}", "\n", "return", "r", ".", "Data", "[", "r", ".", "start", ":", "r", ".", "pos", "]", "\n", "}" ]
// Raw fetches the next item recursively as a data slice
[ "Raw", "fetches", "the", "next", "item", "recursively", "as", "a", "data", "slice" ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L569-L575
train
mailru/easyjson
jlexer/lexer.go
Consumed
func (r *Lexer) Consumed() { if r.pos > len(r.Data) || !r.Ok() { return } for _, c := range r.Data[r.pos:] { if c != ' ' && c != '\t' && c != '\r' && c != '\n' { r.AddError(&LexerError{ Reason: "invalid character '" + string(c) + "' after top-level value", Offset: r.pos, Data: string(r.Data[r.pos:]), }) return } r.pos++ r.start++ } }
go
func (r *Lexer) Consumed() { if r.pos > len(r.Data) || !r.Ok() { return } for _, c := range r.Data[r.pos:] { if c != ' ' && c != '\t' && c != '\r' && c != '\n' { r.AddError(&LexerError{ Reason: "invalid character '" + string(c) + "' after top-level value", Offset: r.pos, Data: string(r.Data[r.pos:]), }) return } r.pos++ r.start++ } }
[ "func", "(", "r", "*", "Lexer", ")", "Consumed", "(", ")", "{", "if", "r", ".", "pos", ">", "len", "(", "r", ".", "Data", ")", "||", "!", "r", ".", "Ok", "(", ")", "{", "return", "\n", "}", "\n", "for", "_", ",", "c", ":=", "range", "r", ".", "Data", "[", "r", ".", "pos", ":", "]", "{", "if", "c", "!=", "' '", "&&", "c", "!=", "'\\t'", "&&", "c", "!=", "'\\r'", "&&", "c", "!=", "'\\n'", "{", "r", ".", "AddError", "(", "&", "LexerError", "{", "Reason", ":", "\"invalid character '\"", "+", "string", "(", "c", ")", "+", "\"' after top-level value\"", ",", "Offset", ":", "r", ".", "pos", ",", "Data", ":", "string", "(", "r", ".", "Data", "[", "r", ".", "pos", ":", "]", ")", ",", "}", ")", "\n", "return", "\n", "}", "\n", "r", ".", "pos", "++", "\n", "r", ".", "start", "++", "\n", "}", "\n", "}" ]
// Consumed reads all remaining bytes from the input, publishing an error if // there is anything but whitespace remaining.
[ "Consumed", "reads", "all", "remaining", "bytes", "from", "the", "input", "publishing", "an", "error", "if", "there", "is", "anything", "but", "whitespace", "remaining", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L585-L603
train
mailru/easyjson
jlexer/lexer.go
String
func (r *Lexer) String() string { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenString { r.errInvalidToken("string") return "" } ret := string(r.token.byteValue) r.consume() return ret }
go
func (r *Lexer) String() string { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenString { r.errInvalidToken("string") return "" } ret := string(r.token.byteValue) r.consume() return ret }
[ "func", "(", "r", "*", "Lexer", ")", "String", "(", ")", "string", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "if", "!", "r", ".", "Ok", "(", ")", "||", "r", ".", "token", ".", "kind", "!=", "tokenString", "{", "r", ".", "errInvalidToken", "(", "\"string\"", ")", "\n", "return", "\"\"", "\n", "}", "\n", "ret", ":=", "string", "(", "r", ".", "token", ".", "byteValue", ")", "\n", "r", ".", "consume", "(", ")", "\n", "return", "ret", "\n", "}" ]
// String reads a string literal.
[ "String", "reads", "a", "string", "literal", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L635-L646
train
mailru/easyjson
jlexer/lexer.go
Bytes
func (r *Lexer) Bytes() []byte { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenString { r.errInvalidToken("string") return nil } ret := make([]byte, base64.StdEncoding.DecodedLen(len(r.token.byteValue))) n, err := base64.StdEncoding.Decode(ret, r.token.byteValue) if err != nil { r.fatalError = &LexerError{ Reason: err.Error(), } return nil } r.consume() return ret[:n] }
go
func (r *Lexer) Bytes() []byte { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenString { r.errInvalidToken("string") return nil } ret := make([]byte, base64.StdEncoding.DecodedLen(len(r.token.byteValue))) n, err := base64.StdEncoding.Decode(ret, r.token.byteValue) if err != nil { r.fatalError = &LexerError{ Reason: err.Error(), } return nil } r.consume() return ret[:n] }
[ "func", "(", "r", "*", "Lexer", ")", "Bytes", "(", ")", "[", "]", "byte", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "if", "!", "r", ".", "Ok", "(", ")", "||", "r", ".", "token", ".", "kind", "!=", "tokenString", "{", "r", ".", "errInvalidToken", "(", "\"string\"", ")", "\n", "return", "nil", "\n", "}", "\n", "ret", ":=", "make", "(", "[", "]", "byte", ",", "base64", ".", "StdEncoding", ".", "DecodedLen", "(", "len", "(", "r", ".", "token", ".", "byteValue", ")", ")", ")", "\n", "n", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "Decode", "(", "ret", ",", "r", ".", "token", ".", "byteValue", ")", "\n", "if", "err", "!=", "nil", "{", "r", ".", "fatalError", "=", "&", "LexerError", "{", "Reason", ":", "err", ".", "Error", "(", ")", ",", "}", "\n", "return", "nil", "\n", "}", "\n", "r", ".", "consume", "(", ")", "\n", "return", "ret", "[", ":", "n", "]", "\n", "}" ]
// Bytes reads a string literal and base64 decodes it into a byte slice.
[ "Bytes", "reads", "a", "string", "literal", "and", "base64", "decodes", "it", "into", "a", "byte", "slice", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L649-L668
train
mailru/easyjson
jlexer/lexer.go
Bool
func (r *Lexer) Bool() bool { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenBool { r.errInvalidToken("bool") return false } ret := r.token.boolValue r.consume() return ret }
go
func (r *Lexer) Bool() bool { if r.token.kind == tokenUndef && r.Ok() { r.FetchToken() } if !r.Ok() || r.token.kind != tokenBool { r.errInvalidToken("bool") return false } ret := r.token.boolValue r.consume() return ret }
[ "func", "(", "r", "*", "Lexer", ")", "Bool", "(", ")", "bool", "{", "if", "r", ".", "token", ".", "kind", "==", "tokenUndef", "&&", "r", ".", "Ok", "(", ")", "{", "r", ".", "FetchToken", "(", ")", "\n", "}", "\n", "if", "!", "r", ".", "Ok", "(", ")", "||", "r", ".", "token", ".", "kind", "!=", "tokenBool", "{", "r", ".", "errInvalidToken", "(", "\"bool\"", ")", "\n", "return", "false", "\n", "}", "\n", "ret", ":=", "r", ".", "token", ".", "boolValue", "\n", "r", ".", "consume", "(", ")", "\n", "return", "ret", "\n", "}" ]
// Bool reads a true or false boolean keyword.
[ "Bool", "reads", "a", "true", "or", "false", "boolean", "keyword", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L671-L682
train
mailru/easyjson
helpers.go
Marshal
func Marshal(v Marshaler) ([]byte, error) { w := jwriter.Writer{} v.MarshalEasyJSON(&w) return w.BuildBytes() }
go
func Marshal(v Marshaler) ([]byte, error) { w := jwriter.Writer{} v.MarshalEasyJSON(&w) return w.BuildBytes() }
[ "func", "Marshal", "(", "v", "Marshaler", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "w", ":=", "jwriter", ".", "Writer", "{", "}", "\n", "v", ".", "MarshalEasyJSON", "(", "&", "w", ")", "\n", "return", "w", ".", "BuildBytes", "(", ")", "\n", "}" ]
// Marshal returns data as a single byte slice. Method is suboptimal as the data is likely to be copied // from a chain of smaller chunks.
[ "Marshal", "returns", "data", "as", "a", "single", "byte", "slice", ".", "Method", "is", "suboptimal", "as", "the", "data", "is", "likely", "to", "be", "copied", "from", "a", "chain", "of", "smaller", "chunks", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/helpers.go#L31-L35
train
mailru/easyjson
helpers.go
MarshalToWriter
func MarshalToWriter(v Marshaler, w io.Writer) (written int, err error) { jw := jwriter.Writer{} v.MarshalEasyJSON(&jw) return jw.DumpTo(w) }
go
func MarshalToWriter(v Marshaler, w io.Writer) (written int, err error) { jw := jwriter.Writer{} v.MarshalEasyJSON(&jw) return jw.DumpTo(w) }
[ "func", "MarshalToWriter", "(", "v", "Marshaler", ",", "w", "io", ".", "Writer", ")", "(", "written", "int", ",", "err", "error", ")", "{", "jw", ":=", "jwriter", ".", "Writer", "{", "}", "\n", "v", ".", "MarshalEasyJSON", "(", "&", "jw", ")", "\n", "return", "jw", ".", "DumpTo", "(", "w", ")", "\n", "}" ]
// MarshalToWriter marshals the data to an io.Writer.
[ "MarshalToWriter", "marshals", "the", "data", "to", "an", "io", ".", "Writer", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/helpers.go#L38-L42
train
mailru/easyjson
helpers.go
Unmarshal
func Unmarshal(data []byte, v Unmarshaler) error { l := jlexer.Lexer{Data: data} v.UnmarshalEasyJSON(&l) return l.Error() }
go
func Unmarshal(data []byte, v Unmarshaler) error { l := jlexer.Lexer{Data: data} v.UnmarshalEasyJSON(&l) return l.Error() }
[ "func", "Unmarshal", "(", "data", "[", "]", "byte", ",", "v", "Unmarshaler", ")", "error", "{", "l", ":=", "jlexer", ".", "Lexer", "{", "Data", ":", "data", "}", "\n", "v", ".", "UnmarshalEasyJSON", "(", "&", "l", ")", "\n", "return", "l", ".", "Error", "(", ")", "\n", "}" ]
// Unmarshal decodes the JSON in data into the object.
[ "Unmarshal", "decodes", "the", "JSON", "in", "data", "into", "the", "object", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/helpers.go#L63-L67
train
mailru/easyjson
helpers.go
UnmarshalFromReader
func UnmarshalFromReader(r io.Reader, v Unmarshaler) error { data, err := ioutil.ReadAll(r) if err != nil { return err } l := jlexer.Lexer{Data: data} v.UnmarshalEasyJSON(&l) return l.Error() }
go
func UnmarshalFromReader(r io.Reader, v Unmarshaler) error { data, err := ioutil.ReadAll(r) if err != nil { return err } l := jlexer.Lexer{Data: data} v.UnmarshalEasyJSON(&l) return l.Error() }
[ "func", "UnmarshalFromReader", "(", "r", "io", ".", "Reader", ",", "v", "Unmarshaler", ")", "error", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "l", ":=", "jlexer", ".", "Lexer", "{", "Data", ":", "data", "}", "\n", "v", ".", "UnmarshalEasyJSON", "(", "&", "l", ")", "\n", "return", "l", ".", "Error", "(", ")", "\n", "}" ]
// UnmarshalFromReader reads all the data in the reader and decodes as JSON into the object.
[ "UnmarshalFromReader", "reads", "all", "the", "data", "in", "the", "reader", "and", "decodes", "as", "JSON", "into", "the", "object", "." ]
1ea4449da9834f4d333f1cc461c374aea217d249
https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/helpers.go#L70-L78
train
fogleman/gg
gradient.go
Less
func (s stops) Less(i, j int) bool { return s[i].pos < s[j].pos }
go
func (s stops) Less(i, j int) bool { return s[i].pos < s[j].pos }
[ "func", "(", "s", "stops", ")", "Less", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "s", "[", "i", "]", ".", "pos", "<", "s", "[", "j", "]", ".", "pos", "\n", "}" ]
// Less satisfies the Sort interface.
[ "Less", "satisfies", "the", "Sort", "interface", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/gradient.go#L22-L24
train
fogleman/gg
gradient.go
Swap
func (s stops) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
go
func (s stops) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
[ "func", "(", "s", "stops", ")", "Swap", "(", "i", ",", "j", "int", ")", "{", "s", "[", "i", "]", ",", "s", "[", "j", "]", "=", "s", "[", "j", "]", ",", "s", "[", "i", "]", "\n", "}" ]
// Swap satisfies the Sort interface.
[ "Swap", "satisfies", "the", "Sort", "interface", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/gradient.go#L27-L29
train
fogleman/gg
util.go
LoadFontFace
func LoadFontFace(path string, points float64) (font.Face, error) { fontBytes, err := ioutil.ReadFile(path) if err != nil { return nil, err } f, err := truetype.Parse(fontBytes) if err != nil { return nil, err } face := truetype.NewFace(f, &truetype.Options{ Size: points, // Hinting: font.HintingFull, }) return face, nil }
go
func LoadFontFace(path string, points float64) (font.Face, error) { fontBytes, err := ioutil.ReadFile(path) if err != nil { return nil, err } f, err := truetype.Parse(fontBytes) if err != nil { return nil, err } face := truetype.NewFace(f, &truetype.Options{ Size: points, // Hinting: font.HintingFull, }) return face, nil }
[ "func", "LoadFontFace", "(", "path", "string", ",", "points", "float64", ")", "(", "font", ".", "Face", ",", "error", ")", "{", "fontBytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "f", ",", "err", ":=", "truetype", ".", "Parse", "(", "fontBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "face", ":=", "truetype", ".", "NewFace", "(", "f", ",", "&", "truetype", ".", "Options", "{", "Size", ":", "points", ",", "}", ")", "\n", "return", "face", ",", "nil", "\n", "}" ]
// LoadFontFace is a helper function to load the specified font file with // the specified point size. Note that the returned `font.Face` objects // are not thread safe and cannot be used in parallel across goroutines. // You can usually just use the Context.LoadFontFace function instead of // this package-level function.
[ "LoadFontFace", "is", "a", "helper", "function", "to", "load", "the", "specified", "font", "file", "with", "the", "specified", "point", "size", ".", "Note", "that", "the", "returned", "font", ".", "Face", "objects", "are", "not", "thread", "safe", "and", "cannot", "be", "used", "in", "parallel", "across", "goroutines", ".", "You", "can", "usually", "just", "use", "the", "Context", ".", "LoadFontFace", "function", "instead", "of", "this", "package", "-", "level", "function", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/util.go#L132-L146
train
fogleman/gg
context.go
NewContext
func NewContext(width, height int) *Context { return NewContextForRGBA(image.NewRGBA(image.Rect(0, 0, width, height))) }
go
func NewContext(width, height int) *Context { return NewContextForRGBA(image.NewRGBA(image.Rect(0, 0, width, height))) }
[ "func", "NewContext", "(", "width", ",", "height", "int", ")", "*", "Context", "{", "return", "NewContextForRGBA", "(", "image", ".", "NewRGBA", "(", "image", ".", "Rect", "(", "0", ",", "0", ",", "width", ",", "height", ")", ")", ")", "\n", "}" ]
// NewContext creates a new image.RGBA with the specified width and height // and prepares a context for rendering onto that image.
[ "NewContext", "creates", "a", "new", "image", ".", "RGBA", "with", "the", "specified", "width", "and", "height", "and", "prepares", "a", "context", "for", "rendering", "onto", "that", "image", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L83-L85
train
fogleman/gg
context.go
NewContextForRGBA
func NewContextForRGBA(im *image.RGBA) *Context { w := im.Bounds().Size().X h := im.Bounds().Size().Y return &Context{ width: w, height: h, rasterizer: raster.NewRasterizer(w, h), im: im, color: color.Transparent, fillPattern: defaultFillStyle, strokePattern: defaultStrokeStyle, lineWidth: 1, fillRule: FillRuleWinding, fontFace: basicfont.Face7x13, fontHeight: 13, matrix: Identity(), } }
go
func NewContextForRGBA(im *image.RGBA) *Context { w := im.Bounds().Size().X h := im.Bounds().Size().Y return &Context{ width: w, height: h, rasterizer: raster.NewRasterizer(w, h), im: im, color: color.Transparent, fillPattern: defaultFillStyle, strokePattern: defaultStrokeStyle, lineWidth: 1, fillRule: FillRuleWinding, fontFace: basicfont.Face7x13, fontHeight: 13, matrix: Identity(), } }
[ "func", "NewContextForRGBA", "(", "im", "*", "image", ".", "RGBA", ")", "*", "Context", "{", "w", ":=", "im", ".", "Bounds", "(", ")", ".", "Size", "(", ")", ".", "X", "\n", "h", ":=", "im", ".", "Bounds", "(", ")", ".", "Size", "(", ")", ".", "Y", "\n", "return", "&", "Context", "{", "width", ":", "w", ",", "height", ":", "h", ",", "rasterizer", ":", "raster", ".", "NewRasterizer", "(", "w", ",", "h", ")", ",", "im", ":", "im", ",", "color", ":", "color", ".", "Transparent", ",", "fillPattern", ":", "defaultFillStyle", ",", "strokePattern", ":", "defaultStrokeStyle", ",", "lineWidth", ":", "1", ",", "fillRule", ":", "FillRuleWinding", ",", "fontFace", ":", "basicfont", ".", "Face7x13", ",", "fontHeight", ":", "13", ",", "matrix", ":", "Identity", "(", ")", ",", "}", "\n", "}" ]
// NewContextForRGBA prepares a context for rendering onto the specified image. // No copy is made.
[ "NewContextForRGBA", "prepares", "a", "context", "for", "rendering", "onto", "the", "specified", "image", ".", "No", "copy", "is", "made", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L95-L112
train
fogleman/gg
context.go
GetCurrentPoint
func (dc *Context) GetCurrentPoint() (Point, bool) { if dc.hasCurrent { return dc.current, true } return Point{}, false }
go
func (dc *Context) GetCurrentPoint() (Point, bool) { if dc.hasCurrent { return dc.current, true } return Point{}, false }
[ "func", "(", "dc", "*", "Context", ")", "GetCurrentPoint", "(", ")", "(", "Point", ",", "bool", ")", "{", "if", "dc", ".", "hasCurrent", "{", "return", "dc", ".", "current", ",", "true", "\n", "}", "\n", "return", "Point", "{", "}", ",", "false", "\n", "}" ]
// GetCurrentPoint will return the current point and if there is a current point. // The point will have been transformed by the context's transformation matrix.
[ "GetCurrentPoint", "will", "return", "the", "current", "point", "and", "if", "there", "is", "a", "current", "point", ".", "The", "point", "will", "have", "been", "transformed", "by", "the", "context", "s", "transformation", "matrix", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L116-L121
train
fogleman/gg
context.go
SavePNG
func (dc *Context) SavePNG(path string) error { return SavePNG(path, dc.im) }
go
func (dc *Context) SavePNG(path string) error { return SavePNG(path, dc.im) }
[ "func", "(", "dc", "*", "Context", ")", "SavePNG", "(", "path", "string", ")", "error", "{", "return", "SavePNG", "(", "path", ",", "dc", ".", "im", ")", "\n", "}" ]
// SavePNG encodes the image as a PNG and writes it to disk.
[ "SavePNG", "encodes", "the", "image", "as", "a", "PNG", "and", "writes", "it", "to", "disk", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L139-L141
train
fogleman/gg
context.go
SaveJPG
func (dc *Context) SaveJPG(path string, quality int) error { return SaveJPG(path, dc.im, quality) }
go
func (dc *Context) SaveJPG(path string, quality int) error { return SaveJPG(path, dc.im, quality) }
[ "func", "(", "dc", "*", "Context", ")", "SaveJPG", "(", "path", "string", ",", "quality", "int", ")", "error", "{", "return", "SaveJPG", "(", "path", ",", "dc", ".", "im", ",", "quality", ")", "\n", "}" ]
// SaveJPG encodes the image as a JPG and writes it to disk.
[ "SaveJPG", "encodes", "the", "image", "as", "a", "JPG", "and", "writes", "it", "to", "disk", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L144-L146
train
fogleman/gg
context.go
EncodePNG
func (dc *Context) EncodePNG(w io.Writer) error { return png.Encode(w, dc.im) }
go
func (dc *Context) EncodePNG(w io.Writer) error { return png.Encode(w, dc.im) }
[ "func", "(", "dc", "*", "Context", ")", "EncodePNG", "(", "w", "io", ".", "Writer", ")", "error", "{", "return", "png", ".", "Encode", "(", "w", ",", "dc", ".", "im", ")", "\n", "}" ]
// EncodePNG encodes the image as a PNG and writes it to the provided io.Writer.
[ "EncodePNG", "encodes", "the", "image", "as", "a", "PNG", "and", "writes", "it", "to", "the", "provided", "io", ".", "Writer", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L149-L151
train
fogleman/gg
context.go
SetFillStyle
func (dc *Context) SetFillStyle(pattern Pattern) { // if pattern is SolidPattern, also change dc.color(for dc.Clear, dc.drawString) if fillStyle, ok := pattern.(*solidPattern); ok { dc.color = fillStyle.color } dc.fillPattern = pattern }
go
func (dc *Context) SetFillStyle(pattern Pattern) { // if pattern is SolidPattern, also change dc.color(for dc.Clear, dc.drawString) if fillStyle, ok := pattern.(*solidPattern); ok { dc.color = fillStyle.color } dc.fillPattern = pattern }
[ "func", "(", "dc", "*", "Context", ")", "SetFillStyle", "(", "pattern", "Pattern", ")", "{", "if", "fillStyle", ",", "ok", ":=", "pattern", ".", "(", "*", "solidPattern", ")", ";", "ok", "{", "dc", ".", "color", "=", "fillStyle", ".", "color", "\n", "}", "\n", "dc", ".", "fillPattern", "=", "pattern", "\n", "}" ]
// SetFillStyle sets current fill style
[ "SetFillStyle", "sets", "current", "fill", "style" ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L219-L225
train
fogleman/gg
context.go
SetRGBA255
func (dc *Context) SetRGBA255(r, g, b, a int) { dc.color = color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(a)} dc.setFillAndStrokeColor(dc.color) }
go
func (dc *Context) SetRGBA255(r, g, b, a int) { dc.color = color.NRGBA{uint8(r), uint8(g), uint8(b), uint8(a)} dc.setFillAndStrokeColor(dc.color) }
[ "func", "(", "dc", "*", "Context", ")", "SetRGBA255", "(", "r", ",", "g", ",", "b", ",", "a", "int", ")", "{", "dc", ".", "color", "=", "color", ".", "NRGBA", "{", "uint8", "(", "r", ")", ",", "uint8", "(", "g", ")", ",", "uint8", "(", "b", ")", ",", "uint8", "(", "a", ")", "}", "\n", "dc", ".", "setFillAndStrokeColor", "(", "dc", ".", "color", ")", "\n", "}" ]
// SetRGBA255 sets the current color. r, g, b, a values should be between 0 and // 255, inclusive.
[ "SetRGBA255", "sets", "the", "current", "color", ".", "r", "g", "b", "a", "values", "should", "be", "between", "0", "and", "255", "inclusive", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L247-L250
train
fogleman/gg
context.go
SetRGBA
func (dc *Context) SetRGBA(r, g, b, a float64) { dc.color = color.NRGBA{ uint8(r * 255), uint8(g * 255), uint8(b * 255), uint8(a * 255), } dc.setFillAndStrokeColor(dc.color) }
go
func (dc *Context) SetRGBA(r, g, b, a float64) { dc.color = color.NRGBA{ uint8(r * 255), uint8(g * 255), uint8(b * 255), uint8(a * 255), } dc.setFillAndStrokeColor(dc.color) }
[ "func", "(", "dc", "*", "Context", ")", "SetRGBA", "(", "r", ",", "g", ",", "b", ",", "a", "float64", ")", "{", "dc", ".", "color", "=", "color", ".", "NRGBA", "{", "uint8", "(", "r", "*", "255", ")", ",", "uint8", "(", "g", "*", "255", ")", ",", "uint8", "(", "b", "*", "255", ")", ",", "uint8", "(", "a", "*", "255", ")", ",", "}", "\n", "dc", ".", "setFillAndStrokeColor", "(", "dc", ".", "color", ")", "\n", "}" ]
// SetRGBA sets the current color. r, g, b, a values should be between 0 and 1, // inclusive.
[ "SetRGBA", "sets", "the", "current", "color", ".", "r", "g", "b", "a", "values", "should", "be", "between", "0", "and", "1", "inclusive", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L260-L268
train
fogleman/gg
context.go
MoveTo
func (dc *Context) MoveTo(x, y float64) { if dc.hasCurrent { dc.fillPath.Add1(dc.start.Fixed()) } x, y = dc.TransformPoint(x, y) p := Point{x, y} dc.strokePath.Start(p.Fixed()) dc.fillPath.Start(p.Fixed()) dc.start = p dc.current = p dc.hasCurrent = true }
go
func (dc *Context) MoveTo(x, y float64) { if dc.hasCurrent { dc.fillPath.Add1(dc.start.Fixed()) } x, y = dc.TransformPoint(x, y) p := Point{x, y} dc.strokePath.Start(p.Fixed()) dc.fillPath.Start(p.Fixed()) dc.start = p dc.current = p dc.hasCurrent = true }
[ "func", "(", "dc", "*", "Context", ")", "MoveTo", "(", "x", ",", "y", "float64", ")", "{", "if", "dc", ".", "hasCurrent", "{", "dc", ".", "fillPath", ".", "Add1", "(", "dc", ".", "start", ".", "Fixed", "(", ")", ")", "\n", "}", "\n", "x", ",", "y", "=", "dc", ".", "TransformPoint", "(", "x", ",", "y", ")", "\n", "p", ":=", "Point", "{", "x", ",", "y", "}", "\n", "dc", ".", "strokePath", ".", "Start", "(", "p", ".", "Fixed", "(", ")", ")", "\n", "dc", ".", "fillPath", ".", "Start", "(", "p", ".", "Fixed", "(", ")", ")", "\n", "dc", ".", "start", "=", "p", "\n", "dc", ".", "current", "=", "p", "\n", "dc", ".", "hasCurrent", "=", "true", "\n", "}" ]
// Path Manipulation // MoveTo starts a new subpath within the current path starting at the // specified point.
[ "Path", "Manipulation", "MoveTo", "starts", "a", "new", "subpath", "within", "the", "current", "path", "starting", "at", "the", "specified", "point", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L280-L291
train
fogleman/gg
context.go
ClosePath
func (dc *Context) ClosePath() { if dc.hasCurrent { dc.strokePath.Add1(dc.start.Fixed()) dc.fillPath.Add1(dc.start.Fixed()) dc.current = dc.start } }
go
func (dc *Context) ClosePath() { if dc.hasCurrent { dc.strokePath.Add1(dc.start.Fixed()) dc.fillPath.Add1(dc.start.Fixed()) dc.current = dc.start } }
[ "func", "(", "dc", "*", "Context", ")", "ClosePath", "(", ")", "{", "if", "dc", ".", "hasCurrent", "{", "dc", ".", "strokePath", ".", "Add1", "(", "dc", ".", "start", ".", "Fixed", "(", ")", ")", "\n", "dc", ".", "fillPath", ".", "Add1", "(", "dc", ".", "start", ".", "Fixed", "(", ")", ")", "\n", "dc", ".", "current", "=", "dc", ".", "start", "\n", "}", "\n", "}" ]
// ClosePath adds a line segment from the current point to the beginning // of the current subpath. If there is no current point, this is a no-op.
[ "ClosePath", "adds", "a", "line", "segment", "from", "the", "current", "point", "to", "the", "beginning", "of", "the", "current", "subpath", ".", "If", "there", "is", "no", "current", "point", "this", "is", "a", "no", "-", "op", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L352-L358
train
fogleman/gg
context.go
ClearPath
func (dc *Context) ClearPath() { dc.strokePath.Clear() dc.fillPath.Clear() dc.hasCurrent = false }
go
func (dc *Context) ClearPath() { dc.strokePath.Clear() dc.fillPath.Clear() dc.hasCurrent = false }
[ "func", "(", "dc", "*", "Context", ")", "ClearPath", "(", ")", "{", "dc", ".", "strokePath", ".", "Clear", "(", ")", "\n", "dc", ".", "fillPath", ".", "Clear", "(", ")", "\n", "dc", ".", "hasCurrent", "=", "false", "\n", "}" ]
// ClearPath clears the current path. There is no current point after this // operation.
[ "ClearPath", "clears", "the", "current", "path", ".", "There", "is", "no", "current", "point", "after", "this", "operation", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L362-L366
train
fogleman/gg
context.go
NewSubPath
func (dc *Context) NewSubPath() { if dc.hasCurrent { dc.fillPath.Add1(dc.start.Fixed()) } dc.hasCurrent = false }
go
func (dc *Context) NewSubPath() { if dc.hasCurrent { dc.fillPath.Add1(dc.start.Fixed()) } dc.hasCurrent = false }
[ "func", "(", "dc", "*", "Context", ")", "NewSubPath", "(", ")", "{", "if", "dc", ".", "hasCurrent", "{", "dc", ".", "fillPath", ".", "Add1", "(", "dc", ".", "start", ".", "Fixed", "(", ")", ")", "\n", "}", "\n", "dc", ".", "hasCurrent", "=", "false", "\n", "}" ]
// NewSubPath starts a new subpath within the current path. There is no current // point after this operation.
[ "NewSubPath", "starts", "a", "new", "subpath", "within", "the", "current", "path", ".", "There", "is", "no", "current", "point", "after", "this", "operation", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L370-L375
train
fogleman/gg
context.go
StrokePreserve
func (dc *Context) StrokePreserve() { var painter raster.Painter if dc.mask == nil { if pattern, ok := dc.strokePattern.(*solidPattern); ok { // with a nil mask and a solid color pattern, we can be more efficient // TODO: refactor so we don't have to do this type assertion stuff? p := raster.NewRGBAPainter(dc.im) p.SetColor(pattern.color) painter = p } } if painter == nil { painter = newPatternPainter(dc.im, dc.mask, dc.strokePattern) } dc.stroke(painter) }
go
func (dc *Context) StrokePreserve() { var painter raster.Painter if dc.mask == nil { if pattern, ok := dc.strokePattern.(*solidPattern); ok { // with a nil mask and a solid color pattern, we can be more efficient // TODO: refactor so we don't have to do this type assertion stuff? p := raster.NewRGBAPainter(dc.im) p.SetColor(pattern.color) painter = p } } if painter == nil { painter = newPatternPainter(dc.im, dc.mask, dc.strokePattern) } dc.stroke(painter) }
[ "func", "(", "dc", "*", "Context", ")", "StrokePreserve", "(", ")", "{", "var", "painter", "raster", ".", "Painter", "\n", "if", "dc", ".", "mask", "==", "nil", "{", "if", "pattern", ",", "ok", ":=", "dc", ".", "strokePattern", ".", "(", "*", "solidPattern", ")", ";", "ok", "{", "p", ":=", "raster", ".", "NewRGBAPainter", "(", "dc", ".", "im", ")", "\n", "p", ".", "SetColor", "(", "pattern", ".", "color", ")", "\n", "painter", "=", "p", "\n", "}", "\n", "}", "\n", "if", "painter", "==", "nil", "{", "painter", "=", "newPatternPainter", "(", "dc", ".", "im", ",", "dc", ".", "mask", ",", "dc", ".", "strokePattern", ")", "\n", "}", "\n", "dc", ".", "stroke", "(", "painter", ")", "\n", "}" ]
// StrokePreserve strokes the current path with the current color, line width, // line cap, line join and dash settings. The path is preserved after this // operation.
[ "StrokePreserve", "strokes", "the", "current", "path", "with", "the", "current", "color", "line", "width", "line", "cap", "line", "join", "and", "dash", "settings", ".", "The", "path", "is", "preserved", "after", "this", "operation", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L434-L449
train
fogleman/gg
context.go
FillPreserve
func (dc *Context) FillPreserve() { var painter raster.Painter if dc.mask == nil { if pattern, ok := dc.fillPattern.(*solidPattern); ok { // with a nil mask and a solid color pattern, we can be more efficient // TODO: refactor so we don't have to do this type assertion stuff? p := raster.NewRGBAPainter(dc.im) p.SetColor(pattern.color) painter = p } } if painter == nil { painter = newPatternPainter(dc.im, dc.mask, dc.fillPattern) } dc.fill(painter) }
go
func (dc *Context) FillPreserve() { var painter raster.Painter if dc.mask == nil { if pattern, ok := dc.fillPattern.(*solidPattern); ok { // with a nil mask and a solid color pattern, we can be more efficient // TODO: refactor so we don't have to do this type assertion stuff? p := raster.NewRGBAPainter(dc.im) p.SetColor(pattern.color) painter = p } } if painter == nil { painter = newPatternPainter(dc.im, dc.mask, dc.fillPattern) } dc.fill(painter) }
[ "func", "(", "dc", "*", "Context", ")", "FillPreserve", "(", ")", "{", "var", "painter", "raster", ".", "Painter", "\n", "if", "dc", ".", "mask", "==", "nil", "{", "if", "pattern", ",", "ok", ":=", "dc", ".", "fillPattern", ".", "(", "*", "solidPattern", ")", ";", "ok", "{", "p", ":=", "raster", ".", "NewRGBAPainter", "(", "dc", ".", "im", ")", "\n", "p", ".", "SetColor", "(", "pattern", ".", "color", ")", "\n", "painter", "=", "p", "\n", "}", "\n", "}", "\n", "if", "painter", "==", "nil", "{", "painter", "=", "newPatternPainter", "(", "dc", ".", "im", ",", "dc", ".", "mask", ",", "dc", ".", "fillPattern", ")", "\n", "}", "\n", "dc", ".", "fill", "(", "painter", ")", "\n", "}" ]
// FillPreserve fills the current path with the current color. Open subpaths // are implicity closed. The path is preserved after this operation.
[ "FillPreserve", "fills", "the", "current", "path", "with", "the", "current", "color", ".", "Open", "subpaths", "are", "implicity", "closed", ".", "The", "path", "is", "preserved", "after", "this", "operation", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L461-L476
train
fogleman/gg
context.go
InvertMask
func (dc *Context) InvertMask() { if dc.mask == nil { dc.mask = image.NewAlpha(dc.im.Bounds()) } else { for i, a := range dc.mask.Pix { dc.mask.Pix[i] = 255 - a } } }
go
func (dc *Context) InvertMask() { if dc.mask == nil { dc.mask = image.NewAlpha(dc.im.Bounds()) } else { for i, a := range dc.mask.Pix { dc.mask.Pix[i] = 255 - a } } }
[ "func", "(", "dc", "*", "Context", ")", "InvertMask", "(", ")", "{", "if", "dc", ".", "mask", "==", "nil", "{", "dc", ".", "mask", "=", "image", ".", "NewAlpha", "(", "dc", ".", "im", ".", "Bounds", "(", ")", ")", "\n", "}", "else", "{", "for", "i", ",", "a", ":=", "range", "dc", ".", "mask", ".", "Pix", "{", "dc", ".", "mask", ".", "Pix", "[", "i", "]", "=", "255", "-", "a", "\n", "}", "\n", "}", "\n", "}" ]
// InvertMask inverts the alpha values in the current clipping mask such that // a fully transparent region becomes fully opaque and vice versa.
[ "InvertMask", "inverts", "the", "alpha", "values", "in", "the", "current", "clipping", "mask", "such", "that", "a", "fully", "transparent", "region", "becomes", "fully", "opaque", "and", "vice", "versa", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L523-L531
train
fogleman/gg
context.go
Clear
func (dc *Context) Clear() { src := image.NewUniform(dc.color) draw.Draw(dc.im, dc.im.Bounds(), src, image.ZP, draw.Src) }
go
func (dc *Context) Clear() { src := image.NewUniform(dc.color) draw.Draw(dc.im, dc.im.Bounds(), src, image.ZP, draw.Src) }
[ "func", "(", "dc", "*", "Context", ")", "Clear", "(", ")", "{", "src", ":=", "image", ".", "NewUniform", "(", "dc", ".", "color", ")", "\n", "draw", ".", "Draw", "(", "dc", ".", "im", ",", "dc", ".", "im", ".", "Bounds", "(", ")", ",", "src", ",", "image", ".", "ZP", ",", "draw", ".", "Src", ")", "\n", "}" ]
// Convenient Drawing Functions // Clear fills the entire image with the current color.
[ "Convenient", "Drawing", "Functions", "Clear", "fills", "the", "entire", "image", "with", "the", "current", "color", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L549-L552
train
fogleman/gg
context.go
SetPixel
func (dc *Context) SetPixel(x, y int) { dc.im.Set(x, y, dc.color) }
go
func (dc *Context) SetPixel(x, y int) { dc.im.Set(x, y, dc.color) }
[ "func", "(", "dc", "*", "Context", ")", "SetPixel", "(", "x", ",", "y", "int", ")", "{", "dc", ".", "im", ".", "Set", "(", "x", ",", "y", ",", "dc", ".", "color", ")", "\n", "}" ]
// SetPixel sets the color of the specified pixel using the current color.
[ "SetPixel", "sets", "the", "color", "of", "the", "specified", "pixel", "using", "the", "current", "color", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L555-L557
train
fogleman/gg
context.go
DrawPoint
func (dc *Context) DrawPoint(x, y, r float64) { dc.Push() tx, ty := dc.TransformPoint(x, y) dc.Identity() dc.DrawCircle(tx, ty, r) dc.Pop() }
go
func (dc *Context) DrawPoint(x, y, r float64) { dc.Push() tx, ty := dc.TransformPoint(x, y) dc.Identity() dc.DrawCircle(tx, ty, r) dc.Pop() }
[ "func", "(", "dc", "*", "Context", ")", "DrawPoint", "(", "x", ",", "y", ",", "r", "float64", ")", "{", "dc", ".", "Push", "(", ")", "\n", "tx", ",", "ty", ":=", "dc", ".", "TransformPoint", "(", "x", ",", "y", ")", "\n", "dc", ".", "Identity", "(", ")", "\n", "dc", ".", "DrawCircle", "(", "tx", ",", "ty", ",", "r", ")", "\n", "dc", ".", "Pop", "(", ")", "\n", "}" ]
// DrawPoint is like DrawCircle but ensures that a circle of the specified // size is drawn regardless of the current transformation matrix. The position // is still transformed, but not the shape of the point.
[ "DrawPoint", "is", "like", "DrawCircle", "but", "ensures", "that", "a", "circle", "of", "the", "specified", "size", "is", "drawn", "regardless", "of", "the", "current", "transformation", "matrix", ".", "The", "position", "is", "still", "transformed", "but", "not", "the", "shape", "of", "the", "point", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L562-L568
train
fogleman/gg
context.go
DrawImage
func (dc *Context) DrawImage(im image.Image, x, y int) { dc.DrawImageAnchored(im, x, y, 0, 0) }
go
func (dc *Context) DrawImage(im image.Image, x, y int) { dc.DrawImageAnchored(im, x, y, 0, 0) }
[ "func", "(", "dc", "*", "Context", ")", "DrawImage", "(", "im", "image", ".", "Image", ",", "x", ",", "y", "int", ")", "{", "dc", ".", "DrawImageAnchored", "(", "im", ",", "x", ",", "y", ",", "0", ",", "0", ")", "\n", "}" ]
// DrawImage draws the specified image at the specified point.
[ "DrawImage", "draws", "the", "specified", "image", "at", "the", "specified", "point", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L657-L659
train
fogleman/gg
context.go
DrawString
func (dc *Context) DrawString(s string, x, y float64) { dc.DrawStringAnchored(s, x, y, 0, 0) }
go
func (dc *Context) DrawString(s string, x, y float64) { dc.DrawStringAnchored(s, x, y, 0, 0) }
[ "func", "(", "dc", "*", "Context", ")", "DrawString", "(", "s", "string", ",", "x", ",", "y", "float64", ")", "{", "dc", ".", "DrawStringAnchored", "(", "s", ",", "x", ",", "y", ",", "0", ",", "0", ")", "\n", "}" ]
// DrawString draws the specified text at the specified point.
[ "DrawString", "draws", "the", "specified", "text", "at", "the", "specified", "point", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L737-L739
train
fogleman/gg
context.go
DrawStringWrapped
func (dc *Context) DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align) { lines := dc.WordWrap(s, width) // sync h formula with MeasureMultilineString h := float64(len(lines)) * dc.fontHeight * lineSpacing h -= (lineSpacing - 1) * dc.fontHeight x -= ax * width y -= ay * h switch align { case AlignLeft: ax = 0 case AlignCenter: ax = 0.5 x += width / 2 case AlignRight: ax = 1 x += width } ay = 1 for _, line := range lines { dc.DrawStringAnchored(line, x, y, ax, ay) y += dc.fontHeight * lineSpacing } }
go
func (dc *Context) DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align) { lines := dc.WordWrap(s, width) // sync h formula with MeasureMultilineString h := float64(len(lines)) * dc.fontHeight * lineSpacing h -= (lineSpacing - 1) * dc.fontHeight x -= ax * width y -= ay * h switch align { case AlignLeft: ax = 0 case AlignCenter: ax = 0.5 x += width / 2 case AlignRight: ax = 1 x += width } ay = 1 for _, line := range lines { dc.DrawStringAnchored(line, x, y, ax, ay) y += dc.fontHeight * lineSpacing } }
[ "func", "(", "dc", "*", "Context", ")", "DrawStringWrapped", "(", "s", "string", ",", "x", ",", "y", ",", "ax", ",", "ay", ",", "width", ",", "lineSpacing", "float64", ",", "align", "Align", ")", "{", "lines", ":=", "dc", ".", "WordWrap", "(", "s", ",", "width", ")", "\n", "h", ":=", "float64", "(", "len", "(", "lines", ")", ")", "*", "dc", ".", "fontHeight", "*", "lineSpacing", "\n", "h", "-=", "(", "lineSpacing", "-", "1", ")", "*", "dc", ".", "fontHeight", "\n", "x", "-=", "ax", "*", "width", "\n", "y", "-=", "ay", "*", "h", "\n", "switch", "align", "{", "case", "AlignLeft", ":", "ax", "=", "0", "\n", "case", "AlignCenter", ":", "ax", "=", "0.5", "\n", "x", "+=", "width", "/", "2", "\n", "case", "AlignRight", ":", "ax", "=", "1", "\n", "x", "+=", "width", "\n", "}", "\n", "ay", "=", "1", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "dc", ".", "DrawStringAnchored", "(", "line", ",", "x", ",", "y", ",", "ax", ",", "ay", ")", "\n", "y", "+=", "dc", ".", "fontHeight", "*", "lineSpacing", "\n", "}", "\n", "}" ]
// DrawStringWrapped word-wraps the specified string to the given max width // and then draws it at the specified anchor point using the given line // spacing and text alignment.
[ "DrawStringWrapped", "word", "-", "wraps", "the", "specified", "string", "to", "the", "given", "max", "width", "and", "then", "draws", "it", "at", "the", "specified", "anchor", "point", "using", "the", "given", "line", "spacing", "and", "text", "alignment", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L760-L784
train
fogleman/gg
context.go
MeasureString
func (dc *Context) MeasureString(s string) (w, h float64) { d := &font.Drawer{ Face: dc.fontFace, } a := d.MeasureString(s) return float64(a >> 6), dc.fontHeight }
go
func (dc *Context) MeasureString(s string) (w, h float64) { d := &font.Drawer{ Face: dc.fontFace, } a := d.MeasureString(s) return float64(a >> 6), dc.fontHeight }
[ "func", "(", "dc", "*", "Context", ")", "MeasureString", "(", "s", "string", ")", "(", "w", ",", "h", "float64", ")", "{", "d", ":=", "&", "font", ".", "Drawer", "{", "Face", ":", "dc", ".", "fontFace", ",", "}", "\n", "a", ":=", "d", ".", "MeasureString", "(", "s", ")", "\n", "return", "float64", "(", "a", ">>", "6", ")", ",", "dc", ".", "fontHeight", "\n", "}" ]
// MeasureString returns the rendered width and height of the specified text // given the current font face.
[ "MeasureString", "returns", "the", "rendered", "width", "and", "height", "of", "the", "specified", "text", "given", "the", "current", "font", "face", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L811-L817
train
fogleman/gg
context.go
WordWrap
func (dc *Context) WordWrap(s string, w float64) []string { return wordWrap(dc, s, w) }
go
func (dc *Context) WordWrap(s string, w float64) []string { return wordWrap(dc, s, w) }
[ "func", "(", "dc", "*", "Context", ")", "WordWrap", "(", "s", "string", ",", "w", "float64", ")", "[", "]", "string", "{", "return", "wordWrap", "(", "dc", ",", "s", ",", "w", ")", "\n", "}" ]
// WordWrap wraps the specified string to the given max width and current // font face.
[ "WordWrap", "wraps", "the", "specified", "string", "to", "the", "given", "max", "width", "and", "current", "font", "face", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L821-L823
train
fogleman/gg
context.go
Translate
func (dc *Context) Translate(x, y float64) { dc.matrix = dc.matrix.Translate(x, y) }
go
func (dc *Context) Translate(x, y float64) { dc.matrix = dc.matrix.Translate(x, y) }
[ "func", "(", "dc", "*", "Context", ")", "Translate", "(", "x", ",", "y", "float64", ")", "{", "dc", ".", "matrix", "=", "dc", ".", "matrix", ".", "Translate", "(", "x", ",", "y", ")", "\n", "}" ]
// Translate updates the current matrix with a translation.
[ "Translate", "updates", "the", "current", "matrix", "with", "a", "translation", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L834-L836
train
fogleman/gg
context.go
Scale
func (dc *Context) Scale(x, y float64) { dc.matrix = dc.matrix.Scale(x, y) }
go
func (dc *Context) Scale(x, y float64) { dc.matrix = dc.matrix.Scale(x, y) }
[ "func", "(", "dc", "*", "Context", ")", "Scale", "(", "x", ",", "y", "float64", ")", "{", "dc", ".", "matrix", "=", "dc", ".", "matrix", ".", "Scale", "(", "x", ",", "y", ")", "\n", "}" ]
// Scale updates the current matrix with a scaling factor. // Scaling occurs about the origin.
[ "Scale", "updates", "the", "current", "matrix", "with", "a", "scaling", "factor", ".", "Scaling", "occurs", "about", "the", "origin", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L840-L842
train
fogleman/gg
context.go
ScaleAbout
func (dc *Context) ScaleAbout(sx, sy, x, y float64) { dc.Translate(x, y) dc.Scale(sx, sy) dc.Translate(-x, -y) }
go
func (dc *Context) ScaleAbout(sx, sy, x, y float64) { dc.Translate(x, y) dc.Scale(sx, sy) dc.Translate(-x, -y) }
[ "func", "(", "dc", "*", "Context", ")", "ScaleAbout", "(", "sx", ",", "sy", ",", "x", ",", "y", "float64", ")", "{", "dc", ".", "Translate", "(", "x", ",", "y", ")", "\n", "dc", ".", "Scale", "(", "sx", ",", "sy", ")", "\n", "dc", ".", "Translate", "(", "-", "x", ",", "-", "y", ")", "\n", "}" ]
// ScaleAbout updates the current matrix with a scaling factor. // Scaling occurs about the specified point.
[ "ScaleAbout", "updates", "the", "current", "matrix", "with", "a", "scaling", "factor", ".", "Scaling", "occurs", "about", "the", "specified", "point", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L846-L850
train
fogleman/gg
context.go
Rotate
func (dc *Context) Rotate(angle float64) { dc.matrix = dc.matrix.Rotate(angle) }
go
func (dc *Context) Rotate(angle float64) { dc.matrix = dc.matrix.Rotate(angle) }
[ "func", "(", "dc", "*", "Context", ")", "Rotate", "(", "angle", "float64", ")", "{", "dc", ".", "matrix", "=", "dc", ".", "matrix", ".", "Rotate", "(", "angle", ")", "\n", "}" ]
// Rotate updates the current matrix with a clockwise rotation. // Rotation occurs about the origin. Angle is specified in radians.
[ "Rotate", "updates", "the", "current", "matrix", "with", "a", "clockwise", "rotation", ".", "Rotation", "occurs", "about", "the", "origin", ".", "Angle", "is", "specified", "in", "radians", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L854-L856
train
fogleman/gg
context.go
RotateAbout
func (dc *Context) RotateAbout(angle, x, y float64) { dc.Translate(x, y) dc.Rotate(angle) dc.Translate(-x, -y) }
go
func (dc *Context) RotateAbout(angle, x, y float64) { dc.Translate(x, y) dc.Rotate(angle) dc.Translate(-x, -y) }
[ "func", "(", "dc", "*", "Context", ")", "RotateAbout", "(", "angle", ",", "x", ",", "y", "float64", ")", "{", "dc", ".", "Translate", "(", "x", ",", "y", ")", "\n", "dc", ".", "Rotate", "(", "angle", ")", "\n", "dc", ".", "Translate", "(", "-", "x", ",", "-", "y", ")", "\n", "}" ]
// RotateAbout updates the current matrix with a clockwise rotation. // Rotation occurs about the specified point. Angle is specified in radians.
[ "RotateAbout", "updates", "the", "current", "matrix", "with", "a", "clockwise", "rotation", ".", "Rotation", "occurs", "about", "the", "specified", "point", ".", "Angle", "is", "specified", "in", "radians", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L860-L864
train
fogleman/gg
context.go
Shear
func (dc *Context) Shear(x, y float64) { dc.matrix = dc.matrix.Shear(x, y) }
go
func (dc *Context) Shear(x, y float64) { dc.matrix = dc.matrix.Shear(x, y) }
[ "func", "(", "dc", "*", "Context", ")", "Shear", "(", "x", ",", "y", "float64", ")", "{", "dc", ".", "matrix", "=", "dc", ".", "matrix", ".", "Shear", "(", "x", ",", "y", ")", "\n", "}" ]
// Shear updates the current matrix with a shearing angle. // Shearing occurs about the origin.
[ "Shear", "updates", "the", "current", "matrix", "with", "a", "shearing", "angle", ".", "Shearing", "occurs", "about", "the", "origin", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L868-L870
train
fogleman/gg
context.go
ShearAbout
func (dc *Context) ShearAbout(sx, sy, x, y float64) { dc.Translate(x, y) dc.Shear(sx, sy) dc.Translate(-x, -y) }
go
func (dc *Context) ShearAbout(sx, sy, x, y float64) { dc.Translate(x, y) dc.Shear(sx, sy) dc.Translate(-x, -y) }
[ "func", "(", "dc", "*", "Context", ")", "ShearAbout", "(", "sx", ",", "sy", ",", "x", ",", "y", "float64", ")", "{", "dc", ".", "Translate", "(", "x", ",", "y", ")", "\n", "dc", ".", "Shear", "(", "sx", ",", "sy", ")", "\n", "dc", ".", "Translate", "(", "-", "x", ",", "-", "y", ")", "\n", "}" ]
// ShearAbout updates the current matrix with a shearing angle. // Shearing occurs about the specified point.
[ "ShearAbout", "updates", "the", "current", "matrix", "with", "a", "shearing", "angle", ".", "Shearing", "occurs", "about", "the", "specified", "point", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L874-L878
train
fogleman/gg
context.go
TransformPoint
func (dc *Context) TransformPoint(x, y float64) (tx, ty float64) { return dc.matrix.TransformPoint(x, y) }
go
func (dc *Context) TransformPoint(x, y float64) (tx, ty float64) { return dc.matrix.TransformPoint(x, y) }
[ "func", "(", "dc", "*", "Context", ")", "TransformPoint", "(", "x", ",", "y", "float64", ")", "(", "tx", ",", "ty", "float64", ")", "{", "return", "dc", ".", "matrix", ".", "TransformPoint", "(", "x", ",", "y", ")", "\n", "}" ]
// TransformPoint multiplies the specified point by the current matrix, // returning a transformed position.
[ "TransformPoint", "multiplies", "the", "specified", "point", "by", "the", "current", "matrix", "returning", "a", "transformed", "position", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L882-L884
train
fogleman/gg
context.go
InvertY
func (dc *Context) InvertY() { dc.Translate(0, float64(dc.height)) dc.Scale(1, -1) }
go
func (dc *Context) InvertY() { dc.Translate(0, float64(dc.height)) dc.Scale(1, -1) }
[ "func", "(", "dc", "*", "Context", ")", "InvertY", "(", ")", "{", "dc", ".", "Translate", "(", "0", ",", "float64", "(", "dc", ".", "height", ")", ")", "\n", "dc", ".", "Scale", "(", "1", ",", "-", "1", ")", "\n", "}" ]
// InvertY flips the Y axis so that Y grows from bottom to top and Y=0 is at // the bottom of the image.
[ "InvertY", "flips", "the", "Y", "axis", "so", "that", "Y", "grows", "from", "bottom", "to", "top", "and", "Y", "=", "0", "is", "at", "the", "bottom", "of", "the", "image", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L888-L891
train
fogleman/gg
context.go
Push
func (dc *Context) Push() { x := *dc dc.stack = append(dc.stack, &x) }
go
func (dc *Context) Push() { x := *dc dc.stack = append(dc.stack, &x) }
[ "func", "(", "dc", "*", "Context", ")", "Push", "(", ")", "{", "x", ":=", "*", "dc", "\n", "dc", ".", "stack", "=", "append", "(", "dc", ".", "stack", ",", "&", "x", ")", "\n", "}" ]
// Stack // Push saves the current state of the context for later retrieval. These // can be nested.
[ "Stack", "Push", "saves", "the", "current", "state", "of", "the", "context", "for", "later", "retrieval", ".", "These", "can", "be", "nested", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L897-L900
train
fogleman/gg
context.go
Pop
func (dc *Context) Pop() { before := *dc s := dc.stack x, s := s[len(s)-1], s[:len(s)-1] *dc = *x dc.mask = before.mask dc.strokePath = before.strokePath dc.fillPath = before.fillPath dc.start = before.start dc.current = before.current dc.hasCurrent = before.hasCurrent }
go
func (dc *Context) Pop() { before := *dc s := dc.stack x, s := s[len(s)-1], s[:len(s)-1] *dc = *x dc.mask = before.mask dc.strokePath = before.strokePath dc.fillPath = before.fillPath dc.start = before.start dc.current = before.current dc.hasCurrent = before.hasCurrent }
[ "func", "(", "dc", "*", "Context", ")", "Pop", "(", ")", "{", "before", ":=", "*", "dc", "\n", "s", ":=", "dc", ".", "stack", "\n", "x", ",", "s", ":=", "s", "[", "len", "(", "s", ")", "-", "1", "]", ",", "s", "[", ":", "len", "(", "s", ")", "-", "1", "]", "\n", "*", "dc", "=", "*", "x", "\n", "dc", ".", "mask", "=", "before", ".", "mask", "\n", "dc", ".", "strokePath", "=", "before", ".", "strokePath", "\n", "dc", ".", "fillPath", "=", "before", ".", "fillPath", "\n", "dc", ".", "start", "=", "before", ".", "start", "\n", "dc", ".", "current", "=", "before", ".", "current", "\n", "dc", ".", "hasCurrent", "=", "before", ".", "hasCurrent", "\n", "}" ]
// Pop restores the last saved context state from the stack.
[ "Pop", "restores", "the", "last", "saved", "context", "state", "from", "the", "stack", "." ]
72436a171bf31757dc87fb8fa9f7485307350307
https://github.com/fogleman/gg/blob/72436a171bf31757dc87fb8fa9f7485307350307/context.go#L903-L914
train
faiface/pixel
imdraw/imdraw.go
New
func New(pic pixel.Picture) *IMDraw { tri := &pixel.TrianglesData{} im := &IMDraw{ tri: tri, batch: pixel.NewBatch(tri, pic), } im.SetMatrix(pixel.IM) im.SetColorMask(pixel.Alpha(1)) im.Reset() return im }
go
func New(pic pixel.Picture) *IMDraw { tri := &pixel.TrianglesData{} im := &IMDraw{ tri: tri, batch: pixel.NewBatch(tri, pic), } im.SetMatrix(pixel.IM) im.SetColorMask(pixel.Alpha(1)) im.Reset() return im }
[ "func", "New", "(", "pic", "pixel", ".", "Picture", ")", "*", "IMDraw", "{", "tri", ":=", "&", "pixel", ".", "TrianglesData", "{", "}", "\n", "im", ":=", "&", "IMDraw", "{", "tri", ":", "tri", ",", "batch", ":", "pixel", ".", "NewBatch", "(", "tri", ",", "pic", ")", ",", "}", "\n", "im", ".", "SetMatrix", "(", "pixel", ".", "IM", ")", "\n", "im", ".", "SetColorMask", "(", "pixel", ".", "Alpha", "(", "1", ")", ")", "\n", "im", ".", "Reset", "(", ")", "\n", "return", "im", "\n", "}" ]
// New creates a new empty IMDraw. An optional Picture can be used to draw with a Picture. // // If you just want to draw primitive shapes, pass nil as the Picture.
[ "New", "creates", "a", "new", "empty", "IMDraw", ".", "An", "optional", "Picture", "can", "be", "used", "to", "draw", "with", "a", "Picture", ".", "If", "you", "just", "want", "to", "draw", "primitive", "shapes", "pass", "nil", "as", "the", "Picture", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L91-L101
train
faiface/pixel
imdraw/imdraw.go
Reset
func (imd *IMDraw) Reset() { imd.points = imd.points[:0] imd.Color = pixel.Alpha(1) imd.Picture = pixel.ZV imd.Intensity = 0 imd.Precision = 64 imd.EndShape = NoEndShape }
go
func (imd *IMDraw) Reset() { imd.points = imd.points[:0] imd.Color = pixel.Alpha(1) imd.Picture = pixel.ZV imd.Intensity = 0 imd.Precision = 64 imd.EndShape = NoEndShape }
[ "func", "(", "imd", "*", "IMDraw", ")", "Reset", "(", ")", "{", "imd", ".", "points", "=", "imd", ".", "points", "[", ":", "0", "]", "\n", "imd", ".", "Color", "=", "pixel", ".", "Alpha", "(", "1", ")", "\n", "imd", ".", "Picture", "=", "pixel", ".", "ZV", "\n", "imd", ".", "Intensity", "=", "0", "\n", "imd", ".", "Precision", "=", "64", "\n", "imd", ".", "EndShape", "=", "NoEndShape", "\n", "}" ]
// Reset restores all point properties to defaults and removes all Pushed points. // // This does not affect matrix and color mask set by SetMatrix and SetColorMask.
[ "Reset", "restores", "all", "point", "properties", "to", "defaults", "and", "removes", "all", "Pushed", "points", ".", "This", "does", "not", "affect", "matrix", "and", "color", "mask", "set", "by", "SetMatrix", "and", "SetColorMask", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L112-L119
train
faiface/pixel
imdraw/imdraw.go
Draw
func (imd *IMDraw) Draw(t pixel.Target) { imd.batch.Draw(t) }
go
func (imd *IMDraw) Draw(t pixel.Target) { imd.batch.Draw(t) }
[ "func", "(", "imd", "*", "IMDraw", ")", "Draw", "(", "t", "pixel", ".", "Target", ")", "{", "imd", ".", "batch", ".", "Draw", "(", "t", ")", "\n", "}" ]
// Draw draws all currently drawn shapes inside the IM onto another Target. // // Note, that IMDraw's matrix and color mask have no effect here.
[ "Draw", "draws", "all", "currently", "drawn", "shapes", "inside", "the", "IM", "onto", "another", "Target", ".", "Note", "that", "IMDraw", "s", "matrix", "and", "color", "mask", "have", "no", "effect", "here", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L124-L126
train
faiface/pixel
imdraw/imdraw.go
Push
func (imd *IMDraw) Push(pts ...pixel.Vec) { if _, ok := imd.Color.(pixel.RGBA); !ok { imd.Color = pixel.ToRGBA(imd.Color) } opts := point{ col: imd.Color.(pixel.RGBA), pic: imd.Picture, in: imd.Intensity, precision: imd.Precision, endshape: imd.EndShape, } for _, pt := range pts { imd.pushPt(pt, opts) } }
go
func (imd *IMDraw) Push(pts ...pixel.Vec) { if _, ok := imd.Color.(pixel.RGBA); !ok { imd.Color = pixel.ToRGBA(imd.Color) } opts := point{ col: imd.Color.(pixel.RGBA), pic: imd.Picture, in: imd.Intensity, precision: imd.Precision, endshape: imd.EndShape, } for _, pt := range pts { imd.pushPt(pt, opts) } }
[ "func", "(", "imd", "*", "IMDraw", ")", "Push", "(", "pts", "...", "pixel", ".", "Vec", ")", "{", "if", "_", ",", "ok", ":=", "imd", ".", "Color", ".", "(", "pixel", ".", "RGBA", ")", ";", "!", "ok", "{", "imd", ".", "Color", "=", "pixel", ".", "ToRGBA", "(", "imd", ".", "Color", ")", "\n", "}", "\n", "opts", ":=", "point", "{", "col", ":", "imd", ".", "Color", ".", "(", "pixel", ".", "RGBA", ")", ",", "pic", ":", "imd", ".", "Picture", ",", "in", ":", "imd", ".", "Intensity", ",", "precision", ":", "imd", ".", "Precision", ",", "endshape", ":", "imd", ".", "EndShape", ",", "}", "\n", "for", "_", ",", "pt", ":=", "range", "pts", "{", "imd", ".", "pushPt", "(", "pt", ",", "opts", ")", "\n", "}", "\n", "}" ]
// Push adds some points to the IM queue. All Pushed points will have the same properties except for // the position.
[ "Push", "adds", "some", "points", "to", "the", "IM", "queue", ".", "All", "Pushed", "points", "will", "have", "the", "same", "properties", "except", "for", "the", "position", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L130-L144
train
faiface/pixel
imdraw/imdraw.go
SetMatrix
func (imd *IMDraw) SetMatrix(m pixel.Matrix) { imd.matrix = m imd.batch.SetMatrix(imd.matrix) }
go
func (imd *IMDraw) SetMatrix(m pixel.Matrix) { imd.matrix = m imd.batch.SetMatrix(imd.matrix) }
[ "func", "(", "imd", "*", "IMDraw", ")", "SetMatrix", "(", "m", "pixel", ".", "Matrix", ")", "{", "imd", ".", "matrix", "=", "m", "\n", "imd", ".", "batch", ".", "SetMatrix", "(", "imd", ".", "matrix", ")", "\n", "}" ]
// SetMatrix sets a Matrix that all further points will be transformed by.
[ "SetMatrix", "sets", "a", "Matrix", "that", "all", "further", "points", "will", "be", "transformed", "by", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L152-L155
train
faiface/pixel
imdraw/imdraw.go
SetColorMask
func (imd *IMDraw) SetColorMask(color color.Color) { imd.mask = pixel.ToRGBA(color) imd.batch.SetColorMask(imd.mask) }
go
func (imd *IMDraw) SetColorMask(color color.Color) { imd.mask = pixel.ToRGBA(color) imd.batch.SetColorMask(imd.mask) }
[ "func", "(", "imd", "*", "IMDraw", ")", "SetColorMask", "(", "color", "color", ".", "Color", ")", "{", "imd", ".", "mask", "=", "pixel", ".", "ToRGBA", "(", "color", ")", "\n", "imd", ".", "batch", ".", "SetColorMask", "(", "imd", ".", "mask", ")", "\n", "}" ]
// SetColorMask sets a color that all further point's color will be multiplied by.
[ "SetColorMask", "sets", "a", "color", "that", "all", "further", "point", "s", "color", "will", "be", "multiplied", "by", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L158-L161
train
faiface/pixel
imdraw/imdraw.go
MakeTriangles
func (imd *IMDraw) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles { return imd.batch.MakeTriangles(t) }
go
func (imd *IMDraw) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles { return imd.batch.MakeTriangles(t) }
[ "func", "(", "imd", "*", "IMDraw", ")", "MakeTriangles", "(", "t", "pixel", ".", "Triangles", ")", "pixel", ".", "TargetTriangles", "{", "return", "imd", ".", "batch", ".", "MakeTriangles", "(", "t", ")", "\n", "}" ]
// MakeTriangles returns a specialized copy of the provided Triangles that draws onto this IMDraw.
[ "MakeTriangles", "returns", "a", "specialized", "copy", "of", "the", "provided", "Triangles", "that", "draws", "onto", "this", "IMDraw", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L164-L166
train
faiface/pixel
imdraw/imdraw.go
MakePicture
func (imd *IMDraw) MakePicture(p pixel.Picture) pixel.TargetPicture { return imd.batch.MakePicture(p) }
go
func (imd *IMDraw) MakePicture(p pixel.Picture) pixel.TargetPicture { return imd.batch.MakePicture(p) }
[ "func", "(", "imd", "*", "IMDraw", ")", "MakePicture", "(", "p", "pixel", ".", "Picture", ")", "pixel", ".", "TargetPicture", "{", "return", "imd", ".", "batch", ".", "MakePicture", "(", "p", ")", "\n", "}" ]
// MakePicture returns a specialized copy of the provided Picture that draws onto this IMDraw.
[ "MakePicture", "returns", "a", "specialized", "copy", "of", "the", "provided", "Picture", "that", "draws", "onto", "this", "IMDraw", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L169-L171
train
faiface/pixel
imdraw/imdraw.go
Rectangle
func (imd *IMDraw) Rectangle(thickness float64) { if thickness == 0 { imd.fillRectangle() } else { imd.outlineRectangle(thickness) } }
go
func (imd *IMDraw) Rectangle(thickness float64) { if thickness == 0 { imd.fillRectangle() } else { imd.outlineRectangle(thickness) } }
[ "func", "(", "imd", "*", "IMDraw", ")", "Rectangle", "(", "thickness", "float64", ")", "{", "if", "thickness", "==", "0", "{", "imd", ".", "fillRectangle", "(", ")", "\n", "}", "else", "{", "imd", ".", "outlineRectangle", "(", "thickness", ")", "\n", "}", "\n", "}" ]
// Rectangle draws a rectangle between each two subsequent Pushed points. Drawing a rectangle // between two points means drawing a rectangle with sides parallel to the axes of the coordinate // system, where the two points specify it's two opposite corners. // // If the thickness is 0, rectangles will be filled, otherwise will be outlined with the given // thickness.
[ "Rectangle", "draws", "a", "rectangle", "between", "each", "two", "subsequent", "Pushed", "points", ".", "Drawing", "a", "rectangle", "between", "two", "points", "means", "drawing", "a", "rectangle", "with", "sides", "parallel", "to", "the", "axes", "of", "the", "coordinate", "system", "where", "the", "two", "points", "specify", "it", "s", "two", "opposite", "corners", ".", "If", "the", "thickness", "is", "0", "rectangles", "will", "be", "filled", "otherwise", "will", "be", "outlined", "with", "the", "given", "thickness", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L184-L190
train
faiface/pixel
imdraw/imdraw.go
Polygon
func (imd *IMDraw) Polygon(thickness float64) { if thickness == 0 { imd.fillPolygon() } else { imd.polyline(thickness, true) } }
go
func (imd *IMDraw) Polygon(thickness float64) { if thickness == 0 { imd.fillPolygon() } else { imd.polyline(thickness, true) } }
[ "func", "(", "imd", "*", "IMDraw", ")", "Polygon", "(", "thickness", "float64", ")", "{", "if", "thickness", "==", "0", "{", "imd", ".", "fillPolygon", "(", ")", "\n", "}", "else", "{", "imd", ".", "polyline", "(", "thickness", ",", "true", ")", "\n", "}", "\n", "}" ]
// Polygon draws a polygon from the Pushed points. If the thickness is 0, the convex polygon will be // filled. Otherwise, an outline of the specified thickness will be drawn. The outline does not have // to be convex. // // Note, that the filled polygon does not have to be strictly convex. The way it's drawn is that a // triangle is drawn between each two adjacent points and the first Pushed point. You can use this // property to draw certain kinds of concave polygons.
[ "Polygon", "draws", "a", "polygon", "from", "the", "Pushed", "points", ".", "If", "the", "thickness", "is", "0", "the", "convex", "polygon", "will", "be", "filled", ".", "Otherwise", "an", "outline", "of", "the", "specified", "thickness", "will", "be", "drawn", ".", "The", "outline", "does", "not", "have", "to", "be", "convex", ".", "Note", "that", "the", "filled", "polygon", "does", "not", "have", "to", "be", "strictly", "convex", ".", "The", "way", "it", "s", "drawn", "is", "that", "a", "triangle", "is", "drawn", "between", "each", "two", "adjacent", "points", "and", "the", "first", "Pushed", "point", ".", "You", "can", "use", "this", "property", "to", "draw", "certain", "kinds", "of", "concave", "polygons", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L199-L205
train
faiface/pixel
imdraw/imdraw.go
Circle
func (imd *IMDraw) Circle(radius, thickness float64) { if thickness == 0 { imd.fillEllipseArc(pixel.V(radius, radius), 0, 2*math.Pi) } else { imd.outlineEllipseArc(pixel.V(radius, radius), 0, 2*math.Pi, thickness, false) } }
go
func (imd *IMDraw) Circle(radius, thickness float64) { if thickness == 0 { imd.fillEllipseArc(pixel.V(radius, radius), 0, 2*math.Pi) } else { imd.outlineEllipseArc(pixel.V(radius, radius), 0, 2*math.Pi, thickness, false) } }
[ "func", "(", "imd", "*", "IMDraw", ")", "Circle", "(", "radius", ",", "thickness", "float64", ")", "{", "if", "thickness", "==", "0", "{", "imd", ".", "fillEllipseArc", "(", "pixel", ".", "V", "(", "radius", ",", "radius", ")", ",", "0", ",", "2", "*", "math", ".", "Pi", ")", "\n", "}", "else", "{", "imd", ".", "outlineEllipseArc", "(", "pixel", ".", "V", "(", "radius", ",", "radius", ")", ",", "0", ",", "2", "*", "math", ".", "Pi", ",", "thickness", ",", "false", ")", "\n", "}", "\n", "}" ]
// Circle draws a circle of the specified radius around each Pushed point. If the thickness is 0, // the circle will be filled, otherwise a circle outline of the specified thickness will be drawn.
[ "Circle", "draws", "a", "circle", "of", "the", "specified", "radius", "around", "each", "Pushed", "point", ".", "If", "the", "thickness", "is", "0", "the", "circle", "will", "be", "filled", "otherwise", "a", "circle", "outline", "of", "the", "specified", "thickness", "will", "be", "drawn", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L209-L215
train
faiface/pixel
imdraw/imdraw.go
Ellipse
func (imd *IMDraw) Ellipse(radius pixel.Vec, thickness float64) { if thickness == 0 { imd.fillEllipseArc(radius, 0, 2*math.Pi) } else { imd.outlineEllipseArc(radius, 0, 2*math.Pi, thickness, false) } }
go
func (imd *IMDraw) Ellipse(radius pixel.Vec, thickness float64) { if thickness == 0 { imd.fillEllipseArc(radius, 0, 2*math.Pi) } else { imd.outlineEllipseArc(radius, 0, 2*math.Pi, thickness, false) } }
[ "func", "(", "imd", "*", "IMDraw", ")", "Ellipse", "(", "radius", "pixel", ".", "Vec", ",", "thickness", "float64", ")", "{", "if", "thickness", "==", "0", "{", "imd", ".", "fillEllipseArc", "(", "radius", ",", "0", ",", "2", "*", "math", ".", "Pi", ")", "\n", "}", "else", "{", "imd", ".", "outlineEllipseArc", "(", "radius", ",", "0", ",", "2", "*", "math", ".", "Pi", ",", "thickness", ",", "false", ")", "\n", "}", "\n", "}" ]
// Ellipse draws an ellipse of the specified radius in each axis around each Pushed points. If the // thickness is 0, the ellipse will be filled, otherwise an ellipse outline of the specified // thickness will be drawn.
[ "Ellipse", "draws", "an", "ellipse", "of", "the", "specified", "radius", "in", "each", "axis", "around", "each", "Pushed", "points", ".", "If", "the", "thickness", "is", "0", "the", "ellipse", "will", "be", "filled", "otherwise", "an", "ellipse", "outline", "of", "the", "specified", "thickness", "will", "be", "drawn", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/imdraw/imdraw.go#L236-L242
train
faiface/pixel
pixelgl/input.go
Pressed
func (w *Window) Pressed(button Button) bool { return w.currInp.buttons[button] }
go
func (w *Window) Pressed(button Button) bool { return w.currInp.buttons[button] }
[ "func", "(", "w", "*", "Window", ")", "Pressed", "(", "button", "Button", ")", "bool", "{", "return", "w", ".", "currInp", ".", "buttons", "[", "button", "]", "\n", "}" ]
// Pressed returns whether the Button is currently pressed down.
[ "Pressed", "returns", "whether", "the", "Button", "is", "currently", "pressed", "down", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/input.go#L10-L12
train
faiface/pixel
pixelgl/input.go
JustPressed
func (w *Window) JustPressed(button Button) bool { return w.currInp.buttons[button] && !w.prevInp.buttons[button] }
go
func (w *Window) JustPressed(button Button) bool { return w.currInp.buttons[button] && !w.prevInp.buttons[button] }
[ "func", "(", "w", "*", "Window", ")", "JustPressed", "(", "button", "Button", ")", "bool", "{", "return", "w", ".", "currInp", ".", "buttons", "[", "button", "]", "&&", "!", "w", ".", "prevInp", ".", "buttons", "[", "button", "]", "\n", "}" ]
// JustPressed returns whether the Button has just been pressed down.
[ "JustPressed", "returns", "whether", "the", "Button", "has", "just", "been", "pressed", "down", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/input.go#L15-L17
train
faiface/pixel
pixelgl/input.go
Repeated
func (w *Window) Repeated(button Button) bool { return w.currInp.repeat[button] }
go
func (w *Window) Repeated(button Button) bool { return w.currInp.repeat[button] }
[ "func", "(", "w", "*", "Window", ")", "Repeated", "(", "button", "Button", ")", "bool", "{", "return", "w", ".", "currInp", ".", "repeat", "[", "button", "]", "\n", "}" ]
// Repeated returns whether a repeat event has been triggered on button. // // Repeat event occurs repeatedly when a button is held down for some time.
[ "Repeated", "returns", "whether", "a", "repeat", "event", "has", "been", "triggered", "on", "button", ".", "Repeat", "event", "occurs", "repeatedly", "when", "a", "button", "is", "held", "down", "for", "some", "time", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/input.go#L27-L29
train
faiface/pixel
pixelgl/input.go
SetMousePosition
func (w *Window) SetMousePosition(v pixel.Vec) { mainthread.Call(func() { if (v.X >= 0 && v.X <= w.bounds.W()) && (v.Y >= 0 && v.Y <= w.bounds.H()) { w.window.SetCursorPos( v.X+w.bounds.Min.X, (w.bounds.H()-v.Y)+w.bounds.Min.Y, ) w.prevInp.mouse = v w.currInp.mouse = v w.tempInp.mouse = v } }) }
go
func (w *Window) SetMousePosition(v pixel.Vec) { mainthread.Call(func() { if (v.X >= 0 && v.X <= w.bounds.W()) && (v.Y >= 0 && v.Y <= w.bounds.H()) { w.window.SetCursorPos( v.X+w.bounds.Min.X, (w.bounds.H()-v.Y)+w.bounds.Min.Y, ) w.prevInp.mouse = v w.currInp.mouse = v w.tempInp.mouse = v } }) }
[ "func", "(", "w", "*", "Window", ")", "SetMousePosition", "(", "v", "pixel", ".", "Vec", ")", "{", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "if", "(", "v", ".", "X", ">=", "0", "&&", "v", ".", "X", "<=", "w", ".", "bounds", ".", "W", "(", ")", ")", "&&", "(", "v", ".", "Y", ">=", "0", "&&", "v", ".", "Y", "<=", "w", ".", "bounds", ".", "H", "(", ")", ")", "{", "w", ".", "window", ".", "SetCursorPos", "(", "v", ".", "X", "+", "w", ".", "bounds", ".", "Min", ".", "X", ",", "(", "w", ".", "bounds", ".", "H", "(", ")", "-", "v", ".", "Y", ")", "+", "w", ".", "bounds", ".", "Min", ".", "Y", ",", ")", "\n", "w", ".", "prevInp", ".", "mouse", "=", "v", "\n", "w", ".", "currInp", ".", "mouse", "=", "v", "\n", "w", ".", "tempInp", ".", "mouse", "=", "v", "\n", "}", "\n", "}", ")", "\n", "}" ]
// SetMousePosition positions the mouse cursor anywhere within the Window's Bounds.
[ "SetMousePosition", "positions", "the", "mouse", "cursor", "anywhere", "within", "the", "Window", "s", "Bounds", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/input.go#L42-L55
train
faiface/pixel
pixelgl/input.go
String
func (b Button) String() string { name, ok := buttonNames[b] if !ok { return "Invalid" } return name }
go
func (b Button) String() string { name, ok := buttonNames[b] if !ok { return "Invalid" } return name }
[ "func", "(", "b", "Button", ")", "String", "(", ")", "string", "{", "name", ",", "ok", ":=", "buttonNames", "[", "b", "]", "\n", "if", "!", "ok", "{", "return", "\"Invalid\"", "\n", "}", "\n", "return", "name", "\n", "}" ]
// String returns a human-readable string describing the Button.
[ "String", "returns", "a", "human", "-", "readable", "string", "describing", "the", "Button", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/input.go#L218-L224
train
faiface/pixel
pixelgl/input.go
UpdateInput
func (w *Window) UpdateInput() { mainthread.Call(func() { glfw.PollEvents() }) w.prevInp = w.currInp w.currInp = w.tempInp w.tempInp.repeat = [KeyLast + 1]bool{} w.tempInp.scroll = pixel.ZV w.tempInp.typed = "" w.updateJoystickInput() }
go
func (w *Window) UpdateInput() { mainthread.Call(func() { glfw.PollEvents() }) w.prevInp = w.currInp w.currInp = w.tempInp w.tempInp.repeat = [KeyLast + 1]bool{} w.tempInp.scroll = pixel.ZV w.tempInp.typed = "" w.updateJoystickInput() }
[ "func", "(", "w", "*", "Window", ")", "UpdateInput", "(", ")", "{", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "glfw", ".", "PollEvents", "(", ")", "\n", "}", ")", "\n", "w", ".", "prevInp", "=", "w", ".", "currInp", "\n", "w", ".", "currInp", "=", "w", ".", "tempInp", "\n", "w", ".", "tempInp", ".", "repeat", "=", "[", "KeyLast", "+", "1", "]", "bool", "{", "}", "\n", "w", ".", "tempInp", ".", "scroll", "=", "pixel", ".", "ZV", "\n", "w", ".", "tempInp", ".", "typed", "=", "\"\"", "\n", "w", ".", "updateJoystickInput", "(", ")", "\n", "}" ]
// UpdateInput polls window events. Call this function to poll window events // without swapping buffers. Note that the Update method invokes UpdateInput.
[ "UpdateInput", "polls", "window", "events", ".", "Call", "this", "function", "to", "poll", "window", "events", "without", "swapping", "buffers", ".", "Note", "that", "the", "Update", "method", "invokes", "UpdateInput", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/input.go#L407-L420
train
faiface/pixel
pixelgl/glshader.go
update
func (gs *glShader) update() { gs.uf = nil for _, u := range gs.uniforms { gs.uf = append(gs.uf, glhf.Attr{ Name: u.Name, Type: u.Type, }) } var shader *glhf.Shader mainthread.Call(func() { var err error shader, err = glhf.NewShader( gs.vf, gs.uf, gs.vs, gs.fs, ) if err != nil { panic(errors.Wrap(err, "failed to create Canvas, there's a bug in the shader")) } }) gs.s = shader }
go
func (gs *glShader) update() { gs.uf = nil for _, u := range gs.uniforms { gs.uf = append(gs.uf, glhf.Attr{ Name: u.Name, Type: u.Type, }) } var shader *glhf.Shader mainthread.Call(func() { var err error shader, err = glhf.NewShader( gs.vf, gs.uf, gs.vs, gs.fs, ) if err != nil { panic(errors.Wrap(err, "failed to create Canvas, there's a bug in the shader")) } }) gs.s = shader }
[ "func", "(", "gs", "*", "glShader", ")", "update", "(", ")", "{", "gs", ".", "uf", "=", "nil", "\n", "for", "_", ",", "u", ":=", "range", "gs", ".", "uniforms", "{", "gs", ".", "uf", "=", "append", "(", "gs", ".", "uf", ",", "glhf", ".", "Attr", "{", "Name", ":", "u", ".", "Name", ",", "Type", ":", "u", ".", "Type", ",", "}", ")", "\n", "}", "\n", "var", "shader", "*", "glhf", ".", "Shader", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "var", "err", "error", "\n", "shader", ",", "err", "=", "glhf", ".", "NewShader", "(", "gs", ".", "vf", ",", "gs", ".", "uf", ",", "gs", ".", "vs", ",", "gs", ".", "fs", ",", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "errors", ".", "Wrap", "(", "err", ",", "\"failed to create Canvas, there's a bug in the shader\"", ")", ")", "\n", "}", "\n", "}", ")", "\n", "gs", ".", "s", "=", "shader", "\n", "}" ]
// reinitialize GLShader data and recompile the underlying gl shader object
[ "reinitialize", "GLShader", "data", "and", "recompile", "the", "underlying", "gl", "shader", "object" ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/glshader.go#L36-L59
train
faiface/pixel
pixelgl/glshader.go
getUniform
func (gs *glShader) getUniform(Name string) int { for i, u := range gs.uniforms { if u.Name == Name { return i } } return -1 }
go
func (gs *glShader) getUniform(Name string) int { for i, u := range gs.uniforms { if u.Name == Name { return i } } return -1 }
[ "func", "(", "gs", "*", "glShader", ")", "getUniform", "(", "Name", "string", ")", "int", "{", "for", "i", ",", "u", ":=", "range", "gs", ".", "uniforms", "{", "if", "u", ".", "Name", "==", "Name", "{", "return", "i", "\n", "}", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// gets the uniform index from GLShader
[ "gets", "the", "uniform", "index", "from", "GLShader" ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/glshader.go#L62-L69
train
faiface/pixel
pixelgl/glshader.go
baseShader
func baseShader(c *Canvas) { gs := &glShader{ vf: defaultCanvasVertexFormat, vs: baseCanvasVertexShader, fs: baseCanvasFragmentShader, } gs.setUniform("uTransform", &gs.uniformDefaults.transform) gs.setUniform("uColorMask", &gs.uniformDefaults.colormask) gs.setUniform("uBounds", &gs.uniformDefaults.bounds) gs.setUniform("uTexBounds", &gs.uniformDefaults.texbounds) c.shader = gs }
go
func baseShader(c *Canvas) { gs := &glShader{ vf: defaultCanvasVertexFormat, vs: baseCanvasVertexShader, fs: baseCanvasFragmentShader, } gs.setUniform("uTransform", &gs.uniformDefaults.transform) gs.setUniform("uColorMask", &gs.uniformDefaults.colormask) gs.setUniform("uBounds", &gs.uniformDefaults.bounds) gs.setUniform("uTexBounds", &gs.uniformDefaults.texbounds) c.shader = gs }
[ "func", "baseShader", "(", "c", "*", "Canvas", ")", "{", "gs", ":=", "&", "glShader", "{", "vf", ":", "defaultCanvasVertexFormat", ",", "vs", ":", "baseCanvasVertexShader", ",", "fs", ":", "baseCanvasFragmentShader", ",", "}", "\n", "gs", ".", "setUniform", "(", "\"uTransform\"", ",", "&", "gs", ".", "uniformDefaults", ".", "transform", ")", "\n", "gs", ".", "setUniform", "(", "\"uColorMask\"", ",", "&", "gs", ".", "uniformDefaults", ".", "colormask", ")", "\n", "gs", ".", "setUniform", "(", "\"uBounds\"", ",", "&", "gs", ".", "uniformDefaults", ".", "bounds", ")", "\n", "gs", ".", "setUniform", "(", "\"uTexBounds\"", ",", "&", "gs", ".", "uniformDefaults", ".", "texbounds", ")", "\n", "c", ".", "shader", "=", "gs", "\n", "}" ]
// Sets up a base shader with everything needed for a Pixel // canvas to render correctly. The defaults can be overridden // by simply using the SetUniform function.
[ "Sets", "up", "a", "base", "shader", "with", "everything", "needed", "for", "a", "Pixel", "canvas", "to", "render", "correctly", ".", "The", "defaults", "can", "be", "overridden", "by", "simply", "using", "the", "SetUniform", "function", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/glshader.go#L98-L111
train
faiface/pixel
pixelgl/glshader.go
Value
func (gu *gsUniformAttr) Value() interface{} { if !gu.ispointer { return gu.value } switch gu.Type { case glhf.Vec2: return *gu.value.(*mgl32.Vec2) case glhf.Vec3: return *gu.value.(*mgl32.Vec3) case glhf.Vec4: return *gu.value.(*mgl32.Vec4) case glhf.Mat2: return *gu.value.(*mgl32.Mat2) case glhf.Mat23: return *gu.value.(*mgl32.Mat2x3) case glhf.Mat24: return *gu.value.(*mgl32.Mat2x4) case glhf.Mat3: return *gu.value.(*mgl32.Mat3) case glhf.Mat32: return *gu.value.(*mgl32.Mat3x2) case glhf.Mat34: return *gu.value.(*mgl32.Mat3x4) case glhf.Mat4: return *gu.value.(*mgl32.Mat4) case glhf.Mat42: return *gu.value.(*mgl32.Mat4x2) case glhf.Mat43: return *gu.value.(*mgl32.Mat4x3) case glhf.Int: return *gu.value.(*int32) case glhf.Float: return *gu.value.(*float32) default: panic("invalid attrtype") } }
go
func (gu *gsUniformAttr) Value() interface{} { if !gu.ispointer { return gu.value } switch gu.Type { case glhf.Vec2: return *gu.value.(*mgl32.Vec2) case glhf.Vec3: return *gu.value.(*mgl32.Vec3) case glhf.Vec4: return *gu.value.(*mgl32.Vec4) case glhf.Mat2: return *gu.value.(*mgl32.Mat2) case glhf.Mat23: return *gu.value.(*mgl32.Mat2x3) case glhf.Mat24: return *gu.value.(*mgl32.Mat2x4) case glhf.Mat3: return *gu.value.(*mgl32.Mat3) case glhf.Mat32: return *gu.value.(*mgl32.Mat3x2) case glhf.Mat34: return *gu.value.(*mgl32.Mat3x4) case glhf.Mat4: return *gu.value.(*mgl32.Mat4) case glhf.Mat42: return *gu.value.(*mgl32.Mat4x2) case glhf.Mat43: return *gu.value.(*mgl32.Mat4x3) case glhf.Int: return *gu.value.(*int32) case glhf.Float: return *gu.value.(*float32) default: panic("invalid attrtype") } }
[ "func", "(", "gu", "*", "gsUniformAttr", ")", "Value", "(", ")", "interface", "{", "}", "{", "if", "!", "gu", ".", "ispointer", "{", "return", "gu", ".", "value", "\n", "}", "\n", "switch", "gu", ".", "Type", "{", "case", "glhf", ".", "Vec2", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Vec2", ")", "\n", "case", "glhf", ".", "Vec3", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Vec3", ")", "\n", "case", "glhf", ".", "Vec4", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Vec4", ")", "\n", "case", "glhf", ".", "Mat2", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat2", ")", "\n", "case", "glhf", ".", "Mat23", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat2x3", ")", "\n", "case", "glhf", ".", "Mat24", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat2x4", ")", "\n", "case", "glhf", ".", "Mat3", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat3", ")", "\n", "case", "glhf", ".", "Mat32", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat3x2", ")", "\n", "case", "glhf", ".", "Mat34", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat3x4", ")", "\n", "case", "glhf", ".", "Mat4", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat4", ")", "\n", "case", "glhf", ".", "Mat42", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat4x2", ")", "\n", "case", "glhf", ".", "Mat43", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "mgl32", ".", "Mat4x3", ")", "\n", "case", "glhf", ".", "Int", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "int32", ")", "\n", "case", "glhf", ".", "Float", ":", "return", "*", "gu", ".", "value", ".", "(", "*", "float32", ")", "\n", "default", ":", "panic", "(", "\"invalid attrtype\"", ")", "\n", "}", "\n", "}" ]
// Value returns the attribute's concrete value. If the stored value // is a pointer, we return the dereferenced value.
[ "Value", "returns", "the", "attribute", "s", "concrete", "value", ".", "If", "the", "stored", "value", "is", "a", "pointer", "we", "return", "the", "dereferenced", "value", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/glshader.go#L115-L151
train
faiface/pixel
pixelgl/window.go
Update
func (w *Window) Update() { mainthread.Call(func() { _, _, oldW, oldH := intBounds(w.bounds) newW, newH := w.window.GetSize() w.bounds = w.bounds.ResizedMin(w.bounds.Size().Add(pixel.V( float64(newW-oldW), float64(newH-oldH), ))) }) w.canvas.SetBounds(w.bounds) mainthread.Call(func() { w.begin() framebufferWidth, framebufferHeight := w.window.GetFramebufferSize() glhf.Bounds(0, 0, framebufferWidth, framebufferHeight) glhf.Clear(0, 0, 0, 0) w.canvas.gf.Frame().Begin() w.canvas.gf.Frame().Blit( nil, 0, 0, w.canvas.Texture().Width(), w.canvas.Texture().Height(), 0, 0, framebufferWidth, framebufferHeight, ) w.canvas.gf.Frame().End() if w.vsync { glfw.SwapInterval(1) } else { glfw.SwapInterval(0) } w.window.SwapBuffers() w.end() }) w.UpdateInput() }
go
func (w *Window) Update() { mainthread.Call(func() { _, _, oldW, oldH := intBounds(w.bounds) newW, newH := w.window.GetSize() w.bounds = w.bounds.ResizedMin(w.bounds.Size().Add(pixel.V( float64(newW-oldW), float64(newH-oldH), ))) }) w.canvas.SetBounds(w.bounds) mainthread.Call(func() { w.begin() framebufferWidth, framebufferHeight := w.window.GetFramebufferSize() glhf.Bounds(0, 0, framebufferWidth, framebufferHeight) glhf.Clear(0, 0, 0, 0) w.canvas.gf.Frame().Begin() w.canvas.gf.Frame().Blit( nil, 0, 0, w.canvas.Texture().Width(), w.canvas.Texture().Height(), 0, 0, framebufferWidth, framebufferHeight, ) w.canvas.gf.Frame().End() if w.vsync { glfw.SwapInterval(1) } else { glfw.SwapInterval(0) } w.window.SwapBuffers() w.end() }) w.UpdateInput() }
[ "func", "(", "w", "*", "Window", ")", "Update", "(", ")", "{", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "_", ",", "_", ",", "oldW", ",", "oldH", ":=", "intBounds", "(", "w", ".", "bounds", ")", "\n", "newW", ",", "newH", ":=", "w", ".", "window", ".", "GetSize", "(", ")", "\n", "w", ".", "bounds", "=", "w", ".", "bounds", ".", "ResizedMin", "(", "w", ".", "bounds", ".", "Size", "(", ")", ".", "Add", "(", "pixel", ".", "V", "(", "float64", "(", "newW", "-", "oldW", ")", ",", "float64", "(", "newH", "-", "oldH", ")", ",", ")", ")", ")", "\n", "}", ")", "\n", "w", ".", "canvas", ".", "SetBounds", "(", "w", ".", "bounds", ")", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "w", ".", "begin", "(", ")", "\n", "framebufferWidth", ",", "framebufferHeight", ":=", "w", ".", "window", ".", "GetFramebufferSize", "(", ")", "\n", "glhf", ".", "Bounds", "(", "0", ",", "0", ",", "framebufferWidth", ",", "framebufferHeight", ")", "\n", "glhf", ".", "Clear", "(", "0", ",", "0", ",", "0", ",", "0", ")", "\n", "w", ".", "canvas", ".", "gf", ".", "Frame", "(", ")", ".", "Begin", "(", ")", "\n", "w", ".", "canvas", ".", "gf", ".", "Frame", "(", ")", ".", "Blit", "(", "nil", ",", "0", ",", "0", ",", "w", ".", "canvas", ".", "Texture", "(", ")", ".", "Width", "(", ")", ",", "w", ".", "canvas", ".", "Texture", "(", ")", ".", "Height", "(", ")", ",", "0", ",", "0", ",", "framebufferWidth", ",", "framebufferHeight", ",", ")", "\n", "w", ".", "canvas", ".", "gf", ".", "Frame", "(", ")", ".", "End", "(", ")", "\n", "if", "w", ".", "vsync", "{", "glfw", ".", "SwapInterval", "(", "1", ")", "\n", "}", "else", "{", "glfw", ".", "SwapInterval", "(", "0", ")", "\n", "}", "\n", "w", ".", "window", ".", "SwapBuffers", "(", ")", "\n", "w", ".", "end", "(", ")", "\n", "}", ")", "\n", "w", ".", "UpdateInput", "(", ")", "\n", "}" ]
// Update swaps buffers and polls events. Call this method at the end of each frame.
[ "Update", "swaps", "buffers", "and", "polls", "events", ".", "Call", "this", "method", "at", "the", "end", "of", "each", "frame", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L163-L200
train
faiface/pixel
pixelgl/window.go
SetClosed
func (w *Window) SetClosed(closed bool) { mainthread.Call(func() { w.window.SetShouldClose(closed) }) }
go
func (w *Window) SetClosed(closed bool) { mainthread.Call(func() { w.window.SetShouldClose(closed) }) }
[ "func", "(", "w", "*", "Window", ")", "SetClosed", "(", "closed", "bool", ")", "{", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "w", ".", "window", ".", "SetShouldClose", "(", "closed", ")", "\n", "}", ")", "\n", "}" ]
// SetClosed sets the closed flag of the Window. // // This is useful when overriding the user's attempt to close the Window, or just to close the // Window from within the program.
[ "SetClosed", "sets", "the", "closed", "flag", "of", "the", "Window", ".", "This", "is", "useful", "when", "overriding", "the", "user", "s", "attempt", "to", "close", "the", "Window", "or", "just", "to", "close", "the", "Window", "from", "within", "the", "program", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L206-L210
train
faiface/pixel
pixelgl/window.go
Closed
func (w *Window) Closed() bool { var closed bool mainthread.Call(func() { closed = w.window.ShouldClose() }) return closed }
go
func (w *Window) Closed() bool { var closed bool mainthread.Call(func() { closed = w.window.ShouldClose() }) return closed }
[ "func", "(", "w", "*", "Window", ")", "Closed", "(", ")", "bool", "{", "var", "closed", "bool", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "closed", "=", "w", ".", "window", ".", "ShouldClose", "(", ")", "\n", "}", ")", "\n", "return", "closed", "\n", "}" ]
// Closed returns the closed flag of the Window, which reports whether the Window should be closed. // // The closed flag is automatically set when a user attempts to close the Window.
[ "Closed", "returns", "the", "closed", "flag", "of", "the", "Window", "which", "reports", "whether", "the", "Window", "should", "be", "closed", ".", "The", "closed", "flag", "is", "automatically", "set", "when", "a", "user", "attempts", "to", "close", "the", "Window", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L215-L221
train