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
nareix/joy4
av/av.go
MakeAudioCodecType
func MakeAudioCodecType(base uint32) (c CodecType) { c = CodecType(base)<<codecTypeOtherBits | CodecType(codecTypeAudioBit) return }
go
func MakeAudioCodecType(base uint32) (c CodecType) { c = CodecType(base)<<codecTypeOtherBits | CodecType(codecTypeAudioBit) return }
[ "func", "MakeAudioCodecType", "(", "base", "uint32", ")", "(", "c", "CodecType", ")", "{", "c", "=", "CodecType", "(", "base", ")", "<<", "codecTypeOtherBits", "|", "CodecType", "(", "codecTypeAudioBit", ")", "\n", "return", "\n", "}" ]
// Make a new audio codec type.
[ "Make", "a", "new", "audio", "codec", "type", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L157-L160
train
nareix/joy4
av/av.go
HasSameFormat
func (self AudioFrame) HasSameFormat(other AudioFrame) bool { if self.SampleRate != other.SampleRate { return false } if self.ChannelLayout != other.ChannelLayout { return false } if self.SampleFormat != other.SampleFormat { return false } return true }
go
func (self AudioFrame) HasSameFormat(other AudioFrame) bool { if self.SampleRate != other.SampleRate { return false } if self.ChannelLayout != other.ChannelLayout { return false } if self.SampleFormat != other.SampleFormat { return false } return true }
[ "func", "(", "self", "AudioFrame", ")", "HasSameFormat", "(", "other", "AudioFrame", ")", "bool", "{", "if", "self", ".", "SampleRate", "!=", "other", ".", "SampleRate", "{", "return", "false", "\n", "}", "\n", "if", "self", ".", "ChannelLayout", "!=", "other", ".", "ChannelLayout", "{", "return", "false", "\n", "}", "\n", "if", "self", ".", "SampleFormat", "!=", "other", ".", "SampleFormat", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Check this audio frame has same format as other audio frame.
[ "Check", "this", "audio", "frame", "has", "same", "format", "as", "other", "audio", "frame", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L252-L263
train
nareix/joy4
av/av.go
Slice
func (self AudioFrame) Slice(start int, end int) (out AudioFrame) { if start > end { panic(fmt.Sprintf("av: AudioFrame split failed start=%d end=%d invalid", start, end)) } out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount = end - start size := self.SampleFormat.BytesPerSample() for i := range out.Data { out.Data[i] = out.Data[i][start*size : end*size] } return }
go
func (self AudioFrame) Slice(start int, end int) (out AudioFrame) { if start > end { panic(fmt.Sprintf("av: AudioFrame split failed start=%d end=%d invalid", start, end)) } out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount = end - start size := self.SampleFormat.BytesPerSample() for i := range out.Data { out.Data[i] = out.Data[i][start*size : end*size] } return }
[ "func", "(", "self", "AudioFrame", ")", "Slice", "(", "start", "int", ",", "end", "int", ")", "(", "out", "AudioFrame", ")", "{", "if", "start", ">", "end", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"av: AudioFrame split failed start=%d end=%d invalid\"", ",", "start", ",", "end", ")", ")", "\n", "}", "\n", "out", "=", "self", "\n", "out", ".", "Data", "=", "append", "(", "[", "]", "[", "]", "byte", "(", "nil", ")", ",", "out", ".", "Data", "...", ")", "\n", "out", ".", "SampleCount", "=", "end", "-", "start", "\n", "size", ":=", "self", ".", "SampleFormat", ".", "BytesPerSample", "(", ")", "\n", "for", "i", ":=", "range", "out", ".", "Data", "{", "out", ".", "Data", "[", "i", "]", "=", "out", ".", "Data", "[", "i", "]", "[", "start", "*", "size", ":", "end", "*", "size", "]", "\n", "}", "\n", "return", "\n", "}" ]
// Split sample audio sample from this frame.
[ "Split", "sample", "audio", "sample", "from", "this", "frame", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L266-L278
train
nareix/joy4
av/av.go
Concat
func (self AudioFrame) Concat(in AudioFrame) (out AudioFrame) { out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount += in.SampleCount for i := range out.Data { out.Data[i] = append(out.Data[i], in.Data[i]...) } return }
go
func (self AudioFrame) Concat(in AudioFrame) (out AudioFrame) { out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount += in.SampleCount for i := range out.Data { out.Data[i] = append(out.Data[i], in.Data[i]...) } return }
[ "func", "(", "self", "AudioFrame", ")", "Concat", "(", "in", "AudioFrame", ")", "(", "out", "AudioFrame", ")", "{", "out", "=", "self", "\n", "out", ".", "Data", "=", "append", "(", "[", "]", "[", "]", "byte", "(", "nil", ")", ",", "out", ".", "Data", "...", ")", "\n", "out", ".", "SampleCount", "+=", "in", ".", "SampleCount", "\n", "for", "i", ":=", "range", "out", ".", "Data", "{", "out", ".", "Data", "[", "i", "]", "=", "append", "(", "out", ".", "Data", "[", "i", "]", ",", "in", ".", "Data", "[", "i", "]", "...", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Concat two audio frames.
[ "Concat", "two", "audio", "frames", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L281-L289
train
nareix/joy4
av/transcode/transcode.go
Do
func (self *Transcoder) Do(pkt av.Packet) (out []av.Packet, err error) { stream := self.streams[pkt.Idx] if stream.aenc != nil && stream.adec != nil { if out, err = stream.audioDecodeAndEncode(pkt); err != nil { return } } else { out = append(out, pkt) } return }
go
func (self *Transcoder) Do(pkt av.Packet) (out []av.Packet, err error) { stream := self.streams[pkt.Idx] if stream.aenc != nil && stream.adec != nil { if out, err = stream.audioDecodeAndEncode(pkt); err != nil { return } } else { out = append(out, pkt) } return }
[ "func", "(", "self", "*", "Transcoder", ")", "Do", "(", "pkt", "av", ".", "Packet", ")", "(", "out", "[", "]", "av", ".", "Packet", ",", "err", "error", ")", "{", "stream", ":=", "self", ".", "streams", "[", "pkt", ".", "Idx", "]", "\n", "if", "stream", ".", "aenc", "!=", "nil", "&&", "stream", ".", "adec", "!=", "nil", "{", "if", "out", ",", "err", "=", "stream", ".", "audioDecodeAndEncode", "(", "pkt", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "else", "{", "out", "=", "append", "(", "out", ",", "pkt", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Do the transcode. // // In audio transcoding one Packet may transcode into many Packets // packet time will be adjusted automatically.
[ "Do", "the", "transcode", ".", "In", "audio", "transcoding", "one", "Packet", "may", "transcode", "into", "many", "Packets", "packet", "time", "will", "be", "adjusted", "automatically", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L114-L124
train
nareix/joy4
av/transcode/transcode.go
Streams
func (self *Transcoder) Streams() (streams []av.CodecData, err error) { for _, stream := range self.streams { streams = append(streams, stream.codec) } return }
go
func (self *Transcoder) Streams() (streams []av.CodecData, err error) { for _, stream := range self.streams { streams = append(streams, stream.codec) } return }
[ "func", "(", "self", "*", "Transcoder", ")", "Streams", "(", ")", "(", "streams", "[", "]", "av", ".", "CodecData", ",", "err", "error", ")", "{", "for", "_", ",", "stream", ":=", "range", "self", ".", "streams", "{", "streams", "=", "append", "(", "streams", ",", "stream", ".", "codec", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Get CodecDatas after transcoding.
[ "Get", "CodecDatas", "after", "transcoding", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L127-L132
train
nareix/joy4
av/transcode/transcode.go
Close
func (self *Transcoder) Close() (err error) { for _, stream := range self.streams { if stream.aenc != nil { stream.aenc.Close() stream.aenc = nil } if stream.adec != nil { stream.adec.Close() stream.adec = nil } } self.streams = nil return }
go
func (self *Transcoder) Close() (err error) { for _, stream := range self.streams { if stream.aenc != nil { stream.aenc.Close() stream.aenc = nil } if stream.adec != nil { stream.adec.Close() stream.adec = nil } } self.streams = nil return }
[ "func", "(", "self", "*", "Transcoder", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "for", "_", ",", "stream", ":=", "range", "self", ".", "streams", "{", "if", "stream", ".", "aenc", "!=", "nil", "{", "stream", ".", "aenc", ".", "Close", "(", ")", "\n", "stream", ".", "aenc", "=", "nil", "\n", "}", "\n", "if", "stream", ".", "adec", "!=", "nil", "{", "stream", ".", "adec", ".", "Close", "(", ")", "\n", "stream", ".", "adec", "=", "nil", "\n", "}", "\n", "}", "\n", "self", ".", "streams", "=", "nil", "\n", "return", "\n", "}" ]
// Close transcoder, close related encoder and decoders.
[ "Close", "transcoder", "close", "related", "encoder", "and", "decoders", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L135-L148
train
nareix/joy4
av/pubsub/queue.go
WritePacket
func (self *Queue) WritePacket(pkt av.Packet) (err error) { self.lock.Lock() self.buf.Push(pkt) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount++ } for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 { pkt := self.buf.Pop() if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount-- } if self.curgopcount < self.maxgopcount { break } } //println("shrink", self.curgopcount, self.maxgopcount, self.buf.Head, self.buf.Tail, "count", self.buf.Count, "size", self.buf.Size) self.cond.Broadcast() self.lock.Unlock() return }
go
func (self *Queue) WritePacket(pkt av.Packet) (err error) { self.lock.Lock() self.buf.Push(pkt) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount++ } for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 { pkt := self.buf.Pop() if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount-- } if self.curgopcount < self.maxgopcount { break } } //println("shrink", self.curgopcount, self.maxgopcount, self.buf.Head, self.buf.Tail, "count", self.buf.Count, "size", self.buf.Size) self.cond.Broadcast() self.lock.Unlock() return }
[ "func", "(", "self", "*", "Queue", ")", "WritePacket", "(", "pkt", "av", ".", "Packet", ")", "(", "err", "error", ")", "{", "self", ".", "lock", ".", "Lock", "(", ")", "\n", "self", ".", "buf", ".", "Push", "(", "pkt", ")", "\n", "if", "pkt", ".", "Idx", "==", "int8", "(", "self", ".", "videoidx", ")", "&&", "pkt", ".", "IsKeyFrame", "{", "self", ".", "curgopcount", "++", "\n", "}", "\n", "for", "self", ".", "curgopcount", ">=", "self", ".", "maxgopcount", "&&", "self", ".", "buf", ".", "Count", ">", "1", "{", "pkt", ":=", "self", ".", "buf", ".", "Pop", "(", ")", "\n", "if", "pkt", ".", "Idx", "==", "int8", "(", "self", ".", "videoidx", ")", "&&", "pkt", ".", "IsKeyFrame", "{", "self", ".", "curgopcount", "--", "\n", "}", "\n", "if", "self", ".", "curgopcount", "<", "self", ".", "maxgopcount", "{", "break", "\n", "}", "\n", "}", "\n", "self", ".", "cond", ".", "Broadcast", "(", ")", "\n", "self", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "\n", "}" ]
// Put packet into buffer, old packets will be discared.
[ "Put", "packet", "into", "buffer", "old", "packets", "will", "be", "discared", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L83-L106
train
nareix/joy4
av/pubsub/queue.go
Oldest
func (self *Queue) Oldest() *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { return buf.Head } return cursor }
go
func (self *Queue) Oldest() *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { return buf.Head } return cursor }
[ "func", "(", "self", "*", "Queue", ")", "Oldest", "(", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", "Buf", ",", "videoidx", "int", ")", "pktque", ".", "BufPos", "{", "return", "buf", ".", "Head", "\n", "}", "\n", "return", "cursor", "\n", "}" ]
// Create cursor position at oldest buffered packet.
[ "Create", "cursor", "position", "at", "oldest", "buffered", "packet", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L131-L137
train
nareix/joy4
av/pubsub/queue.go
DelayedTime
func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if buf.IsValidPos(i) { end := buf.Get(i) for buf.IsValidPos(i) { if end.Time-buf.Get(i).Time > dur { break } i-- } } return i } return cursor }
go
func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if buf.IsValidPos(i) { end := buf.Get(i) for buf.IsValidPos(i) { if end.Time-buf.Get(i).Time > dur { break } i-- } } return i } return cursor }
[ "func", "(", "self", "*", "Queue", ")", "DelayedTime", "(", "dur", "time", ".", "Duration", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", "Buf", ",", "videoidx", "int", ")", "pktque", ".", "BufPos", "{", "i", ":=", "buf", ".", "Tail", "-", "1", "\n", "if", "buf", ".", "IsValidPos", "(", "i", ")", "{", "end", ":=", "buf", ".", "Get", "(", "i", ")", "\n", "for", "buf", ".", "IsValidPos", "(", "i", ")", "{", "if", "end", ".", "Time", "-", "buf", ".", "Get", "(", "i", ")", ".", "Time", ">", "dur", "{", "break", "\n", "}", "\n", "i", "--", "\n", "}", "\n", "}", "\n", "return", "i", "\n", "}", "\n", "return", "cursor", "\n", "}" ]
// Create cursor position at specific time in buffered packets.
[ "Create", "cursor", "position", "at", "specific", "time", "in", "buffered", "packets", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L140-L156
train
nareix/joy4
av/pubsub/queue.go
DelayedGopCount
func (self *Queue) DelayedGopCount(n int) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if videoidx != -1 { for gop := 0; buf.IsValidPos(i) && gop < n; i-- { pkt := buf.Get(i) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { gop++ } } } return i } return cursor }
go
func (self *Queue) DelayedGopCount(n int) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if videoidx != -1 { for gop := 0; buf.IsValidPos(i) && gop < n; i-- { pkt := buf.Get(i) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { gop++ } } } return i } return cursor }
[ "func", "(", "self", "*", "Queue", ")", "DelayedGopCount", "(", "n", "int", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", "Buf", ",", "videoidx", "int", ")", "pktque", ".", "BufPos", "{", "i", ":=", "buf", ".", "Tail", "-", "1", "\n", "if", "videoidx", "!=", "-", "1", "{", "for", "gop", ":=", "0", ";", "buf", ".", "IsValidPos", "(", "i", ")", "&&", "gop", "<", "n", ";", "i", "--", "{", "pkt", ":=", "buf", ".", "Get", "(", "i", ")", "\n", "if", "pkt", ".", "Idx", "==", "int8", "(", "self", ".", "videoidx", ")", "&&", "pkt", ".", "IsKeyFrame", "{", "gop", "++", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "i", "\n", "}", "\n", "return", "cursor", "\n", "}" ]
// Create cursor position at specific delayed GOP count in buffered packets.
[ "Create", "cursor", "position", "at", "specific", "delayed", "GOP", "count", "in", "buffered", "packets", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L159-L174
train
nareix/joy4
av/pubsub/queue.go
ReadPacket
func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) { self.que.cond.L.Lock() buf := self.que.buf if !self.gotpos { self.pos = self.init(buf, self.que.videoidx) self.gotpos = true } for { if self.pos.LT(buf.Head) { self.pos = buf.Head } else if self.pos.GT(buf.Tail) { self.pos = buf.Tail } if buf.IsValidPos(self.pos) { pkt = buf.Get(self.pos) self.pos++ break } if self.que.closed { err = io.EOF break } self.que.cond.Wait() } self.que.cond.L.Unlock() return }
go
func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) { self.que.cond.L.Lock() buf := self.que.buf if !self.gotpos { self.pos = self.init(buf, self.que.videoidx) self.gotpos = true } for { if self.pos.LT(buf.Head) { self.pos = buf.Head } else if self.pos.GT(buf.Tail) { self.pos = buf.Tail } if buf.IsValidPos(self.pos) { pkt = buf.Get(self.pos) self.pos++ break } if self.que.closed { err = io.EOF break } self.que.cond.Wait() } self.que.cond.L.Unlock() return }
[ "func", "(", "self", "*", "QueueCursor", ")", "ReadPacket", "(", ")", "(", "pkt", "av", ".", "Packet", ",", "err", "error", ")", "{", "self", ".", "que", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "buf", ":=", "self", ".", "que", ".", "buf", "\n", "if", "!", "self", ".", "gotpos", "{", "self", ".", "pos", "=", "self", ".", "init", "(", "buf", ",", "self", ".", "que", ".", "videoidx", ")", "\n", "self", ".", "gotpos", "=", "true", "\n", "}", "\n", "for", "{", "if", "self", ".", "pos", ".", "LT", "(", "buf", ".", "Head", ")", "{", "self", ".", "pos", "=", "buf", ".", "Head", "\n", "}", "else", "if", "self", ".", "pos", ".", "GT", "(", "buf", ".", "Tail", ")", "{", "self", ".", "pos", "=", "buf", ".", "Tail", "\n", "}", "\n", "if", "buf", ".", "IsValidPos", "(", "self", ".", "pos", ")", "{", "pkt", "=", "buf", ".", "Get", "(", "self", ".", "pos", ")", "\n", "self", ".", "pos", "++", "\n", "break", "\n", "}", "\n", "if", "self", ".", "que", ".", "closed", "{", "err", "=", "io", ".", "EOF", "\n", "break", "\n", "}", "\n", "self", ".", "que", ".", "cond", ".", "Wait", "(", ")", "\n", "}", "\n", "self", ".", "que", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n", "return", "\n", "}" ]
// ReadPacket will not consume packets in Queue, it's just a cursor.
[ "ReadPacket", "will", "not", "consume", "packets", "in", "Queue", "it", "s", "just", "a", "cursor", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L191-L217
train
go-martini/martini
martini.go
New
func New() *Martini { m := &Martini{Injector: inject.New(), action: func() {}, logger: log.New(os.Stdout, "[martini] ", 0)} m.Map(m.logger) m.Map(defaultReturnHandler()) return m }
go
func New() *Martini { m := &Martini{Injector: inject.New(), action: func() {}, logger: log.New(os.Stdout, "[martini] ", 0)} m.Map(m.logger) m.Map(defaultReturnHandler()) return m }
[ "func", "New", "(", ")", "*", "Martini", "{", "m", ":=", "&", "Martini", "{", "Injector", ":", "inject", ".", "New", "(", ")", ",", "action", ":", "func", "(", ")", "{", "}", ",", "logger", ":", "log", ".", "New", "(", "os", ".", "Stdout", ",", "\"[martini] \"", ",", "0", ")", "}", "\n", "m", ".", "Map", "(", "m", ".", "logger", ")", "\n", "m", ".", "Map", "(", "defaultReturnHandler", "(", ")", ")", "\n", "return", "m", "\n", "}" ]
// New creates a bare bones Martini instance. Use this method if you want to have full control over the middleware that is used.
[ "New", "creates", "a", "bare", "bones", "Martini", "instance", ".", "Use", "this", "method", "if", "you", "want", "to", "have", "full", "control", "over", "the", "middleware", "that", "is", "used", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L38-L43
train
go-martini/martini
martini.go
Logger
func (m *Martini) Logger(logger *log.Logger) { m.logger = logger m.Map(m.logger) }
go
func (m *Martini) Logger(logger *log.Logger) { m.logger = logger m.Map(m.logger) }
[ "func", "(", "m", "*", "Martini", ")", "Logger", "(", "logger", "*", "log", ".", "Logger", ")", "{", "m", ".", "logger", "=", "logger", "\n", "m", ".", "Map", "(", "m", ".", "logger", ")", "\n", "}" ]
// Logger sets the logger
[ "Logger", "sets", "the", "logger" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L61-L64
train
go-martini/martini
martini.go
Use
func (m *Martini) Use(handler Handler) { validateHandler(handler) m.handlers = append(m.handlers, handler) }
go
func (m *Martini) Use(handler Handler) { validateHandler(handler) m.handlers = append(m.handlers, handler) }
[ "func", "(", "m", "*", "Martini", ")", "Use", "(", "handler", "Handler", ")", "{", "validateHandler", "(", "handler", ")", "\n", "m", ".", "handlers", "=", "append", "(", "m", ".", "handlers", ",", "handler", ")", "\n", "}" ]
// Use adds a middleware Handler to the stack. Will panic if the handler is not a callable func. Middleware Handlers are invoked in the order that they are added.
[ "Use", "adds", "a", "middleware", "Handler", "to", "the", "stack", ".", "Will", "panic", "if", "the", "handler", "is", "not", "a", "callable", "func", ".", "Middleware", "Handlers", "are", "invoked", "in", "the", "order", "that", "they", "are", "added", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L67-L71
train
go-martini/martini
martini.go
ServeHTTP
func (m *Martini) ServeHTTP(res http.ResponseWriter, req *http.Request) { m.createContext(res, req).run() }
go
func (m *Martini) ServeHTTP(res http.ResponseWriter, req *http.Request) { m.createContext(res, req).run() }
[ "func", "(", "m", "*", "Martini", ")", "ServeHTTP", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "m", ".", "createContext", "(", "res", ",", "req", ")", ".", "run", "(", ")", "\n", "}" ]
// ServeHTTP is the HTTP Entry point for a Martini instance. Useful if you want to control your own HTTP server.
[ "ServeHTTP", "is", "the", "HTTP", "Entry", "point", "for", "a", "Martini", "instance", ".", "Useful", "if", "you", "want", "to", "control", "your", "own", "HTTP", "server", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L74-L76
train
go-martini/martini
martini.go
RunOnAddr
func (m *Martini) RunOnAddr(addr string) { // TODO: Should probably be implemented using a new instance of http.Server in place of // calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use. // This would also allow to improve testing when a custom host and port are passed. logger := m.Injector.Get(reflect.TypeOf(m.logger)).Interface().(*log.Logger) logger.Printf("listening on %s (%s)\n", addr, Env) logger.Fatalln(http.ListenAndServe(addr, m)) }
go
func (m *Martini) RunOnAddr(addr string) { // TODO: Should probably be implemented using a new instance of http.Server in place of // calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use. // This would also allow to improve testing when a custom host and port are passed. logger := m.Injector.Get(reflect.TypeOf(m.logger)).Interface().(*log.Logger) logger.Printf("listening on %s (%s)\n", addr, Env) logger.Fatalln(http.ListenAndServe(addr, m)) }
[ "func", "(", "m", "*", "Martini", ")", "RunOnAddr", "(", "addr", "string", ")", "{", "logger", ":=", "m", ".", "Injector", ".", "Get", "(", "reflect", ".", "TypeOf", "(", "m", ".", "logger", ")", ")", ".", "Interface", "(", ")", ".", "(", "*", "log", ".", "Logger", ")", "\n", "logger", ".", "Printf", "(", "\"listening on %s (%s)\\n\"", ",", "\\n", ",", "addr", ")", "\n", "Env", "\n", "}" ]
// Run the http server on a given host and port.
[ "Run", "the", "http", "server", "on", "a", "given", "host", "and", "port", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L79-L87
train
go-martini/martini
martini.go
Classic
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("public")) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
go
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("public")) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
[ "func", "Classic", "(", ")", "*", "ClassicMartini", "{", "r", ":=", "NewRouter", "(", ")", "\n", "m", ":=", "New", "(", ")", "\n", "m", ".", "Use", "(", "Logger", "(", ")", ")", "\n", "m", ".", "Use", "(", "Recovery", "(", ")", ")", "\n", "m", ".", "Use", "(", "Static", "(", "\"public\"", ")", ")", "\n", "m", ".", "MapTo", "(", "r", ",", "(", "*", "Routes", ")", "(", "nil", ")", ")", "\n", "m", ".", "Action", "(", "r", ".", "Handle", ")", "\n", "return", "&", "ClassicMartini", "{", "m", ",", "r", "}", "\n", "}" ]
// Classic creates a classic Martini with some basic default middleware - martini.Logger, martini.Recovery and martini.Static. // Classic also maps martini.Routes as a service.
[ "Classic", "creates", "a", "classic", "Martini", "with", "some", "basic", "default", "middleware", "-", "martini", ".", "Logger", "martini", ".", "Recovery", "and", "martini", ".", "Static", ".", "Classic", "also", "maps", "martini", ".", "Routes", "as", "a", "service", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L118-L127
train
go-martini/martini
router.go
URLWith
func (r *route) URLWith(args []string) string { if len(args) > 0 { argCount := len(args) i := 0 url := urlReg.ReplaceAllStringFunc(r.pattern, func(m string) string { var val interface{} if i < argCount { val = args[i] } else { val = m } i += 1 return fmt.Sprintf(`%v`, val) }) return url } return r.pattern }
go
func (r *route) URLWith(args []string) string { if len(args) > 0 { argCount := len(args) i := 0 url := urlReg.ReplaceAllStringFunc(r.pattern, func(m string) string { var val interface{} if i < argCount { val = args[i] } else { val = m } i += 1 return fmt.Sprintf(`%v`, val) }) return url } return r.pattern }
[ "func", "(", "r", "*", "route", ")", "URLWith", "(", "args", "[", "]", "string", ")", "string", "{", "if", "len", "(", "args", ")", ">", "0", "{", "argCount", ":=", "len", "(", "args", ")", "\n", "i", ":=", "0", "\n", "url", ":=", "urlReg", ".", "ReplaceAllStringFunc", "(", "r", ".", "pattern", ",", "func", "(", "m", "string", ")", "string", "{", "var", "val", "interface", "{", "}", "\n", "if", "i", "<", "argCount", "{", "val", "=", "args", "[", "i", "]", "\n", "}", "else", "{", "val", "=", "m", "\n", "}", "\n", "i", "+=", "1", "\n", "return", "fmt", ".", "Sprintf", "(", "`%v`", ",", "val", ")", "\n", "}", ")", "\n", "return", "url", "\n", "}", "\n", "return", "r", ".", "pattern", "\n", "}" ]
// URLWith returns the url pattern replacing the parameters for its values
[ "URLWith", "returns", "the", "url", "pattern", "replacing", "the", "parameters", "for", "its", "values" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L291-L309
train
go-martini/martini
router.go
URLFor
func (r *router) URLFor(name string, params ...interface{}) string { route := r.findRoute(name) if route == nil { panic("route not found") } var args []string for _, param := range params { switch v := param.(type) { case int: args = append(args, strconv.FormatInt(int64(v), 10)) case string: args = append(args, v) default: if v != nil { panic("Arguments passed to URLFor must be integers or strings") } } } return route.URLWith(args) }
go
func (r *router) URLFor(name string, params ...interface{}) string { route := r.findRoute(name) if route == nil { panic("route not found") } var args []string for _, param := range params { switch v := param.(type) { case int: args = append(args, strconv.FormatInt(int64(v), 10)) case string: args = append(args, v) default: if v != nil { panic("Arguments passed to URLFor must be integers or strings") } } } return route.URLWith(args) }
[ "func", "(", "r", "*", "router", ")", "URLFor", "(", "name", "string", ",", "params", "...", "interface", "{", "}", ")", "string", "{", "route", ":=", "r", ".", "findRoute", "(", "name", ")", "\n", "if", "route", "==", "nil", "{", "panic", "(", "\"route not found\"", ")", "\n", "}", "\n", "var", "args", "[", "]", "string", "\n", "for", "_", ",", "param", ":=", "range", "params", "{", "switch", "v", ":=", "param", ".", "(", "type", ")", "{", "case", "int", ":", "args", "=", "append", "(", "args", ",", "strconv", ".", "FormatInt", "(", "int64", "(", "v", ")", ",", "10", ")", ")", "\n", "case", "string", ":", "args", "=", "append", "(", "args", ",", "v", ")", "\n", "default", ":", "if", "v", "!=", "nil", "{", "panic", "(", "\"Arguments passed to URLFor must be integers or strings\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "route", ".", "URLWith", "(", "args", ")", "\n", "}" ]
// URLFor returns the url for the given route name.
[ "URLFor", "returns", "the", "url", "for", "the", "given", "route", "name", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L338-L360
train
go-martini/martini
router.go
MethodsFor
func (r *router) MethodsFor(path string) []string { methods := []string{} for _, route := range r.getRoutes() { matches := route.regex.FindStringSubmatch(path) if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) { methods = append(methods, route.method) } } return methods }
go
func (r *router) MethodsFor(path string) []string { methods := []string{} for _, route := range r.getRoutes() { matches := route.regex.FindStringSubmatch(path) if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) { methods = append(methods, route.method) } } return methods }
[ "func", "(", "r", "*", "router", ")", "MethodsFor", "(", "path", "string", ")", "[", "]", "string", "{", "methods", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "route", ":=", "range", "r", ".", "getRoutes", "(", ")", "{", "matches", ":=", "route", ".", "regex", ".", "FindStringSubmatch", "(", "path", ")", "\n", "if", "len", "(", "matches", ")", ">", "0", "&&", "matches", "[", "0", "]", "==", "path", "&&", "!", "hasMethod", "(", "methods", ",", "route", ".", "method", ")", "{", "methods", "=", "append", "(", "methods", ",", "route", ".", "method", ")", "\n", "}", "\n", "}", "\n", "return", "methods", "\n", "}" ]
// MethodsFor returns all methods available for path
[ "MethodsFor", "returns", "all", "methods", "available", "for", "path" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L383-L392
train
go-martini/martini
logger.go
Logger
func Logger() Handler { return func(res http.ResponseWriter, req *http.Request, c Context, log *log.Logger) { start := time.Now() addr := req.Header.Get("X-Real-IP") if addr == "" { addr = req.Header.Get("X-Forwarded-For") if addr == "" { addr = req.RemoteAddr } } log.Printf("Started %s %s for %s", req.Method, req.URL.Path, addr) rw := res.(ResponseWriter) c.Next() log.Printf("Completed %v %s in %v\n", rw.Status(), http.StatusText(rw.Status()), time.Since(start)) } }
go
func Logger() Handler { return func(res http.ResponseWriter, req *http.Request, c Context, log *log.Logger) { start := time.Now() addr := req.Header.Get("X-Real-IP") if addr == "" { addr = req.Header.Get("X-Forwarded-For") if addr == "" { addr = req.RemoteAddr } } log.Printf("Started %s %s for %s", req.Method, req.URL.Path, addr) rw := res.(ResponseWriter) c.Next() log.Printf("Completed %v %s in %v\n", rw.Status(), http.StatusText(rw.Status()), time.Since(start)) } }
[ "func", "Logger", "(", ")", "Handler", "{", "return", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "c", "Context", ",", "log", "*", "log", ".", "Logger", ")", "{", "start", ":=", "time", ".", "Now", "(", ")", "\n", "addr", ":=", "req", ".", "Header", ".", "Get", "(", "\"X-Real-IP\"", ")", "\n", "if", "addr", "==", "\"\"", "{", "addr", "=", "req", ".", "Header", ".", "Get", "(", "\"X-Forwarded-For\"", ")", "\n", "if", "addr", "==", "\"\"", "{", "addr", "=", "req", ".", "RemoteAddr", "\n", "}", "\n", "}", "\n", "log", ".", "Printf", "(", "\"Started %s %s for %s\"", ",", "req", ".", "Method", ",", "req", ".", "URL", ".", "Path", ",", "addr", ")", "\n", "rw", ":=", "res", ".", "(", "ResponseWriter", ")", "\n", "c", ".", "Next", "(", ")", "\n", "log", ".", "Printf", "(", "\"Completed %v %s in %v\\n\"", ",", "\\n", ",", "rw", ".", "Status", "(", ")", ",", "http", ".", "StatusText", "(", "rw", ".", "Status", "(", ")", ")", ")", "\n", "}", "\n", "}" ]
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
[ "Logger", "returns", "a", "middleware", "handler", "that", "logs", "the", "request", "as", "it", "goes", "in", "and", "the", "response", "as", "it", "goes", "out", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/logger.go#L10-L29
train
buger/jsonparser
escape.go
decodeSingleUnicodeEscape
func decodeSingleUnicodeEscape(in []byte) (rune, bool) { // We need at least 6 characters total if len(in) < 6 { return utf8.RuneError, false } // Convert hex to decimal h1, h2, h3, h4 := h2I(in[2]), h2I(in[3]), h2I(in[4]), h2I(in[5]) if h1 == badHex || h2 == badHex || h3 == badHex || h4 == badHex { return utf8.RuneError, false } // Compose the hex digits return rune(h1<<12 + h2<<8 + h3<<4 + h4), true }
go
func decodeSingleUnicodeEscape(in []byte) (rune, bool) { // We need at least 6 characters total if len(in) < 6 { return utf8.RuneError, false } // Convert hex to decimal h1, h2, h3, h4 := h2I(in[2]), h2I(in[3]), h2I(in[4]), h2I(in[5]) if h1 == badHex || h2 == badHex || h3 == badHex || h4 == badHex { return utf8.RuneError, false } // Compose the hex digits return rune(h1<<12 + h2<<8 + h3<<4 + h4), true }
[ "func", "decodeSingleUnicodeEscape", "(", "in", "[", "]", "byte", ")", "(", "rune", ",", "bool", ")", "{", "if", "len", "(", "in", ")", "<", "6", "{", "return", "utf8", ".", "RuneError", ",", "false", "\n", "}", "\n", "h1", ",", "h2", ",", "h3", ",", "h4", ":=", "h2I", "(", "in", "[", "2", "]", ")", ",", "h2I", "(", "in", "[", "3", "]", ")", ",", "h2I", "(", "in", "[", "4", "]", ")", ",", "h2I", "(", "in", "[", "5", "]", ")", "\n", "if", "h1", "==", "badHex", "||", "h2", "==", "badHex", "||", "h3", "==", "badHex", "||", "h4", "==", "badHex", "{", "return", "utf8", ".", "RuneError", ",", "false", "\n", "}", "\n", "return", "rune", "(", "h1", "<<", "12", "+", "h2", "<<", "8", "+", "h3", "<<", "4", "+", "h4", ")", ",", "true", "\n", "}" ]
// decodeSingleUnicodeEscape decodes a single \uXXXX escape sequence. The prefix \u is assumed to be present and // is not checked. // In JSON, these escapes can either come alone or as part of "UTF16 surrogate pairs" that must be handled together. // This function only handles one; decodeUnicodeEscape handles this more complex case.
[ "decodeSingleUnicodeEscape", "decodes", "a", "single", "\\", "uXXXX", "escape", "sequence", ".", "The", "prefix", "\\", "u", "is", "assumed", "to", "be", "present", "and", "is", "not", "checked", ".", "In", "JSON", "these", "escapes", "can", "either", "come", "alone", "or", "as", "part", "of", "UTF16", "surrogate", "pairs", "that", "must", "be", "handled", "together", ".", "This", "function", "only", "handles", "one", ";", "decodeUnicodeEscape", "handles", "this", "more", "complex", "case", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/escape.go#L39-L53
train
buger/jsonparser
bytes.go
parseInt
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) { if len(bytes) == 0 { return 0, false, false } var neg bool = false if bytes[0] == '-' { neg = true bytes = bytes[1:] } var b int64 = 0 for _, c := range bytes { if c >= '0' && c <= '9' { b = (10 * v) + int64(c-'0') } else { return 0, false, false } if overflow = (b < v); overflow { break } v = b } if overflow { if neg && bio.Equal(bytes, []byte(minInt64)) { return b, true, false } return 0, false, true } if neg { return -v, true, false } else { return v, true, false } }
go
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) { if len(bytes) == 0 { return 0, false, false } var neg bool = false if bytes[0] == '-' { neg = true bytes = bytes[1:] } var b int64 = 0 for _, c := range bytes { if c >= '0' && c <= '9' { b = (10 * v) + int64(c-'0') } else { return 0, false, false } if overflow = (b < v); overflow { break } v = b } if overflow { if neg && bio.Equal(bytes, []byte(minInt64)) { return b, true, false } return 0, false, true } if neg { return -v, true, false } else { return v, true, false } }
[ "func", "parseInt", "(", "bytes", "[", "]", "byte", ")", "(", "v", "int64", ",", "ok", "bool", ",", "overflow", "bool", ")", "{", "if", "len", "(", "bytes", ")", "==", "0", "{", "return", "0", ",", "false", ",", "false", "\n", "}", "\n", "var", "neg", "bool", "=", "false", "\n", "if", "bytes", "[", "0", "]", "==", "'-'", "{", "neg", "=", "true", "\n", "bytes", "=", "bytes", "[", "1", ":", "]", "\n", "}", "\n", "var", "b", "int64", "=", "0", "\n", "for", "_", ",", "c", ":=", "range", "bytes", "{", "if", "c", ">=", "'0'", "&&", "c", "<=", "'9'", "{", "b", "=", "(", "10", "*", "v", ")", "+", "int64", "(", "c", "-", "'0'", ")", "\n", "}", "else", "{", "return", "0", ",", "false", ",", "false", "\n", "}", "\n", "if", "overflow", "=", "(", "b", "<", "v", ")", ";", "overflow", "{", "break", "\n", "}", "\n", "v", "=", "b", "\n", "}", "\n", "if", "overflow", "{", "if", "neg", "&&", "bio", ".", "Equal", "(", "bytes", ",", "[", "]", "byte", "(", "minInt64", ")", ")", "{", "return", "b", ",", "true", ",", "false", "\n", "}", "\n", "return", "0", ",", "false", ",", "true", "\n", "}", "\n", "if", "neg", "{", "return", "-", "v", ",", "true", ",", "false", "\n", "}", "else", "{", "return", "v", ",", "true", ",", "false", "\n", "}", "\n", "}" ]
// About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON
[ "About", "2x", "faster", "then", "strconv", ".", "ParseInt", "because", "it", "only", "supports", "base", "10", "which", "is", "enough", "for", "JSON" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/bytes.go#L11-L47
train
buger/jsonparser
parser.go
lastToken
func lastToken(data []byte) int { for i := len(data) - 1; i >= 0; i-- { switch data[i] { case ' ', '\n', '\r', '\t': continue default: return i } } return -1 }
go
func lastToken(data []byte) int { for i := len(data) - 1; i >= 0; i-- { switch data[i] { case ' ', '\n', '\r', '\t': continue default: return i } } return -1 }
[ "func", "lastToken", "(", "data", "[", "]", "byte", ")", "int", "{", "for", "i", ":=", "len", "(", "data", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "switch", "data", "[", "i", "]", "{", "case", "' '", ",", "'\\n'", ",", "'\\r'", ",", "'\\t'", ":", "continue", "\n", "default", ":", "return", "i", "\n", "}", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// Find position of last character which is not whitespace
[ "Find", "position", "of", "last", "character", "which", "is", "not", "whitespace" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L137-L148
train
buger/jsonparser
parser.go
stringEnd
func stringEnd(data []byte) (int, bool) { escaped := false for i, c := range data { if c == '"' { if !escaped { return i + 1, false } else { j := i - 1 for { if j < 0 || data[j] != '\\' { return i + 1, true // even number of backslashes } j-- if j < 0 || data[j] != '\\' { break // odd number of backslashes } j-- } } } else if c == '\\' { escaped = true } } return -1, escaped }
go
func stringEnd(data []byte) (int, bool) { escaped := false for i, c := range data { if c == '"' { if !escaped { return i + 1, false } else { j := i - 1 for { if j < 0 || data[j] != '\\' { return i + 1, true // even number of backslashes } j-- if j < 0 || data[j] != '\\' { break // odd number of backslashes } j-- } } } else if c == '\\' { escaped = true } } return -1, escaped }
[ "func", "stringEnd", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "bool", ")", "{", "escaped", ":=", "false", "\n", "for", "i", ",", "c", ":=", "range", "data", "{", "if", "c", "==", "'\"'", "{", "if", "!", "escaped", "{", "return", "i", "+", "1", ",", "false", "\n", "}", "else", "{", "j", ":=", "i", "-", "1", "\n", "for", "{", "if", "j", "<", "0", "||", "data", "[", "j", "]", "!=", "'\\\\'", "{", "return", "i", "+", "1", ",", "true", "\n", "}", "\n", "j", "--", "\n", "if", "j", "<", "0", "||", "data", "[", "j", "]", "!=", "'\\\\'", "{", "break", "\n", "}", "\n", "j", "--", "\n", "}", "\n", "}", "\n", "}", "else", "if", "c", "==", "'\\\\'", "{", "escaped", "=", "true", "\n", "}", "\n", "}", "\n", "return", "-", "1", ",", "escaped", "\n", "}" ]
// Tries to find the end of string // Support if string contains escaped quote symbols.
[ "Tries", "to", "find", "the", "end", "of", "string", "Support", "if", "string", "contains", "escaped", "quote", "symbols", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L152-L178
train
buger/jsonparser
parser.go
ArrayEach
func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int, err error), keys ...string) (offset int, err error) { if len(data) == 0 { return -1, MalformedObjectError } offset = 1 if len(keys) > 0 { if offset = searchKeys(data, keys...); offset == -1 { return offset, KeyPathNotFoundError } // Go to closest value nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] != '[' { return offset, MalformedArrayError } offset++ } nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] == ']' { return offset, nil } for true { v, t, o, e := Get(data[offset:]) if e != nil { return offset, e } if o == 0 { break } if t != NotExist { cb(v, t, offset+o-len(v), e) } if e != nil { break } offset += o skipToToken := nextToken(data[offset:]) if skipToToken == -1 { return offset, MalformedArrayError } offset += skipToToken if data[offset] == ']' { break } if data[offset] != ',' { return offset, MalformedArrayError } offset++ } return offset, nil }
go
func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int, err error), keys ...string) (offset int, err error) { if len(data) == 0 { return -1, MalformedObjectError } offset = 1 if len(keys) > 0 { if offset = searchKeys(data, keys...); offset == -1 { return offset, KeyPathNotFoundError } // Go to closest value nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] != '[' { return offset, MalformedArrayError } offset++ } nO := nextToken(data[offset:]) if nO == -1 { return offset, MalformedJsonError } offset += nO if data[offset] == ']' { return offset, nil } for true { v, t, o, e := Get(data[offset:]) if e != nil { return offset, e } if o == 0 { break } if t != NotExist { cb(v, t, offset+o-len(v), e) } if e != nil { break } offset += o skipToToken := nextToken(data[offset:]) if skipToToken == -1 { return offset, MalformedArrayError } offset += skipToToken if data[offset] == ']' { break } if data[offset] != ',' { return offset, MalformedArrayError } offset++ } return offset, nil }
[ "func", "ArrayEach", "(", "data", "[", "]", "byte", ",", "cb", "func", "(", "value", "[", "]", "byte", ",", "dataType", "ValueType", ",", "offset", "int", ",", "err", "error", ")", ",", "keys", "...", "string", ")", "(", "offset", "int", ",", "err", "error", ")", "{", "if", "len", "(", "data", ")", "==", "0", "{", "return", "-", "1", ",", "MalformedObjectError", "\n", "}", "\n", "offset", "=", "1", "\n", "if", "len", "(", "keys", ")", ">", "0", "{", "if", "offset", "=", "searchKeys", "(", "data", ",", "keys", "...", ")", ";", "offset", "==", "-", "1", "{", "return", "offset", ",", "KeyPathNotFoundError", "\n", "}", "\n", "nO", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", "\n", "if", "nO", "==", "-", "1", "{", "return", "offset", ",", "MalformedJsonError", "\n", "}", "\n", "offset", "+=", "nO", "\n", "if", "data", "[", "offset", "]", "!=", "'['", "{", "return", "offset", ",", "MalformedArrayError", "\n", "}", "\n", "offset", "++", "\n", "}", "\n", "nO", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", "\n", "if", "nO", "==", "-", "1", "{", "return", "offset", ",", "MalformedJsonError", "\n", "}", "\n", "offset", "+=", "nO", "\n", "if", "data", "[", "offset", "]", "==", "']'", "{", "return", "offset", ",", "nil", "\n", "}", "\n", "for", "true", "{", "v", ",", "t", ",", "o", ",", "e", ":=", "Get", "(", "data", "[", "offset", ":", "]", ")", "\n", "if", "e", "!=", "nil", "{", "return", "offset", ",", "e", "\n", "}", "\n", "if", "o", "==", "0", "{", "break", "\n", "}", "\n", "if", "t", "!=", "NotExist", "{", "cb", "(", "v", ",", "t", ",", "offset", "+", "o", "-", "len", "(", "v", ")", ",", "e", ")", "\n", "}", "\n", "if", "e", "!=", "nil", "{", "break", "\n", "}", "\n", "offset", "+=", "o", "\n", "skipToToken", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", "\n", "if", "skipToToken", "==", "-", "1", "{", "return", "offset", ",", "MalformedArrayError", "\n", "}", "\n", "offset", "+=", "skipToToken", "\n", "if", "data", "[", "offset", "]", "==", "']'", "{", "break", "\n", "}", "\n", "if", "data", "[", "offset", "]", "!=", "','", "{", "return", "offset", ",", "MalformedArrayError", "\n", "}", "\n", "offset", "++", "\n", "}", "\n", "return", "offset", ",", "nil", "\n", "}" ]
// ArrayEach is used when iterating arrays, accepts a callback function with the same return arguments as `Get`.
[ "ArrayEach", "is", "used", "when", "iterating", "arrays", "accepts", "a", "callback", "function", "with", "the", "same", "return", "arguments", "as", "Get", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L902-L979
train
buger/jsonparser
parser.go
ObjectEach
func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) { var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings offset := 0 // Descend to the desired key, if requested if len(keys) > 0 { if off := searchKeys(data, keys...); off == -1 { return KeyPathNotFoundError } else { offset = off } } // Validate and skip past opening brace if off := nextToken(data[offset:]); off == -1 { return MalformedObjectError } else if offset += off; data[offset] != '{' { return MalformedObjectError } else { offset++ } // Skip to the first token inside the object, or stop if we find the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] == '}' { return nil } // Loop pre-condition: data[offset] points to what should be either the next entry's key, or the closing brace (if it's anything else, the JSON is malformed) for offset < len(data) { // Step 1: find the next key var key []byte // Check what the the next token is: start of string, end of object, or something else (error) switch data[offset] { case '"': offset++ // accept as string and skip opening quote case '}': return nil // we found the end of the object; stop and return success default: return MalformedObjectError } // Find the end of the key string var keyEscaped bool if off, esc := stringEnd(data[offset:]); off == -1 { return MalformedJsonError } else { key, keyEscaped = data[offset:offset+off-1], esc offset += off } // Unescape the string if needed if keyEscaped { if keyUnescaped, err := Unescape(key, stackbuf[:]); err != nil { return MalformedStringEscapeError } else { key = keyUnescaped } } // Step 2: skip the colon if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] != ':' { return MalformedJsonError } else { offset++ } // Step 3: find the associated value, then invoke the callback if value, valueType, off, err := Get(data[offset:]); err != nil { return err } else if err := callback(key, value, valueType, offset+off); err != nil { // Invoke the callback here! return err } else { offset += off } // Step 4: skip over the next comma to the following token, or stop if we hit the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off switch data[offset] { case '}': return nil // Stop if we hit the close brace case ',': offset++ // Ignore the comma default: return MalformedObjectError } } // Skip to the next token after the comma if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off } } return MalformedObjectError // we shouldn't get here; it's expected that we will return via finding the ending brace }
go
func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) { var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings offset := 0 // Descend to the desired key, if requested if len(keys) > 0 { if off := searchKeys(data, keys...); off == -1 { return KeyPathNotFoundError } else { offset = off } } // Validate and skip past opening brace if off := nextToken(data[offset:]); off == -1 { return MalformedObjectError } else if offset += off; data[offset] != '{' { return MalformedObjectError } else { offset++ } // Skip to the first token inside the object, or stop if we find the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] == '}' { return nil } // Loop pre-condition: data[offset] points to what should be either the next entry's key, or the closing brace (if it's anything else, the JSON is malformed) for offset < len(data) { // Step 1: find the next key var key []byte // Check what the the next token is: start of string, end of object, or something else (error) switch data[offset] { case '"': offset++ // accept as string and skip opening quote case '}': return nil // we found the end of the object; stop and return success default: return MalformedObjectError } // Find the end of the key string var keyEscaped bool if off, esc := stringEnd(data[offset:]); off == -1 { return MalformedJsonError } else { key, keyEscaped = data[offset:offset+off-1], esc offset += off } // Unescape the string if needed if keyEscaped { if keyUnescaped, err := Unescape(key, stackbuf[:]); err != nil { return MalformedStringEscapeError } else { key = keyUnescaped } } // Step 2: skip the colon if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] != ':' { return MalformedJsonError } else { offset++ } // Step 3: find the associated value, then invoke the callback if value, valueType, off, err := Get(data[offset:]); err != nil { return err } else if err := callback(key, value, valueType, offset+off); err != nil { // Invoke the callback here! return err } else { offset += off } // Step 4: skip over the next comma to the following token, or stop if we hit the ending brace if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off switch data[offset] { case '}': return nil // Stop if we hit the close brace case ',': offset++ // Ignore the comma default: return MalformedObjectError } } // Skip to the next token after the comma if off := nextToken(data[offset:]); off == -1 { return MalformedArrayError } else { offset += off } } return MalformedObjectError // we shouldn't get here; it's expected that we will return via finding the ending brace }
[ "func", "ObjectEach", "(", "data", "[", "]", "byte", ",", "callback", "func", "(", "key", "[", "]", "byte", ",", "value", "[", "]", "byte", ",", "dataType", "ValueType", ",", "offset", "int", ")", "error", ",", "keys", "...", "string", ")", "(", "err", "error", ")", "{", "var", "stackbuf", "[", "unescapeStackBufSize", "]", "byte", "\n", "offset", ":=", "0", "\n", "if", "len", "(", "keys", ")", ">", "0", "{", "if", "off", ":=", "searchKeys", "(", "data", ",", "keys", "...", ")", ";", "off", "==", "-", "1", "{", "return", "KeyPathNotFoundError", "\n", "}", "else", "{", "offset", "=", "off", "\n", "}", "\n", "}", "\n", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedObjectError", "\n", "}", "else", "if", "offset", "+=", "off", ";", "data", "[", "offset", "]", "!=", "'{'", "{", "return", "MalformedObjectError", "\n", "}", "else", "{", "offset", "++", "\n", "}", "\n", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedJsonError", "\n", "}", "else", "if", "offset", "+=", "off", ";", "data", "[", "offset", "]", "==", "'}'", "{", "return", "nil", "\n", "}", "\n", "for", "offset", "<", "len", "(", "data", ")", "{", "var", "key", "[", "]", "byte", "\n", "switch", "data", "[", "offset", "]", "{", "case", "'\"'", ":", "offset", "++", "\n", "case", "'}'", ":", "return", "nil", "\n", "default", ":", "return", "MalformedObjectError", "\n", "}", "\n", "var", "keyEscaped", "bool", "\n", "if", "off", ",", "esc", ":=", "stringEnd", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedJsonError", "\n", "}", "else", "{", "key", ",", "keyEscaped", "=", "data", "[", "offset", ":", "offset", "+", "off", "-", "1", "]", ",", "esc", "\n", "offset", "+=", "off", "\n", "}", "\n", "if", "keyEscaped", "{", "if", "keyUnescaped", ",", "err", ":=", "Unescape", "(", "key", ",", "stackbuf", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "MalformedStringEscapeError", "\n", "}", "else", "{", "key", "=", "keyUnescaped", "\n", "}", "\n", "}", "\n", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedJsonError", "\n", "}", "else", "if", "offset", "+=", "off", ";", "data", "[", "offset", "]", "!=", "':'", "{", "return", "MalformedJsonError", "\n", "}", "else", "{", "offset", "++", "\n", "}", "\n", "if", "value", ",", "valueType", ",", "off", ",", "err", ":=", "Get", "(", "data", "[", "offset", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "else", "if", "err", ":=", "callback", "(", "key", ",", "value", ",", "valueType", ",", "offset", "+", "off", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "else", "{", "offset", "+=", "off", "\n", "}", "\n", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedArrayError", "\n", "}", "else", "{", "offset", "+=", "off", "\n", "switch", "data", "[", "offset", "]", "{", "case", "'}'", ":", "return", "nil", "\n", "case", "','", ":", "offset", "++", "\n", "default", ":", "return", "MalformedObjectError", "\n", "}", "\n", "}", "\n", "if", "off", ":=", "nextToken", "(", "data", "[", "offset", ":", "]", ")", ";", "off", "==", "-", "1", "{", "return", "MalformedArrayError", "\n", "}", "else", "{", "offset", "+=", "off", "\n", "}", "\n", "}", "\n", "return", "MalformedObjectError", "\n", "}" ]
// ObjectEach iterates over the key-value pairs of a JSON object, invoking a given callback for each such entry
[ "ObjectEach", "iterates", "over", "the", "key", "-", "value", "pairs", "of", "a", "JSON", "object", "invoking", "a", "given", "callback", "for", "each", "such", "entry" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L982-L1086
train
buger/jsonparser
parser.go
GetUnsafeString
func GetUnsafeString(data []byte, keys ...string) (val string, err error) { v, _, _, e := Get(data, keys...) if e != nil { return "", e } return bytesToString(&v), nil }
go
func GetUnsafeString(data []byte, keys ...string) (val string, err error) { v, _, _, e := Get(data, keys...) if e != nil { return "", e } return bytesToString(&v), nil }
[ "func", "GetUnsafeString", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "string", ",", "err", "error", ")", "{", "v", ",", "_", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n", "if", "e", "!=", "nil", "{", "return", "\"\"", ",", "e", "\n", "}", "\n", "return", "bytesToString", "(", "&", "v", ")", ",", "nil", "\n", "}" ]
// GetUnsafeString returns the value retrieved by `Get`, use creates string without memory allocation by mapping string to slice memory. It does not handle escape symbols.
[ "GetUnsafeString", "returns", "the", "value", "retrieved", "by", "Get", "use", "creates", "string", "without", "memory", "allocation", "by", "mapping", "string", "to", "slice", "memory", ".", "It", "does", "not", "handle", "escape", "symbols", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1089-L1097
train
buger/jsonparser
parser.go
GetString
func GetString(data []byte, keys ...string) (val string, err error) { v, t, _, e := Get(data, keys...) if e != nil { return "", e } if t != String { return "", fmt.Errorf("Value is not a string: %s", string(v)) } // If no escapes return raw conten if bytes.IndexByte(v, '\\') == -1 { return string(v), nil } return ParseString(v) }
go
func GetString(data []byte, keys ...string) (val string, err error) { v, t, _, e := Get(data, keys...) if e != nil { return "", e } if t != String { return "", fmt.Errorf("Value is not a string: %s", string(v)) } // If no escapes return raw conten if bytes.IndexByte(v, '\\') == -1 { return string(v), nil } return ParseString(v) }
[ "func", "GetString", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "string", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n", "if", "e", "!=", "nil", "{", "return", "\"\"", ",", "e", "\n", "}", "\n", "if", "t", "!=", "String", "{", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Value is not a string: %s\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n", "if", "bytes", ".", "IndexByte", "(", "v", ",", "'\\\\'", ")", "==", "-", "1", "{", "return", "string", "(", "v", ")", ",", "nil", "\n", "}", "\n", "return", "ParseString", "(", "v", ")", "\n", "}" ]
// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols // If key data type do not match, it will return an error.
[ "GetString", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "string", "if", "possible", "trying", "to", "properly", "handle", "escape", "and", "utf8", "symbols", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "an", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1101-L1118
train
buger/jsonparser
parser.go
GetFloat
func GetFloat(data []byte, keys ...string) (val float64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseFloat(v) }
go
func GetFloat(data []byte, keys ...string) (val float64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseFloat(v) }
[ "func", "GetFloat", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "float64", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n", "if", "e", "!=", "nil", "{", "return", "0", ",", "e", "\n", "}", "\n", "if", "t", "!=", "Number", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"Value is not a number: %s\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n", "return", "ParseFloat", "(", "v", ")", "\n", "}" ]
// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible. // The offset is the same as in `Get`. // If key data type do not match, it will return an error.
[ "GetFloat", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "float64", "if", "possible", ".", "The", "offset", "is", "the", "same", "as", "in", "Get", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "an", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1123-L1135
train
buger/jsonparser
parser.go
GetInt
func GetInt(data []byte, keys ...string) (val int64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseInt(v) }
go
func GetInt(data []byte, keys ...string) (val int64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseInt(v) }
[ "func", "GetInt", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "int64", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n", "if", "e", "!=", "nil", "{", "return", "0", ",", "e", "\n", "}", "\n", "if", "t", "!=", "Number", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"Value is not a number: %s\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n", "return", "ParseInt", "(", "v", ")", "\n", "}" ]
// GetInt returns the value retrieved by `Get`, cast to a int64 if possible. // If key data type do not match, it will return an error.
[ "GetInt", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "int64", "if", "possible", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "an", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1139-L1151
train
buger/jsonparser
parser.go
GetBoolean
func GetBoolean(data []byte, keys ...string) (val bool, err error) { v, t, _, e := Get(data, keys...) if e != nil { return false, e } if t != Boolean { return false, fmt.Errorf("Value is not a boolean: %s", string(v)) } return ParseBoolean(v) }
go
func GetBoolean(data []byte, keys ...string) (val bool, err error) { v, t, _, e := Get(data, keys...) if e != nil { return false, e } if t != Boolean { return false, fmt.Errorf("Value is not a boolean: %s", string(v)) } return ParseBoolean(v) }
[ "func", "GetBoolean", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "bool", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n", "if", "e", "!=", "nil", "{", "return", "false", ",", "e", "\n", "}", "\n", "if", "t", "!=", "Boolean", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"Value is not a boolean: %s\"", ",", "string", "(", "v", ")", ")", "\n", "}", "\n", "return", "ParseBoolean", "(", "v", ")", "\n", "}" ]
// GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. // The offset is the same as in `Get`. // If key data type do not match, it will return error.
[ "GetBoolean", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "bool", "if", "possible", ".", "The", "offset", "is", "the", "same", "as", "in", "Get", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1156-L1168
train
buger/jsonparser
parser.go
ParseFloat
func ParseFloat(b []byte) (float64, error) { if v, err := parseFloat(&b); err != nil { return 0, MalformedValueError } else { return v, nil } }
go
func ParseFloat(b []byte) (float64, error) { if v, err := parseFloat(&b); err != nil { return 0, MalformedValueError } else { return v, nil } }
[ "func", "ParseFloat", "(", "b", "[", "]", "byte", ")", "(", "float64", ",", "error", ")", "{", "if", "v", ",", "err", ":=", "parseFloat", "(", "&", "b", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "MalformedValueError", "\n", "}", "else", "{", "return", "v", ",", "nil", "\n", "}", "\n", "}" ]
// ParseNumber parses a Number ValueType into a Go float64
[ "ParseNumber", "parses", "a", "Number", "ValueType", "into", "a", "Go", "float64" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1193-L1199
train
buger/jsonparser
parser.go
ParseInt
func ParseInt(b []byte) (int64, error) { if v, ok, overflow := parseInt(b); !ok { if overflow { return 0, OverflowIntegerError } return 0, MalformedValueError } else { return v, nil } }
go
func ParseInt(b []byte) (int64, error) { if v, ok, overflow := parseInt(b); !ok { if overflow { return 0, OverflowIntegerError } return 0, MalformedValueError } else { return v, nil } }
[ "func", "ParseInt", "(", "b", "[", "]", "byte", ")", "(", "int64", ",", "error", ")", "{", "if", "v", ",", "ok", ",", "overflow", ":=", "parseInt", "(", "b", ")", ";", "!", "ok", "{", "if", "overflow", "{", "return", "0", ",", "OverflowIntegerError", "\n", "}", "\n", "return", "0", ",", "MalformedValueError", "\n", "}", "else", "{", "return", "v", ",", "nil", "\n", "}", "\n", "}" ]
// ParseInt parses a Number ValueType into a Go int64
[ "ParseInt", "parses", "a", "Number", "ValueType", "into", "a", "Go", "int64" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1202-L1211
train
jung-kurt/gofpdf
fpdf.go
SetErrorf
func (f *Fpdf) SetErrorf(fmtStr string, args ...interface{}) { if f.err == nil { f.err = fmt.Errorf(fmtStr, args...) } }
go
func (f *Fpdf) SetErrorf(fmtStr string, args ...interface{}) { if f.err == nil { f.err = fmt.Errorf(fmtStr, args...) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetErrorf", "(", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "f", ".", "err", "==", "nil", "{", "f", ".", "err", "=", "fmt", ".", "Errorf", "(", "fmtStr", ",", "args", "...", ")", "\n", "}", "\n", "}" ]
// SetErrorf sets the internal Fpdf error with formatted text to halt PDF // generation; this may facilitate error handling by application. If an error // condition is already set, this call is ignored. // // See the documentation for printing in the standard fmt package for details // about fmtStr and args.
[ "SetErrorf", "sets", "the", "internal", "Fpdf", "error", "with", "formatted", "text", "to", "halt", "PDF", "generation", ";", "this", "may", "facilitate", "error", "handling", "by", "application", ".", "If", "an", "error", "condition", "is", "already", "set", "this", "call", "is", "ignored", ".", "See", "the", "documentation", "for", "printing", "in", "the", "standard", "fmt", "package", "for", "details", "about", "fmtStr", "and", "args", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L259-L263
train
jung-kurt/gofpdf
fpdf.go
SetMargins
func (f *Fpdf) SetMargins(left, top, right float64) { f.lMargin = left f.tMargin = top if right < 0 { right = left } f.rMargin = right }
go
func (f *Fpdf) SetMargins(left, top, right float64) { f.lMargin = left f.tMargin = top if right < 0 { right = left } f.rMargin = right }
[ "func", "(", "f", "*", "Fpdf", ")", "SetMargins", "(", "left", ",", "top", ",", "right", "float64", ")", "{", "f", ".", "lMargin", "=", "left", "\n", "f", ".", "tMargin", "=", "top", "\n", "if", "right", "<", "0", "{", "right", "=", "left", "\n", "}", "\n", "f", ".", "rMargin", "=", "right", "\n", "}" ]
// SetMargins defines the left, top and right margins. By default, they equal 1 // cm. Call this method to change them. If the value of the right margin is // less than zero, it is set to the same as the left margin.
[ "SetMargins", "defines", "the", "left", "top", "and", "right", "margins", ".", "By", "default", "they", "equal", "1", "cm", ".", "Call", "this", "method", "to", "change", "them", ".", "If", "the", "value", "of", "the", "right", "margin", "is", "less", "than", "zero", "it", "is", "set", "to", "the", "same", "as", "the", "left", "margin", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L307-L314
train
jung-kurt/gofpdf
fpdf.go
SetLeftMargin
func (f *Fpdf) SetLeftMargin(margin float64) { f.lMargin = margin if f.page > 0 && f.x < margin { f.x = margin } }
go
func (f *Fpdf) SetLeftMargin(margin float64) { f.lMargin = margin if f.page > 0 && f.x < margin { f.x = margin } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLeftMargin", "(", "margin", "float64", ")", "{", "f", ".", "lMargin", "=", "margin", "\n", "if", "f", ".", "page", ">", "0", "&&", "f", ".", "x", "<", "margin", "{", "f", ".", "x", "=", "margin", "\n", "}", "\n", "}" ]
// SetLeftMargin defines the left margin. The method can be called before // creating the first page. If the current abscissa gets out of page, it is // brought back to the margin.
[ "SetLeftMargin", "defines", "the", "left", "margin", ".", "The", "method", "can", "be", "called", "before", "creating", "the", "first", "page", ".", "If", "the", "current", "abscissa", "gets", "out", "of", "page", "it", "is", "brought", "back", "to", "the", "margin", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L319-L324
train
jung-kurt/gofpdf
fpdf.go
SetPageBox
func (f *Fpdf) SetPageBox(t string, x, y, wd, ht float64) { f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) }
go
func (f *Fpdf) SetPageBox(t string, x, y, wd, ht float64) { f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetPageBox", "(", "t", "string", ",", "x", ",", "y", ",", "wd", ",", "ht", "float64", ")", "{", "f", ".", "SetPageBoxRec", "(", "t", ",", "PageBox", "{", "SizeType", "{", "Wd", ":", "wd", ",", "Ht", ":", "ht", "}", ",", "PointType", "{", "X", ":", "x", ",", "Y", ":", "y", "}", "}", ")", "\n", "}" ]
// SetPageBox sets the page box for the current page, and any following pages. // Allowable types are trim, trimbox, crop, cropbox, bleed, bleedbox, art and // artbox box types are case insensitive.
[ "SetPageBox", "sets", "the", "page", "box", "for", "the", "current", "page", "and", "any", "following", "pages", ".", "Allowable", "types", "are", "trim", "trimbox", "crop", "cropbox", "bleed", "bleedbox", "art", "and", "artbox", "box", "types", "are", "case", "insensitive", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L383-L385
train
jung-kurt/gofpdf
fpdf.go
GetAutoPageBreak
func (f *Fpdf) GetAutoPageBreak() (auto bool, margin float64) { auto = f.autoPageBreak margin = f.bMargin return }
go
func (f *Fpdf) GetAutoPageBreak() (auto bool, margin float64) { auto = f.autoPageBreak margin = f.bMargin return }
[ "func", "(", "f", "*", "Fpdf", ")", "GetAutoPageBreak", "(", ")", "(", "auto", "bool", ",", "margin", "float64", ")", "{", "auto", "=", "f", ".", "autoPageBreak", "\n", "margin", "=", "f", ".", "bMargin", "\n", "return", "\n", "}" ]
// GetAutoPageBreak returns true if automatic pages breaks are enabled, false // otherwise. This is followed by the triggering limit from the bottom of the // page. This value applies only if automatic page breaks are enabled.
[ "GetAutoPageBreak", "returns", "true", "if", "automatic", "pages", "breaks", "are", "enabled", "false", "otherwise", ".", "This", "is", "followed", "by", "the", "triggering", "limit", "from", "the", "bottom", "of", "the", "page", ".", "This", "value", "applies", "only", "if", "automatic", "page", "breaks", "are", "enabled", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L484-L488
train
jung-kurt/gofpdf
fpdf.go
SetAutoPageBreak
func (f *Fpdf) SetAutoPageBreak(auto bool, margin float64) { f.autoPageBreak = auto f.bMargin = margin f.pageBreakTrigger = f.h - margin }
go
func (f *Fpdf) SetAutoPageBreak(auto bool, margin float64) { f.autoPageBreak = auto f.bMargin = margin f.pageBreakTrigger = f.h - margin }
[ "func", "(", "f", "*", "Fpdf", ")", "SetAutoPageBreak", "(", "auto", "bool", ",", "margin", "float64", ")", "{", "f", ".", "autoPageBreak", "=", "auto", "\n", "f", ".", "bMargin", "=", "margin", "\n", "f", ".", "pageBreakTrigger", "=", "f", ".", "h", "-", "margin", "\n", "}" ]
// SetAutoPageBreak enables or disables the automatic page breaking mode. When // enabling, the second parameter is the distance from the bottom of the page // that defines the triggering limit. By default, the mode is on and the margin // is 2 cm.
[ "SetAutoPageBreak", "enables", "or", "disables", "the", "automatic", "page", "breaking", "mode", ".", "When", "enabling", "the", "second", "parameter", "is", "the", "distance", "from", "the", "bottom", "of", "the", "page", "that", "defines", "the", "triggering", "limit", ".", "By", "default", "the", "mode", "is", "on", "and", "the", "margin", "is", "2", "cm", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L494-L498
train
jung-kurt/gofpdf
fpdf.go
SetKeywords
func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) { if isUTF8 { keywordsStr = utf8toutf16(keywordsStr) } f.keywords = keywordsStr }
go
func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) { if isUTF8 { keywordsStr = utf8toutf16(keywordsStr) } f.keywords = keywordsStr }
[ "func", "(", "f", "*", "Fpdf", ")", "SetKeywords", "(", "keywordsStr", "string", ",", "isUTF8", "bool", ")", "{", "if", "isUTF8", "{", "keywordsStr", "=", "utf8toutf16", "(", "keywordsStr", ")", "\n", "}", "\n", "f", ".", "keywords", "=", "keywordsStr", "\n", "}" ]
// SetKeywords defines the keywords of the document. keywordStr is a // space-delimited string, for example "invoice August". isUTF8 indicates if // the string is encoded
[ "SetKeywords", "defines", "the", "keywords", "of", "the", "document", ".", "keywordStr", "is", "a", "space", "-", "delimited", "string", "for", "example", "invoice", "August", ".", "isUTF8", "indicates", "if", "the", "string", "is", "encoded" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L588-L593
train
jung-kurt/gofpdf
fpdf.go
GetStringWidth
func (f *Fpdf) GetStringWidth(s string) float64 { if f.err != nil { return 0 } w := 0 for _, ch := range []byte(s) { if ch == 0 { break } w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 }
go
func (f *Fpdf) GetStringWidth(s string) float64 { if f.err != nil { return 0 } w := 0 for _, ch := range []byte(s) { if ch == 0 { break } w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 }
[ "func", "(", "f", "*", "Fpdf", ")", "GetStringWidth", "(", "s", "string", ")", "float64", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "w", ":=", "0", "\n", "for", "_", ",", "ch", ":=", "range", "[", "]", "byte", "(", "s", ")", "{", "if", "ch", "==", "0", "{", "break", "\n", "}", "\n", "w", "+=", "f", ".", "currentFont", ".", "Cw", "[", "ch", "]", "\n", "}", "\n", "return", "float64", "(", "w", ")", "*", "f", ".", "fontSize", "/", "1000", "\n", "}" ]
// GetStringWidth returns the length of a string in user units. A font must be // currently selected.
[ "GetStringWidth", "returns", "the", "length", "of", "a", "string", "in", "user", "units", ".", "A", "font", "must", "be", "currently", "selected", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L914-L926
train
jung-kurt/gofpdf
fpdf.go
SetLineCapStyle
func (f *Fpdf) SetLineCapStyle(styleStr string) { var capStyle int switch styleStr { case "round": capStyle = 1 case "square": capStyle = 2 default: capStyle = 0 } f.capStyle = capStyle if f.page > 0 { f.outf("%d J", f.capStyle) } }
go
func (f *Fpdf) SetLineCapStyle(styleStr string) { var capStyle int switch styleStr { case "round": capStyle = 1 case "square": capStyle = 2 default: capStyle = 0 } f.capStyle = capStyle if f.page > 0 { f.outf("%d J", f.capStyle) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLineCapStyle", "(", "styleStr", "string", ")", "{", "var", "capStyle", "int", "\n", "switch", "styleStr", "{", "case", "\"round\"", ":", "capStyle", "=", "1", "\n", "case", "\"square\"", ":", "capStyle", "=", "2", "\n", "default", ":", "capStyle", "=", "0", "\n", "}", "\n", "f", ".", "capStyle", "=", "capStyle", "\n", "if", "f", ".", "page", ">", "0", "{", "f", ".", "outf", "(", "\"%d J\"", ",", "f", ".", "capStyle", ")", "\n", "}", "\n", "}" ]
// SetLineCapStyle defines the line cap style. styleStr should be "butt", // "round" or "square". A square style projects from the end of the line. The // method can be called before the first page is created. The value is // retained from page to page.
[ "SetLineCapStyle", "defines", "the", "line", "cap", "style", ".", "styleStr", "should", "be", "butt", "round", "or", "square", ".", "A", "square", "style", "projects", "from", "the", "end", "of", "the", "line", ".", "The", "method", "can", "be", "called", "before", "the", "first", "page", "is", "created", ".", "The", "value", "is", "retained", "from", "page", "to", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L951-L965
train
jung-kurt/gofpdf
fpdf.go
SetLineJoinStyle
func (f *Fpdf) SetLineJoinStyle(styleStr string) { var joinStyle int switch styleStr { case "round": joinStyle = 1 case "bevel": joinStyle = 2 default: joinStyle = 0 } f.joinStyle = joinStyle if f.page > 0 { f.outf("%d j", f.joinStyle) } }
go
func (f *Fpdf) SetLineJoinStyle(styleStr string) { var joinStyle int switch styleStr { case "round": joinStyle = 1 case "bevel": joinStyle = 2 default: joinStyle = 0 } f.joinStyle = joinStyle if f.page > 0 { f.outf("%d j", f.joinStyle) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLineJoinStyle", "(", "styleStr", "string", ")", "{", "var", "joinStyle", "int", "\n", "switch", "styleStr", "{", "case", "\"round\"", ":", "joinStyle", "=", "1", "\n", "case", "\"bevel\"", ":", "joinStyle", "=", "2", "\n", "default", ":", "joinStyle", "=", "0", "\n", "}", "\n", "f", ".", "joinStyle", "=", "joinStyle", "\n", "if", "f", ".", "page", ">", "0", "{", "f", ".", "outf", "(", "\"%d j\"", ",", "f", ".", "joinStyle", ")", "\n", "}", "\n", "}" ]
// SetLineJoinStyle defines the line cap style. styleStr should be "miter", // "round" or "bevel". The method can be called before the first page // is created. The value is retained from page to page.
[ "SetLineJoinStyle", "defines", "the", "line", "cap", "style", ".", "styleStr", "should", "be", "miter", "round", "or", "bevel", ".", "The", "method", "can", "be", "called", "before", "the", "first", "page", "is", "created", ".", "The", "value", "is", "retained", "from", "page", "to", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L970-L984
train
jung-kurt/gofpdf
fpdf.go
fillDrawOp
func fillDrawOp(styleStr string) (opStr string) { switch strings.ToUpper(styleStr) { case "", "D": // Stroke the path. opStr = "S" case "F": // fill the path, using the nonzero winding number rule opStr = "f" case "F*": // fill the path, using the even-odd rule opStr = "f*" case "FD", "DF": // fill and then stroke the path, using the nonzero winding number rule opStr = "B" case "FD*", "DF*": // fill and then stroke the path, using the even-odd rule opStr = "B*" default: opStr = styleStr } return }
go
func fillDrawOp(styleStr string) (opStr string) { switch strings.ToUpper(styleStr) { case "", "D": // Stroke the path. opStr = "S" case "F": // fill the path, using the nonzero winding number rule opStr = "f" case "F*": // fill the path, using the even-odd rule opStr = "f*" case "FD", "DF": // fill and then stroke the path, using the nonzero winding number rule opStr = "B" case "FD*", "DF*": // fill and then stroke the path, using the even-odd rule opStr = "B*" default: opStr = styleStr } return }
[ "func", "fillDrawOp", "(", "styleStr", "string", ")", "(", "opStr", "string", ")", "{", "switch", "strings", ".", "ToUpper", "(", "styleStr", ")", "{", "case", "\"\"", ",", "\"D\"", ":", "opStr", "=", "\"S\"", "\n", "case", "\"F\"", ":", "opStr", "=", "\"f\"", "\n", "case", "\"F*\"", ":", "opStr", "=", "\"f*\"", "\n", "case", "\"FD\"", ",", "\"DF\"", ":", "opStr", "=", "\"B\"", "\n", "case", "\"FD*\"", ",", "\"DF*\"", ":", "opStr", "=", "\"B*\"", "\n", "default", ":", "opStr", "=", "styleStr", "\n", "}", "\n", "return", "\n", "}" ]
// fillDrawOp corrects path painting operators
[ "fillDrawOp", "corrects", "path", "painting", "operators" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1031-L1052
train
jung-kurt/gofpdf
fpdf.go
point
func (f *Fpdf) point(x, y float64) { f.outf("%.2f %.2f m", x*f.k, (f.h-y)*f.k) }
go
func (f *Fpdf) point(x, y float64) { f.outf("%.2f %.2f m", x*f.k, (f.h-y)*f.k) }
[ "func", "(", "f", "*", "Fpdf", ")", "point", "(", "x", ",", "y", "float64", ")", "{", "f", ".", "outf", "(", "\"%.2f %.2f m\"", ",", "x", "*", "f", ".", "k", ",", "(", "f", ".", "h", "-", "y", ")", "*", "f", ".", "k", ")", "\n", "}" ]
// point outputs current point
[ "point", "outputs", "current", "point" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1148-L1150
train
jung-kurt/gofpdf
fpdf.go
GetAlpha
func (f *Fpdf) GetAlpha() (alpha float64, blendModeStr string) { return f.alpha, f.blendMode }
go
func (f *Fpdf) GetAlpha() (alpha float64, blendModeStr string) { return f.alpha, f.blendMode }
[ "func", "(", "f", "*", "Fpdf", ")", "GetAlpha", "(", ")", "(", "alpha", "float64", ",", "blendModeStr", "string", ")", "{", "return", "f", ".", "alpha", ",", "f", ".", "blendMode", "\n", "}" ]
// GetAlpha returns the alpha blending channel, which consists of the // alpha transparency value and the blend mode. See SetAlpha for more // details.
[ "GetAlpha", "returns", "the", "alpha", "blending", "channel", "which", "consists", "of", "the", "alpha", "transparency", "value", "and", "the", "blend", "mode", ".", "See", "SetAlpha", "for", "more", "details", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1231-L1233
train
jung-kurt/gofpdf
fpdf.go
getFontKey
func getFontKey(familyStr, styleStr string) string { familyStr = strings.ToLower(familyStr) styleStr = strings.ToUpper(styleStr) if styleStr == "IB" { styleStr = "BI" } return familyStr + styleStr }
go
func getFontKey(familyStr, styleStr string) string { familyStr = strings.ToLower(familyStr) styleStr = strings.ToUpper(styleStr) if styleStr == "IB" { styleStr = "BI" } return familyStr + styleStr }
[ "func", "getFontKey", "(", "familyStr", ",", "styleStr", "string", ")", "string", "{", "familyStr", "=", "strings", ".", "ToLower", "(", "familyStr", ")", "\n", "styleStr", "=", "strings", ".", "ToUpper", "(", "styleStr", ")", "\n", "if", "styleStr", "==", "\"IB\"", "{", "styleStr", "=", "\"BI\"", "\n", "}", "\n", "return", "familyStr", "+", "styleStr", "\n", "}" ]
// getFontKey is used by AddFontFromReader and GetFontDesc
[ "getFontKey", "is", "used", "by", "AddFontFromReader", "and", "GetFontDesc" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1638-L1645
train
jung-kurt/gofpdf
fpdf.go
AddFontFromReader
func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) { if f.err != nil { return } // dbg("Adding family [%s], style [%s]", familyStr, styleStr) var ok bool fontkey := getFontKey(familyStr, styleStr) _, ok = f.fonts[fontkey] if ok { return } var info fontDefType info = f.loadfont(r) if f.err != nil { return } if len(info.Diff) > 0 { // Search existing encodings n := -1 for j, str := range f.diffs { if str == info.Diff { n = j + 1 break } } if n < 0 { f.diffs = append(f.diffs, info.Diff) n = len(f.diffs) } info.DiffN = n } // dbg("font [%s], type [%s]", info.File, info.Tp) if len(info.File) > 0 { // Embedded font if info.Tp == "TrueType" { f.fontFiles[info.File] = fontFileType{length1: int64(info.OriginalSize)} } else { f.fontFiles[info.File] = fontFileType{length1: int64(info.Size1), length2: int64(info.Size2)} } } f.fonts[fontkey] = info return }
go
func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) { if f.err != nil { return } // dbg("Adding family [%s], style [%s]", familyStr, styleStr) var ok bool fontkey := getFontKey(familyStr, styleStr) _, ok = f.fonts[fontkey] if ok { return } var info fontDefType info = f.loadfont(r) if f.err != nil { return } if len(info.Diff) > 0 { // Search existing encodings n := -1 for j, str := range f.diffs { if str == info.Diff { n = j + 1 break } } if n < 0 { f.diffs = append(f.diffs, info.Diff) n = len(f.diffs) } info.DiffN = n } // dbg("font [%s], type [%s]", info.File, info.Tp) if len(info.File) > 0 { // Embedded font if info.Tp == "TrueType" { f.fontFiles[info.File] = fontFileType{length1: int64(info.OriginalSize)} } else { f.fontFiles[info.File] = fontFileType{length1: int64(info.Size1), length2: int64(info.Size2)} } } f.fonts[fontkey] = info return }
[ "func", "(", "f", "*", "Fpdf", ")", "AddFontFromReader", "(", "familyStr", ",", "styleStr", "string", ",", "r", "io", ".", "Reader", ")", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "var", "ok", "bool", "\n", "fontkey", ":=", "getFontKey", "(", "familyStr", ",", "styleStr", ")", "\n", "_", ",", "ok", "=", "f", ".", "fonts", "[", "fontkey", "]", "\n", "if", "ok", "{", "return", "\n", "}", "\n", "var", "info", "fontDefType", "\n", "info", "=", "f", ".", "loadfont", "(", "r", ")", "\n", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "len", "(", "info", ".", "Diff", ")", ">", "0", "{", "n", ":=", "-", "1", "\n", "for", "j", ",", "str", ":=", "range", "f", ".", "diffs", "{", "if", "str", "==", "info", ".", "Diff", "{", "n", "=", "j", "+", "1", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "n", "<", "0", "{", "f", ".", "diffs", "=", "append", "(", "f", ".", "diffs", ",", "info", ".", "Diff", ")", "\n", "n", "=", "len", "(", "f", ".", "diffs", ")", "\n", "}", "\n", "info", ".", "DiffN", "=", "n", "\n", "}", "\n", "if", "len", "(", "info", ".", "File", ")", ">", "0", "{", "if", "info", ".", "Tp", "==", "\"TrueType\"", "{", "f", ".", "fontFiles", "[", "info", ".", "File", "]", "=", "fontFileType", "{", "length1", ":", "int64", "(", "info", ".", "OriginalSize", ")", "}", "\n", "}", "else", "{", "f", ".", "fontFiles", "[", "info", ".", "File", "]", "=", "fontFileType", "{", "length1", ":", "int64", "(", "info", ".", "Size1", ")", ",", "length2", ":", "int64", "(", "info", ".", "Size2", ")", "}", "\n", "}", "\n", "}", "\n", "f", ".", "fonts", "[", "fontkey", "]", "=", "info", "\n", "return", "\n", "}" ]
// AddFontFromReader imports a TrueType, OpenType or Type1 font and makes it // available using a reader that satisifies the io.Reader interface. See // AddFont for details about familyStr and styleStr.
[ "AddFontFromReader", "imports", "a", "TrueType", "OpenType", "or", "Type1", "font", "and", "makes", "it", "available", "using", "a", "reader", "that", "satisifies", "the", "io", ".", "Reader", "interface", ".", "See", "AddFont", "for", "details", "about", "familyStr", "and", "styleStr", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1650-L1692
train
jung-kurt/gofpdf
fpdf.go
GetFontDesc
func (f *Fpdf) GetFontDesc(familyStr, styleStr string) FontDescType { if familyStr == "" { return f.currentFont.Desc } return f.fonts[getFontKey(familyStr, styleStr)].Desc }
go
func (f *Fpdf) GetFontDesc(familyStr, styleStr string) FontDescType { if familyStr == "" { return f.currentFont.Desc } return f.fonts[getFontKey(familyStr, styleStr)].Desc }
[ "func", "(", "f", "*", "Fpdf", ")", "GetFontDesc", "(", "familyStr", ",", "styleStr", "string", ")", "FontDescType", "{", "if", "familyStr", "==", "\"\"", "{", "return", "f", ".", "currentFont", ".", "Desc", "\n", "}", "\n", "return", "f", ".", "fonts", "[", "getFontKey", "(", "familyStr", ",", "styleStr", ")", "]", ".", "Desc", "\n", "}" ]
// GetFontDesc returns the font descriptor, which can be used for // example to find the baseline of a font. If familyStr is empty // current font descriptor will be returned. // See FontDescType for documentation about the font descriptor. // See AddFont for details about familyStr and styleStr.
[ "GetFontDesc", "returns", "the", "font", "descriptor", "which", "can", "be", "used", "for", "example", "to", "find", "the", "baseline", "of", "a", "font", ".", "If", "familyStr", "is", "empty", "current", "font", "descriptor", "will", "be", "returned", ".", "See", "FontDescType", "for", "documentation", "about", "the", "font", "descriptor", ".", "See", "AddFont", "for", "details", "about", "familyStr", "and", "styleStr", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1699-L1704
train
jung-kurt/gofpdf
fpdf.go
newLink
func (f *Fpdf) newLink(x, y, w, h float64, link int, linkStr string) { // linkList, ok := f.pageLinks[f.page] // if !ok { // linkList = make([]linkType, 0, 8) // f.pageLinks[f.page] = linkList // } f.pageLinks[f.page] = append(f.pageLinks[f.page], linkType{x * f.k, f.hPt - y*f.k, w * f.k, h * f.k, link, linkStr}) }
go
func (f *Fpdf) newLink(x, y, w, h float64, link int, linkStr string) { // linkList, ok := f.pageLinks[f.page] // if !ok { // linkList = make([]linkType, 0, 8) // f.pageLinks[f.page] = linkList // } f.pageLinks[f.page] = append(f.pageLinks[f.page], linkType{x * f.k, f.hPt - y*f.k, w * f.k, h * f.k, link, linkStr}) }
[ "func", "(", "f", "*", "Fpdf", ")", "newLink", "(", "x", ",", "y", ",", "w", ",", "h", "float64", ",", "link", "int", ",", "linkStr", "string", ")", "{", "f", ".", "pageLinks", "[", "f", ".", "page", "]", "=", "append", "(", "f", ".", "pageLinks", "[", "f", ".", "page", "]", ",", "linkType", "{", "x", "*", "f", ".", "k", ",", "f", ".", "hPt", "-", "y", "*", "f", ".", "k", ",", "w", "*", "f", ".", "k", ",", "h", "*", "f", ".", "k", ",", "link", ",", "linkStr", "}", ")", "\n", "}" ]
// newLink adds a new clickable link on current page
[ "newLink", "adds", "a", "new", "clickable", "link", "on", "current", "page" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1855-L1863
train
jung-kurt/gofpdf
fpdf.go
Bookmark
func (f *Fpdf) Bookmark(txtStr string, level int, y float64) { if y == -1 { y = f.y } f.outlines = append(f.outlines, outlineType{text: txtStr, level: level, y: y, p: f.PageNo(), prev: -1, last: -1, next: -1, first: -1}) }
go
func (f *Fpdf) Bookmark(txtStr string, level int, y float64) { if y == -1 { y = f.y } f.outlines = append(f.outlines, outlineType{text: txtStr, level: level, y: y, p: f.PageNo(), prev: -1, last: -1, next: -1, first: -1}) }
[ "func", "(", "f", "*", "Fpdf", ")", "Bookmark", "(", "txtStr", "string", ",", "level", "int", ",", "y", "float64", ")", "{", "if", "y", "==", "-", "1", "{", "y", "=", "f", ".", "y", "\n", "}", "\n", "f", ".", "outlines", "=", "append", "(", "f", ".", "outlines", ",", "outlineType", "{", "text", ":", "txtStr", ",", "level", ":", "level", ",", "y", ":", "y", ",", "p", ":", "f", ".", "PageNo", "(", ")", ",", "prev", ":", "-", "1", ",", "last", ":", "-", "1", ",", "next", ":", "-", "1", ",", "first", ":", "-", "1", "}", ")", "\n", "}" ]
// Bookmark sets a bookmark that will be displayed in a sidebar outline. txtStr // is the title of the bookmark. level specifies the level of the bookmark in // the outline; 0 is the top level, 1 is just below, and so on. y specifies the // vertical position of the bookmark destination in the current page; -1 // indicates the current position.
[ "Bookmark", "sets", "a", "bookmark", "that", "will", "be", "displayed", "in", "a", "sidebar", "outline", ".", "txtStr", "is", "the", "title", "of", "the", "bookmark", ".", "level", "specifies", "the", "level", "of", "the", "bookmark", "in", "the", "outline", ";", "0", "is", "the", "top", "level", "1", "is", "just", "below", "and", "so", "on", ".", "y", "specifies", "the", "vertical", "position", "of", "the", "bookmark", "destination", "in", "the", "current", "page", ";", "-", "1", "indicates", "the", "current", "position", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1886-L1891
train
jung-kurt/gofpdf
fpdf.go
Cell
func (f *Fpdf) Cell(w, h float64, txtStr string) { f.CellFormat(w, h, txtStr, "", 0, "L", false, 0, "") }
go
func (f *Fpdf) Cell(w, h float64, txtStr string) { f.CellFormat(w, h, txtStr, "", 0, "L", false, 0, "") }
[ "func", "(", "f", "*", "Fpdf", ")", "Cell", "(", "w", ",", "h", "float64", ",", "txtStr", "string", ")", "{", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "txtStr", ",", "\"\"", ",", "0", ",", "\"L\"", ",", "false", ",", "0", ",", "\"\"", ")", "\n", "}" ]
// Cell is a simpler version of CellFormat with no fill, border, links or // special alignment.
[ "Cell", "is", "a", "simpler", "version", "of", "CellFormat", "with", "no", "fill", "border", "links", "or", "special", "alignment", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2114-L2116
train
jung-kurt/gofpdf
fpdf.go
Cellf
func (f *Fpdf) Cellf(w, h float64, fmtStr string, args ...interface{}) { f.CellFormat(w, h, sprintf(fmtStr, args...), "", 0, "L", false, 0, "") }
go
func (f *Fpdf) Cellf(w, h float64, fmtStr string, args ...interface{}) { f.CellFormat(w, h, sprintf(fmtStr, args...), "", 0, "L", false, 0, "") }
[ "func", "(", "f", "*", "Fpdf", ")", "Cellf", "(", "w", ",", "h", "float64", ",", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "sprintf", "(", "fmtStr", ",", "args", "...", ")", ",", "\"\"", ",", "0", ",", "\"L\"", ",", "false", ",", "0", ",", "\"\"", ")", "\n", "}" ]
// Cellf is a simpler printf-style version of CellFormat with no fill, border, // links or special alignment. See documentation for the fmt package for // details on fmtStr and args.
[ "Cellf", "is", "a", "simpler", "printf", "-", "style", "version", "of", "CellFormat", "with", "no", "fill", "border", "links", "or", "special", "alignment", ".", "See", "documentation", "for", "the", "fmt", "package", "for", "details", "on", "fmtStr", "and", "args", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2121-L2123
train
jung-kurt/gofpdf
fpdf.go
SplitLines
func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte { // Function contributed by Bruno Michel lines := [][]byte{} cw := &f.currentFont.Cw wmax := int(math.Ceil((w - 2*f.cMargin) * 1000 / f.fontSize)) s := bytes.Replace(txt, []byte("\r"), []byte{}, -1) nb := len(s) for nb > 0 && s[nb-1] == '\n' { nb-- } s = s[0:nb] sep := -1 i := 0 j := 0 l := 0 for i < nb { c := s[i] l += cw[c] if c == ' ' || c == '\t' || c == '\n' { sep = i } if c == '\n' || l > wmax { if sep == -1 { if i == j { i++ } sep = i } else { i = sep + 1 } lines = append(lines, s[j:sep]) sep = -1 j = i l = 0 } else { i++ } } if i != j { lines = append(lines, s[j:i]) } return lines }
go
func (f *Fpdf) SplitLines(txt []byte, w float64) [][]byte { // Function contributed by Bruno Michel lines := [][]byte{} cw := &f.currentFont.Cw wmax := int(math.Ceil((w - 2*f.cMargin) * 1000 / f.fontSize)) s := bytes.Replace(txt, []byte("\r"), []byte{}, -1) nb := len(s) for nb > 0 && s[nb-1] == '\n' { nb-- } s = s[0:nb] sep := -1 i := 0 j := 0 l := 0 for i < nb { c := s[i] l += cw[c] if c == ' ' || c == '\t' || c == '\n' { sep = i } if c == '\n' || l > wmax { if sep == -1 { if i == j { i++ } sep = i } else { i = sep + 1 } lines = append(lines, s[j:sep]) sep = -1 j = i l = 0 } else { i++ } } if i != j { lines = append(lines, s[j:i]) } return lines }
[ "func", "(", "f", "*", "Fpdf", ")", "SplitLines", "(", "txt", "[", "]", "byte", ",", "w", "float64", ")", "[", "]", "[", "]", "byte", "{", "lines", ":=", "[", "]", "[", "]", "byte", "{", "}", "\n", "cw", ":=", "&", "f", ".", "currentFont", ".", "Cw", "\n", "wmax", ":=", "int", "(", "math", ".", "Ceil", "(", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", ")", ")", "\n", "s", ":=", "bytes", ".", "Replace", "(", "txt", ",", "[", "]", "byte", "(", "\"\\r\"", ")", ",", "\\r", ",", "[", "]", "byte", "{", "}", ")", "\n", "-", "1", "\n", "nb", ":=", "len", "(", "s", ")", "\n", "for", "nb", ">", "0", "&&", "s", "[", "nb", "-", "1", "]", "==", "'\\n'", "{", "nb", "--", "\n", "}", "\n", "s", "=", "s", "[", "0", ":", "nb", "]", "\n", "sep", ":=", "-", "1", "\n", "i", ":=", "0", "\n", "j", ":=", "0", "\n", "l", ":=", "0", "\n", "for", "i", "<", "nb", "{", "c", ":=", "s", "[", "i", "]", "\n", "l", "+=", "cw", "[", "c", "]", "\n", "if", "c", "==", "' '", "||", "c", "==", "'\\t'", "||", "c", "==", "'\\n'", "{", "sep", "=", "i", "\n", "}", "\n", "if", "c", "==", "'\\n'", "||", "l", ">", "wmax", "{", "if", "sep", "==", "-", "1", "{", "if", "i", "==", "j", "{", "i", "++", "\n", "}", "\n", "sep", "=", "i", "\n", "}", "else", "{", "i", "=", "sep", "+", "1", "\n", "}", "\n", "lines", "=", "append", "(", "lines", ",", "s", "[", "j", ":", "sep", "]", ")", "\n", "sep", "=", "-", "1", "\n", "j", "=", "i", "\n", "l", "=", "0", "\n", "}", "else", "{", "i", "++", "\n", "}", "\n", "}", "\n", "if", "i", "!=", "j", "{", "lines", "=", "append", "(", "lines", ",", "s", "[", "j", ":", "i", "]", ")", "\n", "}", "\n", "}" ]
// SplitLines splits text into several lines using the current font. Each line // has its length limited to a maximum width given by w. This function can be // used to determine the total height of wrapped text for vertical placement // purposes. // // You can use MultiCell if you want to print a text on several lines in a // simple way.
[ "SplitLines", "splits", "text", "into", "several", "lines", "using", "the", "current", "font", ".", "Each", "line", "has", "its", "length", "limited", "to", "a", "maximum", "width", "given", "by", "w", ".", "This", "function", "can", "be", "used", "to", "determine", "the", "total", "height", "of", "wrapped", "text", "for", "vertical", "placement", "purposes", ".", "You", "can", "use", "MultiCell", "if", "you", "want", "to", "print", "a", "text", "on", "several", "lines", "in", "a", "simple", "way", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2132-L2174
train
jung-kurt/gofpdf
fpdf.go
write
func (f *Fpdf) write(h float64, txtStr string, link int, linkStr string) { // dbg("Write") cw := &f.currentFont.Cw w := f.w - f.rMargin - f.x wmax := (w - 2*f.cMargin) * 1000 / f.fontSize s := strings.Replace(txtStr, "\r", "", -1) nb := len(s) sep := -1 i := 0 j := 0 l := 0.0 nl := 1 for i < nb { // Get next character c := []byte(s)[i] if c == '\n' { // Explicit line break f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) i++ sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ continue } if c == ' ' { sep = i } l += float64(cw[c]) if l > wmax { // Automatic line break if sep == -1 { if f.x > f.lMargin { // Move to next line f.x = f.lMargin f.y += h w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize i++ nl++ continue } if i == j { i++ } f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) } else { f.CellFormat(w, h, s[j:sep], "", 2, "", false, link, linkStr) i = sep + 1 } sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ } else { i++ } } // Last chunk if i != j { f.CellFormat(l/1000*f.fontSize, h, s[j:], "", 0, "", false, link, linkStr) } }
go
func (f *Fpdf) write(h float64, txtStr string, link int, linkStr string) { // dbg("Write") cw := &f.currentFont.Cw w := f.w - f.rMargin - f.x wmax := (w - 2*f.cMargin) * 1000 / f.fontSize s := strings.Replace(txtStr, "\r", "", -1) nb := len(s) sep := -1 i := 0 j := 0 l := 0.0 nl := 1 for i < nb { // Get next character c := []byte(s)[i] if c == '\n' { // Explicit line break f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) i++ sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ continue } if c == ' ' { sep = i } l += float64(cw[c]) if l > wmax { // Automatic line break if sep == -1 { if f.x > f.lMargin { // Move to next line f.x = f.lMargin f.y += h w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize i++ nl++ continue } if i == j { i++ } f.CellFormat(w, h, s[j:i], "", 2, "", false, link, linkStr) } else { f.CellFormat(w, h, s[j:sep], "", 2, "", false, link, linkStr) i = sep + 1 } sep = -1 j = i l = 0.0 if nl == 1 { f.x = f.lMargin w = f.w - f.rMargin - f.x wmax = (w - 2*f.cMargin) * 1000 / f.fontSize } nl++ } else { i++ } } // Last chunk if i != j { f.CellFormat(l/1000*f.fontSize, h, s[j:], "", 0, "", false, link, linkStr) } }
[ "func", "(", "f", "*", "Fpdf", ")", "write", "(", "h", "float64", ",", "txtStr", "string", ",", "link", "int", ",", "linkStr", "string", ")", "{", "cw", ":=", "&", "f", ".", "currentFont", ".", "Cw", "\n", "w", ":=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", ":=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "s", ":=", "strings", ".", "Replace", "(", "txtStr", ",", "\"\\r\"", ",", "\\r", ",", "\"\"", ")", "\n", "-", "1", "\n", "nb", ":=", "len", "(", "s", ")", "\n", "sep", ":=", "-", "1", "\n", "i", ":=", "0", "\n", "j", ":=", "0", "\n", "l", ":=", "0.0", "\n", "nl", ":=", "1", "\n", "for", "i", "<", "nb", "{", "c", ":=", "[", "]", "byte", "(", "s", ")", "[", "i", "]", "\n", "if", "c", "==", "'\\n'", "{", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "s", "[", "j", ":", "i", "]", ",", "\"\"", ",", "2", ",", "\"\"", ",", "false", ",", "link", ",", "linkStr", ")", "\n", "i", "++", "\n", "sep", "=", "-", "1", "\n", "j", "=", "i", "\n", "l", "=", "0.0", "\n", "if", "nl", "==", "1", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "w", "=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", "=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "}", "\n", "nl", "++", "\n", "continue", "\n", "}", "\n", "if", "c", "==", "' '", "{", "sep", "=", "i", "\n", "}", "\n", "l", "+=", "float64", "(", "cw", "[", "c", "]", ")", "\n", "if", "l", ">", "wmax", "{", "if", "sep", "==", "-", "1", "{", "if", "f", ".", "x", ">", "f", ".", "lMargin", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "f", ".", "y", "+=", "h", "\n", "w", "=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", "=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "i", "++", "\n", "nl", "++", "\n", "continue", "\n", "}", "\n", "if", "i", "==", "j", "{", "i", "++", "\n", "}", "\n", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "s", "[", "j", ":", "i", "]", ",", "\"\"", ",", "2", ",", "\"\"", ",", "false", ",", "link", ",", "linkStr", ")", "\n", "}", "else", "{", "f", ".", "CellFormat", "(", "w", ",", "h", ",", "s", "[", "j", ":", "sep", "]", ",", "\"\"", ",", "2", ",", "\"\"", ",", "false", ",", "link", ",", "linkStr", ")", "\n", "i", "=", "sep", "+", "1", "\n", "}", "\n", "sep", "=", "-", "1", "\n", "j", "=", "i", "\n", "l", "=", "0.0", "\n", "if", "nl", "==", "1", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "w", "=", "f", ".", "w", "-", "f", ".", "rMargin", "-", "f", ".", "x", "\n", "wmax", "=", "(", "w", "-", "2", "*", "f", ".", "cMargin", ")", "*", "1000", "/", "f", ".", "fontSize", "\n", "}", "\n", "nl", "++", "\n", "}", "else", "{", "i", "++", "\n", "}", "\n", "}", "\n", "}" ]
// write outputs text in flowing mode
[ "write", "outputs", "text", "in", "flowing", "mode" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2312-L2384
train
jung-kurt/gofpdf
fpdf.go
Writef
func (f *Fpdf) Writef(h float64, fmtStr string, args ...interface{}) { f.write(h, sprintf(fmtStr, args...), 0, "") }
go
func (f *Fpdf) Writef(h float64, fmtStr string, args ...interface{}) { f.write(h, sprintf(fmtStr, args...), 0, "") }
[ "func", "(", "f", "*", "Fpdf", ")", "Writef", "(", "h", "float64", ",", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "write", "(", "h", ",", "sprintf", "(", "fmtStr", ",", "args", "...", ")", ",", "0", ",", "\"\"", ")", "\n", "}" ]
// Writef is like Write but uses printf-style formatting. See the documentation // for package fmt for more details on fmtStr and args.
[ "Writef", "is", "like", "Write", "but", "uses", "printf", "-", "style", "formatting", ".", "See", "the", "documentation", "for", "package", "fmt", "for", "more", "details", "on", "fmtStr", "and", "args", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2400-L2402
train
jung-kurt/gofpdf
fpdf.go
Ln
func (f *Fpdf) Ln(h float64) { f.x = f.lMargin if h < 0 { f.y += f.lasth } else { f.y += h } }
go
func (f *Fpdf) Ln(h float64) { f.x = f.lMargin if h < 0 { f.y += f.lasth } else { f.y += h } }
[ "func", "(", "f", "*", "Fpdf", ")", "Ln", "(", "h", "float64", ")", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "if", "h", "<", "0", "{", "f", ".", "y", "+=", "f", ".", "lasth", "\n", "}", "else", "{", "f", ".", "y", "+=", "h", "\n", "}", "\n", "}" ]
// Ln performs a line break. The current abscissa goes back to the left margin // and the ordinate increases by the amount passed in parameter. A negative // value of h indicates the height of the last printed cell. // // This method is demonstrated in the example for MultiCell.
[ "Ln", "performs", "a", "line", "break", ".", "The", "current", "abscissa", "goes", "back", "to", "the", "left", "margin", "and", "the", "ordinate", "increases", "by", "the", "amount", "passed", "in", "parameter", ".", "A", "negative", "value", "of", "h", "indicates", "the", "height", "of", "the", "last", "printed", "cell", ".", "This", "method", "is", "demonstrated", "in", "the", "example", "for", "MultiCell", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2463-L2470
train
jung-kurt/gofpdf
fpdf.go
RegisterImageReader
func (f *Fpdf) RegisterImageReader(imgName, tp string, r io.Reader) (info *ImageInfoType) { options := ImageOptions{ ReadDpi: false, ImageType: tp, } return f.RegisterImageOptionsReader(imgName, options, r) }
go
func (f *Fpdf) RegisterImageReader(imgName, tp string, r io.Reader) (info *ImageInfoType) { options := ImageOptions{ ReadDpi: false, ImageType: tp, } return f.RegisterImageOptionsReader(imgName, options, r) }
[ "func", "(", "f", "*", "Fpdf", ")", "RegisterImageReader", "(", "imgName", ",", "tp", "string", ",", "r", "io", ".", "Reader", ")", "(", "info", "*", "ImageInfoType", ")", "{", "options", ":=", "ImageOptions", "{", "ReadDpi", ":", "false", ",", "ImageType", ":", "tp", ",", "}", "\n", "return", "f", ".", "RegisterImageOptionsReader", "(", "imgName", ",", "options", ",", "r", ")", "\n", "}" ]
// RegisterImageReader registers an image, reading it from Reader r, adding it // to the PDF file but not adding it to the page. // // This function is now deprecated in favor of RegisterImageOptionsReader
[ "RegisterImageReader", "registers", "an", "image", "reading", "it", "from", "Reader", "r", "adding", "it", "to", "the", "PDF", "file", "but", "not", "adding", "it", "to", "the", "page", ".", "This", "function", "is", "now", "deprecated", "in", "favor", "of", "RegisterImageOptionsReader" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2612-L2618
train
jung-kurt/gofpdf
fpdf.go
GetImageInfo
func (f *Fpdf) GetImageInfo(imageStr string) (info *ImageInfoType) { return f.images[imageStr] }
go
func (f *Fpdf) GetImageInfo(imageStr string) (info *ImageInfoType) { return f.images[imageStr] }
[ "func", "(", "f", "*", "Fpdf", ")", "GetImageInfo", "(", "imageStr", "string", ")", "(", "info", "*", "ImageInfoType", ")", "{", "return", "f", ".", "images", "[", "imageStr", "]", "\n", "}" ]
// GetImageInfo returns information about the registered image specified by // imageStr. If the image has not been registered, nil is returned. The // internal error is not modified by this method.
[ "GetImageInfo", "returns", "information", "about", "the", "registered", "image", "specified", "by", "imageStr", ".", "If", "the", "image", "has", "not", "been", "registered", "nil", "is", "returned", ".", "The", "internal", "error", "is", "not", "modified", "by", "this", "method", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2737-L2739
train
jung-kurt/gofpdf
fpdf.go
SetX
func (f *Fpdf) SetX(x float64) { if x >= 0 { f.x = x } else { f.x = f.w + x } }
go
func (f *Fpdf) SetX(x float64) { if x >= 0 { f.x = x } else { f.x = f.w + x } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetX", "(", "x", "float64", ")", "{", "if", "x", ">=", "0", "{", "f", ".", "x", "=", "x", "\n", "}", "else", "{", "f", ".", "x", "=", "f", ".", "w", "+", "x", "\n", "}", "\n", "}" ]
// SetX defines the abscissa of the current position. If the passed value is // negative, it is relative to the right of the page.
[ "SetX", "defines", "the", "abscissa", "of", "the", "current", "position", ".", "If", "the", "passed", "value", "is", "negative", "it", "is", "relative", "to", "the", "right", "of", "the", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2768-L2774
train
jung-kurt/gofpdf
fpdf.go
SetY
func (f *Fpdf) SetY(y float64) { // dbg("SetY x %.2f, lMargin %.2f", f.x, f.lMargin) f.x = f.lMargin if y >= 0 { f.y = y } else { f.y = f.h + y } }
go
func (f *Fpdf) SetY(y float64) { // dbg("SetY x %.2f, lMargin %.2f", f.x, f.lMargin) f.x = f.lMargin if y >= 0 { f.y = y } else { f.y = f.h + y } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetY", "(", "y", "float64", ")", "{", "f", ".", "x", "=", "f", ".", "lMargin", "\n", "if", "y", ">=", "0", "{", "f", ".", "y", "=", "y", "\n", "}", "else", "{", "f", ".", "y", "=", "f", ".", "h", "+", "y", "\n", "}", "\n", "}" ]
// SetY moves the current abscissa back to the left margin and sets the // ordinate. If the passed value is negative, it is relative to the bottom of // the page.
[ "SetY", "moves", "the", "current", "abscissa", "back", "to", "the", "left", "margin", "and", "sets", "the", "ordinate", ".", "If", "the", "passed", "value", "is", "negative", "it", "is", "relative", "to", "the", "bottom", "of", "the", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2784-L2792
train
jung-kurt/gofpdf
fpdf.go
SetHomeXY
func (f *Fpdf) SetHomeXY() { f.SetY(f.tMargin) f.SetX(f.lMargin) }
go
func (f *Fpdf) SetHomeXY() { f.SetY(f.tMargin) f.SetX(f.lMargin) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetHomeXY", "(", ")", "{", "f", ".", "SetY", "(", "f", ".", "tMargin", ")", "\n", "f", ".", "SetX", "(", "f", ".", "lMargin", ")", "\n", "}" ]
// SetHomeXY is a convenience method that sets the current position to the left // and top margins.
[ "SetHomeXY", "is", "a", "convenience", "method", "that", "sets", "the", "current", "position", "to", "the", "left", "and", "top", "margins", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2796-L2799
train
jung-kurt/gofpdf
fpdf.go
SetXY
func (f *Fpdf) SetXY(x, y float64) { f.SetY(y) f.SetX(x) }
go
func (f *Fpdf) SetXY(x, y float64) { f.SetY(y) f.SetX(x) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetXY", "(", "x", ",", "y", "float64", ")", "{", "f", ".", "SetY", "(", "y", ")", "\n", "f", ".", "SetX", "(", "x", ")", "\n", "}" ]
// SetXY defines the abscissa and ordinate of the current position. If the // passed values are negative, they are relative respectively to the right and // bottom of the page.
[ "SetXY", "defines", "the", "abscissa", "and", "ordinate", "of", "the", "current", "position", ".", "If", "the", "passed", "values", "are", "negative", "they", "are", "relative", "respectively", "to", "the", "right", "and", "bottom", "of", "the", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2804-L2807
train
jung-kurt/gofpdf
fpdf.go
SetProtection
func (f *Fpdf) SetProtection(actionFlag byte, userPassStr, ownerPassStr string) { if f.err != nil { return } f.protect.setProtection(actionFlag, userPassStr, ownerPassStr) }
go
func (f *Fpdf) SetProtection(actionFlag byte, userPassStr, ownerPassStr string) { if f.err != nil { return } f.protect.setProtection(actionFlag, userPassStr, ownerPassStr) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetProtection", "(", "actionFlag", "byte", ",", "userPassStr", ",", "ownerPassStr", "string", ")", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "f", ".", "protect", ".", "setProtection", "(", "actionFlag", ",", "userPassStr", ",", "ownerPassStr", ")", "\n", "}" ]
// SetProtection applies certain constraints on the finished PDF document. // // actionFlag is a bitflag that controls various document operations. // CnProtectPrint allows the document to be printed. CnProtectModify allows a // document to be modified by a PDF editor. CnProtectCopy allows text and // images to be copied into the system clipboard. CnProtectAnnotForms allows // annotations and forms to be added by a PDF editor. These values can be // combined by or-ing them together, for example, // CnProtectCopy|CnProtectModify. This flag is advisory; not all PDF readers // implement the constraints that this argument attempts to control. // // userPassStr specifies the password that will need to be provided to view the // contents of the PDF. The permissions specified by actionFlag will apply. // // ownerPassStr specifies the password that will need to be provided to gain // full access to the document regardless of the actionFlag value. An empty // string for this argument will be replaced with a random value, effectively // prohibiting full access to the document.
[ "SetProtection", "applies", "certain", "constraints", "on", "the", "finished", "PDF", "document", ".", "actionFlag", "is", "a", "bitflag", "that", "controls", "various", "document", "operations", ".", "CnProtectPrint", "allows", "the", "document", "to", "be", "printed", ".", "CnProtectModify", "allows", "a", "document", "to", "be", "modified", "by", "a", "PDF", "editor", ".", "CnProtectCopy", "allows", "text", "and", "images", "to", "be", "copied", "into", "the", "system", "clipboard", ".", "CnProtectAnnotForms", "allows", "annotations", "and", "forms", "to", "be", "added", "by", "a", "PDF", "editor", ".", "These", "values", "can", "be", "combined", "by", "or", "-", "ing", "them", "together", "for", "example", "CnProtectCopy|CnProtectModify", ".", "This", "flag", "is", "advisory", ";", "not", "all", "PDF", "readers", "implement", "the", "constraints", "that", "this", "argument", "attempts", "to", "control", ".", "userPassStr", "specifies", "the", "password", "that", "will", "need", "to", "be", "provided", "to", "view", "the", "contents", "of", "the", "PDF", ".", "The", "permissions", "specified", "by", "actionFlag", "will", "apply", ".", "ownerPassStr", "specifies", "the", "password", "that", "will", "need", "to", "be", "provided", "to", "gain", "full", "access", "to", "the", "document", "regardless", "of", "the", "actionFlag", "value", ".", "An", "empty", "string", "for", "this", "argument", "will", "be", "replaced", "with", "a", "random", "value", "effectively", "prohibiting", "full", "access", "to", "the", "document", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2827-L2832
train
jung-kurt/gofpdf
fpdf.go
OutputAndClose
func (f *Fpdf) OutputAndClose(w io.WriteCloser) error { f.Output(w) w.Close() return f.err }
go
func (f *Fpdf) OutputAndClose(w io.WriteCloser) error { f.Output(w) w.Close() return f.err }
[ "func", "(", "f", "*", "Fpdf", ")", "OutputAndClose", "(", "w", "io", ".", "WriteCloser", ")", "error", "{", "f", ".", "Output", "(", "w", ")", "\n", "w", ".", "Close", "(", ")", "\n", "return", "f", ".", "err", "\n", "}" ]
// OutputAndClose sends the PDF document to the writer specified by w. This // method will close both f and w, even if an error is detected and no document // is produced.
[ "OutputAndClose", "sends", "the", "PDF", "document", "to", "the", "writer", "specified", "by", "w", ".", "This", "method", "will", "close", "both", "f", "and", "w", "even", "if", "an", "error", "is", "detected", "and", "no", "document", "is", "produced", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2837-L2841
train
jung-kurt/gofpdf
fpdf.go
OutputFileAndClose
func (f *Fpdf) OutputFileAndClose(fileStr string) error { if f.err == nil { pdfFile, err := os.Create(fileStr) if err == nil { f.Output(pdfFile) pdfFile.Close() } else { f.err = err } } return f.err }
go
func (f *Fpdf) OutputFileAndClose(fileStr string) error { if f.err == nil { pdfFile, err := os.Create(fileStr) if err == nil { f.Output(pdfFile) pdfFile.Close() } else { f.err = err } } return f.err }
[ "func", "(", "f", "*", "Fpdf", ")", "OutputFileAndClose", "(", "fileStr", "string", ")", "error", "{", "if", "f", ".", "err", "==", "nil", "{", "pdfFile", ",", "err", ":=", "os", ".", "Create", "(", "fileStr", ")", "\n", "if", "err", "==", "nil", "{", "f", ".", "Output", "(", "pdfFile", ")", "\n", "pdfFile", ".", "Close", "(", ")", "\n", "}", "else", "{", "f", ".", "err", "=", "err", "\n", "}", "\n", "}", "\n", "return", "f", ".", "err", "\n", "}" ]
// OutputFileAndClose creates or truncates the file specified by fileStr and // writes the PDF document to it. This method will close f and the newly // written file, even if an error is detected and no document is produced. // // Most examples demonstrate the use of this method.
[ "OutputFileAndClose", "creates", "or", "truncates", "the", "file", "specified", "by", "fileStr", "and", "writes", "the", "PDF", "document", "to", "it", ".", "This", "method", "will", "close", "f", "and", "the", "newly", "written", "file", "even", "if", "an", "error", "is", "detected", "and", "no", "document", "is", "produced", ".", "Most", "examples", "demonstrate", "the", "use", "of", "this", "method", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2848-L2859
train
jung-kurt/gofpdf
fpdf.go
Output
func (f *Fpdf) Output(w io.Writer) error { if f.err != nil { return f.err } // dbg("Output") if f.state < 3 { f.Close() } _, err := f.buffer.WriteTo(w) if err != nil { f.err = err } return f.err }
go
func (f *Fpdf) Output(w io.Writer) error { if f.err != nil { return f.err } // dbg("Output") if f.state < 3 { f.Close() } _, err := f.buffer.WriteTo(w) if err != nil { f.err = err } return f.err }
[ "func", "(", "f", "*", "Fpdf", ")", "Output", "(", "w", "io", ".", "Writer", ")", "error", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "f", ".", "err", "\n", "}", "\n", "if", "f", ".", "state", "<", "3", "{", "f", ".", "Close", "(", ")", "\n", "}", "\n", "_", ",", "err", ":=", "f", ".", "buffer", ".", "WriteTo", "(", "w", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "}", "\n", "return", "f", ".", "err", "\n", "}" ]
// Output sends the PDF document to the writer specified by w. No output will // take place if an error has occurred in the document generation process. w // remains open after this function returns. After returning, f is in a closed // state and its methods should not be called.
[ "Output", "sends", "the", "PDF", "document", "to", "the", "writer", "specified", "by", "w", ".", "No", "output", "will", "take", "place", "if", "an", "error", "has", "occurred", "in", "the", "document", "generation", "process", ".", "w", "remains", "open", "after", "this", "function", "returns", ".", "After", "returning", "f", "is", "in", "a", "closed", "state", "and", "its", "methods", "should", "not", "be", "called", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2865-L2878
train
jung-kurt/gofpdf
fpdf.go
loadfont
func (f *Fpdf) loadfont(r io.Reader) (def fontDefType) { if f.err != nil { return } // dbg("Loading font [%s]", fontStr) var buf bytes.Buffer _, err := buf.ReadFrom(r) if err != nil { f.err = err return } err = json.Unmarshal(buf.Bytes(), &def) if err != nil { f.err = err return } if def.i, err = generateFontID(def); err != nil { f.err = err } // dump(def) return }
go
func (f *Fpdf) loadfont(r io.Reader) (def fontDefType) { if f.err != nil { return } // dbg("Loading font [%s]", fontStr) var buf bytes.Buffer _, err := buf.ReadFrom(r) if err != nil { f.err = err return } err = json.Unmarshal(buf.Bytes(), &def) if err != nil { f.err = err return } if def.i, err = generateFontID(def); err != nil { f.err = err } // dump(def) return }
[ "func", "(", "f", "*", "Fpdf", ")", "loadfont", "(", "r", "io", ".", "Reader", ")", "(", "def", "fontDefType", ")", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "_", ",", "err", ":=", "buf", ".", "ReadFrom", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "err", "=", "json", ".", "Unmarshal", "(", "buf", ".", "Bytes", "(", ")", ",", "&", "def", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "if", "def", ".", "i", ",", "err", "=", "generateFontID", "(", "def", ")", ";", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "}", "\n", "return", "\n", "}" ]
// Load a font definition file from the given Reader
[ "Load", "a", "font", "definition", "file", "from", "the", "given", "Reader" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2960-L2982
train
jung-kurt/gofpdf
fpdf.go
escape
func (f *Fpdf) escape(s string) string { s = strings.Replace(s, "\\", "\\\\", -1) s = strings.Replace(s, "(", "\\(", -1) s = strings.Replace(s, ")", "\\)", -1) s = strings.Replace(s, "\r", "\\r", -1) return s }
go
func (f *Fpdf) escape(s string) string { s = strings.Replace(s, "\\", "\\\\", -1) s = strings.Replace(s, "(", "\\(", -1) s = strings.Replace(s, ")", "\\)", -1) s = strings.Replace(s, "\r", "\\r", -1) return s }
[ "func", "(", "f", "*", "Fpdf", ")", "escape", "(", "s", "string", ")", "string", "{", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"\\\\\"", ",", "\\\\", ",", "\"\\\\\\\\\"", ")", "\n", "\\\\", "\n", "\\\\", "\n", "-", "1", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"(\"", ",", "\"\\\\(\"", ",", "\\\\", ")", "\n", "}" ]
// Escape special characters in strings
[ "Escape", "special", "characters", "in", "strings" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2985-L2991
train
jung-kurt/gofpdf
fpdf.go
textstring
func (f *Fpdf) textstring(s string) string { if f.protect.encrypted { b := []byte(s) f.protect.rc4(uint32(f.n), &b) s = string(b) } return "(" + f.escape(s) + ")" }
go
func (f *Fpdf) textstring(s string) string { if f.protect.encrypted { b := []byte(s) f.protect.rc4(uint32(f.n), &b) s = string(b) } return "(" + f.escape(s) + ")" }
[ "func", "(", "f", "*", "Fpdf", ")", "textstring", "(", "s", "string", ")", "string", "{", "if", "f", ".", "protect", ".", "encrypted", "{", "b", ":=", "[", "]", "byte", "(", "s", ")", "\n", "f", ".", "protect", ".", "rc4", "(", "uint32", "(", "f", ".", "n", ")", ",", "&", "b", ")", "\n", "s", "=", "string", "(", "b", ")", "\n", "}", "\n", "return", "\"(\"", "+", "f", ".", "escape", "(", "s", ")", "+", "\")\"", "\n", "}" ]
// textstring formats a text string
[ "textstring", "formats", "a", "text", "string" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2994-L3001
train
jung-kurt/gofpdf
fpdf.go
parsejpg
func (f *Fpdf) parsejpg(r io.Reader) (info *ImageInfoType) { info = f.newImageInfo() var ( data bytes.Buffer err error ) _, err = data.ReadFrom(r) if err != nil { f.err = err return } info.data = data.Bytes() config, err := jpeg.DecodeConfig(bytes.NewReader(info.data)) if err != nil { f.err = err return } info.w = float64(config.Width) info.h = float64(config.Height) info.f = "DCTDecode" info.bpc = 8 switch config.ColorModel { case color.GrayModel: info.cs = "DeviceGray" case color.YCbCrModel: info.cs = "DeviceRGB" case color.CMYKModel: info.cs = "DeviceCMYK" default: f.err = fmt.Errorf("image JPEG buffer has unsupported color space (%v)", config.ColorModel) return } return }
go
func (f *Fpdf) parsejpg(r io.Reader) (info *ImageInfoType) { info = f.newImageInfo() var ( data bytes.Buffer err error ) _, err = data.ReadFrom(r) if err != nil { f.err = err return } info.data = data.Bytes() config, err := jpeg.DecodeConfig(bytes.NewReader(info.data)) if err != nil { f.err = err return } info.w = float64(config.Width) info.h = float64(config.Height) info.f = "DCTDecode" info.bpc = 8 switch config.ColorModel { case color.GrayModel: info.cs = "DeviceGray" case color.YCbCrModel: info.cs = "DeviceRGB" case color.CMYKModel: info.cs = "DeviceCMYK" default: f.err = fmt.Errorf("image JPEG buffer has unsupported color space (%v)", config.ColorModel) return } return }
[ "func", "(", "f", "*", "Fpdf", ")", "parsejpg", "(", "r", "io", ".", "Reader", ")", "(", "info", "*", "ImageInfoType", ")", "{", "info", "=", "f", ".", "newImageInfo", "(", ")", "\n", "var", "(", "data", "bytes", ".", "Buffer", "\n", "err", "error", "\n", ")", "\n", "_", ",", "err", "=", "data", ".", "ReadFrom", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "info", ".", "data", "=", "data", ".", "Bytes", "(", ")", "\n", "config", ",", "err", ":=", "jpeg", ".", "DecodeConfig", "(", "bytes", ".", "NewReader", "(", "info", ".", "data", ")", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "info", ".", "w", "=", "float64", "(", "config", ".", "Width", ")", "\n", "info", ".", "h", "=", "float64", "(", "config", ".", "Height", ")", "\n", "info", ".", "f", "=", "\"DCTDecode\"", "\n", "info", ".", "bpc", "=", "8", "\n", "switch", "config", ".", "ColorModel", "{", "case", "color", ".", "GrayModel", ":", "info", ".", "cs", "=", "\"DeviceGray\"", "\n", "case", "color", ".", "YCbCrModel", ":", "info", ".", "cs", "=", "\"DeviceRGB\"", "\n", "case", "color", ".", "CMYKModel", ":", "info", ".", "cs", "=", "\"DeviceCMYK\"", "\n", "default", ":", "f", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"image JPEG buffer has unsupported color space (%v)\"", ",", "config", ".", "ColorModel", ")", "\n", "return", "\n", "}", "\n", "return", "\n", "}" ]
// parsejpg extracts info from io.Reader with JPEG data // Thank you, Bruno Michel, for providing this code.
[ "parsejpg", "extracts", "info", "from", "io", ".", "Reader", "with", "JPEG", "data", "Thank", "you", "Bruno", "Michel", "for", "providing", "this", "code", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3037-L3071
train
jung-kurt/gofpdf
fpdf.go
parsepng
func (f *Fpdf) parsepng(r io.Reader, readdpi bool) (info *ImageInfoType) { buf, err := bufferFromReader(r) if err != nil { f.err = err return } return f.parsepngstream(buf, readdpi) }
go
func (f *Fpdf) parsepng(r io.Reader, readdpi bool) (info *ImageInfoType) { buf, err := bufferFromReader(r) if err != nil { f.err = err return } return f.parsepngstream(buf, readdpi) }
[ "func", "(", "f", "*", "Fpdf", ")", "parsepng", "(", "r", "io", ".", "Reader", ",", "readdpi", "bool", ")", "(", "info", "*", "ImageInfoType", ")", "{", "buf", ",", "err", ":=", "bufferFromReader", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "return", "f", ".", "parsepngstream", "(", "buf", ",", "readdpi", ")", "\n", "}" ]
// parsepng extracts info from a PNG data
[ "parsepng", "extracts", "info", "from", "a", "PNG", "data" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3074-L3081
train
jung-kurt/gofpdf
fpdf.go
newobj
func (f *Fpdf) newobj() { // dbg("newobj") f.n++ for j := len(f.offsets); j <= f.n; j++ { f.offsets = append(f.offsets, 0) } f.offsets[f.n] = f.buffer.Len() f.outf("%d 0 obj", f.n) }
go
func (f *Fpdf) newobj() { // dbg("newobj") f.n++ for j := len(f.offsets); j <= f.n; j++ { f.offsets = append(f.offsets, 0) } f.offsets[f.n] = f.buffer.Len() f.outf("%d 0 obj", f.n) }
[ "func", "(", "f", "*", "Fpdf", ")", "newobj", "(", ")", "{", "f", ".", "n", "++", "\n", "for", "j", ":=", "len", "(", "f", ".", "offsets", ")", ";", "j", "<=", "f", ".", "n", ";", "j", "++", "{", "f", ".", "offsets", "=", "append", "(", "f", ".", "offsets", ",", "0", ")", "\n", "}", "\n", "f", ".", "offsets", "[", "f", ".", "n", "]", "=", "f", ".", "buffer", ".", "Len", "(", ")", "\n", "f", ".", "outf", "(", "\"%d 0 obj\"", ",", "f", ".", "n", ")", "\n", "}" ]
// newobj begins a new object
[ "newobj", "begins", "a", "new", "object" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3122-L3130
train
jung-kurt/gofpdf
fpdf.go
out
func (f *Fpdf) out(s string) { if f.state == 2 { f.pages[f.page].WriteString(s) f.pages[f.page].WriteString("\n") } else { f.buffer.WriteString(s) f.buffer.WriteString("\n") } }
go
func (f *Fpdf) out(s string) { if f.state == 2 { f.pages[f.page].WriteString(s) f.pages[f.page].WriteString("\n") } else { f.buffer.WriteString(s) f.buffer.WriteString("\n") } }
[ "func", "(", "f", "*", "Fpdf", ")", "out", "(", "s", "string", ")", "{", "if", "f", ".", "state", "==", "2", "{", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "WriteString", "(", "s", ")", "\n", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "WriteString", "(", "\"\\n\"", ")", "\n", "}", "else", "\\n", "\n", "}" ]
// out; Add a line to the document
[ "out", ";", "Add", "a", "line", "to", "the", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3143-L3151
train
jung-kurt/gofpdf
fpdf.go
outbuf
func (f *Fpdf) outbuf(r io.Reader) { if f.state == 2 { f.pages[f.page].ReadFrom(r) f.pages[f.page].WriteString("\n") } else { f.buffer.ReadFrom(r) f.buffer.WriteString("\n") } }
go
func (f *Fpdf) outbuf(r io.Reader) { if f.state == 2 { f.pages[f.page].ReadFrom(r) f.pages[f.page].WriteString("\n") } else { f.buffer.ReadFrom(r) f.buffer.WriteString("\n") } }
[ "func", "(", "f", "*", "Fpdf", ")", "outbuf", "(", "r", "io", ".", "Reader", ")", "{", "if", "f", ".", "state", "==", "2", "{", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "ReadFrom", "(", "r", ")", "\n", "f", ".", "pages", "[", "f", ".", "page", "]", ".", "WriteString", "(", "\"\\n\"", ")", "\n", "}", "else", "\\n", "\n", "}" ]
// outbuf adds a buffered line to the document
[ "outbuf", "adds", "a", "buffered", "line", "to", "the", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3154-L3162
train
jung-kurt/gofpdf
fpdf.go
outf
func (f *Fpdf) outf(fmtStr string, args ...interface{}) { f.out(sprintf(fmtStr, args...)) }
go
func (f *Fpdf) outf(fmtStr string, args ...interface{}) { f.out(sprintf(fmtStr, args...)) }
[ "func", "(", "f", "*", "Fpdf", ")", "outf", "(", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "out", "(", "sprintf", "(", "fmtStr", ",", "args", "...", ")", ")", "\n", "}" ]
// outf adds a formatted line to the document
[ "outf", "adds", "a", "formatted", "line", "to", "the", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3181-L3183
train
jung-kurt/gofpdf
util.go
fileExist
func fileExist(filename string) (ok bool) { info, err := os.Stat(filename) if err == nil { if ^os.ModePerm&info.Mode() == 0 { ok = true } } return ok }
go
func fileExist(filename string) (ok bool) { info, err := os.Stat(filename) if err == nil { if ^os.ModePerm&info.Mode() == 0 { ok = true } } return ok }
[ "func", "fileExist", "(", "filename", "string", ")", "(", "ok", "bool", ")", "{", "info", ",", "err", ":=", "os", ".", "Stat", "(", "filename", ")", "\n", "if", "err", "==", "nil", "{", "if", "^", "os", ".", "ModePerm", "&", "info", ".", "Mode", "(", ")", "==", "0", "{", "ok", "=", "true", "\n", "}", "\n", "}", "\n", "return", "ok", "\n", "}" ]
// fileExist returns true if the specified normal file exists
[ "fileExist", "returns", "true", "if", "the", "specified", "normal", "file", "exists" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L43-L51
train
jung-kurt/gofpdf
util.go
fileSize
func fileSize(filename string) (size int64, ok bool) { info, err := os.Stat(filename) ok = err == nil if ok { size = info.Size() } return }
go
func fileSize(filename string) (size int64, ok bool) { info, err := os.Stat(filename) ok = err == nil if ok { size = info.Size() } return }
[ "func", "fileSize", "(", "filename", "string", ")", "(", "size", "int64", ",", "ok", "bool", ")", "{", "info", ",", "err", ":=", "os", ".", "Stat", "(", "filename", ")", "\n", "ok", "=", "err", "==", "nil", "\n", "if", "ok", "{", "size", "=", "info", ".", "Size", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// fileSize returns the size of the specified file; ok will be false // if the file does not exist or is not an ordinary file
[ "fileSize", "returns", "the", "size", "of", "the", "specified", "file", ";", "ok", "will", "be", "false", "if", "the", "file", "does", "not", "exist", "or", "is", "not", "an", "ordinary", "file" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L55-L62
train
jung-kurt/gofpdf
util.go
bufferFromReader
func bufferFromReader(r io.Reader) (b *bytes.Buffer, err error) { b = new(bytes.Buffer) _, err = b.ReadFrom(r) return }
go
func bufferFromReader(r io.Reader) (b *bytes.Buffer, err error) { b = new(bytes.Buffer) _, err = b.ReadFrom(r) return }
[ "func", "bufferFromReader", "(", "r", "io", ".", "Reader", ")", "(", "b", "*", "bytes", ".", "Buffer", ",", "err", "error", ")", "{", "b", "=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "_", ",", "err", "=", "b", ".", "ReadFrom", "(", "r", ")", "\n", "return", "\n", "}" ]
// bufferFromReader returns a new buffer populated with the contents of the specified Reader
[ "bufferFromReader", "returns", "a", "new", "buffer", "populated", "with", "the", "contents", "of", "the", "specified", "Reader" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L65-L69
train
jung-kurt/gofpdf
util.go
slicesEqual
func slicesEqual(a, b []float64) bool { if len(a) != len(b) { return false } for i := range a { if a[i] != b[i] { return false } } return true }
go
func slicesEqual(a, b []float64) bool { if len(a) != len(b) { return false } for i := range a { if a[i] != b[i] { return false } } return true }
[ "func", "slicesEqual", "(", "a", ",", "b", "[", "]", "float64", ")", "bool", "{", "if", "len", "(", "a", ")", "!=", "len", "(", "b", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "range", "a", "{", "if", "a", "[", "i", "]", "!=", "b", "[", "i", "]", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// slicesEqual returns true if the two specified float slices are equal
[ "slicesEqual", "returns", "true", "if", "the", "two", "specified", "float", "slices", "are", "equal" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L72-L82
train
jung-kurt/gofpdf
util.go
sliceCompress
func sliceCompress(data []byte) []byte { var buf bytes.Buffer cmp, _ := zlib.NewWriterLevel(&buf, zlib.BestSpeed) cmp.Write(data) cmp.Close() return buf.Bytes() }
go
func sliceCompress(data []byte) []byte { var buf bytes.Buffer cmp, _ := zlib.NewWriterLevel(&buf, zlib.BestSpeed) cmp.Write(data) cmp.Close() return buf.Bytes() }
[ "func", "sliceCompress", "(", "data", "[", "]", "byte", ")", "[", "]", "byte", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "cmp", ",", "_", ":=", "zlib", ".", "NewWriterLevel", "(", "&", "buf", ",", "zlib", ".", "BestSpeed", ")", "\n", "cmp", ".", "Write", "(", "data", ")", "\n", "cmp", ".", "Close", "(", ")", "\n", "return", "buf", ".", "Bytes", "(", ")", "\n", "}" ]
// sliceCompress returns a zlib-compressed copy of the specified byte array
[ "sliceCompress", "returns", "a", "zlib", "-", "compressed", "copy", "of", "the", "specified", "byte", "array" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L85-L91
train
jung-kurt/gofpdf
util.go
sliceUncompress
func sliceUncompress(data []byte) (outData []byte, err error) { inBuf := bytes.NewReader(data) r, err := zlib.NewReader(inBuf) defer r.Close() if err == nil { var outBuf bytes.Buffer _, err = outBuf.ReadFrom(r) if err == nil { outData = outBuf.Bytes() } } return }
go
func sliceUncompress(data []byte) (outData []byte, err error) { inBuf := bytes.NewReader(data) r, err := zlib.NewReader(inBuf) defer r.Close() if err == nil { var outBuf bytes.Buffer _, err = outBuf.ReadFrom(r) if err == nil { outData = outBuf.Bytes() } } return }
[ "func", "sliceUncompress", "(", "data", "[", "]", "byte", ")", "(", "outData", "[", "]", "byte", ",", "err", "error", ")", "{", "inBuf", ":=", "bytes", ".", "NewReader", "(", "data", ")", "\n", "r", ",", "err", ":=", "zlib", ".", "NewReader", "(", "inBuf", ")", "\n", "defer", "r", ".", "Close", "(", ")", "\n", "if", "err", "==", "nil", "{", "var", "outBuf", "bytes", ".", "Buffer", "\n", "_", ",", "err", "=", "outBuf", ".", "ReadFrom", "(", "r", ")", "\n", "if", "err", "==", "nil", "{", "outData", "=", "outBuf", ".", "Bytes", "(", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// sliceUncompress returns an uncompressed copy of the specified zlib-compressed byte array
[ "sliceUncompress", "returns", "an", "uncompressed", "copy", "of", "the", "specified", "zlib", "-", "compressed", "byte", "array" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L94-L106
train
jung-kurt/gofpdf
util.go
intIf
func intIf(cnd bool, a, b int) int { if cnd { return a } return b }
go
func intIf(cnd bool, a, b int) int { if cnd { return a } return b }
[ "func", "intIf", "(", "cnd", "bool", ",", "a", ",", "b", "int", ")", "int", "{", "if", "cnd", "{", "return", "a", "\n", "}", "\n", "return", "b", "\n", "}" ]
// intIf returns a if cnd is true, otherwise b
[ "intIf", "returns", "a", "if", "cnd", "is", "true", "otherwise", "b" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L141-L146
train
jung-kurt/gofpdf
util.go
strIf
func strIf(cnd bool, aStr, bStr string) string { if cnd { return aStr } return bStr }
go
func strIf(cnd bool, aStr, bStr string) string { if cnd { return aStr } return bStr }
[ "func", "strIf", "(", "cnd", "bool", ",", "aStr", ",", "bStr", "string", ")", "string", "{", "if", "cnd", "{", "return", "aStr", "\n", "}", "\n", "return", "bStr", "\n", "}" ]
// strIf returns aStr if cnd is true, otherwise bStr
[ "strIf", "returns", "aStr", "if", "cnd", "is", "true", "otherwise", "bStr" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L149-L154
train
jung-kurt/gofpdf
util.go
UnicodeTranslator
func UnicodeTranslator(r io.Reader) (f func(string) string, err error) { m := make(map[rune]byte) var uPos, cPos uint32 var lineStr, nameStr string sc := bufio.NewScanner(r) for sc.Scan() { lineStr = sc.Text() lineStr = strings.TrimSpace(lineStr) if len(lineStr) > 0 { _, err = fmt.Sscanf(lineStr, "!%2X U+%4X %s", &cPos, &uPos, &nameStr) if err == nil { if cPos >= 0x80 { m[rune(uPos)] = byte(cPos) } } } } if err == nil { f = repClosure(m) } else { f = doNothing } return }
go
func UnicodeTranslator(r io.Reader) (f func(string) string, err error) { m := make(map[rune]byte) var uPos, cPos uint32 var lineStr, nameStr string sc := bufio.NewScanner(r) for sc.Scan() { lineStr = sc.Text() lineStr = strings.TrimSpace(lineStr) if len(lineStr) > 0 { _, err = fmt.Sscanf(lineStr, "!%2X U+%4X %s", &cPos, &uPos, &nameStr) if err == nil { if cPos >= 0x80 { m[rune(uPos)] = byte(cPos) } } } } if err == nil { f = repClosure(m) } else { f = doNothing } return }
[ "func", "UnicodeTranslator", "(", "r", "io", ".", "Reader", ")", "(", "f", "func", "(", "string", ")", "string", ",", "err", "error", ")", "{", "m", ":=", "make", "(", "map", "[", "rune", "]", "byte", ")", "\n", "var", "uPos", ",", "cPos", "uint32", "\n", "var", "lineStr", ",", "nameStr", "string", "\n", "sc", ":=", "bufio", ".", "NewScanner", "(", "r", ")", "\n", "for", "sc", ".", "Scan", "(", ")", "{", "lineStr", "=", "sc", ".", "Text", "(", ")", "\n", "lineStr", "=", "strings", ".", "TrimSpace", "(", "lineStr", ")", "\n", "if", "len", "(", "lineStr", ")", ">", "0", "{", "_", ",", "err", "=", "fmt", ".", "Sscanf", "(", "lineStr", ",", "\"!%2X U+%4X %s\"", ",", "&", "cPos", ",", "&", "uPos", ",", "&", "nameStr", ")", "\n", "if", "err", "==", "nil", "{", "if", "cPos", ">=", "0x80", "{", "m", "[", "rune", "(", "uPos", ")", "]", "=", "byte", "(", "cPos", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "err", "==", "nil", "{", "f", "=", "repClosure", "(", "m", ")", "\n", "}", "else", "{", "f", "=", "doNothing", "\n", "}", "\n", "return", "\n", "}" ]
// UnicodeTranslator returns a function that can be used to translate, where // possible, utf-8 strings to a form that is compatible with the specified code // page. The returned function accepts a string and returns a string. // // r is a reader that should read a buffer made up of content lines that // pertain to the code page of interest. Each line is made up of three // whitespace separated fields. The first begins with "!" and is followed by // two hexadecimal digits that identify the glyph position in the code page of // interest. The second field begins with "U+" and is followed by the unicode // code point value. The third is the glyph name. A number of these code page // map files are packaged with the gfpdf library in the font directory. // // An error occurs only if a line is read that does not conform to the expected // format. In this case, the returned function is valid but does not perform // any rune translation.
[ "UnicodeTranslator", "returns", "a", "function", "that", "can", "be", "used", "to", "translate", "where", "possible", "utf", "-", "8", "strings", "to", "a", "form", "that", "is", "compatible", "with", "the", "specified", "code", "page", ".", "The", "returned", "function", "accepts", "a", "string", "and", "returns", "a", "string", ".", "r", "is", "a", "reader", "that", "should", "read", "a", "buffer", "made", "up", "of", "content", "lines", "that", "pertain", "to", "the", "code", "page", "of", "interest", ".", "Each", "line", "is", "made", "up", "of", "three", "whitespace", "separated", "fields", ".", "The", "first", "begins", "with", "!", "and", "is", "followed", "by", "two", "hexadecimal", "digits", "that", "identify", "the", "glyph", "position", "in", "the", "code", "page", "of", "interest", ".", "The", "second", "field", "begins", "with", "U", "+", "and", "is", "followed", "by", "the", "unicode", "code", "point", "value", ".", "The", "third", "is", "the", "glyph", "name", ".", "A", "number", "of", "these", "code", "page", "map", "files", "are", "packaged", "with", "the", "gfpdf", "library", "in", "the", "font", "directory", ".", "An", "error", "occurs", "only", "if", "a", "line", "is", "read", "that", "does", "not", "conform", "to", "the", "expected", "format", ".", "In", "this", "case", "the", "returned", "function", "is", "valid", "but", "does", "not", "perform", "any", "rune", "translation", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L207-L230
train
jung-kurt/gofpdf
util.go
UnicodeTranslatorFromFile
func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error) { var fl *os.File fl, err = os.Open(fileStr) if err == nil { f, err = UnicodeTranslator(fl) fl.Close() } else { f = doNothing } return }
go
func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error) { var fl *os.File fl, err = os.Open(fileStr) if err == nil { f, err = UnicodeTranslator(fl) fl.Close() } else { f = doNothing } return }
[ "func", "UnicodeTranslatorFromFile", "(", "fileStr", "string", ")", "(", "f", "func", "(", "string", ")", "string", ",", "err", "error", ")", "{", "var", "fl", "*", "os", ".", "File", "\n", "fl", ",", "err", "=", "os", ".", "Open", "(", "fileStr", ")", "\n", "if", "err", "==", "nil", "{", "f", ",", "err", "=", "UnicodeTranslator", "(", "fl", ")", "\n", "fl", ".", "Close", "(", ")", "\n", "}", "else", "{", "f", "=", "doNothing", "\n", "}", "\n", "return", "\n", "}" ]
// UnicodeTranslatorFromFile returns a function that can be used to translate, // where possible, utf-8 strings to a form that is compatible with the // specified code page. See UnicodeTranslator for more details. // // fileStr identifies a font descriptor file that maps glyph positions to names. // // If an error occurs reading the file, the returned function is valid but does // not perform any rune translation.
[ "UnicodeTranslatorFromFile", "returns", "a", "function", "that", "can", "be", "used", "to", "translate", "where", "possible", "utf", "-", "8", "strings", "to", "a", "form", "that", "is", "compatible", "with", "the", "specified", "code", "page", ".", "See", "UnicodeTranslator", "for", "more", "details", ".", "fileStr", "identifies", "a", "font", "descriptor", "file", "that", "maps", "glyph", "positions", "to", "names", ".", "If", "an", "error", "occurs", "reading", "the", "file", "the", "returned", "function", "is", "valid", "but", "does", "not", "perform", "any", "rune", "translation", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L240-L250
train
jung-kurt/gofpdf
util.go
Transform
func (p *PointType) Transform(x, y float64) PointType { return PointType{p.X + x, p.Y + y} }
go
func (p *PointType) Transform(x, y float64) PointType { return PointType{p.X + x, p.Y + y} }
[ "func", "(", "p", "*", "PointType", ")", "Transform", "(", "x", ",", "y", "float64", ")", "PointType", "{", "return", "PointType", "{", "p", ".", "X", "+", "x", ",", "p", ".", "Y", "+", "y", "}", "\n", "}" ]
// Transform moves a point by given X, Y offset
[ "Transform", "moves", "a", "point", "by", "given", "X", "Y", "offset" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L285-L287
train
jung-kurt/gofpdf
util.go
ScaleBy
func (s *SizeType) ScaleBy(factor float64) SizeType { return SizeType{s.Wd * factor, s.Ht * factor} }
go
func (s *SizeType) ScaleBy(factor float64) SizeType { return SizeType{s.Wd * factor, s.Ht * factor} }
[ "func", "(", "s", "*", "SizeType", ")", "ScaleBy", "(", "factor", "float64", ")", "SizeType", "{", "return", "SizeType", "{", "s", ".", "Wd", "*", "factor", ",", "s", ".", "Ht", "*", "factor", "}", "\n", "}" ]
// ScaleBy expands a size by a certain factor
[ "ScaleBy", "expands", "a", "size", "by", "a", "certain", "factor" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L302-L304
train
jung-kurt/gofpdf
util.go
ScaleToWidth
func (s *SizeType) ScaleToWidth(width float64) SizeType { height := s.Ht * width / s.Wd return SizeType{width, height} }
go
func (s *SizeType) ScaleToWidth(width float64) SizeType { height := s.Ht * width / s.Wd return SizeType{width, height} }
[ "func", "(", "s", "*", "SizeType", ")", "ScaleToWidth", "(", "width", "float64", ")", "SizeType", "{", "height", ":=", "s", ".", "Ht", "*", "width", "/", "s", ".", "Wd", "\n", "return", "SizeType", "{", "width", ",", "height", "}", "\n", "}" ]
// ScaleToWidth adjusts the height of a size to match the given width
[ "ScaleToWidth", "adjusts", "the", "height", "of", "a", "size", "to", "match", "the", "given", "width" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L307-L310
train
jung-kurt/gofpdf
util.go
ScaleToHeight
func (s *SizeType) ScaleToHeight(height float64) SizeType { width := s.Wd * height / s.Ht return SizeType{width, height} }
go
func (s *SizeType) ScaleToHeight(height float64) SizeType { width := s.Wd * height / s.Ht return SizeType{width, height} }
[ "func", "(", "s", "*", "SizeType", ")", "ScaleToHeight", "(", "height", "float64", ")", "SizeType", "{", "width", ":=", "s", ".", "Wd", "*", "height", "/", "s", ".", "Ht", "\n", "return", "SizeType", "{", "width", ",", "height", "}", "\n", "}" ]
// ScaleToHeight adjusts the width of a size to match the given height
[ "ScaleToHeight", "adjusts", "the", "width", "of", "a", "size", "to", "match", "the", "given", "height" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L313-L316
train
jung-kurt/gofpdf
template.go
CreateTemplate
func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template { return newTpl(PointType{0, 0}, f.curPageSize, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
go
func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template { return newTpl(PointType{0, 0}, f.curPageSize, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
[ "func", "(", "f", "*", "Fpdf", ")", "CreateTemplate", "(", "fn", "func", "(", "*", "Tpl", ")", ")", "Template", "{", "return", "newTpl", "(", "PointType", "{", "0", ",", "0", "}", ",", "f", ".", "curPageSize", ",", "f", ".", "defOrientation", ",", "f", ".", "unitStr", ",", "f", ".", "fontDirStr", ",", "fn", ",", "f", ")", "\n", "}" ]
// CreateTemplate defines a new template using the current page size.
[ "CreateTemplate", "defines", "a", "new", "template", "using", "the", "current", "page", "size", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L26-L28
train
jung-kurt/gofpdf
template.go
CreateTemplateCustom
func (f *Fpdf) CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template { return newTpl(corner, size, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
go
func (f *Fpdf) CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template { return newTpl(corner, size, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
[ "func", "(", "f", "*", "Fpdf", ")", "CreateTemplateCustom", "(", "corner", "PointType", ",", "size", "SizeType", ",", "fn", "func", "(", "*", "Tpl", ")", ")", "Template", "{", "return", "newTpl", "(", "corner", ",", "size", ",", "f", ".", "defOrientation", ",", "f", ".", "unitStr", ",", "f", ".", "fontDirStr", ",", "fn", ",", "f", ")", "\n", "}" ]
// CreateTemplateCustom starts a template, using the given bounds.
[ "CreateTemplateCustom", "starts", "a", "template", "using", "the", "given", "bounds", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L31-L33
train
jung-kurt/gofpdf
template.go
CreateTpl
func CreateTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl)) Template { return newTpl(corner, size, orientationStr, unitStr, fontDirStr, fn, nil) }
go
func CreateTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl)) Template { return newTpl(corner, size, orientationStr, unitStr, fontDirStr, fn, nil) }
[ "func", "CreateTpl", "(", "corner", "PointType", ",", "size", "SizeType", ",", "orientationStr", ",", "unitStr", ",", "fontDirStr", "string", ",", "fn", "func", "(", "*", "Tpl", ")", ")", "Template", "{", "return", "newTpl", "(", "corner", ",", "size", ",", "orientationStr", ",", "unitStr", ",", "fontDirStr", ",", "fn", ",", "nil", ")", "\n", "}" ]
// CreateTpl creates a template not attached to any document
[ "CreateTpl", "creates", "a", "template", "not", "attached", "to", "any", "document" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L52-L54
train
jung-kurt/gofpdf
template.go
UseTemplate
func (f *Fpdf) UseTemplate(t Template) { if t == nil { f.SetErrorf("template is nil") return } corner, size := t.Size() f.UseTemplateScaled(t, corner, size) }
go
func (f *Fpdf) UseTemplate(t Template) { if t == nil { f.SetErrorf("template is nil") return } corner, size := t.Size() f.UseTemplateScaled(t, corner, size) }
[ "func", "(", "f", "*", "Fpdf", ")", "UseTemplate", "(", "t", "Template", ")", "{", "if", "t", "==", "nil", "{", "f", ".", "SetErrorf", "(", "\"template is nil\"", ")", "\n", "return", "\n", "}", "\n", "corner", ",", "size", ":=", "t", ".", "Size", "(", ")", "\n", "f", ".", "UseTemplateScaled", "(", "t", ",", "corner", ",", "size", ")", "\n", "}" ]
// UseTemplate adds a template to the current page or another template, // using the size and position at which it was originally written.
[ "UseTemplate", "adds", "a", "template", "to", "the", "current", "page", "or", "another", "template", "using", "the", "size", "and", "position", "at", "which", "it", "was", "originally", "written", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L58-L65
train
jung-kurt/gofpdf
template.go
UseTemplateScaled
func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType) { if t == nil { f.SetErrorf("template is nil") return } // You have to add at least a page first if f.page <= 0 { f.SetErrorf("cannot use a template without first adding a page") return } // make a note of the fact that we actually use this template, as well as any other templates, // images or fonts it uses f.templates[t.ID()] = t for _, tt := range t.Templates() { f.templates[tt.ID()] = tt } for name, ti := range t.Images() { name = sprintf("t%s-%s", t.ID(), name) f.images[name] = ti } // template data _, templateSize := t.Size() scaleX := size.Wd / templateSize.Wd scaleY := size.Ht / templateSize.Ht tx := corner.X * f.k ty := (f.curPageSize.Ht - corner.Y - size.Ht) * f.k f.outf("q %.4f 0 0 %.4f %.4f %.4f cm", scaleX, scaleY, tx, ty) // Translate f.outf("/TPL%s Do Q", t.ID()) }
go
func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType) { if t == nil { f.SetErrorf("template is nil") return } // You have to add at least a page first if f.page <= 0 { f.SetErrorf("cannot use a template without first adding a page") return } // make a note of the fact that we actually use this template, as well as any other templates, // images or fonts it uses f.templates[t.ID()] = t for _, tt := range t.Templates() { f.templates[tt.ID()] = tt } for name, ti := range t.Images() { name = sprintf("t%s-%s", t.ID(), name) f.images[name] = ti } // template data _, templateSize := t.Size() scaleX := size.Wd / templateSize.Wd scaleY := size.Ht / templateSize.Ht tx := corner.X * f.k ty := (f.curPageSize.Ht - corner.Y - size.Ht) * f.k f.outf("q %.4f 0 0 %.4f %.4f %.4f cm", scaleX, scaleY, tx, ty) // Translate f.outf("/TPL%s Do Q", t.ID()) }
[ "func", "(", "f", "*", "Fpdf", ")", "UseTemplateScaled", "(", "t", "Template", ",", "corner", "PointType", ",", "size", "SizeType", ")", "{", "if", "t", "==", "nil", "{", "f", ".", "SetErrorf", "(", "\"template is nil\"", ")", "\n", "return", "\n", "}", "\n", "if", "f", ".", "page", "<=", "0", "{", "f", ".", "SetErrorf", "(", "\"cannot use a template without first adding a page\"", ")", "\n", "return", "\n", "}", "\n", "f", ".", "templates", "[", "t", ".", "ID", "(", ")", "]", "=", "t", "\n", "for", "_", ",", "tt", ":=", "range", "t", ".", "Templates", "(", ")", "{", "f", ".", "templates", "[", "tt", ".", "ID", "(", ")", "]", "=", "tt", "\n", "}", "\n", "for", "name", ",", "ti", ":=", "range", "t", ".", "Images", "(", ")", "{", "name", "=", "sprintf", "(", "\"t%s-%s\"", ",", "t", ".", "ID", "(", ")", ",", "name", ")", "\n", "f", ".", "images", "[", "name", "]", "=", "ti", "\n", "}", "\n", "_", ",", "templateSize", ":=", "t", ".", "Size", "(", ")", "\n", "scaleX", ":=", "size", ".", "Wd", "/", "templateSize", ".", "Wd", "\n", "scaleY", ":=", "size", ".", "Ht", "/", "templateSize", ".", "Ht", "\n", "tx", ":=", "corner", ".", "X", "*", "f", ".", "k", "\n", "ty", ":=", "(", "f", ".", "curPageSize", ".", "Ht", "-", "corner", ".", "Y", "-", "size", ".", "Ht", ")", "*", "f", ".", "k", "\n", "f", ".", "outf", "(", "\"q %.4f 0 0 %.4f %.4f %.4f cm\"", ",", "scaleX", ",", "scaleY", ",", "tx", ",", "ty", ")", "\n", "f", ".", "outf", "(", "\"/TPL%s Do Q\"", ",", "t", ".", "ID", "(", ")", ")", "\n", "}" ]
// UseTemplateScaled adds a template to the current page or another template, // using the given page coordinates.
[ "UseTemplateScaled", "adds", "a", "template", "to", "the", "current", "page", "or", "another", "template", "using", "the", "given", "page", "coordinates", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L69-L101
train
jung-kurt/gofpdf
template.go
putTemplates
func (f *Fpdf) putTemplates() { filter := "" if f.compress { filter = "/Filter /FlateDecode " } templates := sortTemplates(f.templates, f.catalogSort) var t Template for _, t = range templates { corner, size := t.Size() f.newobj() f.templateObjects[t.ID()] = f.n f.outf("<<%s/Type /XObject", filter) f.out("/Subtype /Form") f.out("/Formtype 1") f.outf("/BBox [%.2f %.2f %.2f %.2f]", corner.X*f.k, corner.Y*f.k, (corner.X+size.Wd)*f.k, (corner.Y+size.Ht)*f.k) if corner.X != 0 || corner.Y != 0 { f.outf("/Matrix [1 0 0 1 %.5f %.5f]", -corner.X*f.k*2, corner.Y*f.k*2) } // Template's resource dictionary f.out("/Resources ") f.out("<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]") f.templateFontCatalog() tImages := t.Images() tTemplates := t.Templates() if len(tImages) > 0 || len(tTemplates) > 0 { f.out("/XObject <<") { var key string var keyList []string var ti *ImageInfoType for key = range tImages { keyList = append(keyList, key) } if gl.catalogSort { sort.Strings(keyList) } for _, key = range keyList { // for _, ti := range tImages { ti = tImages[key] f.outf("/I%s %d 0 R", ti.i, ti.n) } } for _, tt := range tTemplates { id := tt.ID() if objID, ok := f.templateObjects[id]; ok { f.outf("/TPL%s %d 0 R", id, objID) } } f.out(">>") } f.out(">>") // Write the template's byte stream buffer := t.Bytes() // fmt.Println("Put template bytes", string(buffer[:])) if f.compress { buffer = sliceCompress(buffer) } f.outf("/Length %d >>", len(buffer)) f.putstream(buffer) f.out("endobj") } }
go
func (f *Fpdf) putTemplates() { filter := "" if f.compress { filter = "/Filter /FlateDecode " } templates := sortTemplates(f.templates, f.catalogSort) var t Template for _, t = range templates { corner, size := t.Size() f.newobj() f.templateObjects[t.ID()] = f.n f.outf("<<%s/Type /XObject", filter) f.out("/Subtype /Form") f.out("/Formtype 1") f.outf("/BBox [%.2f %.2f %.2f %.2f]", corner.X*f.k, corner.Y*f.k, (corner.X+size.Wd)*f.k, (corner.Y+size.Ht)*f.k) if corner.X != 0 || corner.Y != 0 { f.outf("/Matrix [1 0 0 1 %.5f %.5f]", -corner.X*f.k*2, corner.Y*f.k*2) } // Template's resource dictionary f.out("/Resources ") f.out("<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]") f.templateFontCatalog() tImages := t.Images() tTemplates := t.Templates() if len(tImages) > 0 || len(tTemplates) > 0 { f.out("/XObject <<") { var key string var keyList []string var ti *ImageInfoType for key = range tImages { keyList = append(keyList, key) } if gl.catalogSort { sort.Strings(keyList) } for _, key = range keyList { // for _, ti := range tImages { ti = tImages[key] f.outf("/I%s %d 0 R", ti.i, ti.n) } } for _, tt := range tTemplates { id := tt.ID() if objID, ok := f.templateObjects[id]; ok { f.outf("/TPL%s %d 0 R", id, objID) } } f.out(">>") } f.out(">>") // Write the template's byte stream buffer := t.Bytes() // fmt.Println("Put template bytes", string(buffer[:])) if f.compress { buffer = sliceCompress(buffer) } f.outf("/Length %d >>", len(buffer)) f.putstream(buffer) f.out("endobj") } }
[ "func", "(", "f", "*", "Fpdf", ")", "putTemplates", "(", ")", "{", "filter", ":=", "\"\"", "\n", "if", "f", ".", "compress", "{", "filter", "=", "\"/Filter /FlateDecode \"", "\n", "}", "\n", "templates", ":=", "sortTemplates", "(", "f", ".", "templates", ",", "f", ".", "catalogSort", ")", "\n", "var", "t", "Template", "\n", "for", "_", ",", "t", "=", "range", "templates", "{", "corner", ",", "size", ":=", "t", ".", "Size", "(", ")", "\n", "f", ".", "newobj", "(", ")", "\n", "f", ".", "templateObjects", "[", "t", ".", "ID", "(", ")", "]", "=", "f", ".", "n", "\n", "f", ".", "outf", "(", "\"<<%s/Type /XObject\"", ",", "filter", ")", "\n", "f", ".", "out", "(", "\"/Subtype /Form\"", ")", "\n", "f", ".", "out", "(", "\"/Formtype 1\"", ")", "\n", "f", ".", "outf", "(", "\"/BBox [%.2f %.2f %.2f %.2f]\"", ",", "corner", ".", "X", "*", "f", ".", "k", ",", "corner", ".", "Y", "*", "f", ".", "k", ",", "(", "corner", ".", "X", "+", "size", ".", "Wd", ")", "*", "f", ".", "k", ",", "(", "corner", ".", "Y", "+", "size", ".", "Ht", ")", "*", "f", ".", "k", ")", "\n", "if", "corner", ".", "X", "!=", "0", "||", "corner", ".", "Y", "!=", "0", "{", "f", ".", "outf", "(", "\"/Matrix [1 0 0 1 %.5f %.5f]\"", ",", "-", "corner", ".", "X", "*", "f", ".", "k", "*", "2", ",", "corner", ".", "Y", "*", "f", ".", "k", "*", "2", ")", "\n", "}", "\n", "f", ".", "out", "(", "\"/Resources \"", ")", "\n", "f", ".", "out", "(", "\"<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\"", ")", "\n", "f", ".", "templateFontCatalog", "(", ")", "\n", "tImages", ":=", "t", ".", "Images", "(", ")", "\n", "tTemplates", ":=", "t", ".", "Templates", "(", ")", "\n", "if", "len", "(", "tImages", ")", ">", "0", "||", "len", "(", "tTemplates", ")", ">", "0", "{", "f", ".", "out", "(", "\"/XObject <<\"", ")", "\n", "{", "var", "key", "string", "\n", "var", "keyList", "[", "]", "string", "\n", "var", "ti", "*", "ImageInfoType", "\n", "for", "key", "=", "range", "tImages", "{", "keyList", "=", "append", "(", "keyList", ",", "key", ")", "\n", "}", "\n", "if", "gl", ".", "catalogSort", "{", "sort", ".", "Strings", "(", "keyList", ")", "\n", "}", "\n", "for", "_", ",", "key", "=", "range", "keyList", "{", "ti", "=", "tImages", "[", "key", "]", "\n", "f", ".", "outf", "(", "\"/I%s %d 0 R\"", ",", "ti", ".", "i", ",", "ti", ".", "n", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "tt", ":=", "range", "tTemplates", "{", "id", ":=", "tt", ".", "ID", "(", ")", "\n", "if", "objID", ",", "ok", ":=", "f", ".", "templateObjects", "[", "id", "]", ";", "ok", "{", "f", ".", "outf", "(", "\"/TPL%s %d 0 R\"", ",", "id", ",", "objID", ")", "\n", "}", "\n", "}", "\n", "f", ".", "out", "(", "\">>\"", ")", "\n", "}", "\n", "f", ".", "out", "(", "\">>\"", ")", "\n", "buffer", ":=", "t", ".", "Bytes", "(", ")", "\n", "if", "f", ".", "compress", "{", "buffer", "=", "sliceCompress", "(", "buffer", ")", "\n", "}", "\n", "f", ".", "outf", "(", "\"/Length %d >>\"", ",", "len", "(", "buffer", ")", ")", "\n", "f", ".", "putstream", "(", "buffer", ")", "\n", "f", ".", "out", "(", "\"endobj\"", ")", "\n", "}", "\n", "}" ]
// putTemplates writes the templates to the PDF
[ "putTemplates", "writes", "the", "templates", "to", "the", "PDF" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L137-L205
train
jung-kurt/gofpdf
template.go
sortTemplates
func sortTemplates(templates map[string]Template, catalogSort bool) []Template { chain := make([]Template, 0, len(templates)*2) // build a full set of dependency chains var keyList []string var key string var t Template keyList = templateKeyList(templates, catalogSort) for _, key = range keyList { t = templates[key] tlist := templateChainDependencies(t) for _, tt := range tlist { if tt != nil { chain = append(chain, tt) } } } // reduce that to make a simple list sorted := make([]Template, 0, len(templates)) chain: for _, t := range chain { for _, already := range sorted { if t == already { continue chain } } sorted = append(sorted, t) } return sorted }
go
func sortTemplates(templates map[string]Template, catalogSort bool) []Template { chain := make([]Template, 0, len(templates)*2) // build a full set of dependency chains var keyList []string var key string var t Template keyList = templateKeyList(templates, catalogSort) for _, key = range keyList { t = templates[key] tlist := templateChainDependencies(t) for _, tt := range tlist { if tt != nil { chain = append(chain, tt) } } } // reduce that to make a simple list sorted := make([]Template, 0, len(templates)) chain: for _, t := range chain { for _, already := range sorted { if t == already { continue chain } } sorted = append(sorted, t) } return sorted }
[ "func", "sortTemplates", "(", "templates", "map", "[", "string", "]", "Template", ",", "catalogSort", "bool", ")", "[", "]", "Template", "{", "chain", ":=", "make", "(", "[", "]", "Template", ",", "0", ",", "len", "(", "templates", ")", "*", "2", ")", "\n", "var", "keyList", "[", "]", "string", "\n", "var", "key", "string", "\n", "var", "t", "Template", "\n", "keyList", "=", "templateKeyList", "(", "templates", ",", "catalogSort", ")", "\n", "for", "_", ",", "key", "=", "range", "keyList", "{", "t", "=", "templates", "[", "key", "]", "\n", "tlist", ":=", "templateChainDependencies", "(", "t", ")", "\n", "for", "_", ",", "tt", ":=", "range", "tlist", "{", "if", "tt", "!=", "nil", "{", "chain", "=", "append", "(", "chain", ",", "tt", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "sorted", ":=", "make", "(", "[", "]", "Template", ",", "0", ",", "len", "(", "templates", ")", ")", "\n", "chain", ":", "for", "_", ",", "t", ":=", "range", "chain", "{", "for", "_", ",", "already", ":=", "range", "sorted", "{", "if", "t", "==", "already", "{", "continue", "chain", "\n", "}", "\n", "}", "\n", "sorted", "=", "append", "(", "sorted", ",", "t", ")", "\n", "}", "\n", "return", "sorted", "\n", "}" ]
// sortTemplates puts templates in a suitable order based on dependices
[ "sortTemplates", "puts", "templates", "in", "a", "suitable", "order", "based", "on", "dependices" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L225-L256
train
jung-kurt/gofpdf
template.go
templateChainDependencies
func templateChainDependencies(template Template) []Template { requires := template.Templates() chain := make([]Template, len(requires)*2) for _, req := range requires { chain = append(chain, templateChainDependencies(req)...) } chain = append(chain, template) return chain }
go
func templateChainDependencies(template Template) []Template { requires := template.Templates() chain := make([]Template, len(requires)*2) for _, req := range requires { chain = append(chain, templateChainDependencies(req)...) } chain = append(chain, template) return chain }
[ "func", "templateChainDependencies", "(", "template", "Template", ")", "[", "]", "Template", "{", "requires", ":=", "template", ".", "Templates", "(", ")", "\n", "chain", ":=", "make", "(", "[", "]", "Template", ",", "len", "(", "requires", ")", "*", "2", ")", "\n", "for", "_", ",", "req", ":=", "range", "requires", "{", "chain", "=", "append", "(", "chain", ",", "templateChainDependencies", "(", "req", ")", "...", ")", "\n", "}", "\n", "chain", "=", "append", "(", "chain", ",", "template", ")", "\n", "return", "chain", "\n", "}" ]
// templateChainDependencies is a recursive function for determining the full chain of template dependencies
[ "templateChainDependencies", "is", "a", "recursive", "function", "for", "determining", "the", "full", "chain", "of", "template", "dependencies" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L259-L267
train