_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3 values | text stringlengths 52 85.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q15700 | Eval | train | func (p *Predicate) Eval(row virtualRow) (bool, error) {
if p.True {
return true, nil
}
// Find left attribute
left := p.LeftValue.table + "." + p.LeftValue.lexeme
val, ok := row[left]
if !ok {
return false, fmt.Errorf("Attribute [%s] not found in row", left)
}
p.LeftValue.v = val.v
return p.Operator(p.LeftValue, p.RightValue), nil
} | go | {
"resource": ""
} |
q15701 | NewAttribute | train | func NewAttribute(name string, typeName string, autoIncrement bool) Attribute {
a := Attribute{
name: name,
typeName: typeName,
autoIncrement: autoIncrement,
}
return a
} | go | {
"resource": ""
} |
q15702 | Close | train | func (c *Conn) Close() error {
log.Debug("Conn.Close")
c.conn.Close()
if c.parent != nil {
c.parent.closingConn()
}
return nil
} | go | {
"resource": ""
} |
q15703 | Begin | train | func (c *Conn) Begin() (driver.Tx, error) {
tx := Tx{
conn: c,
}
return &tx, nil
} | go | {
"resource": ""
} |
q15704 | Run | train | func Run(db *sql.DB) {
// Readline
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("ramsql> ")
buffer, err := reader.ReadBytes(';')
if err != nil {
if err == io.EOF {
fmt.Printf("exit\n")
return
}
fmt.Printf("Reading error\n")
return
}
buffer = buffer[:len(buffer)-1]
if len(buffer) == 0 {
continue
}
stmt := string(buffer)
stmt = strings.Replace(stmt, "\n", "", -1)
// Do things here
if strings.HasPrefix(stmt, "SELECT") {
query(db, stmt)
} else if strings.HasPrefix(stmt, "SHOW") {
query(db, stmt)
} else if strings.HasPrefix(stmt, "DESCRIBE") {
query(db, stmt)
} else {
exec(db, stmt)
}
}
} | go | {
"resource": ""
} |
q15705 | Close | train | func (cdc *ChannelDriverConn) Close() {
if cdc.conn == nil {
return
}
close(cdc.conn)
cdc.conn = nil
} | go | {
"resource": ""
} |
q15706 | New | train | func (cde *ChannelDriverEndpoint) New(uri string) (DriverConn, error) {
if cde.newConnChannel == nil {
return nil, fmt.Errorf("connection closed")
}
channel := make(chan message)
cdc := &ChannelDriverConn{conn: channel}
cde.newConnChannel <- channel
return cdc, nil
} | go | {
"resource": ""
} |
q15707 | Accept | train | func (cee *ChannelEngineEndpoint) Accept() (EngineConn, error) {
newConn, ok := <-cee.newConnChannel
if !ok {
return nil, io.EOF
}
return NewChannelEngineConn(newConn), nil
} | go | {
"resource": ""
} |
q15708 | ReadStatement | train | func (cec *ChannelEngineConn) ReadStatement() (string, error) {
message, ok := <-cec.conn
if !ok {
cec.conn = nil
return "", io.EOF
}
return message.Value[0], nil
} | go | {
"resource": ""
} |
q15709 | WriteResult | train | func (cec *ChannelEngineConn) WriteResult(lastInsertedID int64, rowsAffected int64) error {
m := message{
Type: resultMessage,
Value: []string{fmt.Sprintf("%d %d", lastInsertedID, rowsAffected)},
}
cec.conn <- m
return nil
} | go | {
"resource": ""
} |
q15710 | WriteError | train | func (cec *ChannelEngineConn) WriteError(err error) error {
m := message{
Type: errMessage,
Value: []string{err.Error()},
}
cec.conn <- m
return nil
} | go | {
"resource": ""
} |
q15711 | WriteRowHeader | train | func (cec *ChannelEngineConn) WriteRowHeader(header []string) error {
m := message{
Type: rowHeaderMessage,
Value: header,
}
cec.conn <- m
return nil
} | go | {
"resource": ""
} |
q15712 | WriteRow | train | func (cec *ChannelEngineConn) WriteRow(row []string) error {
m := message{
Type: rowValueMessage,
Value: row,
}
cec.conn <- m
return nil
} | go | {
"resource": ""
} |
q15713 | WriteRowEnd | train | func (cec *ChannelEngineConn) WriteRowEnd() error {
m := message{
Type: rowEndMessage,
}
cec.conn <- m
return nil
} | go | {
"resource": ""
} |
q15714 | WriteQuery | train | func (cdc *ChannelDriverConn) WriteQuery(query string) error {
if cdc.conn == nil {
return fmt.Errorf("connection closed")
}
m := message{
Type: queryMessage,
Value: []string{query},
}
cdc.conn <- m
return nil
} | go | {
"resource": ""
} |
q15715 | WriteExec | train | func (cdc *ChannelDriverConn) WriteExec(statement string) error {
if cdc.conn == nil {
return fmt.Errorf("connection closed")
}
m := message{
Type: execMessage,
Value: []string{statement},
}
cdc.conn <- m
return nil
} | go | {
"resource": ""
} |
q15716 | ReadResult | train | func (cdc *ChannelDriverConn) ReadResult() (lastInsertedID int64, rowsAffected int64, err error) {
if cdc.conn == nil {
return 0, 0, fmt.Errorf("connection closed")
}
m := <-cdc.conn
if m.Type != resultMessage {
if m.Type == errMessage {
return 0, 0, errors.New(m.Value[0])
}
return 0, 0, fmt.Errorf("Protocal error: ReadResult received %v", m)
}
_, err = fmt.Sscanf(m.Value[0], "%d %d", &lastInsertedID, &rowsAffected)
return lastInsertedID, rowsAffected, err
} | go | {
"resource": ""
} |
q15717 | ReadRows | train | func (cdc *ChannelDriverConn) ReadRows() (chan []string, error) {
if cdc.conn == nil {
return nil, fmt.Errorf("connection closed")
}
m := <-cdc.conn
if m.Type == errMessage {
return nil, errors.New(m.Value[0])
}
if m.Type != rowHeaderMessage {
return nil, errors.New("not a rows header")
}
return UnlimitedRowsChannel(cdc.conn, m), nil
} | go | {
"resource": ""
} |
q15718 | Insert | train | func (r *Relation) Insert(t *Tuple) error {
// Maybe do somthing like lock read/write here
// Maybe index
r.rows = append(r.rows, t)
return nil
} | go | {
"resource": ""
} |
q15719 | Exec | train | func (s *Stmt) Exec(args []driver.Value) (r driver.Result, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("fatalf error: %s", r)
return
}
}()
defer s.conn.mutex.Unlock()
if s.query == "" {
return nil, fmt.Errorf("empty statement")
}
var finalQuery string
// replace $* by arguments in query string
finalQuery = replaceArguments(s.query, args)
log.Info("Exec <%s>\n", finalQuery)
// Send query to server
err = s.conn.conn.WriteExec(finalQuery)
if err != nil {
log.Warning("Exec: Cannot send query to server: %s", err)
return nil, fmt.Errorf("Cannot send query to server: %s", err)
}
// Get answer from server
lastInsertedID, rowsAffected, err := s.conn.conn.ReadResult()
if err != nil {
return nil, err
}
// Create a driver.Result
return newResult(lastInsertedID, rowsAffected), nil
} | go | {
"resource": ""
} |
q15720 | Query | train | func (s *Stmt) Query(args []driver.Value) (r driver.Rows, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("fatalf error: %s", r)
return
}
}()
defer s.conn.mutex.Unlock()
if s.query == "" {
return nil, fmt.Errorf("empty statement")
}
finalQuery := replaceArguments(s.query, args)
log.Info("Query < %s >\n", finalQuery)
err = s.conn.conn.WriteQuery(finalQuery)
if err != nil {
return nil, err
}
rowsChannel, err := s.conn.conn.ReadRows()
if err != nil {
return nil, err
}
r = newRows(rowsChannel)
return r, nil
} | go | {
"resource": ""
} |
q15721 | UnlimitedRowsChannel | train | func UnlimitedRowsChannel(bufferThis chan message, firstMessage message) chan []string {
driverChannel := make(chan []string)
rowList := list.New()
rowList.PushBack(firstMessage.Value)
go func() {
for {
// If nothing comes in and nothing is going out...
if rowList.Len() == 0 && bufferThis == nil {
close(driverChannel)
return
}
// Create a copy of driverChannel because if there is nothing to send
// We can disable the case in select with a nil channel and get a chance
// to fetch new data on bufferThis channel
driverChannelNullable := driverChannel
var nextRow []string
if rowList.Len() != 0 {
nextRow = rowList.Front().Value.([]string)
} else {
driverChannelNullable = nil
}
select {
// In case a new row is sent to driver
case driverChannelNullable <- nextRow:
if nextRow != nil {
rowList.Remove(rowList.Front())
}
// In case we receive a new value to buffer from engine channel
case newRow, ok := <-bufferThis:
if !ok || newRow.Type == rowEndMessage {
// Stop listening to bufferThis channel
bufferThis = nil
// If there is nothing more to listen and there is nothing in buffer, exit
// close driverChannel so *Rows knows there is nothing more to read
if rowList.Len() == 0 {
if driverChannel != nil {
close(driverChannel)
}
return
}
if driverChannel == nil {
log.Critical("Unlimited: But there is nobody to read it, exiting")
return
}
} else if newRow.Type == errMessage {
log.Critical("Runtime error: %s", newRow.Value[0])
if driverChannel != nil {
close(driverChannel)
}
return
} else {
// Everything is ok, buffering new value
rowList.PushBack(newRow.Value)
}
case exit := <-driverChannel:
// this means driverChannel is closed
// set driverChannel to nil so we don't try to close it again
driverChannel = nil
_ = exit
}
}
}()
return driverChannel
} | go | {
"resource": ""
} |
q15722 | NewOperator | train | func NewOperator(token int, lexeme string) (Operator, error) {
switch token {
case parser.EqualityToken:
return equalityOperator, nil
case parser.LeftDipleToken:
return lessThanOperator, nil
case parser.RightDipleToken:
return greaterThanOperator, nil
case parser.LessOrEqualToken:
return lessOrEqualOperator, nil
case parser.GreaterOrEqualToken:
return greaterOrEqualOperator, nil
}
return nil, fmt.Errorf("Operator '%s' does not exist", lexeme)
} | go | {
"resource": ""
} |
q15723 | equalityOperator | train | func equalityOperator(leftValue Value, rightValue Value) bool {
if fmt.Sprintf("%v", leftValue.v) == rightValue.lexeme {
return true
}
return false
} | go | {
"resource": ""
} |
q15724 | AddAttribute | train | func (t *Table) AddAttribute(attr Attribute) error {
t.attributes = append(t.attributes, attr)
return nil
} | go | {
"resource": ""
} |
q15725 | String | train | func (t Table) String() string {
stringy := t.name + " ("
for i, a := range t.attributes {
if i != 0 {
stringy += " | "
}
stringy += a.name + " " + a.typeName
}
stringy += ")"
return stringy
} | go | {
"resource": ""
} |
q15726 | Debug | train | func Debug(format string, values ...interface{}) {
if lvl() <= DebugLevel {
logger.Logf("[DEBUG] "+format, values...)
}
} | go | {
"resource": ""
} |
q15727 | Info | train | func Info(format string, values ...interface{}) {
if lvl() <= InfoLevel {
logger.Logf("[INFO] "+format, values...)
}
} | go | {
"resource": ""
} |
q15728 | Notice | train | func Notice(format string, values ...interface{}) {
if lvl() <= NoticeLevel {
logger.Logf("[NOTICE] "+format, values...)
}
} | go | {
"resource": ""
} |
q15729 | Warning | train | func Warning(format string, values ...interface{}) {
if lvl() <= WarningLevel {
logger.Logf("[WARNING] "+format, values...)
}
} | go | {
"resource": ""
} |
q15730 | Critical | train | func Critical(format string, values ...interface{}) {
mu.Lock()
logger.Logf("[CRITICAL] "+format, values...)
mu.Unlock()
} | go | {
"resource": ""
} |
q15731 | Logf | train | func (l BaseLogger) Logf(fmt string, values ...interface{}) {
log.Printf(fmt, values...)
} | go | {
"resource": ""
} |
q15732 | Logf | train | func (l TestLogger) Logf(fmt string, values ...interface{}) {
l.t.Logf(fmt, values...)
} | go | {
"resource": ""
} |
q15733 | ParseInstruction | train | func ParseInstruction(instruction string) ([]Instruction, error) {
l := lexer{}
tokens, err := l.lex([]byte(instruction))
if err != nil {
return nil, err
}
p := parser{}
instructions, err := p.parse(tokens)
if err != nil {
return nil, err
}
if len(instructions) == 0 {
return nil, errors.New("Error in syntax near " + instruction)
}
return instructions, nil
} | go | {
"resource": ""
} |
q15734 | ParseDate | train | func ParseDate(data string) (*time.Time, error) {
t, err := time.Parse(DateLongFormat, data)
if err == nil {
return &t, nil
}
t, err = time.Parse(time.RFC3339, data)
if err == nil {
return &t, nil
}
t, err = time.Parse(DateShortFormat, data)
if err == nil {
return &t, nil
}
t, err = time.Parse(DateNumberFormat, data)
if err == nil {
return &t, nil
}
return nil, fmt.Errorf("not a date")
} | go | {
"resource": ""
} |
q15735 | Open | train | func (rs *Driver) Open(dsn string) (conn driver.Conn, err error) {
rs.Lock()
connConf, err := parseConnectionURI(dsn)
if err != nil {
rs.Unlock()
return nil, err
}
dsnServer, exist := rs.servers[dsn]
if !exist {
driverEndpoint, engineEndpoint, err := endpoints(connConf)
if err != nil {
rs.Unlock()
return nil, err
}
server, err := engine.New(engineEndpoint)
if err != nil {
rs.Unlock()
return nil, err
}
driverConn, err := driverEndpoint.New(dsn)
if err != nil {
rs.Unlock()
return nil, err
}
s := &Server{
endpoint: driverEndpoint,
server: server,
}
rs.servers[dsn] = s
rs.Unlock()
return newConn(driverConn, s), nil
}
rs.Unlock()
driverConn, err := dsnServer.endpoint.New(dsn)
return newConn(driverConn, dsnServer), err
} | go | {
"resource": ""
} |
q15736 | Close | train | func (r *Rows) Close() error {
r.Lock()
defer r.Unlock()
if r.rowsChannel == nil {
return nil
}
_, ok := <-r.rowsChannel
if !ok {
return nil
}
// Tels UnlimitedRowsChannel to close itself
//r.rowsChannel <- []string{}
r.rowsChannel = nil
return nil
} | go | {
"resource": ""
} |
q15737 | NewChannelEndpoints | train | func NewChannelEndpoints() (DriverEndpoint, EngineEndpoint) {
channel := make(chan chan message)
return NewChannelDriverEndpoint(channel), NewChannelEngineEndpoint(channel)
} | go | {
"resource": ""
} |
q15738 | Equal | train | func (l Line) Equal(b Line) bool {
if l.Type != b.Type {
return false
}
return bytes.Equal(l.Value, b.Value)
} | go | {
"resource": ""
} |
q15739 | Decode | train | func (l *Line) Decode(b []byte) error {
delimiter := bytes.IndexRune(b, lineDelimiter)
if delimiter == -1 {
reason := `delimiter "=" not found`
err := newDecodeError("line", reason)
return errors.Wrap(err, "failed to decode")
}
if len(b) <= (delimiter + 1) {
reason := fmt.Sprintf(
"len(b) %d < (%d + 1), no value found after delimiter",
len(b), delimiter,
)
err := newDecodeError("line", reason)
return errors.Wrap(err, "failed to decode")
}
r, _ := utf8.DecodeRune(b[:delimiter])
l.Type = Type(r)
l.Value = append(l.Value, b[delimiter+1:]...)
return nil
} | go | {
"resource": ""
} |
q15740 | AppendTo | train | func (l Line) AppendTo(b []byte) []byte {
b = l.Type.appendTo(b)
b = appendRune(b, lineDelimiter)
return append(b, l.Value...)
} | go | {
"resource": ""
} |
q15741 | AppendTo | train | func (s Session) AppendTo(b []byte) []byte {
for _, l := range s {
b = l.AppendTo(b)
b = appendCLRF(b)
}
return b
} | go | {
"resource": ""
} |
q15742 | Equal | train | func (s Session) Equal(b Session) bool {
if len(s) != len(b) {
return false
}
for i := range s {
if !s[i].Equal(b[i]) {
return false
}
}
return true
} | go | {
"resource": ""
} |
q15743 | Value | train | func (a Attributes) Value(attribute string) string {
for _, v := range a {
if v.Key == attribute {
return v.Value
}
}
return blank
} | go | {
"resource": ""
} |
q15744 | Values | train | func (a Attributes) Values(attribute string) []string {
var values []string
for _, v := range a {
if v.Key == attribute {
values = append(values, v.Value)
}
}
return values
} | go | {
"resource": ""
} |
q15745 | Start | train | func (m *Message) Start() time.Time {
if len(m.Timing) == 0 {
return time.Time{}
}
return m.Timing[0].Start
} | go | {
"resource": ""
} |
q15746 | End | train | func (m *Message) End() time.Time {
if len(m.Timing) == 0 {
return time.Time{}
}
return m.Timing[0].End
} | go | {
"resource": ""
} |
q15747 | PayloadFormat | train | func (m *Media) PayloadFormat(payloadType string) string {
for _, v := range m.Attributes.Values("rtpmap") {
if strings.HasPrefix(v, payloadType) {
return strings.TrimSpace(
strings.TrimPrefix(v, payloadType),
)
}
}
return ""
} | go | {
"resource": ""
} |
q15748 | appendUint | train | func appendUint(dst []byte, n int) []byte {
if n < 0 {
panic("BUG: n should be positive")
}
var b [20]byte
buf := b[:]
i := len(buf)
var q int
for n >= 10 {
i--
q = n / 10
buf[i] = '0' + byte(n-q*10)
n = q
}
i--
buf[i] = '0' + byte(n)
dst = append(dst, buf[i:]...)
return dst
} | go | {
"resource": ""
} |
q15749 | AddRaw | train | func (s Session) AddRaw(k rune, v string) Session {
return s.appendString(Type(k), v)
} | go | {
"resource": ""
} |
q15750 | AddLine | train | func (s Session) AddLine(t Type, v string) Session {
return s.appendString(t, v)
} | go | {
"resource": ""
} |
q15751 | AddVersion | train | func (s Session) AddVersion(version int) Session {
v := make([]byte, 0, 64)
v = appendInt(v, version)
return s.append(TypeProtocolVersion, v)
} | go | {
"resource": ""
} |
q15752 | AddPhone | train | func (s Session) AddPhone(phone string) Session {
return s.appendString(TypePhone, phone)
} | go | {
"resource": ""
} |
q15753 | AddEmail | train | func (s Session) AddEmail(email string) Session {
return s.appendString(TypeEmail, email)
} | go | {
"resource": ""
} |
q15754 | AddConnectionData | train | func (s Session) AddConnectionData(data ConnectionData) Session {
v := make([]byte, 0, 512)
v = append(v, data.getNetworkType()...)
v = appendSpace(v)
v = append(v, data.getAddressType()...)
v = appendSpace(v)
v = data.appendAddress(v)
return s.append(TypeConnectionData, v)
} | go | {
"resource": ""
} |
q15755 | AddConnectionDataIP | train | func (s Session) AddConnectionDataIP(ip net.IP) Session {
return s.AddConnectionData(ConnectionData{
IP: ip,
})
} | go | {
"resource": ""
} |
q15756 | AddSessionName | train | func (s Session) AddSessionName(name string) Session {
return s.appendString(TypeSessionName, name)
} | go | {
"resource": ""
} |
q15757 | AddSessionInfo | train | func (s Session) AddSessionInfo(info string) Session {
return s.appendString(TypeSessionInformation, info)
} | go | {
"resource": ""
} |
q15758 | AddURI | train | func (s Session) AddURI(uri string) Session {
return s.appendString(TypeURI, uri)
} | go | {
"resource": ""
} |
q15759 | Equal | train | func (c ConnectionData) Equal(b ConnectionData) bool {
if c.NetworkType != b.NetworkType {
return false
}
if c.AddressType != b.AddressType {
return false
}
if !c.IP.Equal(b.IP) {
return false
}
if c.TTL != b.TTL {
return false
}
if c.Addresses != b.Addresses {
return false
}
return true
} | go | {
"resource": ""
} |
q15760 | Equal | train | func (o *Origin) Equal(b Origin) bool {
if o.Username != b.Username {
return false
}
if o.SessionID != b.SessionID {
return false
}
if o.SessionVersion != b.SessionVersion {
return false
}
if o.NetworkType != b.NetworkType {
return false
}
if o.AddressType != b.AddressType {
return false
}
if o.Address != b.Address {
return false
}
return true
} | go | {
"resource": ""
} |
q15761 | AddOrigin | train | func (s Session) AddOrigin(o Origin) Session {
v := make([]byte, 0, 2048)
v = appendSpace(append(v, o.Username...))
v = appendSpace(appendInt(v, o.SessionID))
v = appendSpace(appendInt(v, o.SessionVersion))
v = appendSpace(append(v, o.getNetworkType()...))
v = appendSpace(append(v, o.getAddressType()...))
v = append(v, o.Address...)
return s.append(TypeOrigin, v)
} | go | {
"resource": ""
} |
q15762 | TimeToNTP | train | func TimeToNTP(t time.Time) uint64 {
if t.IsZero() {
return 0
}
return uint64(t.Unix()) + ntpDelta
} | go | {
"resource": ""
} |
q15763 | NTPToTime | train | func NTPToTime(v uint64) time.Time {
if v == 0 {
return time.Time{}
}
return time.Unix(int64(v-ntpDelta), 0)
} | go | {
"resource": ""
} |
q15764 | AddTiming | train | func (s Session) AddTiming(start, end time.Time) Session {
v := make([]byte, 0, 256)
v = appendUint64(v, TimeToNTP(start))
v = appendSpace(v)
v = appendUint64(v, TimeToNTP(end))
return s.append(TypeTiming, v)
} | go | {
"resource": ""
} |
q15765 | AddTimingNTP | train | func (s Session) AddTimingNTP(start, end uint64) Session {
return s.AddTiming(NTPToTime(start), NTPToTime(end))
} | go | {
"resource": ""
} |
q15766 | AddBandwidth | train | func (s Session) AddBandwidth(t BandwidthType, bandwidth int) Session {
v := make([]byte, 0, 128)
v = append(v, string(t)...)
v = appendRune(v, ':')
v = appendInt(v, bandwidth)
return s.append(TypeBandwidth, v)
} | go | {
"resource": ""
} |
q15767 | AddRepeatTimes | train | func (s Session) AddRepeatTimes(interval, duration time.Duration,
offsets ...time.Duration) Session {
return s.addRepeatTimes(false, interval, duration, offsets...)
} | go | {
"resource": ""
} |
q15768 | AddRepeatTimesCompact | train | func (s Session) AddRepeatTimesCompact(interval, duration time.Duration,
offsets ...time.Duration) Session {
return s.addRepeatTimes(true, interval, duration, offsets...)
} | go | {
"resource": ""
} |
q15769 | Equal | train | func (m MediaDescription) Equal(b MediaDescription) bool {
if m.Type != b.Type {
return false
}
if m.Port != b.Port {
return false
}
if m.PortsNumber != b.PortsNumber {
return false
}
if m.Protocol != b.Protocol {
return false
}
if len(m.Formats) != len(b.Formats) {
return false
}
for i := range m.Formats {
if m.Formats[i] != b.Formats[i] {
return false
}
}
return true
} | go | {
"resource": ""
} |
q15770 | AddMediaDescription | train | func (s Session) AddMediaDescription(m MediaDescription) Session {
v := make([]byte, 0, 512)
v = appendSpace(append(v, m.Type...))
v = appendInt(v, m.Port)
if m.PortsNumber != 0 {
v = appendRune(v, '/')
v = appendInt(v, m.PortsNumber)
}
v = appendSpace(v)
v = appendSpace(append(v, m.Protocol...))
for i := range m.Formats {
v = append(v, m.Formats[i]...)
if i != len(m.Formats)-1 {
v = appendRune(v, fieldsDelimiter)
}
}
return s.append(TypeMediaDescription, v)
} | go | {
"resource": ""
} |
q15771 | AddEncryption | train | func (s Session) AddEncryption(e Encryption) Session {
return s.AddEncryptionKey(e.Method, e.Key)
} | go | {
"resource": ""
} |
q15772 | AddTimeZones | train | func (s Session) AddTimeZones(zones ...TimeZone) Session {
v := make([]byte, 0, 512)
for i, zone := range zones {
v = zone.append(v)
if i != len(zones)-1 {
v = appendSpace(v)
}
}
return s.append(TypeTimeZones, v)
} | go | {
"resource": ""
} |
q15773 | isKnown | train | func isKnown(t Type) bool {
switch t {
case TypeProtocolVersion,
TypeOrigin, TypeSessionName,
TypeSessionInformation, TypeURI,
TypeEmail, TypePhone,
TypeConnectionData, TypeBandwidth,
TypeTiming, TypeRepeatTimes,
TypeTimeZones, TypeEncryptionKey,
TypeAttribute, TypeMediaDescription:
return true
default:
return false
}
} | go | {
"resource": ""
} |
q15774 | isExpected | train | func isExpected(t Type, s section, pos int) error {
o := getOrdering(s)
if len(o) > pos {
for _, expected := range o[pos:] {
if expected == t {
return nil
}
if isOptional(expected) {
continue
}
}
}
// Checking possible section transitions.
switch s {
case sectionSession:
if pos < orderingAfterTime && isExpected(t, sectionTime, 0) == nil {
return nil
}
if isExpected(t, sectionMedia, 0) == nil {
return nil
}
case sectionTime:
if isExpected(t, sectionSession, orderingAfterTime) == nil {
return nil
}
case sectionMedia:
if pos != 0 && isExpected(t, sectionMedia, 0) == nil {
return nil
}
}
if !isKnown(t) {
return errUnknownType
}
// Attribute is known, but out of order.
msg := fmt.Sprintf("no matches in ordering array at %s[%d] for %s",
s, pos, t,
)
err := newSectionDecodeError(s, msg)
return errors.Wrapf(err, "field %s is unexpected", t)
} | go | {
"resource": ""
} |
q15775 | Append | train | func (m *Message) Append(s Session) Session {
s = s.AddVersion(m.Version)
s = s.AddOrigin(m.Origin)
s = s.AddSessionName(m.Name)
if len(m.Info) > 0 {
s = s.AddSessionInfo(m.Info)
}
if len(m.URI) > 0 {
s = s.AddURI(m.URI)
}
if len(m.Email) > 0 {
s = s.AddEmail(m.Email)
}
if len(m.Phone) > 0 {
s = s.AddPhone(m.Phone)
}
if !m.Connection.Blank() {
s = s.AddConnectionData(m.Connection)
}
for t, v := range m.Bandwidths {
s = s.AddBandwidth(t, v)
}
// One or more time descriptions ("t=" and "r=" lines)
for _, t := range m.Timing {
s = s.AddTiming(t.Start, t.End)
if len(t.Offsets) > 0 {
s = s.AddRepeatTimesCompact(t.Repeat, t.Active, t.Offsets...)
}
}
if len(m.TZAdjustments) > 0 {
s = s.AddTimeZones(m.TZAdjustments...)
}
if !m.Encryption.Blank() {
s = s.AddEncryption(m.Encryption)
}
s = s.appendAttributes(m.Attributes)
for i := range m.Medias {
s = s.AddMediaDescription(m.Medias[i].Description)
if len(m.Medias[i].Title) > 0 {
s = s.AddSessionInfo(m.Medias[i].Title)
}
if !m.Medias[i].Connection.Blank() {
s = s.AddConnectionData(m.Medias[i].Connection)
}
for t, v := range m.Medias[i].Bandwidths {
s = s.AddBandwidth(t, v)
}
if !m.Medias[i].Encryption.Blank() {
s = s.AddEncryption(m.Medias[i].Encryption)
}
s = s.appendAttributes(m.Medias[i].Attributes)
}
return s
} | go | {
"resource": ""
} |
q15776 | Optimize | train | func Optimize(optimize bool) Option {
return func(b *builder) Option {
prev := b.optimize
b.optimize = optimize
return Optimize(prev)
}
} | go | {
"resource": ""
} |
q15777 | BuildParser | train | func BuildParser(w io.Writer, g *ast.Grammar, opts ...Option) error {
b := &builder{w: w, recvName: "c"}
b.setOptions(opts)
return b.buildParser(g)
} | go | {
"resource": ""
} |
q15778 | BasicLatinLookup | train | func BasicLatinLookup(chars, ranges []rune, unicodeClasses []string, ignoreCase bool) (basicLatinChars [128]bool) {
for _, rn := range chars {
if rn < 128 {
basicLatinChars[rn] = true
if ignoreCase {
if unicode.IsLower(rn) {
basicLatinChars[unicode.ToUpper(rn)] = true
} else {
basicLatinChars[unicode.ToLower(rn)] = true
}
}
}
}
for i := 0; i < len(ranges); i += 2 {
if ranges[i] < 128 {
for j := ranges[i]; j < 128 && j <= ranges[i+1]; j++ {
basicLatinChars[j] = true
if ignoreCase {
if unicode.IsLower(j) {
basicLatinChars[unicode.ToUpper(j)] = true
} else {
basicLatinChars[unicode.ToLower(j)] = true
}
}
}
}
}
for _, cl := range unicodeClasses {
rt := rangeTable(cl)
for r := rune(0); r < 128; r++ {
if unicode.Is(rt, r) {
basicLatinChars[r] = true
}
}
}
return
} | go | {
"resource": ""
} |
q15779 | argError | train | func argError(exitCode int, msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg, args...)
fmt.Fprintln(os.Stderr)
usage()
exit(exitCode)
} | go | {
"resource": ""
} |
q15780 | input | train | func input(filename string) (nm string, rc io.ReadCloser) {
nm = "stdin"
inf := os.Stdin
if filename != "" {
f, err := os.Open(filename)
if err != nil {
fmt.Fprintln(os.Stderr, err)
exit(2)
}
inf = f
nm = filename
}
r := bufio.NewReader(inf)
return nm, makeReadCloser(r, inf)
} | go | {
"resource": ""
} |
q15781 | output | train | func output(filename string) io.WriteCloser {
out := os.Stdout
if filename != "" {
f, err := os.Create(filename)
if err != nil {
fmt.Fprintln(os.Stderr, err)
exit(4)
}
out = f
}
return out
} | go | {
"resource": ""
} |
q15782 | makeReadCloser | train | func makeReadCloser(r io.Reader, c io.Closer) io.ReadCloser {
rc := struct {
io.Reader
io.Closer
}{r, c}
return io.ReadCloser(rc)
} | go | {
"resource": ""
} |
q15783 | astPos | train | func (c *current) astPos() ast.Pos {
return ast.Pos{Line: c.pos.line, Col: c.pos.col, Off: c.pos.offset}
} | go | {
"resource": ""
} |
q15784 | String | train | func (p Pos) String() string {
if p.Filename != "" {
return fmt.Sprintf("%s:%d:%d (%d)", p.Filename, p.Line, p.Col, p.Off)
}
return fmt.Sprintf("%d:%d (%d)", p.Line, p.Col, p.Off)
} | go | {
"resource": ""
} |
q15785 | NewRule | train | func NewRule(p Pos, name *Identifier) *Rule {
return &Rule{p: p, Name: name}
} | go | {
"resource": ""
} |
q15786 | NewLitMatcher | train | func NewLitMatcher(p Pos, v string) *LitMatcher {
return &LitMatcher{posValue: posValue{p: p, Val: v}}
} | go | {
"resource": ""
} |
q15787 | NewCharClassMatcher | train | func NewCharClassMatcher(p Pos, raw string) *CharClassMatcher {
c := &CharClassMatcher{posValue: posValue{p: p, Val: raw}}
c.parse()
return c
} | go | {
"resource": ""
} |
q15788 | NewAnyMatcher | train | func NewAnyMatcher(p Pos, v string) *AnyMatcher {
return &AnyMatcher{posValue{p, v}}
} | go | {
"resource": ""
} |
q15789 | NewCodeBlock | train | func NewCodeBlock(p Pos, code string) *CodeBlock {
return &CodeBlock{posValue{p, code}}
} | go | {
"resource": ""
} |
q15790 | NewIdentifier | train | func NewIdentifier(p Pos, name string) *Identifier {
return &Identifier{posValue{p: p, Val: name}}
} | go | {
"resource": ""
} |
q15791 | NewStringLit | train | func NewStringLit(p Pos, val string) *StringLit {
return &StringLit{posValue{p: p, Val: val}}
} | go | {
"resource": ""
} |
q15792 | Init | train | func (s *Scanner) Init(filename string, r io.Reader, errh func(ast.Pos, error)) {
s.r = runeReader(r)
s.errh = errh
s.eof = false
s.cpos = ast.Pos{
Filename: filename,
Line: 1,
}
s.cur, s.cw = -1, 0
s.tok.Reset()
} | go | {
"resource": ""
} |
q15793 | read | train | func (s *Scanner) read() {
if s.eof {
return
}
r, w, err := s.r.ReadRune()
if err != nil {
s.fatalError(err)
return
}
s.cur = r
s.cpos.Off += s.cw
s.cw = w
// newline is '\n' as in Go
if r == '\n' {
s.cpos.Line++
s.cpos.Col = 0
} else {
s.cpos.Col++
}
} | go | {
"resource": ""
} |
q15794 | skipWhitespace | train | func (s *Scanner) skipWhitespace() {
for s.cur == ' ' || s.cur == '\t' || s.cur == '\r' {
s.read()
}
} | go | {
"resource": ""
} |
q15795 | isLetter | train | func isLetter(r rune) bool {
return 'a' <= r && r <= 'z' || 'A' <= r && r <= 'Z' || r == '_' ||
r >= 0x80 && unicode.IsLetter(r)
} | go | {
"resource": ""
} |
q15796 | isDigit | train | func isDigit(r rune) bool {
return '0' <= r && r <= '9' || r >= 0x80 && unicode.IsDigit(r)
} | go | {
"resource": ""
} |
q15797 | error | train | func (s *Scanner) error(p ast.Pos, err error) {
if s.errh != nil {
s.errh(p, err)
return
}
fmt.Fprintf(os.Stderr, "%s: %v\n", p, err)
} | go | {
"resource": ""
} |
q15798 | errorf | train | func (s *Scanner) errorf(f string, args ...interface{}) {
s.errorpf(s.cpos, f, args...)
} | go | {
"resource": ""
} |
q15799 | errorpf | train | func (s *Scanner) errorpf(p ast.Pos, f string, args ...interface{}) {
s.error(p, fmt.Errorf(f, args...))
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.