id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
142,200 | qor/widget | render.go | Render | func (w *Widget) Render(context *Context, file string) template.HTML {
var (
err error
content []byte
tmpl *template.Template
)
if file == "" {
file = w.Templates[0]
}
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("Get error when render file %v: %v", file, r)
utils.ExitWith... | go | func (w *Widget) Render(context *Context, file string) template.HTML {
var (
err error
content []byte
tmpl *template.Template
)
if file == "" {
file = w.Templates[0]
}
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("Get error when render file %v: %v", file, r)
utils.ExitWith... | [
"func",
"(",
"w",
"*",
"Widget",
")",
"Render",
"(",
"context",
"*",
"Context",
",",
"file",
"string",
")",
"template",
".",
"HTML",
"{",
"var",
"(",
"err",
"error",
"\n",
"content",
"[",
"]",
"byte",
"\n",
"tmpl",
"*",
"template",
".",
"Template",
... | // Render register widget itself content | [
"Render",
"register",
"widget",
"itself",
"content"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/render.go#L76-L104 |
142,201 | qor/widget | render.go | RegisterViewPath | func (widgets *Widgets) RegisterViewPath(p string) {
if filepath.IsAbs(p) {
viewPaths = append(viewPaths, p)
widgets.AssetFS.RegisterPath(p)
} else {
for _, gopath := range utils.GOPATH() {
viewPaths = append(viewPaths, filepath.Join(gopath, "src", p))
widgets.AssetFS.RegisterPath(filepath.Join(gopath, "s... | go | func (widgets *Widgets) RegisterViewPath(p string) {
if filepath.IsAbs(p) {
viewPaths = append(viewPaths, p)
widgets.AssetFS.RegisterPath(p)
} else {
for _, gopath := range utils.GOPATH() {
viewPaths = append(viewPaths, filepath.Join(gopath, "src", p))
widgets.AssetFS.RegisterPath(filepath.Join(gopath, "s... | [
"func",
"(",
"widgets",
"*",
"Widgets",
")",
"RegisterViewPath",
"(",
"p",
"string",
")",
"{",
"if",
"filepath",
".",
"IsAbs",
"(",
"p",
")",
"{",
"viewPaths",
"=",
"append",
"(",
"viewPaths",
",",
"p",
")",
"\n",
"widgets",
".",
"AssetFS",
".",
"Reg... | // RegisterViewPath register views directory | [
"RegisterViewPath",
"register",
"views",
"directory"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/render.go#L107-L117 |
142,202 | qor/widget | render.go | LoadPreviewAssets | func (widgets *Widgets) LoadPreviewAssets() template.HTML {
tags := ""
for _, asset := range widgets.Config.PreviewAssets {
extension := filepath.Ext(asset)
if extension == ".css" {
tags += fmt.Sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%v\">\n", asset)
} else if extension == ".js" {
tags ... | go | func (widgets *Widgets) LoadPreviewAssets() template.HTML {
tags := ""
for _, asset := range widgets.Config.PreviewAssets {
extension := filepath.Ext(asset)
if extension == ".css" {
tags += fmt.Sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%v\">\n", asset)
} else if extension == ".js" {
tags ... | [
"func",
"(",
"widgets",
"*",
"Widgets",
")",
"LoadPreviewAssets",
"(",
")",
"template",
".",
"HTML",
"{",
"tags",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"asset",
":=",
"range",
"widgets",
".",
"Config",
".",
"PreviewAssets",
"{",
"extension",
":=",
"... | // LoadPreviewAssets will return assets tag used for Preview | [
"LoadPreviewAssets",
"will",
"return",
"assets",
"tag",
"used",
"for",
"Preview"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/render.go#L120-L133 |
142,203 | qor/widget | context.go | Get | func (context Context) Get(name string) (interface{}, bool) {
if value, ok := context.Options[name]; ok {
return value, true
}
return nil, false
} | go | func (context Context) Get(name string) (interface{}, bool) {
if value, ok := context.Options[name]; ok {
return value, true
}
return nil, false
} | [
"func",
"(",
"context",
"Context",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"if",
"value",
",",
"ok",
":=",
"context",
".",
"Options",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"value",
",",
"tr... | // Get get option with name | [
"Get",
"get",
"option",
"with",
"name"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/context.go#L28-L34 |
142,204 | qor/widget | context.go | Set | func (context *Context) Set(name string, value interface{}) {
if context.Options == nil {
context.Options = map[string]interface{}{}
}
context.Options[name] = value
} | go | func (context *Context) Set(name string, value interface{}) {
if context.Options == nil {
context.Options = map[string]interface{}{}
}
context.Options[name] = value
} | [
"func",
"(",
"context",
"*",
"Context",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"context",
".",
"Options",
"==",
"nil",
"{",
"context",
".",
"Options",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
... | // Set set option by name | [
"Set",
"set",
"option",
"by",
"name"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/context.go#L37-L42 |
142,205 | qor/widget | context.go | GetDB | func (context *Context) GetDB() *gorm.DB {
if context.DB != nil {
return context.DB
}
return context.Widgets.Config.DB
} | go | func (context *Context) GetDB() *gorm.DB {
if context.DB != nil {
return context.DB
}
return context.Widgets.Config.DB
} | [
"func",
"(",
"context",
"*",
"Context",
")",
"GetDB",
"(",
")",
"*",
"gorm",
".",
"DB",
"{",
"if",
"context",
".",
"DB",
"!=",
"nil",
"{",
"return",
"context",
".",
"DB",
"\n",
"}",
"\n",
"return",
"context",
".",
"Widgets",
".",
"Config",
".",
"... | // GetDB set option by name | [
"GetDB",
"set",
"option",
"by",
"name"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/context.go#L45-L50 |
142,206 | qor/widget | context.go | Clone | func (context *Context) Clone() *Context {
return &Context{
Widgets: context.Widgets,
DB: context.DB,
AvailableWidgets: context.AvailableWidgets,
Options: context.Options,
InlineEdit: context.InlineEdit,
FuncMaps: context.FuncMaps,
WidgetSetting: context.W... | go | func (context *Context) Clone() *Context {
return &Context{
Widgets: context.Widgets,
DB: context.DB,
AvailableWidgets: context.AvailableWidgets,
Options: context.Options,
InlineEdit: context.InlineEdit,
FuncMaps: context.FuncMaps,
WidgetSetting: context.W... | [
"func",
"(",
"context",
"*",
"Context",
")",
"Clone",
"(",
")",
"*",
"Context",
"{",
"return",
"&",
"Context",
"{",
"Widgets",
":",
"context",
".",
"Widgets",
",",
"DB",
":",
"context",
".",
"DB",
",",
"AvailableWidgets",
":",
"context",
".",
"Availabl... | // Clone clone a context | [
"Clone",
"clone",
"a",
"context"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/context.go#L53-L63 |
142,207 | qor/widget | context.go | Render | func (context *Context) Render(widgetName string, widgetGroupName string) template.HTML {
var (
visibleScopes []string
widgets = context.Widgets
widgetSettingResource = widgets.WidgetSettingResource
clone = context.Clone()
)
for _, scope := range registeredScopes {
if... | go | func (context *Context) Render(widgetName string, widgetGroupName string) template.HTML {
var (
visibleScopes []string
widgets = context.Widgets
widgetSettingResource = widgets.WidgetSettingResource
clone = context.Clone()
)
for _, scope := range registeredScopes {
if... | [
"func",
"(",
"context",
"*",
"Context",
")",
"Render",
"(",
"widgetName",
"string",
",",
"widgetGroupName",
"string",
")",
"template",
".",
"HTML",
"{",
"var",
"(",
"visibleScopes",
"[",
"]",
"string",
"\n",
"widgets",
"=",
"context",
".",
"Widgets",
"\n",... | // Render render widget based on context | [
"Render",
"render",
"widget",
"based",
"on",
"context"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/context.go#L66-L111 |
142,208 | qor/widget | setting.go | GetSerializableArgumentKind | func (widgetSetting *QorWidgetSetting) GetSerializableArgumentKind() string {
if widgetSetting.WidgetType != "" {
return widgetSetting.WidgetType
}
return widgetSetting.Kind
} | go | func (widgetSetting *QorWidgetSetting) GetSerializableArgumentKind() string {
if widgetSetting.WidgetType != "" {
return widgetSetting.WidgetType
}
return widgetSetting.Kind
} | [
"func",
"(",
"widgetSetting",
"*",
"QorWidgetSetting",
")",
"GetSerializableArgumentKind",
"(",
")",
"string",
"{",
"if",
"widgetSetting",
".",
"WidgetType",
"!=",
"\"",
"\"",
"{",
"return",
"widgetSetting",
".",
"WidgetType",
"\n",
"}",
"\n",
"return",
"widgetS... | // GetSerializableArgumentKind get serializable kind | [
"GetSerializableArgumentKind",
"get",
"serializable",
"kind"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/setting.go#L57-L62 |
142,209 | qor/widget | setting.go | SetSerializableArgumentKind | func (widgetSetting *QorWidgetSetting) SetSerializableArgumentKind(name string) {
widgetSetting.WidgetType = name
widgetSetting.Kind = name
} | go | func (widgetSetting *QorWidgetSetting) SetSerializableArgumentKind(name string) {
widgetSetting.WidgetType = name
widgetSetting.Kind = name
} | [
"func",
"(",
"widgetSetting",
"*",
"QorWidgetSetting",
")",
"SetSerializableArgumentKind",
"(",
"name",
"string",
")",
"{",
"widgetSetting",
".",
"WidgetType",
"=",
"name",
"\n",
"widgetSetting",
".",
"Kind",
"=",
"name",
"\n",
"}"
] | // SetSerializableArgumentKind set serializable kind | [
"SetSerializableArgumentKind",
"set",
"serializable",
"kind"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/setting.go#L65-L68 |
142,210 | qor/widget | setting.go | GetTemplate | func (widgetSetting QorWidgetSetting) GetTemplate() string {
if widget := GetWidget(widgetSetting.GetSerializableArgumentKind()); widget != nil {
for _, value := range widget.Templates {
if value == widgetSetting.Template {
return value
}
}
// return first value of defined widget templates
for _, va... | go | func (widgetSetting QorWidgetSetting) GetTemplate() string {
if widget := GetWidget(widgetSetting.GetSerializableArgumentKind()); widget != nil {
for _, value := range widget.Templates {
if value == widgetSetting.Template {
return value
}
}
// return first value of defined widget templates
for _, va... | [
"func",
"(",
"widgetSetting",
"QorWidgetSetting",
")",
"GetTemplate",
"(",
")",
"string",
"{",
"if",
"widget",
":=",
"GetWidget",
"(",
"widgetSetting",
".",
"GetSerializableArgumentKind",
"(",
")",
")",
";",
"widget",
"!=",
"nil",
"{",
"for",
"_",
",",
"valu... | // GetTemplate get used widget template | [
"GetTemplate",
"get",
"used",
"widget",
"template"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/setting.go#L131-L145 |
142,211 | qor/widget | setting.go | GetSerializableArgumentResource | func (widgetSetting *QorWidgetSetting) GetSerializableArgumentResource() *admin.Resource {
widget := GetWidget(widgetSetting.GetSerializableArgumentKind())
if widget != nil {
return widget.Setting
}
return nil
} | go | func (widgetSetting *QorWidgetSetting) GetSerializableArgumentResource() *admin.Resource {
widget := GetWidget(widgetSetting.GetSerializableArgumentKind())
if widget != nil {
return widget.Setting
}
return nil
} | [
"func",
"(",
"widgetSetting",
"*",
"QorWidgetSetting",
")",
"GetSerializableArgumentResource",
"(",
")",
"*",
"admin",
".",
"Resource",
"{",
"widget",
":=",
"GetWidget",
"(",
"widgetSetting",
".",
"GetSerializableArgumentKind",
"(",
")",
")",
"\n",
"if",
"widget",... | // GetSerializableArgumentResource get setting's argument's resource | [
"GetSerializableArgumentResource",
"get",
"setting",
"s",
"argument",
"s",
"resource"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/setting.go#L153-L159 |
142,212 | qor/widget | widget.go | New | func New(config *Config) *Widgets {
widgets := &Widgets{Config: config, funcMaps: template.FuncMap{}, AssetFS: assetfs.AssetFS().NameSpace("widgets")}
if utils.AppRoot != "" {
widgets.RegisterViewPath(filepath.Join(utils.AppRoot, "app/views/widgets"))
}
widgets.RegisterViewPath("app/views/widgets")
return widge... | go | func New(config *Config) *Widgets {
widgets := &Widgets{Config: config, funcMaps: template.FuncMap{}, AssetFS: assetfs.AssetFS().NameSpace("widgets")}
if utils.AppRoot != "" {
widgets.RegisterViewPath(filepath.Join(utils.AppRoot, "app/views/widgets"))
}
widgets.RegisterViewPath("app/views/widgets")
return widge... | [
"func",
"New",
"(",
"config",
"*",
"Config",
")",
"*",
"Widgets",
"{",
"widgets",
":=",
"&",
"Widgets",
"{",
"Config",
":",
"config",
",",
"funcMaps",
":",
"template",
".",
"FuncMap",
"{",
"}",
",",
"AssetFS",
":",
"assetfs",
".",
"AssetFS",
"(",
")"... | // New new widgets container | [
"New",
"new",
"widgets",
"container"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/widget.go#L30-L38 |
142,213 | qor/widget | widget.go | SetAssetFS | func (widgets *Widgets) SetAssetFS(assetFS assetfs.Interface) {
for _, viewPath := range viewPaths {
assetFS.RegisterPath(viewPath)
}
widgets.AssetFS = assetFS
} | go | func (widgets *Widgets) SetAssetFS(assetFS assetfs.Interface) {
for _, viewPath := range viewPaths {
assetFS.RegisterPath(viewPath)
}
widgets.AssetFS = assetFS
} | [
"func",
"(",
"widgets",
"*",
"Widgets",
")",
"SetAssetFS",
"(",
"assetFS",
"assetfs",
".",
"Interface",
")",
"{",
"for",
"_",
",",
"viewPath",
":=",
"range",
"viewPaths",
"{",
"assetFS",
".",
"RegisterPath",
"(",
"viewPath",
")",
"\n",
"}",
"\n\n",
"widg... | // SetAssetFS set asset fs for render | [
"SetAssetFS",
"set",
"asset",
"fs",
"for",
"render"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/widget.go#L50-L56 |
142,214 | qor/widget | widget.go | RegisterFuncMap | func (widgets *Widgets) RegisterFuncMap(name string, fc interface{}) {
widgets.funcMaps[name] = fc
} | go | func (widgets *Widgets) RegisterFuncMap(name string, fc interface{}) {
widgets.funcMaps[name] = fc
} | [
"func",
"(",
"widgets",
"*",
"Widgets",
")",
"RegisterFuncMap",
"(",
"name",
"string",
",",
"fc",
"interface",
"{",
"}",
")",
"{",
"widgets",
".",
"funcMaps",
"[",
"name",
"]",
"=",
"fc",
"\n",
"}"
] | // RegisterFuncMap register view funcs, it could be used when render templates | [
"RegisterFuncMap",
"register",
"view",
"funcs",
"it",
"could",
"be",
"used",
"when",
"render",
"templates"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/widget.go#L69-L71 |
142,215 | qor/widget | widget.go | ConfigureQorResourceBeforeInitialize | func (widgets *Widgets) ConfigureQorResourceBeforeInitialize(res resource.Resourcer) {
if res, ok := res.(*admin.Resource); ok {
// register view paths
res.GetAdmin().RegisterViewPath("github.com/qor/widget/views")
// set resources
widgets.Resource = res
// set setting resource
if widgets.WidgetSettingRe... | go | func (widgets *Widgets) ConfigureQorResourceBeforeInitialize(res resource.Resourcer) {
if res, ok := res.(*admin.Resource); ok {
// register view paths
res.GetAdmin().RegisterViewPath("github.com/qor/widget/views")
// set resources
widgets.Resource = res
// set setting resource
if widgets.WidgetSettingRe... | [
"func",
"(",
"widgets",
"*",
"Widgets",
")",
"ConfigureQorResourceBeforeInitialize",
"(",
"res",
"resource",
".",
"Resourcer",
")",
"{",
"if",
"res",
",",
"ok",
":=",
"res",
".",
"(",
"*",
"admin",
".",
"Resource",
")",
";",
"ok",
"{",
"// register view pa... | // ConfigureQorResourceBeforeInitialize a method used to config Widget for qor admin | [
"ConfigureQorResourceBeforeInitialize",
"a",
"method",
"used",
"to",
"config",
"Widget",
"for",
"qor",
"admin"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/widget.go#L74-L106 |
142,216 | qor/widget | widget.go | GetWidget | func GetWidget(name string) *Widget {
for _, w := range registeredWidgets {
if w.Name == name {
return w
}
}
for _, g := range registeredWidgetsGroup {
if g.Name == name {
for _, widgetName := range g.Widgets {
return GetWidget(widgetName)
}
}
}
return nil
} | go | func GetWidget(name string) *Widget {
for _, w := range registeredWidgets {
if w.Name == name {
return w
}
}
for _, g := range registeredWidgetsGroup {
if g.Name == name {
for _, widgetName := range g.Widgets {
return GetWidget(widgetName)
}
}
}
return nil
} | [
"func",
"GetWidget",
"(",
"name",
"string",
")",
"*",
"Widget",
"{",
"for",
"_",
",",
"w",
":=",
"range",
"registeredWidgets",
"{",
"if",
"w",
".",
"Name",
"==",
"name",
"{",
"return",
"w",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"g",
":="... | // GetWidget get widget by name | [
"GetWidget",
"get",
"widget",
"by",
"name"
] | e280f6f166153605be035918fb42660b1d0e7e0b | https://github.com/qor/widget/blob/e280f6f166153605be035918fb42660b1d0e7e0b/widget.go#L127-L142 |
142,217 | aryann/difflib | difflib.go | String | func (d DiffRecord) String() string {
return fmt.Sprintf("%s %s", d.Delta, d.Payload)
} | go | func (d DiffRecord) String() string {
return fmt.Sprintf("%s %s", d.Delta, d.Payload)
} | [
"func",
"(",
"d",
"DiffRecord",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"d",
".",
"Delta",
",",
"d",
".",
"Payload",
")",
"\n",
"}"
] | // String returns a string representation of d. The string is a
// concatenation of the delta type and the payload. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"d",
".",
"The",
"string",
"is",
"a",
"concatenation",
"of",
"the",
"delta",
"type",
"and",
"the",
"payload",
"."
] | e206f873d14a916d3d26c40ab667bca123f365a3 | https://github.com/aryann/difflib/blob/e206f873d14a916d3d26c40ab667bca123f365a3/difflib.go#L61-L63 |
142,218 | aryann/difflib | difflib.go | Diff | func Diff(seq1, seq2 []string) (diff []DiffRecord) {
// Trims any common elements at the heads and tails of the
// sequences before running the diff algorithm. This is an
// optimization.
start, end := numEqualStartAndEndElements(seq1, seq2)
for _, content := range seq1[:start] {
diff = append(diff, DiffRecord{... | go | func Diff(seq1, seq2 []string) (diff []DiffRecord) {
// Trims any common elements at the heads and tails of the
// sequences before running the diff algorithm. This is an
// optimization.
start, end := numEqualStartAndEndElements(seq1, seq2)
for _, content := range seq1[:start] {
diff = append(diff, DiffRecord{... | [
"func",
"Diff",
"(",
"seq1",
",",
"seq2",
"[",
"]",
"string",
")",
"(",
"diff",
"[",
"]",
"DiffRecord",
")",
"{",
"// Trims any common elements at the heads and tails of the",
"// sequences before running the diff algorithm. This is an",
"// optimization.",
"start",
",",
... | // Diff returns the result of diffing the seq1 and seq2. | [
"Diff",
"returns",
"the",
"result",
"of",
"diffing",
"the",
"seq1",
"and",
"seq2",
"."
] | e206f873d14a916d3d26c40ab667bca123f365a3 | https://github.com/aryann/difflib/blob/e206f873d14a916d3d26c40ab667bca123f365a3/difflib.go#L66-L83 |
142,219 | aryann/difflib | difflib.go | intMatrix | func intMatrix(rows, cols int) [][]int {
matrix := make([][]int, rows)
for i := 0; i < rows; i++ {
matrix[i] = make([]int, cols)
}
return matrix
} | go | func intMatrix(rows, cols int) [][]int {
matrix := make([][]int, rows)
for i := 0; i < rows; i++ {
matrix[i] = make([]int, cols)
}
return matrix
} | [
"func",
"intMatrix",
"(",
"rows",
",",
"cols",
"int",
")",
"[",
"]",
"[",
"]",
"int",
"{",
"matrix",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"int",
",",
"rows",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"rows",
";",
"i",
"++",
"{",
... | // intMatrix returns a 2-dimensional slice of ints with the given
// number of rows and columns. | [
"intMatrix",
"returns",
"a",
"2",
"-",
"dimensional",
"slice",
"of",
"ints",
"with",
"the",
"given",
"number",
"of",
"rows",
"and",
"columns",
"."
] | e206f873d14a916d3d26c40ab667bca123f365a3 | https://github.com/aryann/difflib/blob/e206f873d14a916d3d26c40ab667bca123f365a3/difflib.go#L145-L151 |
142,220 | aryann/difflib | difflib.go | longestCommonSubsequenceMatrix | func longestCommonSubsequenceMatrix(seq1, seq2 []string) [][]int {
matrix := intMatrix(len(seq1)+1, len(seq2)+1)
for i := 1; i < len(matrix); i++ {
for j := 1; j < len(matrix[i]); j++ {
if seq1[len(seq1)-i] == seq2[len(seq2)-j] {
matrix[i][j] = matrix[i-1][j-1] + 1
} else {
matrix[i][j] = int(math.Max... | go | func longestCommonSubsequenceMatrix(seq1, seq2 []string) [][]int {
matrix := intMatrix(len(seq1)+1, len(seq2)+1)
for i := 1; i < len(matrix); i++ {
for j := 1; j < len(matrix[i]); j++ {
if seq1[len(seq1)-i] == seq2[len(seq2)-j] {
matrix[i][j] = matrix[i-1][j-1] + 1
} else {
matrix[i][j] = int(math.Max... | [
"func",
"longestCommonSubsequenceMatrix",
"(",
"seq1",
",",
"seq2",
"[",
"]",
"string",
")",
"[",
"]",
"[",
"]",
"int",
"{",
"matrix",
":=",
"intMatrix",
"(",
"len",
"(",
"seq1",
")",
"+",
"1",
",",
"len",
"(",
"seq2",
")",
"+",
"1",
")",
"\n",
"... | // longestCommonSubsequenceMatrix returns the table that results from
// applying the dynamic programming approach for finding the longest
// common subsequence of seq1 and seq2. | [
"longestCommonSubsequenceMatrix",
"returns",
"the",
"table",
"that",
"results",
"from",
"applying",
"the",
"dynamic",
"programming",
"approach",
"for",
"finding",
"the",
"longest",
"common",
"subsequence",
"of",
"seq1",
"and",
"seq2",
"."
] | e206f873d14a916d3d26c40ab667bca123f365a3 | https://github.com/aryann/difflib/blob/e206f873d14a916d3d26c40ab667bca123f365a3/difflib.go#L156-L169 |
142,221 | aryann/difflib | difflib.go | compute | func compute(seq1, seq2 []string) (diff []DiffRecord) {
matrix := longestCommonSubsequenceMatrix(seq1, seq2)
i, j := len(seq1), len(seq2)
for i > 0 || j > 0 {
if i > 0 && matrix[i][j] == matrix[i-1][j] {
diff = append(diff, DiffRecord{seq1[len(seq1)-i], LeftOnly})
i--
} else if j > 0 && matrix[i][j] == mat... | go | func compute(seq1, seq2 []string) (diff []DiffRecord) {
matrix := longestCommonSubsequenceMatrix(seq1, seq2)
i, j := len(seq1), len(seq2)
for i > 0 || j > 0 {
if i > 0 && matrix[i][j] == matrix[i-1][j] {
diff = append(diff, DiffRecord{seq1[len(seq1)-i], LeftOnly})
i--
} else if j > 0 && matrix[i][j] == mat... | [
"func",
"compute",
"(",
"seq1",
",",
"seq2",
"[",
"]",
"string",
")",
"(",
"diff",
"[",
"]",
"DiffRecord",
")",
"{",
"matrix",
":=",
"longestCommonSubsequenceMatrix",
"(",
"seq1",
",",
"seq2",
")",
"\n",
"i",
",",
"j",
":=",
"len",
"(",
"seq1",
")",
... | // compute is the unexported helper for Diff that returns the results of
// diffing left and right. | [
"compute",
"is",
"the",
"unexported",
"helper",
"for",
"Diff",
"that",
"returns",
"the",
"results",
"of",
"diffing",
"left",
"and",
"right",
"."
] | e206f873d14a916d3d26c40ab667bca123f365a3 | https://github.com/aryann/difflib/blob/e206f873d14a916d3d26c40ab667bca123f365a3/difflib.go#L173-L190 |
142,222 | aryann/difflib | difflib_server/difflib_demo.go | diffHandler | func diffHandler(filename1, filename2 string) http.HandlerFunc {
diff := difflib.HTMLDiff(fileToLines(filename1), fileToLines(filename2))
tmpl, _ := template.New("diffTemplate").Parse(templateString)
return func(w http.ResponseWriter, r *http.Request) {
err := tmpl.Execute(w, map[string]interface{}{
"Diff": ... | go | func diffHandler(filename1, filename2 string) http.HandlerFunc {
diff := difflib.HTMLDiff(fileToLines(filename1), fileToLines(filename2))
tmpl, _ := template.New("diffTemplate").Parse(templateString)
return func(w http.ResponseWriter, r *http.Request) {
err := tmpl.Execute(w, map[string]interface{}{
"Diff": ... | [
"func",
"diffHandler",
"(",
"filename1",
",",
"filename2",
"string",
")",
"http",
".",
"HandlerFunc",
"{",
"diff",
":=",
"difflib",
".",
"HTMLDiff",
"(",
"fileToLines",
"(",
"filename1",
")",
",",
"fileToLines",
"(",
"filename2",
")",
")",
"\n",
"tmpl",
",... | // diffHandler returns an http.HandlerFunc that serves the diff of the
// two given files. | [
"diffHandler",
"returns",
"an",
"http",
".",
"HandlerFunc",
"that",
"serves",
"the",
"diff",
"of",
"the",
"two",
"given",
"files",
"."
] | e206f873d14a916d3d26c40ab667bca123f365a3 | https://github.com/aryann/difflib/blob/e206f873d14a916d3d26c40ab667bca123f365a3/difflib_server/difflib_demo.go#L91-L104 |
142,223 | aryann/difflib | difflib_server/difflib_demo.go | fileToLines | func fileToLines(filename string) []string {
contents, _ := ioutil.ReadFile(filename)
return strings.Split(html.EscapeString(string(contents)), "\n")
} | go | func fileToLines(filename string) []string {
contents, _ := ioutil.ReadFile(filename)
return strings.Split(html.EscapeString(string(contents)), "\n")
} | [
"func",
"fileToLines",
"(",
"filename",
"string",
")",
"[",
"]",
"string",
"{",
"contents",
",",
"_",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"return",
"strings",
".",
"Split",
"(",
"html",
".",
"EscapeString",
"(",
"string",
"(",
... | // filesToLines takes a path to a file and returns a string array of
// the lines in the file. Any HTML in the file is escaped. | [
"filesToLines",
"takes",
"a",
"path",
"to",
"a",
"file",
"and",
"returns",
"a",
"string",
"array",
"of",
"the",
"lines",
"in",
"the",
"file",
".",
"Any",
"HTML",
"in",
"the",
"file",
"is",
"escaped",
"."
] | e206f873d14a916d3d26c40ab667bca123f365a3 | https://github.com/aryann/difflib/blob/e206f873d14a916d3d26c40ab667bca123f365a3/difflib_server/difflib_demo.go#L108-L111 |
142,224 | sclevine/spec | spec.go | Pend | func (g G) Pend(text string, f func(), _ ...Option) {
g(text, f, func(c *config) { c.pend = true })
} | go | func (g G) Pend(text string, f func(), _ ...Option) {
g(text, f, func(c *config) { c.pend = true })
} | [
"func",
"(",
"g",
"G",
")",
"Pend",
"(",
"text",
"string",
",",
"f",
"func",
"(",
")",
",",
"_",
"...",
"Option",
")",
"{",
"g",
"(",
"text",
",",
"f",
",",
"func",
"(",
"c",
"*",
"config",
")",
"{",
"c",
".",
"pend",
"=",
"true",
"}",
")... | // Pend skips all specs in the provided group.
//
// All Options are ignored. | [
"Pend",
"skips",
"all",
"specs",
"in",
"the",
"provided",
"group",
".",
"All",
"Options",
"are",
"ignored",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L21-L23 |
142,225 | sclevine/spec | spec.go | Before | func (s S) Before(f func()) {
s("", f, func(c *config) { c.before = true })
} | go | func (s S) Before(f func()) {
s("", f, func(c *config) { c.before = true })
} | [
"func",
"(",
"s",
"S",
")",
"Before",
"(",
"f",
"func",
"(",
")",
")",
"{",
"s",
"(",
"\"",
"\"",
",",
"f",
",",
"func",
"(",
"c",
"*",
"config",
")",
"{",
"c",
".",
"before",
"=",
"true",
"}",
")",
"\n",
"}"
] | // Before runs a function before each spec in the group. | [
"Before",
"runs",
"a",
"function",
"before",
"each",
"spec",
"in",
"the",
"group",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L41-L43 |
142,226 | sclevine/spec | spec.go | After | func (s S) After(f func()) {
s("", f, func(c *config) { c.after = true })
} | go | func (s S) After(f func()) {
s("", f, func(c *config) { c.after = true })
} | [
"func",
"(",
"s",
"S",
")",
"After",
"(",
"f",
"func",
"(",
")",
")",
"{",
"s",
"(",
"\"",
"\"",
",",
"f",
",",
"func",
"(",
"c",
"*",
"config",
")",
"{",
"c",
".",
"after",
"=",
"true",
"}",
")",
"\n",
"}"
] | // After runs a function after each spec in the group. | [
"After",
"runs",
"a",
"function",
"after",
"each",
"spec",
"in",
"the",
"group",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L46-L48 |
142,227 | sclevine/spec | spec.go | Pend | func (s S) Pend(text string, f func(), _ ...Option) {
s(text, f, func(c *config) { c.pend = true })
} | go | func (s S) Pend(text string, f func(), _ ...Option) {
s(text, f, func(c *config) { c.pend = true })
} | [
"func",
"(",
"s",
"S",
")",
"Pend",
"(",
"text",
"string",
",",
"f",
"func",
"(",
")",
",",
"_",
"...",
"Option",
")",
"{",
"s",
"(",
"text",
",",
"f",
",",
"func",
"(",
"c",
"*",
"config",
")",
"{",
"c",
".",
"pend",
"=",
"true",
"}",
")... | // Pend skips the provided spec.
//
// All Options are ignored. | [
"Pend",
"skips",
"the",
"provided",
"spec",
".",
"All",
"Options",
"are",
"ignored",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L53-L55 |
142,228 | sclevine/spec | spec.go | Before | func (s Suite) Before(f func(*testing.T)) bool {
return s("", func(t *testing.T, _ G, _ S) {
t.Helper()
f(t)
}, func(c *config) { c.before = true })
} | go | func (s Suite) Before(f func(*testing.T)) bool {
return s("", func(t *testing.T, _ G, _ S) {
t.Helper()
f(t)
}, func(c *config) { c.before = true })
} | [
"func",
"(",
"s",
"Suite",
")",
"Before",
"(",
"f",
"func",
"(",
"*",
"testing",
".",
"T",
")",
")",
"bool",
"{",
"return",
"s",
"(",
"\"",
"\"",
",",
"func",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"_",
"G",
",",
"_",
"S",
")",
"{",
"t"... | // Before runs a function before each spec in the suite. | [
"Before",
"runs",
"a",
"function",
"before",
"each",
"spec",
"in",
"the",
"suite",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L89-L94 |
142,229 | sclevine/spec | spec.go | After | func (s Suite) After(f func(*testing.T)) bool {
return s("", func(t *testing.T, _ G, _ S) {
t.Helper()
f(t)
}, func(c *config) { c.after = true })
} | go | func (s Suite) After(f func(*testing.T)) bool {
return s("", func(t *testing.T, _ G, _ S) {
t.Helper()
f(t)
}, func(c *config) { c.after = true })
} | [
"func",
"(",
"s",
"Suite",
")",
"After",
"(",
"f",
"func",
"(",
"*",
"testing",
".",
"T",
")",
")",
"bool",
"{",
"return",
"s",
"(",
"\"",
"\"",
",",
"func",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"_",
"G",
",",
"_",
"S",
")",
"{",
"t",... | // After runs a function after each spec in the suite. | [
"After",
"runs",
"a",
"function",
"after",
"each",
"spec",
"in",
"the",
"suite",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L97-L102 |
142,230 | sclevine/spec | spec.go | Pend | func (s Suite) Pend(text string, f func(*testing.T, G, S), _ ...Option) bool {
return s(text, f, func(c *config) { c.pend = true })
} | go | func (s Suite) Pend(text string, f func(*testing.T, G, S), _ ...Option) bool {
return s(text, f, func(c *config) { c.pend = true })
} | [
"func",
"(",
"s",
"Suite",
")",
"Pend",
"(",
"text",
"string",
",",
"f",
"func",
"(",
"*",
"testing",
".",
"T",
",",
"G",
",",
"S",
")",
",",
"_",
"...",
"Option",
")",
"bool",
"{",
"return",
"s",
"(",
"text",
",",
"f",
",",
"func",
"(",
"c... | // Pend skips the provided top-level group of specs.
//
// All Options are ignored. | [
"Pend",
"skips",
"the",
"provided",
"top",
"-",
"level",
"group",
"of",
"specs",
".",
"All",
"Options",
"are",
"ignored",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L107-L109 |
142,231 | sclevine/spec | spec.go | Run | func (s Suite) Run(t *testing.T) bool {
t.Helper()
return s("", nil, func(c *config) { c.t = t })
} | go | func (s Suite) Run(t *testing.T) bool {
t.Helper()
return s("", nil, func(c *config) { c.t = t })
} | [
"func",
"(",
"s",
"Suite",
")",
"Run",
"(",
"t",
"*",
"testing",
".",
"T",
")",
"bool",
"{",
"t",
".",
"Helper",
"(",
")",
"\n",
"return",
"s",
"(",
"\"",
"\"",
",",
"nil",
",",
"func",
"(",
"c",
"*",
"config",
")",
"{",
"c",
".",
"t",
"=... | // Run executes the specs defined in each top-level group of the suite. | [
"Run",
"executes",
"the",
"specs",
"defined",
"in",
"each",
"top",
"-",
"level",
"group",
"of",
"the",
"suite",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L122-L125 |
142,232 | sclevine/spec | spec.go | Pend | func Pend(t *testing.T, text string, f func(*testing.T, G, S), _ ...Option) bool {
t.Helper()
return Run(t, text, f, func(c *config) { c.pend = true })
} | go | func Pend(t *testing.T, text string, f func(*testing.T, G, S), _ ...Option) bool {
t.Helper()
return Run(t, text, f, func(c *config) { c.pend = true })
} | [
"func",
"Pend",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"text",
"string",
",",
"f",
"func",
"(",
"*",
"testing",
".",
"T",
",",
"G",
",",
"S",
")",
",",
"_",
"...",
"Option",
")",
"bool",
"{",
"t",
".",
"Helper",
"(",
")",
"\n",
"return",
... | // Pend skips all specs in the top-level group.
//
// All Options are ignored. | [
"Pend",
"skips",
"all",
"specs",
"in",
"the",
"top",
"-",
"level",
"group",
".",
"All",
"Options",
"are",
"ignored",
"."
] | b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4 | https://github.com/sclevine/spec/blob/b518b20aa1af75d314a31c9b3acfeeab7c4cbfb4/spec.go#L283-L286 |
142,233 | nbio/st | st.go | Expect | func Expect(t Errorf, have, want interface{}, iter ...int) {
if !reflect.DeepEqual(have, want) {
file, line := caller()
t.Errorf(equal, file, line, exampleNum(iter), have, have, want, want)
}
} | go | func Expect(t Errorf, have, want interface{}, iter ...int) {
if !reflect.DeepEqual(have, want) {
file, line := caller()
t.Errorf(equal, file, line, exampleNum(iter), have, have, want, want)
}
} | [
"func",
"Expect",
"(",
"t",
"Errorf",
",",
"have",
",",
"want",
"interface",
"{",
"}",
",",
"iter",
"...",
"int",
")",
"{",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"have",
",",
"want",
")",
"{",
"file",
",",
"line",
":=",
"caller",
"(",
")",... | // Expect calls t.Error and prints a nice comparison message when have != want.
// Especially useful in table-based tests when passing the loop index as iter. | [
"Expect",
"calls",
"t",
".",
"Error",
"and",
"prints",
"a",
"nice",
"comparison",
"message",
"when",
"have",
"!",
"=",
"want",
".",
"Especially",
"useful",
"in",
"table",
"-",
"based",
"tests",
"when",
"passing",
"the",
"loop",
"index",
"as",
"iter",
"."... | e9e8d9816f3268def6dcbd2dea03301f40e9de94 | https://github.com/nbio/st/blob/e9e8d9816f3268def6dcbd2dea03301f40e9de94/st.go#L38-L43 |
142,234 | nbio/st | st.go | Reject | func Reject(t Errorf, have, want interface{}, iter ...int) {
if reflect.DeepEqual(have, want) {
file, line := caller()
t.Errorf(unequal, file, line, exampleNum(iter), have, have, want, want)
}
} | go | func Reject(t Errorf, have, want interface{}, iter ...int) {
if reflect.DeepEqual(have, want) {
file, line := caller()
t.Errorf(unequal, file, line, exampleNum(iter), have, have, want, want)
}
} | [
"func",
"Reject",
"(",
"t",
"Errorf",
",",
"have",
",",
"want",
"interface",
"{",
"}",
",",
"iter",
"...",
"int",
")",
"{",
"if",
"reflect",
".",
"DeepEqual",
"(",
"have",
",",
"want",
")",
"{",
"file",
",",
"line",
":=",
"caller",
"(",
")",
"\n"... | // Reject calls t.Error and prints a nice comparison message when have == want.
// Especially useful in table-based tests when passing the loop index as iter. | [
"Reject",
"calls",
"t",
".",
"Error",
"and",
"prints",
"a",
"nice",
"comparison",
"message",
"when",
"have",
"==",
"want",
".",
"Especially",
"useful",
"in",
"table",
"-",
"based",
"tests",
"when",
"passing",
"the",
"loop",
"index",
"as",
"iter",
"."
] | e9e8d9816f3268def6dcbd2dea03301f40e9de94 | https://github.com/nbio/st/blob/e9e8d9816f3268def6dcbd2dea03301f40e9de94/st.go#L47-L52 |
142,235 | nbio/st | st.go | Assert | func Assert(t Fatalf, have, want interface{}) {
if !reflect.DeepEqual(have, want) {
file, line := caller()
t.Fatalf(equal, file, line, "", have, have, want, want)
}
} | go | func Assert(t Fatalf, have, want interface{}) {
if !reflect.DeepEqual(have, want) {
file, line := caller()
t.Fatalf(equal, file, line, "", have, have, want, want)
}
} | [
"func",
"Assert",
"(",
"t",
"Fatalf",
",",
"have",
",",
"want",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"have",
",",
"want",
")",
"{",
"file",
",",
"line",
":=",
"caller",
"(",
")",
"\n",
"t",
".",
"Fatalf",
... | // Assert calls t.Fatal to abort the test immediately and prints a nice
// comparison message when have != want. | [
"Assert",
"calls",
"t",
".",
"Fatal",
"to",
"abort",
"the",
"test",
"immediately",
"and",
"prints",
"a",
"nice",
"comparison",
"message",
"when",
"have",
"!",
"=",
"want",
"."
] | e9e8d9816f3268def6dcbd2dea03301f40e9de94 | https://github.com/nbio/st/blob/e9e8d9816f3268def6dcbd2dea03301f40e9de94/st.go#L56-L61 |
142,236 | nbio/st | st.go | Refute | func Refute(t Fatalf, have, want interface{}) {
if reflect.DeepEqual(have, want) {
file, line := caller()
t.Fatalf(unequal, file, line, "", have, have, want, want)
}
} | go | func Refute(t Fatalf, have, want interface{}) {
if reflect.DeepEqual(have, want) {
file, line := caller()
t.Fatalf(unequal, file, line, "", have, have, want, want)
}
} | [
"func",
"Refute",
"(",
"t",
"Fatalf",
",",
"have",
",",
"want",
"interface",
"{",
"}",
")",
"{",
"if",
"reflect",
".",
"DeepEqual",
"(",
"have",
",",
"want",
")",
"{",
"file",
",",
"line",
":=",
"caller",
"(",
")",
"\n",
"t",
".",
"Fatalf",
"(",
... | // Refute calls t.Fatal to abort the test immediately and prints a nice
// comparison message when have != want. | [
"Refute",
"calls",
"t",
".",
"Fatal",
"to",
"abort",
"the",
"test",
"immediately",
"and",
"prints",
"a",
"nice",
"comparison",
"message",
"when",
"have",
"!",
"=",
"want",
"."
] | e9e8d9816f3268def6dcbd2dea03301f40e9de94 | https://github.com/nbio/st/blob/e9e8d9816f3268def6dcbd2dea03301f40e9de94/st.go#L65-L70 |
142,237 | nbio/st | st.go | caller | func caller() (file string, line int) {
var ok bool
_, file, line, ok = runtime.Caller(2)
if !ok {
file = "???"
line = 1
} else {
slash := strings.LastIndex(file, "/")
if slash >= 0 {
file = file[slash+1:]
}
}
return
} | go | func caller() (file string, line int) {
var ok bool
_, file, line, ok = runtime.Caller(2)
if !ok {
file = "???"
line = 1
} else {
slash := strings.LastIndex(file, "/")
if slash >= 0 {
file = file[slash+1:]
}
}
return
} | [
"func",
"caller",
"(",
")",
"(",
"file",
"string",
",",
"line",
"int",
")",
"{",
"var",
"ok",
"bool",
"\n",
"_",
",",
"file",
",",
"line",
",",
"ok",
"=",
"runtime",
".",
"Caller",
"(",
"2",
")",
"\n",
"if",
"!",
"ok",
"{",
"file",
"=",
"\"",... | // returns file and line two stack frames above its invocation | [
"returns",
"file",
"and",
"line",
"two",
"stack",
"frames",
"above",
"its",
"invocation"
] | e9e8d9816f3268def6dcbd2dea03301f40e9de94 | https://github.com/nbio/st/blob/e9e8d9816f3268def6dcbd2dea03301f40e9de94/st.go#L73-L86 |
142,238 | stvp/go-udp-testing | udp.go | ShouldReceiveOnly | func ShouldReceiveOnly(t *testing.T, expected string, body fn) {
got, equals, _ := get(t, expected, body)
if !equals {
printLocation(t)
t.Errorf("Expected: %#v", expected)
t.Errorf("But got: %#v", got)
}
} | go | func ShouldReceiveOnly(t *testing.T, expected string, body fn) {
got, equals, _ := get(t, expected, body)
if !equals {
printLocation(t)
t.Errorf("Expected: %#v", expected)
t.Errorf("But got: %#v", got)
}
} | [
"func",
"ShouldReceiveOnly",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"expected",
"string",
",",
"body",
"fn",
")",
"{",
"got",
",",
"equals",
",",
"_",
":=",
"get",
"(",
"t",
",",
"expected",
",",
"body",
")",
"\n",
"if",
"!",
"equals",
"{",
"pr... | // ShouldReceiveOnly will fire a test error if the given function doesn't send
// exactly the given string over UDP. | [
"ShouldReceiveOnly",
"will",
"fire",
"a",
"test",
"error",
"if",
"the",
"given",
"function",
"doesn",
"t",
"send",
"exactly",
"the",
"given",
"string",
"over",
"UDP",
"."
] | c4434f09ec131ecf30f986d5dcb1636508bfa49a | https://github.com/stvp/go-udp-testing/blob/c4434f09ec131ecf30f986d5dcb1636508bfa49a/udp.go#L78-L85 |
142,239 | stvp/go-udp-testing | udp.go | ShouldNotReceiveOnly | func ShouldNotReceiveOnly(t *testing.T, notExpected string, body fn) {
_, equals, _ := get(t, notExpected, body)
if equals {
printLocation(t)
t.Errorf("Expected not to get: %#v", notExpected)
}
} | go | func ShouldNotReceiveOnly(t *testing.T, notExpected string, body fn) {
_, equals, _ := get(t, notExpected, body)
if equals {
printLocation(t)
t.Errorf("Expected not to get: %#v", notExpected)
}
} | [
"func",
"ShouldNotReceiveOnly",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"notExpected",
"string",
",",
"body",
"fn",
")",
"{",
"_",
",",
"equals",
",",
"_",
":=",
"get",
"(",
"t",
",",
"notExpected",
",",
"body",
")",
"\n",
"if",
"equals",
"{",
"pr... | // ShouldNotReceiveOnly will fire a test error if the given function sends
// exactly the given string over UDP. | [
"ShouldNotReceiveOnly",
"will",
"fire",
"a",
"test",
"error",
"if",
"the",
"given",
"function",
"sends",
"exactly",
"the",
"given",
"string",
"over",
"UDP",
"."
] | c4434f09ec131ecf30f986d5dcb1636508bfa49a | https://github.com/stvp/go-udp-testing/blob/c4434f09ec131ecf30f986d5dcb1636508bfa49a/udp.go#L89-L95 |
142,240 | stvp/go-udp-testing | udp.go | ShouldReceive | func ShouldReceive(t *testing.T, expected string, body fn) {
got, _, contains := get(t, expected, body)
if !contains {
printLocation(t)
t.Errorf("Expected to find: %#v", expected)
t.Errorf("But got: %#v", got)
}
} | go | func ShouldReceive(t *testing.T, expected string, body fn) {
got, _, contains := get(t, expected, body)
if !contains {
printLocation(t)
t.Errorf("Expected to find: %#v", expected)
t.Errorf("But got: %#v", got)
}
} | [
"func",
"ShouldReceive",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"expected",
"string",
",",
"body",
"fn",
")",
"{",
"got",
",",
"_",
",",
"contains",
":=",
"get",
"(",
"t",
",",
"expected",
",",
"body",
")",
"\n",
"if",
"!",
"contains",
"{",
"pr... | // ShouldReceive will fire a test error if the given function doesn't send the
// given string over UDP. | [
"ShouldReceive",
"will",
"fire",
"a",
"test",
"error",
"if",
"the",
"given",
"function",
"doesn",
"t",
"send",
"the",
"given",
"string",
"over",
"UDP",
"."
] | c4434f09ec131ecf30f986d5dcb1636508bfa49a | https://github.com/stvp/go-udp-testing/blob/c4434f09ec131ecf30f986d5dcb1636508bfa49a/udp.go#L99-L106 |
142,241 | stvp/go-udp-testing | udp.go | ShouldReceiveAll | func ShouldReceiveAll(t *testing.T, expected []string, body fn) {
got := getMessage(t, body)
failed := false
for _, str := range expected {
if !strings.Contains(got, str) {
if !failed {
printLocation(t)
failed = true
}
t.Errorf("Expected to find: %#v", str)
}
}
if failed {
t.Errorf("But go... | go | func ShouldReceiveAll(t *testing.T, expected []string, body fn) {
got := getMessage(t, body)
failed := false
for _, str := range expected {
if !strings.Contains(got, str) {
if !failed {
printLocation(t)
failed = true
}
t.Errorf("Expected to find: %#v", str)
}
}
if failed {
t.Errorf("But go... | [
"func",
"ShouldReceiveAll",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"expected",
"[",
"]",
"string",
",",
"body",
"fn",
")",
"{",
"got",
":=",
"getMessage",
"(",
"t",
",",
"body",
")",
"\n",
"failed",
":=",
"false",
"\n\n",
"for",
"_",
",",
"str",
... | // ShouldReceiveAll will fire a test error unless all of the given strings are
// sent over UDP. | [
"ShouldReceiveAll",
"will",
"fire",
"a",
"test",
"error",
"unless",
"all",
"of",
"the",
"given",
"strings",
"are",
"sent",
"over",
"UDP",
"."
] | c4434f09ec131ecf30f986d5dcb1636508bfa49a | https://github.com/stvp/go-udp-testing/blob/c4434f09ec131ecf30f986d5dcb1636508bfa49a/udp.go#L121-L138 |
142,242 | aclements/go-gg | ggstat/agg.go | AggCount | func AggCount(label string) Aggregator {
if label == "" {
label = "count"
}
return func(input table.Grouping, b *table.Builder) {
counts := make([]int, 0, len(input.Tables()))
for _, gid := range input.Tables() {
counts = append(counts, input.Table(gid).Len())
}
b.Add(label, counts)
}
} | go | func AggCount(label string) Aggregator {
if label == "" {
label = "count"
}
return func(input table.Grouping, b *table.Builder) {
counts := make([]int, 0, len(input.Tables()))
for _, gid := range input.Tables() {
counts = append(counts, input.Table(gid).Len())
}
b.Add(label, counts)
}
} | [
"func",
"AggCount",
"(",
"label",
"string",
")",
"Aggregator",
"{",
"if",
"label",
"==",
"\"",
"\"",
"{",
"label",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"func",
"(",
"input",
"table",
".",
"Grouping",
",",
"b",
"*",
"table",
".",
"Builder",
... | // AggCount returns an aggregate function that computes the number of
// rows in each group. The resulting column will be named label, or
// "count" if label is "". | [
"AggCount",
"returns",
"an",
"aggregate",
"function",
"that",
"computes",
"the",
"number",
"of",
"rows",
"in",
"each",
"group",
".",
"The",
"resulting",
"column",
"will",
"be",
"named",
"label",
"or",
"count",
"if",
"label",
"is",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/ggstat/agg.go#L146-L158 |
142,243 | aclements/go-gg | generic/slice/cycle.go | Repeat | func Repeat(v interface{}, length int) T {
if length < 0 {
length = 0
}
rv := reflect.ValueOf(v)
out := reflect.MakeSlice(reflect.SliceOf(rv.Type()), length, length)
for i := 0; i < length; i++ {
out.Index(i).Set(rv)
}
return out.Interface()
} | go | func Repeat(v interface{}, length int) T {
if length < 0 {
length = 0
}
rv := reflect.ValueOf(v)
out := reflect.MakeSlice(reflect.SliceOf(rv.Type()), length, length)
for i := 0; i < length; i++ {
out.Index(i).Set(rv)
}
return out.Interface()
} | [
"func",
"Repeat",
"(",
"v",
"interface",
"{",
"}",
",",
"length",
"int",
")",
"T",
"{",
"if",
"length",
"<",
"0",
"{",
"length",
"=",
"0",
"\n",
"}",
"\n",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"out",
":=",
"reflect",
".",... | // Repeat returns a slice consisting of length copies of v. | [
"Repeat",
"returns",
"a",
"slice",
"consisting",
"of",
"length",
"copies",
"of",
"v",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/slice/cycle.go#L35-L45 |
142,244 | aclements/go-gg | generic/slice/nub.go | Nub | func Nub(v T) T {
rv := reflectSlice(v)
indexes := make([]int, 0)
set := reflect.MakeMap(reflect.MapOf(rv.Type().Elem(), trueVal.Type()))
for i, l := 0, rv.Len(); i < l; i++ {
x := rv.Index(i)
if set.MapIndex(x).IsValid() {
continue
}
set.SetMapIndex(x, trueVal)
indexes = append(indexes, i)
}
return ... | go | func Nub(v T) T {
rv := reflectSlice(v)
indexes := make([]int, 0)
set := reflect.MakeMap(reflect.MapOf(rv.Type().Elem(), trueVal.Type()))
for i, l := 0, rv.Len(); i < l; i++ {
x := rv.Index(i)
if set.MapIndex(x).IsValid() {
continue
}
set.SetMapIndex(x, trueVal)
indexes = append(indexes, i)
}
return ... | [
"func",
"Nub",
"(",
"v",
"T",
")",
"T",
"{",
"rv",
":=",
"reflectSlice",
"(",
"v",
")",
"\n",
"indexes",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
")",
"\n",
"set",
":=",
"reflect",
".",
"MakeMap",
"(",
"reflect",
".",
"MapOf",
"(",
"rv",
... | // Nub returns v with duplicates removed. It keeps the first instance
// of each distinct value and preserves their order. | [
"Nub",
"returns",
"v",
"with",
"duplicates",
"removed",
".",
"It",
"keeps",
"the",
"first",
"instance",
"of",
"each",
"distinct",
"value",
"and",
"preserves",
"their",
"order",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/slice/nub.go#L13-L26 |
142,245 | aclements/go-gg | generic/slice/nub.go | NubAppend | func NubAppend(vs ...T) T {
if len(vs) == 0 {
return nil
}
rv := reflectSlice(vs[0])
set := reflect.MakeMap(reflect.MapOf(rv.Type().Elem(), trueVal.Type()))
out := reflect.MakeSlice(rv.Type(), 0, 0)
for _, v := range vs {
rv := reflectSlice(v)
for i, l := 0, rv.Len(); i < l; i++ {
x := rv.Index(i)
i... | go | func NubAppend(vs ...T) T {
if len(vs) == 0 {
return nil
}
rv := reflectSlice(vs[0])
set := reflect.MakeMap(reflect.MapOf(rv.Type().Elem(), trueVal.Type()))
out := reflect.MakeSlice(rv.Type(), 0, 0)
for _, v := range vs {
rv := reflectSlice(v)
for i, l := 0, rv.Len(); i < l; i++ {
x := rv.Index(i)
i... | [
"func",
"NubAppend",
"(",
"vs",
"...",
"T",
")",
"T",
"{",
"if",
"len",
"(",
"vs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"rv",
":=",
"reflectSlice",
"(",
"vs",
"[",
"0",
"]",
")",
"\n",
"set",
":=",
"reflect",
".",
"MakeMap",... | // NubAppend is equivalent to appending all of the slices in vs and
// then calling Nub on the result, but more efficient. | [
"NubAppend",
"is",
"equivalent",
"to",
"appending",
"all",
"of",
"the",
"slices",
"in",
"vs",
"and",
"then",
"calling",
"Nub",
"on",
"the",
"result",
"but",
"more",
"efficient",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/slice/nub.go#L30-L52 |
142,246 | aclements/go-gg | table/group.go | Ungroup | func Ungroup(g Grouping) Grouping {
groups := g.Tables()
if len(groups) == 0 || len(groups) == 1 && groups[0] == RootGroupID {
return g
}
var out GroupingBuilder
runGid := groups[0].Parent()
runTabs := []*Table{}
for _, gid := range groups {
if gid.Parent() != runGid {
// Flush the run.
out.Add(runGid... | go | func Ungroup(g Grouping) Grouping {
groups := g.Tables()
if len(groups) == 0 || len(groups) == 1 && groups[0] == RootGroupID {
return g
}
var out GroupingBuilder
runGid := groups[0].Parent()
runTabs := []*Table{}
for _, gid := range groups {
if gid.Parent() != runGid {
// Flush the run.
out.Add(runGid... | [
"func",
"Ungroup",
"(",
"g",
"Grouping",
")",
"Grouping",
"{",
"groups",
":=",
"g",
".",
"Tables",
"(",
")",
"\n",
"if",
"len",
"(",
"groups",
")",
"==",
"0",
"||",
"len",
"(",
"groups",
")",
"==",
"1",
"&&",
"groups",
"[",
"0",
"]",
"==",
"Roo... | // Ungroup concatenates adjacent Tables in g that share a group parent
// into a Table identified by the parent, undoing the effects of the
// most recent GroupBy operation. | [
"Ungroup",
"concatenates",
"adjacent",
"Tables",
"in",
"g",
"that",
"share",
"a",
"group",
"parent",
"into",
"a",
"Table",
"identified",
"by",
"the",
"parent",
"undoing",
"the",
"effects",
"of",
"the",
"most",
"recent",
"GroupBy",
"operation",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/group.go#L172-L195 |
142,247 | aclements/go-gg | table/group.go | Flatten | func Flatten(g Grouping) *Table {
groups := g.Tables()
switch len(groups) {
case 0:
return new(Table)
case 1:
return g.Table(groups[0])
}
tabs := make([]*Table, len(groups))
for i, gid := range groups {
tabs[i] = g.Table(gid)
}
return concatRows(tabs...)
} | go | func Flatten(g Grouping) *Table {
groups := g.Tables()
switch len(groups) {
case 0:
return new(Table)
case 1:
return g.Table(groups[0])
}
tabs := make([]*Table, len(groups))
for i, gid := range groups {
tabs[i] = g.Table(gid)
}
return concatRows(tabs...)
} | [
"func",
"Flatten",
"(",
"g",
"Grouping",
")",
"*",
"Table",
"{",
"groups",
":=",
"g",
".",
"Tables",
"(",
")",
"\n",
"switch",
"len",
"(",
"groups",
")",
"{",
"case",
"0",
":",
"return",
"new",
"(",
"Table",
")",
"\n\n",
"case",
"1",
":",
"return... | // Flatten concatenates all of the groups in g into a single Table.
// This is equivalent to repeatedly Ungrouping g. | [
"Flatten",
"concatenates",
"all",
"of",
"the",
"groups",
"in",
"g",
"into",
"a",
"single",
"Table",
".",
"This",
"is",
"equivalent",
"to",
"repeatedly",
"Ungrouping",
"g",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/group.go#L199-L215 |
142,248 | aclements/go-gg | table/group.go | concatRows | func concatRows(tabs ...*Table) *Table {
// TODO: Consider making this public. It would have to check
// the columns, and we would probably also want a concatCols.
switch len(tabs) {
case 0:
return new(Table)
case 1:
return tabs[0]
}
// Construct each column.
var out Builder
seqs := make([]slice.T, len(... | go | func concatRows(tabs ...*Table) *Table {
// TODO: Consider making this public. It would have to check
// the columns, and we would probably also want a concatCols.
switch len(tabs) {
case 0:
return new(Table)
case 1:
return tabs[0]
}
// Construct each column.
var out Builder
seqs := make([]slice.T, len(... | [
"func",
"concatRows",
"(",
"tabs",
"...",
"*",
"Table",
")",
"*",
"Table",
"{",
"// TODO: Consider making this public. It would have to check",
"// the columns, and we would probably also want a concatCols.",
"switch",
"len",
"(",
"tabs",
")",
"{",
"case",
"0",
":",
"retu... | // concatRows concatenates the rows of tabs into a single Table. All
// Tables in tabs must all have the same column set. | [
"concatRows",
"concatenates",
"the",
"rows",
"of",
"tabs",
"into",
"a",
"single",
"Table",
".",
"All",
"Tables",
"in",
"tabs",
"must",
"all",
"have",
"the",
"same",
"column",
"set",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/group.go#L219-L243 |
142,249 | aclements/go-gg | gg/render.go | wrapPath | func wrapPath(p string) string {
const width = 70
if len(p) <= width {
return p
}
// Chop up p until we get below the width limit.
parts := make([]string, 0, 16)
for len(p) > width {
// Find the last command or space before exceeding width.
lastCmd, lastSpace := 0, 0
for i, ch := range p {
if i >= widt... | go | func wrapPath(p string) string {
const width = 70
if len(p) <= width {
return p
}
// Chop up p until we get below the width limit.
parts := make([]string, 0, 16)
for len(p) > width {
// Find the last command or space before exceeding width.
lastCmd, lastSpace := 0, 0
for i, ch := range p {
if i >= widt... | [
"func",
"wrapPath",
"(",
"p",
"string",
")",
"string",
"{",
"const",
"width",
"=",
"70",
"\n",
"if",
"len",
"(",
"p",
")",
"<=",
"width",
"{",
"return",
"p",
"\n",
"}",
"\n",
"// Chop up p until we get below the width limit.",
"parts",
":=",
"make",
"(",
... | // wrapPath wraps path data p to avoid exceeding SVG's recommended
// line length limit of 255 characters. | [
"wrapPath",
"wraps",
"path",
"data",
"p",
"to",
"avoid",
"exceeding",
"SVG",
"s",
"recommended",
"line",
"length",
"limit",
"of",
"255",
"characters",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/render.go#L452-L486 |
142,250 | aclements/go-gg | gg/scale.go | instantiate | func (s *defaultScale) instantiate() {
if s.r != nil {
s.scale.Ranger(s.r)
s.r = nil
}
if s.formatter != nil {
s.scale.SetFormatter(s.formatter)
s.formatter = nil
}
} | go | func (s *defaultScale) instantiate() {
if s.r != nil {
s.scale.Ranger(s.r)
s.r = nil
}
if s.formatter != nil {
s.scale.SetFormatter(s.formatter)
s.formatter = nil
}
} | [
"func",
"(",
"s",
"*",
"defaultScale",
")",
"instantiate",
"(",
")",
"{",
"if",
"s",
".",
"r",
"!=",
"nil",
"{",
"s",
".",
"scale",
".",
"Ranger",
"(",
"s",
".",
"r",
")",
"\n",
"s",
".",
"r",
"=",
"nil",
"\n",
"}",
"\n",
"if",
"s",
".",
... | // instantiate applies the pre-instantiation state to the newly
// instantiated s.scale and clears the state in s. | [
"instantiate",
"applies",
"the",
"pre",
"-",
"instantiation",
"state",
"to",
"the",
"newly",
"instantiated",
"s",
".",
"scale",
"and",
"clears",
"the",
"state",
"in",
"s",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/scale.go#L269-L278 |
142,251 | aclements/go-gg | gg/scale.go | NewLinearScaler | func NewLinearScaler() ContinuousScaler {
// TODO: Control over base.
return &moremathScale{
min: math.NaN(),
max: math.NaN(),
dataMin: math.NaN(),
dataMax: math.NaN(),
}
} | go | func NewLinearScaler() ContinuousScaler {
// TODO: Control over base.
return &moremathScale{
min: math.NaN(),
max: math.NaN(),
dataMin: math.NaN(),
dataMax: math.NaN(),
}
} | [
"func",
"NewLinearScaler",
"(",
")",
"ContinuousScaler",
"{",
"// TODO: Control over base.",
"return",
"&",
"moremathScale",
"{",
"min",
":",
"math",
".",
"NaN",
"(",
")",
",",
"max",
":",
"math",
".",
"NaN",
"(",
")",
",",
"dataMin",
":",
"math",
".",
"... | // NewLinearScaler returns a continuous linear scale. The domain must
// be a VarCardinal.
//
// XXX If I return a Scaler, I can't have methods for setting fixed
// bounds and such. I don't really want to expose the whole type.
// Maybe a sub-interface for continuous Scalers? | [
"NewLinearScaler",
"returns",
"a",
"continuous",
"linear",
"scale",
".",
"The",
"domain",
"must",
"be",
"a",
"VarCardinal",
".",
"XXX",
"If",
"I",
"return",
"a",
"Scaler",
"I",
"can",
"t",
"have",
"methods",
"for",
"setting",
"fixed",
"bounds",
"and",
"suc... | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/scale.go#L424-L432 |
142,252 | aclements/go-gg | gg/layout.go | layoutPlotElts | func layoutPlotElts(elts []plotElt) layout.Element {
// Add padding elements to each subplot.
//
// TODO: Should there be padding between labels and the plot?
for _, elt := range elts {
elt, ok := elt.(*eltSubplot)
if !ok {
continue
}
x, y := elt.xPath[0], elt.yPath[0]
elts = append(elts,
newEltPadd... | go | func layoutPlotElts(elts []plotElt) layout.Element {
// Add padding elements to each subplot.
//
// TODO: Should there be padding between labels and the plot?
for _, elt := range elts {
elt, ok := elt.(*eltSubplot)
if !ok {
continue
}
x, y := elt.xPath[0], elt.yPath[0]
elts = append(elts,
newEltPadd... | [
"func",
"layoutPlotElts",
"(",
"elts",
"[",
"]",
"plotElt",
")",
"layout",
".",
"Element",
"{",
"// Add padding elements to each subplot.",
"//",
"// TODO: Should there be padding between labels and the plot?",
"for",
"_",
",",
"elt",
":=",
"range",
"elts",
"{",
"elt",
... | // layoutPlotElts returns a layout containing all of the elements in
// elts.
//
// layoutPlotElts flattens the X and Y paths of elts into simple
// coordinate indexes and constructs a layout.Grid. | [
"layoutPlotElts",
"returns",
"a",
"layout",
"containing",
"all",
"of",
"the",
"elements",
"in",
"elts",
".",
"layoutPlotElts",
"flattens",
"the",
"X",
"and",
"Y",
"paths",
"of",
"elts",
"into",
"simple",
"coordinate",
"indexes",
"and",
"constructs",
"a",
"layo... | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/layout.go#L609-L675 |
142,253 | aclements/go-gg | gg/plot.go | NewPlot | func NewPlot(data table.Grouping) *Plot {
p := &Plot{
env: &plotEnv{
data: data,
},
scales: make(map[string]scalerTree),
scaledData: make(map[scaledDataKey]*scaledData),
scaleSet: make(map[scaleKey]bool),
axisLabels: make(map[string]string),
autoAxisLabels: make(map[string][]stri... | go | func NewPlot(data table.Grouping) *Plot {
p := &Plot{
env: &plotEnv{
data: data,
},
scales: make(map[string]scalerTree),
scaledData: make(map[scaledDataKey]*scaledData),
scaleSet: make(map[scaleKey]bool),
axisLabels: make(map[string]string),
autoAxisLabels: make(map[string][]stri... | [
"func",
"NewPlot",
"(",
"data",
"table",
".",
"Grouping",
")",
"*",
"Plot",
"{",
"p",
":=",
"&",
"Plot",
"{",
"env",
":",
"&",
"plotEnv",
"{",
"data",
":",
"data",
",",
"}",
",",
"scales",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"scalerTree"... | // NewPlot returns a new Plot backed by data. It has no layers, one
// facet, and all scales are default. | [
"NewPlot",
"returns",
"a",
"new",
"Plot",
"backed",
"by",
"data",
".",
"It",
"has",
"no",
"layers",
"one",
"facet",
"and",
"all",
"scales",
"are",
"default",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L41-L53 |
142,254 | aclements/go-gg | gg/plot.go | SetData | func (p *Plot) SetData(data table.Grouping) *Plot {
p.env.data = data
return p
} | go | func (p *Plot) SetData(data table.Grouping) *Plot {
p.env.data = data
return p
} | [
"func",
"(",
"p",
"*",
"Plot",
")",
"SetData",
"(",
"data",
"table",
".",
"Grouping",
")",
"*",
"Plot",
"{",
"p",
".",
"env",
".",
"data",
"=",
"data",
"\n",
"return",
"p",
"\n",
"}"
] | // SetData sets p's current data table. The caller must not modify
// data in this table after this point. | [
"SetData",
"sets",
"p",
"s",
"current",
"data",
"table",
".",
"The",
"caller",
"must",
"not",
"modify",
"data",
"in",
"this",
"table",
"after",
"this",
"point",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L68-L71 |
142,255 | aclements/go-gg | gg/plot.go | SetScaleAt | func (p *Plot) SetScaleAt(aes string, s Scaler, gid table.GroupID) *Plot {
// TODO: Should aes be an enum so you can't mix up aesthetics
// and column names?
p.getScales(aes).bind(gid, s)
return p
} | go | func (p *Plot) SetScaleAt(aes string, s Scaler, gid table.GroupID) *Plot {
// TODO: Should aes be an enum so you can't mix up aesthetics
// and column names?
p.getScales(aes).bind(gid, s)
return p
} | [
"func",
"(",
"p",
"*",
"Plot",
")",
"SetScaleAt",
"(",
"aes",
"string",
",",
"s",
"Scaler",
",",
"gid",
"table",
".",
"GroupID",
")",
"*",
"Plot",
"{",
"// TODO: Should aes be an enum so you can't mix up aesthetics",
"// and column names?",
"p",
".",
"getScales",
... | // SetScaleAt binds a scale to the given visual aesthetic for all data
// in group gid or descendants of gid. SetScaleAt must be called
// before Add. | [
"SetScaleAt",
"binds",
"a",
"scale",
"to",
"the",
"given",
"visual",
"aesthetic",
"for",
"all",
"data",
"in",
"group",
"gid",
"or",
"descendants",
"of",
"gid",
".",
"SetScaleAt",
"must",
"be",
"called",
"before",
"Add",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L174-L179 |
142,256 | aclements/go-gg | gg/plot.go | GetScale | func (p *Plot) GetScale(aes string) Scaler {
return p.GetScaleAt(aes, table.RootGroupID)
} | go | func (p *Plot) GetScale(aes string) Scaler {
return p.GetScaleAt(aes, table.RootGroupID)
} | [
"func",
"(",
"p",
"*",
"Plot",
")",
"GetScale",
"(",
"aes",
"string",
")",
"Scaler",
"{",
"return",
"p",
".",
"GetScaleAt",
"(",
"aes",
",",
"table",
".",
"RootGroupID",
")",
"\n",
"}"
] | // GetScale returns the scale for the given visual aesthetic used for
// data in the root group. | [
"GetScale",
"returns",
"the",
"scale",
"for",
"the",
"given",
"visual",
"aesthetic",
"used",
"for",
"data",
"in",
"the",
"root",
"group",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L183-L185 |
142,257 | aclements/go-gg | gg/plot.go | GetScaleAt | func (p *Plot) GetScaleAt(aes string, gid table.GroupID) Scaler {
return p.getScales(aes).find(gid)
} | go | func (p *Plot) GetScaleAt(aes string, gid table.GroupID) Scaler {
return p.getScales(aes).find(gid)
} | [
"func",
"(",
"p",
"*",
"Plot",
")",
"GetScaleAt",
"(",
"aes",
"string",
",",
"gid",
"table",
".",
"GroupID",
")",
"Scaler",
"{",
"return",
"p",
".",
"getScales",
"(",
"aes",
")",
".",
"find",
"(",
"gid",
")",
"\n",
"}"
] | // GetScaleAt returns the scale for the given visual aesthetic used
// for data in group gid. | [
"GetScaleAt",
"returns",
"the",
"scale",
"for",
"the",
"given",
"visual",
"aesthetic",
"used",
"for",
"data",
"in",
"group",
"gid",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L189-L191 |
142,258 | aclements/go-gg | gg/plot.go | Save | func (p *Plot) Save() *Plot {
p.env = &plotEnv{
parent: p.env,
data: p.env.data,
}
return p
} | go | func (p *Plot) Save() *Plot {
p.env = &plotEnv{
parent: p.env,
data: p.env.data,
}
return p
} | [
"func",
"(",
"p",
"*",
"Plot",
")",
"Save",
"(",
")",
"*",
"Plot",
"{",
"p",
".",
"env",
"=",
"&",
"plotEnv",
"{",
"parent",
":",
"p",
".",
"env",
",",
"data",
":",
"p",
".",
"env",
".",
"data",
",",
"}",
"\n",
"return",
"p",
"\n",
"}"
] | // Save saves the current data table of p to a stack. | [
"Save",
"saves",
"the",
"current",
"data",
"table",
"of",
"p",
"to",
"a",
"stack",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L260-L266 |
142,259 | aclements/go-gg | gg/plot.go | Restore | func (p *Plot) Restore() *Plot {
if p.env.parent == nil {
panic("unbalanced Save/Restore")
}
p.env = p.env.parent
return p
} | go | func (p *Plot) Restore() *Plot {
if p.env.parent == nil {
panic("unbalanced Save/Restore")
}
p.env = p.env.parent
return p
} | [
"func",
"(",
"p",
"*",
"Plot",
")",
"Restore",
"(",
")",
"*",
"Plot",
"{",
"if",
"p",
".",
"env",
".",
"parent",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"p",
".",
"env",
"=",
"p",
".",
"env",
".",
"parent",
"\n",
... | // Restore restores the data table of p from the save stack. | [
"Restore",
"restores",
"the",
"data",
"table",
"of",
"p",
"from",
"the",
"save",
"stack",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L269-L275 |
142,260 | aclements/go-gg | gg/plot.go | Add | func (p *Plot) Add(plotters ...Plotter) *Plot {
for _, plotter := range plotters {
plotter.Apply(p)
}
return p
} | go | func (p *Plot) Add(plotters ...Plotter) *Plot {
for _, plotter := range plotters {
plotter.Apply(p)
}
return p
} | [
"func",
"(",
"p",
"*",
"Plot",
")",
"Add",
"(",
"plotters",
"...",
"Plotter",
")",
"*",
"Plot",
"{",
"for",
"_",
",",
"plotter",
":=",
"range",
"plotters",
"{",
"plotter",
".",
"Apply",
"(",
"p",
")",
"\n",
"}",
"\n",
"return",
"p",
"\n",
"}"
] | // Add applies each of plotters to Plot in order. | [
"Add",
"applies",
"each",
"of",
"plotters",
"to",
"Plot",
"in",
"order",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/plot.go#L283-L288 |
142,261 | aclements/go-gg | generic/slice/find.go | LastIndex | func LastIndex(s T, val interface{}) int {
rs := reflectSlice(s)
if vt := reflect.TypeOf(val); rs.Type().Elem() != vt {
// TODO: Better "<seq> is not a sequence of <val>".
panic(&generic.TypeError{rs.Type(), vt, "cannot find"})
}
for i := rs.Len() - 1; i >= 0; i-- {
if rs.Index(i).Interface() == val {
ret... | go | func LastIndex(s T, val interface{}) int {
rs := reflectSlice(s)
if vt := reflect.TypeOf(val); rs.Type().Elem() != vt {
// TODO: Better "<seq> is not a sequence of <val>".
panic(&generic.TypeError{rs.Type(), vt, "cannot find"})
}
for i := rs.Len() - 1; i >= 0; i-- {
if rs.Index(i).Interface() == val {
ret... | [
"func",
"LastIndex",
"(",
"s",
"T",
",",
"val",
"interface",
"{",
"}",
")",
"int",
"{",
"rs",
":=",
"reflectSlice",
"(",
"s",
")",
"\n",
"if",
"vt",
":=",
"reflect",
".",
"TypeOf",
"(",
"val",
")",
";",
"rs",
".",
"Type",
"(",
")",
".",
"Elem",... | // LastIndex returns the index of the last instance of val in s, or -1
// if val is not present in s. val's type must be s's element type. | [
"LastIndex",
"returns",
"the",
"index",
"of",
"the",
"last",
"instance",
"of",
"val",
"in",
"s",
"or",
"-",
"1",
"if",
"val",
"is",
"not",
"present",
"in",
"s",
".",
"val",
"s",
"type",
"must",
"be",
"s",
"s",
"element",
"type",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/slice/find.go#L32-L45 |
142,262 | aclements/go-gg | gg/mark.go | cssPaint | func cssPaint(prop string, c color.Color) string {
r, g, b, a := c.RGBA()
if a == 0 {
// No paint.
return prop + ":none"
}
if a != 0xffff {
// Undo alpha pre-multiplication.
r = r * 0xffff / a
g = g * 0xffff / a
b = b * 0xffff / a
}
r, g, b = r>>8, g>>8, b>>8
css := prop
if r>>4 == r&0xF && g>>4 =... | go | func cssPaint(prop string, c color.Color) string {
r, g, b, a := c.RGBA()
if a == 0 {
// No paint.
return prop + ":none"
}
if a != 0xffff {
// Undo alpha pre-multiplication.
r = r * 0xffff / a
g = g * 0xffff / a
b = b * 0xffff / a
}
r, g, b = r>>8, g>>8, b>>8
css := prop
if r>>4 == r&0xF && g>>4 =... | [
"func",
"cssPaint",
"(",
"prop",
"string",
",",
"c",
"color",
".",
"Color",
")",
"string",
"{",
"r",
",",
"g",
",",
"b",
",",
"a",
":=",
"c",
".",
"RGBA",
"(",
")",
"\n",
"if",
"a",
"==",
"0",
"{",
"// No paint.",
"return",
"prop",
"+",
"\"",
... | // cssPaint returns a CSS fragment for setting CSS property prop to
// color c. | [
"cssPaint",
"returns",
"a",
"CSS",
"fragment",
"for",
"setting",
"CSS",
"property",
"prop",
"to",
"color",
"c",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/gg/mark.go#L518-L549 |
142,263 | aclements/go-gg | table/filter.go | FilterEq | func FilterEq(g Grouping, col string, val interface{}) Grouping {
match := make([]int, 0)
return MapTables(g, func(_ GroupID, t *Table) *Table {
// Find the set of row indexes that match val.
seq := t.MustColumn(col)
match = match[:0]
rv := reflect.ValueOf(seq)
for i, len := 0, rv.Len(); i < len; i++ {
i... | go | func FilterEq(g Grouping, col string, val interface{}) Grouping {
match := make([]int, 0)
return MapTables(g, func(_ GroupID, t *Table) *Table {
// Find the set of row indexes that match val.
seq := t.MustColumn(col)
match = match[:0]
rv := reflect.ValueOf(seq)
for i, len := 0, rv.Len(); i < len; i++ {
i... | [
"func",
"FilterEq",
"(",
"g",
"Grouping",
",",
"col",
"string",
",",
"val",
"interface",
"{",
"}",
")",
"Grouping",
"{",
"match",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
")",
"\n",
"return",
"MapTables",
"(",
"g",
",",
"func",
"(",
"_",
"Gr... | // FilterEq filters g to only rows where the value in col equals val. | [
"FilterEq",
"filters",
"g",
"to",
"only",
"rows",
"where",
"the",
"value",
"in",
"col",
"equals",
"val",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/filter.go#L75-L94 |
142,264 | aclements/go-gg | ggstat/fn.go | preserveConsts | func preserveConsts(nt *table.Builder, t *table.Table) {
for _, col := range t.Columns() {
if nt.Has(col) {
// Don't overwrite existing columns in nt.
continue
}
if cv, ok := t.Const(col); ok {
nt.AddConst(col, cv)
}
}
} | go | func preserveConsts(nt *table.Builder, t *table.Table) {
for _, col := range t.Columns() {
if nt.Has(col) {
// Don't overwrite existing columns in nt.
continue
}
if cv, ok := t.Const(col); ok {
nt.AddConst(col, cv)
}
}
} | [
"func",
"preserveConsts",
"(",
"nt",
"*",
"table",
".",
"Builder",
",",
"t",
"*",
"table",
".",
"Table",
")",
"{",
"for",
"_",
",",
"col",
":=",
"range",
"t",
".",
"Columns",
"(",
")",
"{",
"if",
"nt",
".",
"Has",
"(",
"col",
")",
"{",
"// Don'... | // preserveConsts copies the constant columns from t into nt. | [
"preserveConsts",
"copies",
"the",
"constant",
"columns",
"from",
"t",
"into",
"nt",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/ggstat/fn.go#L113-L123 |
142,265 | aclements/go-gg | generic/slice/min.go | Min | func Min(v T) interface{} {
x, _ := minmax(v, -1, true)
return x.Interface()
} | go | func Min(v T) interface{} {
x, _ := minmax(v, -1, true)
return x.Interface()
} | [
"func",
"Min",
"(",
"v",
"T",
")",
"interface",
"{",
"}",
"{",
"x",
",",
"_",
":=",
"minmax",
"(",
"v",
",",
"-",
"1",
",",
"true",
")",
"\n",
"return",
"x",
".",
"Interface",
"(",
")",
"\n",
"}"
] | // Min returns the minimum value in v. v must either implement
// sort.Interface or its elements must be orderable. Min panics if v
// is empty. | [
"Min",
"returns",
"the",
"minimum",
"value",
"in",
"v",
".",
"v",
"must",
"either",
"implement",
"sort",
".",
"Interface",
"or",
"its",
"elements",
"must",
"be",
"orderable",
".",
"Min",
"panics",
"if",
"v",
"is",
"empty",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/slice/min.go#L17-L20 |
142,266 | aclements/go-gg | generic/slice/min.go | Max | func Max(v T) interface{} {
x, _ := minmax(v, 1, true)
return x.Interface()
} | go | func Max(v T) interface{} {
x, _ := minmax(v, 1, true)
return x.Interface()
} | [
"func",
"Max",
"(",
"v",
"T",
")",
"interface",
"{",
"}",
"{",
"x",
",",
"_",
":=",
"minmax",
"(",
"v",
",",
"1",
",",
"true",
")",
"\n",
"return",
"x",
".",
"Interface",
"(",
")",
"\n",
"}"
] | // Max returns the maximum value in v. v must either implement
// sort.Interface or its elements must be orderable. Max panics if v
// is empty. | [
"Max",
"returns",
"the",
"maximum",
"value",
"in",
"v",
".",
"v",
"must",
"either",
"implement",
"sort",
".",
"Interface",
"or",
"its",
"elements",
"must",
"be",
"orderable",
".",
"Max",
"panics",
"if",
"v",
"is",
"empty",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/slice/min.go#L34-L37 |
142,267 | aclements/go-gg | generic/slice/sort.go | CanSort | func CanSort(v interface{}) bool {
switch v.(type) {
case sort.Interface, []time.Time:
return true
}
return generic.CanOrderR(reflect.TypeOf(v).Elem().Kind())
} | go | func CanSort(v interface{}) bool {
switch v.(type) {
case sort.Interface, []time.Time:
return true
}
return generic.CanOrderR(reflect.TypeOf(v).Elem().Kind())
} | [
"func",
"CanSort",
"(",
"v",
"interface",
"{",
"}",
")",
"bool",
"{",
"switch",
"v",
".",
"(",
"type",
")",
"{",
"case",
"sort",
".",
"Interface",
",",
"[",
"]",
"time",
".",
"Time",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"generic",
".... | // CanSort returns whether the value v can be sorted. | [
"CanSort",
"returns",
"whether",
"the",
"value",
"v",
"can",
"be",
"sorted",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/slice/sort.go#L16-L22 |
142,268 | aclements/go-gg | table/head.go | Head | func Head(g Grouping, n int) Grouping {
return headTail(g, n, false)
} | go | func Head(g Grouping, n int) Grouping {
return headTail(g, n, false)
} | [
"func",
"Head",
"(",
"g",
"Grouping",
",",
"n",
"int",
")",
"Grouping",
"{",
"return",
"headTail",
"(",
"g",
",",
"n",
",",
"false",
")",
"\n",
"}"
] | // Head returns the first n rows in each Table of g. | [
"Head",
"returns",
"the",
"first",
"n",
"rows",
"in",
"each",
"Table",
"of",
"g",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/head.go#L10-L12 |
142,269 | aclements/go-gg | table/head.go | Tail | func Tail(g Grouping, n int) Grouping {
return headTail(g, n, true)
} | go | func Tail(g Grouping, n int) Grouping {
return headTail(g, n, true)
} | [
"func",
"Tail",
"(",
"g",
"Grouping",
",",
"n",
"int",
")",
"Grouping",
"{",
"return",
"headTail",
"(",
"g",
",",
"n",
",",
"true",
")",
"\n",
"}"
] | // Tail returns the last n rows in each Table of g. | [
"Tail",
"returns",
"the",
"last",
"n",
"rows",
"in",
"each",
"Table",
"of",
"g",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/head.go#L15-L17 |
142,270 | aclements/go-gg | table/head.go | HeadTables | func HeadTables(g Grouping, n int) Grouping {
return headTailTables(g, n, false)
} | go | func HeadTables(g Grouping, n int) Grouping {
return headTailTables(g, n, false)
} | [
"func",
"HeadTables",
"(",
"g",
"Grouping",
",",
"n",
"int",
")",
"Grouping",
"{",
"return",
"headTailTables",
"(",
"g",
",",
"n",
",",
"false",
")",
"\n",
"}"
] | // HeadTables returns the first n tables in g. | [
"HeadTables",
"returns",
"the",
"first",
"n",
"tables",
"in",
"g",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/head.go#L45-L47 |
142,271 | aclements/go-gg | table/head.go | TailTables | func TailTables(g Grouping, n int) Grouping {
return headTailTables(g, n, true)
} | go | func TailTables(g Grouping, n int) Grouping {
return headTailTables(g, n, true)
} | [
"func",
"TailTables",
"(",
"g",
"Grouping",
",",
"n",
"int",
")",
"Grouping",
"{",
"return",
"headTailTables",
"(",
"g",
",",
"n",
",",
"true",
")",
"\n",
"}"
] | // TailTables returns the first n tables in g. | [
"TailTables",
"returns",
"the",
"first",
"n",
"tables",
"in",
"g",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/head.go#L50-L52 |
142,272 | aclements/go-gg | generic/order.go | CanOrder | func CanOrder(a, b interface{}) bool {
ak, bk := reflect.ValueOf(a).Kind(), reflect.ValueOf(b).Kind()
if ak != bk {
return false
}
return CanOrderR(ak)
} | go | func CanOrder(a, b interface{}) bool {
ak, bk := reflect.ValueOf(a).Kind(), reflect.ValueOf(b).Kind()
if ak != bk {
return false
}
return CanOrderR(ak)
} | [
"func",
"CanOrder",
"(",
"a",
",",
"b",
"interface",
"{",
"}",
")",
"bool",
"{",
"ak",
",",
"bk",
":=",
"reflect",
".",
"ValueOf",
"(",
"a",
")",
".",
"Kind",
"(",
")",
",",
"reflect",
".",
"ValueOf",
"(",
"b",
")",
".",
"Kind",
"(",
")",
"\n... | // CanOrder returns whether the values a and b are orderable according
// to the Go language specification. | [
"CanOrder",
"returns",
"whether",
"the",
"values",
"a",
"and",
"b",
"are",
"orderable",
"according",
"to",
"the",
"Go",
"language",
"specification",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/order.go#L11-L17 |
142,273 | aclements/go-gg | generic/order.go | OrderR | func OrderR(a, b reflect.Value) int {
if a.Kind() != b.Kind() {
panic(&TypeError{a.Type(), b.Type(), "are not orderable because they are different kinds"})
}
switch a.Kind() {
case reflect.Float32, reflect.Float64:
a, b := a.Float(), b.Float()
if a < b {
return -1
} else if a > b {
return 1
}
ret... | go | func OrderR(a, b reflect.Value) int {
if a.Kind() != b.Kind() {
panic(&TypeError{a.Type(), b.Type(), "are not orderable because they are different kinds"})
}
switch a.Kind() {
case reflect.Float32, reflect.Float64:
a, b := a.Float(), b.Float()
if a < b {
return -1
} else if a > b {
return 1
}
ret... | [
"func",
"OrderR",
"(",
"a",
",",
"b",
"reflect",
".",
"Value",
")",
"int",
"{",
"if",
"a",
".",
"Kind",
"(",
")",
"!=",
"b",
".",
"Kind",
"(",
")",
"{",
"panic",
"(",
"&",
"TypeError",
"{",
"a",
".",
"Type",
"(",
")",
",",
"b",
".",
"Type",... | // OrderR is equivalent to Order, but operates on reflect.Values. | [
"OrderR",
"is",
"equivalent",
"to",
"Order",
"but",
"operates",
"on",
"reflect",
".",
"Values",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/generic/order.go#L52-L96 |
142,274 | aclements/go-gg | table/table.go | NewBuilder | func NewBuilder(t *Table) *Builder {
if t == nil {
return new(Builder)
}
b := Builder{Table{
cols: make(map[string]Slice),
consts: make(map[string]interface{}),
colNames: append([]string(nil), t.Columns()...),
len: t.len,
}}
for k, v := range t.cols {
b.t.cols[k] = v
}
for k, v := range t.... | go | func NewBuilder(t *Table) *Builder {
if t == nil {
return new(Builder)
}
b := Builder{Table{
cols: make(map[string]Slice),
consts: make(map[string]interface{}),
colNames: append([]string(nil), t.Columns()...),
len: t.len,
}}
for k, v := range t.cols {
b.t.cols[k] = v
}
for k, v := range t.... | [
"func",
"NewBuilder",
"(",
"t",
"*",
"Table",
")",
"*",
"Builder",
"{",
"if",
"t",
"==",
"nil",
"{",
"return",
"new",
"(",
"Builder",
")",
"\n",
"}",
"\n",
"b",
":=",
"Builder",
"{",
"Table",
"{",
"cols",
":",
"make",
"(",
"map",
"[",
"string",
... | // NewBuilder returns a new Builder. If t is non-nil, it populates the
// new Builder with the columns from t. | [
"NewBuilder",
"returns",
"a",
"new",
"Builder",
".",
"If",
"t",
"is",
"non",
"-",
"nil",
"it",
"populates",
"the",
"new",
"Builder",
"with",
"the",
"columns",
"from",
"t",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L137-L154 |
142,275 | aclements/go-gg | table/table.go | Add | func (b *Builder) Add(name string, data Slice) *Builder {
if data == nil {
// Remove the column.
if _, ok := b.t.cols[name]; !ok {
if _, ok := b.t.consts[name]; !ok {
// Nothing to remove.
return b
}
}
delete(b.t.cols, name)
delete(b.t.consts, name)
for i, n := range b.t.colNames {
if n ==... | go | func (b *Builder) Add(name string, data Slice) *Builder {
if data == nil {
// Remove the column.
if _, ok := b.t.cols[name]; !ok {
if _, ok := b.t.consts[name]; !ok {
// Nothing to remove.
return b
}
}
delete(b.t.cols, name)
delete(b.t.consts, name)
for i, n := range b.t.colNames {
if n ==... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Add",
"(",
"name",
"string",
",",
"data",
"Slice",
")",
"*",
"Builder",
"{",
"if",
"data",
"==",
"nil",
"{",
"// Remove the column.",
"if",
"_",
",",
"ok",
":=",
"b",
".",
"t",
".",
"cols",
"[",
"name",
"]"... | // Add adds a column to b, or removes the named column if data is nil.
// If b already has a column with the given name, Add replaces it. If
// data is non-nil, it must have the same length as any existing
// columns or Add will panic. | [
"Add",
"adds",
"a",
"column",
"to",
"b",
"or",
"removes",
"the",
"named",
"column",
"if",
"data",
"is",
"nil",
".",
"If",
"b",
"already",
"has",
"a",
"column",
"with",
"the",
"given",
"name",
"Add",
"replaces",
"it",
".",
"If",
"data",
"is",
"non",
... | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L160-L212 |
142,276 | aclements/go-gg | table/table.go | AddConst | func (b *Builder) AddConst(name string, val interface{}) *Builder {
// Are we replacing an existing column?
_, replace := b.t.cols[name]
if !replace {
_, replace = b.t.consts[name]
}
if b.t.consts == nil {
b.t.consts = make(map[string]interface{})
}
b.t.consts[name] = val
if replace {
// Make sure it's ... | go | func (b *Builder) AddConst(name string, val interface{}) *Builder {
// Are we replacing an existing column?
_, replace := b.t.cols[name]
if !replace {
_, replace = b.t.consts[name]
}
if b.t.consts == nil {
b.t.consts = make(map[string]interface{})
}
b.t.consts[name] = val
if replace {
// Make sure it's ... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"AddConst",
"(",
"name",
"string",
",",
"val",
"interface",
"{",
"}",
")",
"*",
"Builder",
"{",
"// Are we replacing an existing column?",
"_",
",",
"replace",
":=",
"b",
".",
"t",
".",
"cols",
"[",
"name",
"]",
"... | // AddConst adds a constant column to b whose value is val. If b
// already has a column with this name, AddConst replaces it.
//
// A constant column has the same value in every row of the Table. It
// does not itself have an inherent length. | [
"AddConst",
"adds",
"a",
"constant",
"column",
"to",
"b",
"whose",
"value",
"is",
"val",
".",
"If",
"b",
"already",
"has",
"a",
"column",
"with",
"this",
"name",
"AddConst",
"replaces",
"it",
".",
"A",
"constant",
"column",
"has",
"the",
"same",
"value",... | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L219-L239 |
142,277 | aclements/go-gg | table/table.go | Has | func (b *Builder) Has(name string) bool {
if _, ok := b.t.cols[name]; ok {
return true
}
if _, ok := b.t.consts[name]; ok {
return true
}
return false
} | go | func (b *Builder) Has(name string) bool {
if _, ok := b.t.cols[name]; ok {
return true
}
if _, ok := b.t.consts[name]; ok {
return true
}
return false
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Has",
"(",
"name",
"string",
")",
"bool",
"{",
"if",
"_",
",",
"ok",
":=",
"b",
".",
"t",
".",
"cols",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
... | // Has returns true if b has a column named "name". | [
"Has",
"returns",
"true",
"if",
"b",
"has",
"a",
"column",
"named",
"name",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L242-L250 |
142,278 | aclements/go-gg | table/table.go | Done | func (b *Builder) Done() *Table {
if len(b.t.colNames) == 0 {
return new(Table)
}
t := b.t
b.t = Table{}
return &t
} | go | func (b *Builder) Done() *Table {
if len(b.t.colNames) == 0 {
return new(Table)
}
t := b.t
b.t = Table{}
return &t
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Done",
"(",
")",
"*",
"Table",
"{",
"if",
"len",
"(",
"b",
".",
"t",
".",
"colNames",
")",
"==",
"0",
"{",
"return",
"new",
"(",
"Table",
")",
"\n",
"}",
"\n",
"t",
":=",
"b",
".",
"t",
"\n",
"b",
"... | // Done returns the constructed Table and resets b. | [
"Done",
"returns",
"the",
"constructed",
"Table",
"and",
"resets",
"b",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L253-L260 |
142,279 | aclements/go-gg | table/table.go | Column | func (t *Table) Column(name string) Slice {
if c, ok := t.cols[name]; ok {
// It's a regular column or a constant column with a
// cached expansion.
return c
}
if cv, ok := t.consts[name]; ok {
// Expand the constant column and cache the result.
expanded := slice.Repeat(cv, t.len)
t.cols[name] = expande... | go | func (t *Table) Column(name string) Slice {
if c, ok := t.cols[name]; ok {
// It's a regular column or a constant column with a
// cached expansion.
return c
}
if cv, ok := t.consts[name]; ok {
// Expand the constant column and cache the result.
expanded := slice.Repeat(cv, t.len)
t.cols[name] = expande... | [
"func",
"(",
"t",
"*",
"Table",
")",
"Column",
"(",
"name",
"string",
")",
"Slice",
"{",
"if",
"c",
",",
"ok",
":=",
"t",
".",
"cols",
"[",
"name",
"]",
";",
"ok",
"{",
"// It's a regular column or a constant column with a",
"// cached expansion.",
"return",... | // Column returns the slice of data in column name of Table t, or nil
// if there is no such column. If name is a constant column, this
// returns a slice with the constant value repeated to the length of
// the Table. | [
"Column",
"returns",
"the",
"slice",
"of",
"data",
"in",
"column",
"name",
"of",
"Table",
"t",
"or",
"nil",
"if",
"there",
"is",
"no",
"such",
"column",
".",
"If",
"name",
"is",
"a",
"constant",
"column",
"this",
"returns",
"a",
"slice",
"with",
"the",... | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L277-L292 |
142,280 | aclements/go-gg | table/table.go | MustColumn | func (t *Table) MustColumn(name string) Slice {
if c := t.Column(name); c != nil {
return c
}
panic(fmt.Sprintf("unknown column %q", name))
} | go | func (t *Table) MustColumn(name string) Slice {
if c := t.Column(name); c != nil {
return c
}
panic(fmt.Sprintf("unknown column %q", name))
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"MustColumn",
"(",
"name",
"string",
")",
"Slice",
"{",
"if",
"c",
":=",
"t",
".",
"Column",
"(",
"name",
")",
";",
"c",
"!=",
"nil",
"{",
"return",
"c",
"\n",
"}",
"\n",
"panic",
"(",
"fmt",
".",
"Sprintf",... | // MustColumn is like Column, but panics if there is no such column. | [
"MustColumn",
"is",
"like",
"Column",
"but",
"panics",
"if",
"there",
"is",
"no",
"such",
"column",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L295-L300 |
142,281 | aclements/go-gg | table/table.go | Const | func (t *Table) Const(name string) (val interface{}, ok bool) {
cv, ok := t.consts[name]
return cv, ok
} | go | func (t *Table) Const(name string) (val interface{}, ok bool) {
cv, ok := t.consts[name]
return cv, ok
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Const",
"(",
"name",
"string",
")",
"(",
"val",
"interface",
"{",
"}",
",",
"ok",
"bool",
")",
"{",
"cv",
",",
"ok",
":=",
"t",
".",
"consts",
"[",
"name",
"]",
"\n",
"return",
"cv",
",",
"ok",
"\n",
"}"
... | // Const returns the value of constant column name. If this column
// does not exist or is not a constant column, Const returns nil,
// false. | [
"Const",
"returns",
"the",
"value",
"of",
"constant",
"column",
"name",
".",
"If",
"this",
"column",
"does",
"not",
"exist",
"or",
"is",
"not",
"a",
"constant",
"column",
"Const",
"returns",
"nil",
"false",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L305-L308 |
142,282 | aclements/go-gg | table/table.go | Table | func (t *Table) Table(gid GroupID) *Table {
if gid == RootGroupID && !t.isEmpty() {
return t
}
return nil
} | go | func (t *Table) Table(gid GroupID) *Table {
if gid == RootGroupID && !t.isEmpty() {
return t
}
return nil
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Table",
"(",
"gid",
"GroupID",
")",
"*",
"Table",
"{",
"if",
"gid",
"==",
"RootGroupID",
"&&",
"!",
"t",
".",
"isEmpty",
"(",
")",
"{",
"return",
"t",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Table returns t if gid is RootGroupID and t is not empty; otherwise
// it returns nil. | [
"Table",
"returns",
"t",
"if",
"gid",
"is",
"RootGroupID",
"and",
"t",
"is",
"not",
"empty",
";",
"otherwise",
"it",
"returns",
"nil",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L327-L332 |
142,283 | aclements/go-gg | table/table.go | NewGroupingBuilder | func NewGroupingBuilder(g Grouping) *GroupingBuilder {
if g == nil {
return new(GroupingBuilder)
}
b := GroupingBuilder{groupedTable{
tables: make(map[GroupID]*Table),
groups: append([]GroupID(nil), g.Tables()...),
colNames: append([]string(nil), g.Columns()...),
}, nil}
for _, gid := range g.Tables() ... | go | func NewGroupingBuilder(g Grouping) *GroupingBuilder {
if g == nil {
return new(GroupingBuilder)
}
b := GroupingBuilder{groupedTable{
tables: make(map[GroupID]*Table),
groups: append([]GroupID(nil), g.Tables()...),
colNames: append([]string(nil), g.Columns()...),
}, nil}
for _, gid := range g.Tables() ... | [
"func",
"NewGroupingBuilder",
"(",
"g",
"Grouping",
")",
"*",
"GroupingBuilder",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"new",
"(",
"GroupingBuilder",
")",
"\n",
"}",
"\n",
"b",
":=",
"GroupingBuilder",
"{",
"groupedTable",
"{",
"tables",
":",
"make",... | // NewGroupingBuilder returns a new GroupingBuilder. If g is non-nil,
// it populates the new GroupingBuilder with the tables from g. | [
"NewGroupingBuilder",
"returns",
"a",
"new",
"GroupingBuilder",
".",
"If",
"g",
"is",
"non",
"-",
"nil",
"it",
"populates",
"the",
"new",
"GroupingBuilder",
"with",
"the",
"tables",
"from",
"g",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L336-L353 |
142,284 | aclements/go-gg | table/table.go | Done | func (b *GroupingBuilder) Done() Grouping {
if len(b.g.groups) == 0 {
return new(groupedTable)
}
g := b.g
b.g = groupedTable{}
return &g
} | go | func (b *GroupingBuilder) Done() Grouping {
if len(b.g.groups) == 0 {
return new(groupedTable)
}
g := b.g
b.g = groupedTable{}
return &g
} | [
"func",
"(",
"b",
"*",
"GroupingBuilder",
")",
"Done",
"(",
")",
"Grouping",
"{",
"if",
"len",
"(",
"b",
".",
"g",
".",
"groups",
")",
"==",
"0",
"{",
"return",
"new",
"(",
"groupedTable",
")",
"\n",
"}",
"\n",
"g",
":=",
"b",
".",
"g",
"\n",
... | // Done returns the constructed Grouping and resets b. | [
"Done",
"returns",
"the",
"constructed",
"Grouping",
"and",
"resets",
"b",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/table.go#L452-L459 |
142,285 | aclements/go-gg | table/map.go | MapTables | func MapTables(g Grouping, f func(gid GroupID, table *Table) *Table) Grouping {
var out GroupingBuilder
for _, gid := range g.Tables() {
out.Add(gid, f(gid, g.Table(gid)))
}
return out.Done()
} | go | func MapTables(g Grouping, f func(gid GroupID, table *Table) *Table) Grouping {
var out GroupingBuilder
for _, gid := range g.Tables() {
out.Add(gid, f(gid, g.Table(gid)))
}
return out.Done()
} | [
"func",
"MapTables",
"(",
"g",
"Grouping",
",",
"f",
"func",
"(",
"gid",
"GroupID",
",",
"table",
"*",
"Table",
")",
"*",
"Table",
")",
"Grouping",
"{",
"var",
"out",
"GroupingBuilder",
"\n",
"for",
"_",
",",
"gid",
":=",
"range",
"g",
".",
"Tables",... | // MapTables applies f to each Table in g and returns a new Grouping
// with the same group structure as g, but with the Tables returned by
// f. | [
"MapTables",
"applies",
"f",
"to",
"each",
"Table",
"in",
"g",
"and",
"returns",
"a",
"new",
"Grouping",
"with",
"the",
"same",
"group",
"structure",
"as",
"g",
"but",
"with",
"the",
"Tables",
"returned",
"by",
"f",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/map.go#L17-L23 |
142,286 | aclements/go-gg | table/map.go | Rename | func Rename(g Grouping, from, to string) Grouping {
return MapTables(g, func(_ GroupID, t *Table) *Table {
t.MustColumn(from)
var nt Builder
for _, col := range t.Columns() {
if col == to {
continue
}
ncol := col
if col == from {
ncol = to
}
if cv, ok := t.Const(col); ok {
nt.AddC... | go | func Rename(g Grouping, from, to string) Grouping {
return MapTables(g, func(_ GroupID, t *Table) *Table {
t.MustColumn(from)
var nt Builder
for _, col := range t.Columns() {
if col == to {
continue
}
ncol := col
if col == from {
ncol = to
}
if cv, ok := t.Const(col); ok {
nt.AddC... | [
"func",
"Rename",
"(",
"g",
"Grouping",
",",
"from",
",",
"to",
"string",
")",
"Grouping",
"{",
"return",
"MapTables",
"(",
"g",
",",
"func",
"(",
"_",
"GroupID",
",",
"t",
"*",
"Table",
")",
"*",
"Table",
"{",
"t",
".",
"MustColumn",
"(",
"from",
... | // Rename returns g with column 'from' renamed to 'to'. The column
// retains its position. | [
"Rename",
"returns",
"g",
"with",
"column",
"from",
"renamed",
"to",
"to",
".",
"The",
"column",
"retains",
"its",
"position",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/map.go#L129-L151 |
142,287 | aclements/go-gg | table/map.go | Remove | func Remove(g Grouping, col string) Grouping {
return MapTables(g, func(_ GroupID, t *Table) *Table {
t.MustColumn(col)
var nt Builder
for _, col2 := range t.Columns() {
if col == col2 {
continue
}
if cv, ok := t.Const(col2); ok {
nt.AddConst(col2, cv)
} else {
nt.Add(col2, t.Column(col2)... | go | func Remove(g Grouping, col string) Grouping {
return MapTables(g, func(_ GroupID, t *Table) *Table {
t.MustColumn(col)
var nt Builder
for _, col2 := range t.Columns() {
if col == col2 {
continue
}
if cv, ok := t.Const(col2); ok {
nt.AddConst(col2, cv)
} else {
nt.Add(col2, t.Column(col2)... | [
"func",
"Remove",
"(",
"g",
"Grouping",
",",
"col",
"string",
")",
"Grouping",
"{",
"return",
"MapTables",
"(",
"g",
",",
"func",
"(",
"_",
"GroupID",
",",
"t",
"*",
"Table",
")",
"*",
"Table",
"{",
"t",
".",
"MustColumn",
"(",
"col",
")",
"\n",
... | // Remove returns g with column 'col' removed. | [
"Remove",
"returns",
"g",
"with",
"column",
"col",
"removed",
"."
] | abd1f791f5ee99465ee7cffe771436379d6cee5a | https://github.com/aclements/go-gg/blob/abd1f791f5ee99465ee7cffe771436379d6cee5a/table/map.go#L154-L170 |
142,288 | xojoc/useragent | browser.go | parseChromeSafari | func parseChromeSafari(l *lex) *UserAgent {
ua := new()
if !parseMozillaLike(l, ua) {
return nil
}
if !l.match("AppleWebKit/") {
return nil
}
if _, ok := l.span(" "); !ok {
return nil
}
if !l.match("(KHTML, like Gecko) ") {
return nil
}
if !parseNameVersion(l, ua) {
return nil
}
if ua.Name == "Cr... | go | func parseChromeSafari(l *lex) *UserAgent {
ua := new()
if !parseMozillaLike(l, ua) {
return nil
}
if !l.match("AppleWebKit/") {
return nil
}
if _, ok := l.span(" "); !ok {
return nil
}
if !l.match("(KHTML, like Gecko) ") {
return nil
}
if !parseNameVersion(l, ua) {
return nil
}
if ua.Name == "Cr... | [
"func",
"parseChromeSafari",
"(",
"l",
"*",
"lex",
")",
"*",
"UserAgent",
"{",
"ua",
":=",
"new",
"(",
"",
")",
"\n\n",
"if",
"!",
"parseMozillaLike",
"(",
"l",
",",
"ua",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"l",
".",
"match",
... | // Includes WebKit-based Firefox for iOS | [
"Includes",
"WebKit",
"-",
"based",
"Firefox",
"for",
"iOS"
] | 52903803fc66eef0fce52f158ea57bb3b3feacfe | https://github.com/xojoc/useragent/blob/52903803fc66eef0fce52f158ea57bb3b3feacfe/browser.go#L186-L258 |
142,289 | xojoc/useragent | browser.go | parseIE1 | func parseIE1(l *lex) *UserAgent {
ua := new()
ua.Type = Browser
if !l.match("Mozilla") {
return nil
}
if _, ok := l.span(" ("); !ok {
return nil
}
l.match("compatible; ")
l.match("Compatible; ")
if !l.match("MSIE ") {
return nil
}
ua.Name = "MSIE"
if !parseVersion(l, ua, ";") {
return nil
}
if ... | go | func parseIE1(l *lex) *UserAgent {
ua := new()
ua.Type = Browser
if !l.match("Mozilla") {
return nil
}
if _, ok := l.span(" ("); !ok {
return nil
}
l.match("compatible; ")
l.match("Compatible; ")
if !l.match("MSIE ") {
return nil
}
ua.Name = "MSIE"
if !parseVersion(l, ua, ";") {
return nil
}
if ... | [
"func",
"parseIE1",
"(",
"l",
"*",
"lex",
")",
"*",
"UserAgent",
"{",
"ua",
":=",
"new",
"(",
"",
")",
"\n\n",
"ua",
".",
"Type",
"=",
"Browser",
"\n",
"if",
"!",
"l",
".",
"match",
"(",
"\"",
"\"",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",... | // pre IE11 uas | [
"pre",
"IE11",
"uas"
] | 52903803fc66eef0fce52f158ea57bb3b3feacfe | https://github.com/xojoc/useragent/blob/52903803fc66eef0fce52f158ea57bb3b3feacfe/browser.go#L261-L297 |
142,290 | xojoc/useragent | browser.go | parseOperaClassic | func parseOperaClassic(l *lex) *UserAgent {
ua := new()
if !l.match("Opera/") {
return nil
}
ua.Type = Browser
ua.Name = "Opera"
// Start with the Opera version (versions 9.80+ will overwrite later)
if !parseVersion(l, ua, " ") {
return nil
}
if _, ok := l.span("("); !ok {
return nil
}
switch {
case ... | go | func parseOperaClassic(l *lex) *UserAgent {
ua := new()
if !l.match("Opera/") {
return nil
}
ua.Type = Browser
ua.Name = "Opera"
// Start with the Opera version (versions 9.80+ will overwrite later)
if !parseVersion(l, ua, " ") {
return nil
}
if _, ok := l.span("("); !ok {
return nil
}
switch {
case ... | [
"func",
"parseOperaClassic",
"(",
"l",
"*",
"lex",
")",
"*",
"UserAgent",
"{",
"ua",
":=",
"new",
"(",
"",
")",
"\n\n",
"if",
"!",
"l",
".",
"match",
"(",
"\"",
"\"",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"ua",
".",
"Type",
"=",
"Browser"... | // Non-Mozilla Opera UAs | [
"Non",
"-",
"Mozilla",
"Opera",
"UAs"
] | 52903803fc66eef0fce52f158ea57bb3b3feacfe | https://github.com/xojoc/useragent/blob/52903803fc66eef0fce52f158ea57bb3b3feacfe/browser.go#L330-L380 |
142,291 | xojoc/useragent | lex.go | matchNoConsume | func (l *lex) matchNoConsume(m string) bool {
return strings.HasPrefix(l.s[l.p:], m)
} | go | func (l *lex) matchNoConsume(m string) bool {
return strings.HasPrefix(l.s[l.p:], m)
} | [
"func",
"(",
"l",
"*",
"lex",
")",
"matchNoConsume",
"(",
"m",
"string",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"l",
".",
"s",
"[",
"l",
".",
"p",
":",
"]",
",",
"m",
")",
"\n",
"}"
] | // Returns true iff current position matches input string | [
"Returns",
"true",
"iff",
"current",
"position",
"matches",
"input",
"string"
] | 52903803fc66eef0fce52f158ea57bb3b3feacfe | https://github.com/xojoc/useragent/blob/52903803fc66eef0fce52f158ea57bb3b3feacfe/lex.go#L21-L23 |
142,292 | xojoc/useragent | lex.go | matchFirst | func (l *lex) matchFirst(args ...string) bool {
for _, m := range args {
if l.match(m) {
return true
}
}
return false
} | go | func (l *lex) matchFirst(args ...string) bool {
for _, m := range args {
if l.match(m) {
return true
}
}
return false
} | [
"func",
"(",
"l",
"*",
"lex",
")",
"matchFirst",
"(",
"args",
"...",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"args",
"{",
"if",
"l",
".",
"match",
"(",
"m",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"ret... | // Consumes first provided string that matches the current position;
// returns true on finding any match, false otherwise | [
"Consumes",
"first",
"provided",
"string",
"that",
"matches",
"the",
"current",
"position",
";",
"returns",
"true",
"on",
"finding",
"any",
"match",
"false",
"otherwise"
] | 52903803fc66eef0fce52f158ea57bb3b3feacfe | https://github.com/xojoc/useragent/blob/52903803fc66eef0fce52f158ea57bb3b3feacfe/lex.go#L37-L44 |
142,293 | xojoc/useragent | lex.go | spanRegexp | func (l *lex) spanRegexp(re *regexp.Regexp) (before string, match string, success bool) {
loc := re.FindStringSubmatchIndex(l.s[l.p:])
if loc == nil {
return "", "", false
}
success = true
start, end := loc[2], loc[3]
before = l.s[l.p : l.p+start]
match = l.s[l.p:][start:end]
l.p += end
return
} | go | func (l *lex) spanRegexp(re *regexp.Regexp) (before string, match string, success bool) {
loc := re.FindStringSubmatchIndex(l.s[l.p:])
if loc == nil {
return "", "", false
}
success = true
start, end := loc[2], loc[3]
before = l.s[l.p : l.p+start]
match = l.s[l.p:][start:end]
l.p += end
return
} | [
"func",
"(",
"l",
"*",
"lex",
")",
"spanRegexp",
"(",
"re",
"*",
"regexp",
".",
"Regexp",
")",
"(",
"before",
"string",
",",
"match",
"string",
",",
"success",
"bool",
")",
"{",
"loc",
":=",
"re",
".",
"FindStringSubmatchIndex",
"(",
"l",
".",
"s",
... | // assumes the first group is the bit we want | [
"assumes",
"the",
"first",
"group",
"is",
"the",
"bit",
"we",
"want"
] | 52903803fc66eef0fce52f158ea57bb3b3feacfe | https://github.com/xojoc/useragent/blob/52903803fc66eef0fce52f158ea57bb3b3feacfe/lex.go#L83-L94 |
142,294 | xojoc/useragent | parse.go | Parse | func Parse(uas string) *UserAgent {
// NOTE: parse functions order matters.
for _, f := range []parseFn{parseCrawler, parseBrowser, parseGeneric} {
if ua := f(newLex(uas)); ua != nil {
ua.Original = uas
return ua
}
}
return nil
} | go | func Parse(uas string) *UserAgent {
// NOTE: parse functions order matters.
for _, f := range []parseFn{parseCrawler, parseBrowser, parseGeneric} {
if ua := f(newLex(uas)); ua != nil {
ua.Original = uas
return ua
}
}
return nil
} | [
"func",
"Parse",
"(",
"uas",
"string",
")",
"*",
"UserAgent",
"{",
"// NOTE: parse functions order matters.",
"for",
"_",
",",
"f",
":=",
"range",
"[",
"]",
"parseFn",
"{",
"parseCrawler",
",",
"parseBrowser",
",",
"parseGeneric",
"}",
"{",
"if",
"ua",
":=",... | // Try to extract information about an user agent from uas.
// Since user agent strings don't have a standard, this function uses heuristics. | [
"Try",
"to",
"extract",
"information",
"about",
"an",
"user",
"agent",
"from",
"uas",
".",
"Since",
"user",
"agent",
"strings",
"don",
"t",
"have",
"a",
"standard",
"this",
"function",
"uses",
"heuristics",
"."
] | 52903803fc66eef0fce52f158ea57bb3b3feacfe | https://github.com/xojoc/useragent/blob/52903803fc66eef0fce52f158ea57bb3b3feacfe/parse.go#L141-L150 |
142,295 | voxelbrain/goptions | flag.go | NeedsExtraValue | func (f *Flag) NeedsExtraValue() bool {
// Explicit over implicit
if f.value.Type() == reflect.TypeOf(new([]bool)).Elem() ||
f.value.Type() == reflect.TypeOf(new(bool)).Elem() {
return false
}
if _, ok := f.value.Interface().(Help); ok {
return false
}
return true
} | go | func (f *Flag) NeedsExtraValue() bool {
// Explicit over implicit
if f.value.Type() == reflect.TypeOf(new([]bool)).Elem() ||
f.value.Type() == reflect.TypeOf(new(bool)).Elem() {
return false
}
if _, ok := f.value.Interface().(Help); ok {
return false
}
return true
} | [
"func",
"(",
"f",
"*",
"Flag",
")",
"NeedsExtraValue",
"(",
")",
"bool",
"{",
"// Explicit over implicit",
"if",
"f",
".",
"value",
".",
"Type",
"(",
")",
"==",
"reflect",
".",
"TypeOf",
"(",
"new",
"(",
"[",
"]",
"bool",
")",
")",
".",
"Elem",
"("... | // NeedsExtraValue returns true if the flag expects a separate value. | [
"NeedsExtraValue",
"returns",
"true",
"if",
"the",
"flag",
"expects",
"a",
"separate",
"value",
"."
] | 58cddc247ea2f1b0d682decc39f2aec8c6ff0d00 | https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/flag.go#L36-L46 |
142,296 | voxelbrain/goptions | flag.go | IsMulti | func (f *Flag) IsMulti() bool {
if f.value.Kind() == reflect.Slice {
return true
}
return false
} | go | func (f *Flag) IsMulti() bool {
if f.value.Kind() == reflect.Slice {
return true
}
return false
} | [
"func",
"(",
"f",
"*",
"Flag",
")",
"IsMulti",
"(",
")",
"bool",
"{",
"if",
"f",
".",
"value",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Slice",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsMulti returns true if the flag can be specified multiple times. | [
"IsMulti",
"returns",
"true",
"if",
"the",
"flag",
"can",
"be",
"specified",
"multiple",
"times",
"."
] | 58cddc247ea2f1b0d682decc39f2aec8c6ff0d00 | https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/flag.go#L49-L54 |
142,297 | voxelbrain/goptions | flagset.go | newFlagset | func newFlagset(name string, structValue reflect.Value, parent *FlagSet) *FlagSet {
var once sync.Once
r := &FlagSet{
Name: name,
Flags: make([]*Flag, 0),
HelpFunc: DefaultHelpFunc,
parent: parent,
}
if parent != nil && parent.remainderFlag != nil {
r.remainderFlag = parent.remainderFlag
}
va... | go | func newFlagset(name string, structValue reflect.Value, parent *FlagSet) *FlagSet {
var once sync.Once
r := &FlagSet{
Name: name,
Flags: make([]*Flag, 0),
HelpFunc: DefaultHelpFunc,
parent: parent,
}
if parent != nil && parent.remainderFlag != nil {
r.remainderFlag = parent.remainderFlag
}
va... | [
"func",
"newFlagset",
"(",
"name",
"string",
",",
"structValue",
"reflect",
".",
"Value",
",",
"parent",
"*",
"FlagSet",
")",
"*",
"FlagSet",
"{",
"var",
"once",
"sync",
".",
"Once",
"\n",
"r",
":=",
"&",
"FlagSet",
"{",
"Name",
":",
"name",
",",
"Fl... | // Internal version which skips type checking and takes the "parent"'s
// remainder flag as a parameter. | [
"Internal",
"version",
"which",
"skips",
"type",
"checking",
"and",
"takes",
"the",
"parent",
"s",
"remainder",
"flag",
"as",
"a",
"parameter",
"."
] | 58cddc247ea2f1b0d682decc39f2aec8c6ff0d00 | https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/flagset.go#L51-L106 |
142,298 | voxelbrain/goptions | flagset.go | Parse | func (fs *FlagSet) Parse(args []string) (err error) {
// Parse global flags
for len(args) > 0 {
if !((isLong(args[0]) && fs.hasLongFlag(args[0][2:])) ||
(isShort(args[0]) && fs.hasShortFlag(args[0][1:2]))) {
break
}
f := fs.FlagByName(args[0])
args, err = f.Parse(args)
if err != nil {
return
}
... | go | func (fs *FlagSet) Parse(args []string) (err error) {
// Parse global flags
for len(args) > 0 {
if !((isLong(args[0]) && fs.hasLongFlag(args[0][2:])) ||
(isShort(args[0]) && fs.hasShortFlag(args[0][1:2]))) {
break
}
f := fs.FlagByName(args[0])
args, err = f.Parse(args)
if err != nil {
return
}
... | [
"func",
"(",
"fs",
"*",
"FlagSet",
")",
"Parse",
"(",
"args",
"[",
"]",
"string",
")",
"(",
"err",
"error",
")",
"{",
"// Parse global flags",
"for",
"len",
"(",
"args",
")",
">",
"0",
"{",
"if",
"!",
"(",
"(",
"isLong",
"(",
"args",
"[",
"0",
... | // Parse takes the command line arguments and sets the corresponding values
// in the FlagSet's struct. | [
"Parse",
"takes",
"the",
"command",
"line",
"arguments",
"and",
"sets",
"the",
"corresponding",
"values",
"in",
"the",
"FlagSet",
"s",
"struct",
"."
] | 58cddc247ea2f1b0d682decc39f2aec8c6ff0d00 | https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/flagset.go#L114-L169 |
142,299 | voxelbrain/goptions | flagset.go | MutexGroups | func (fs *FlagSet) MutexGroups() map[string]MutexGroup {
r := make(map[string]MutexGroup)
for _, f := range fs.Flags {
for _, mg := range f.MutexGroups {
if len(mg) == 0 {
continue
}
if _, ok := r[mg]; !ok {
r[mg] = make(MutexGroup, 0)
}
r[mg] = append(r[mg], f)
}
}
return r
} | go | func (fs *FlagSet) MutexGroups() map[string]MutexGroup {
r := make(map[string]MutexGroup)
for _, f := range fs.Flags {
for _, mg := range f.MutexGroups {
if len(mg) == 0 {
continue
}
if _, ok := r[mg]; !ok {
r[mg] = make(MutexGroup, 0)
}
r[mg] = append(r[mg], f)
}
}
return r
} | [
"func",
"(",
"fs",
"*",
"FlagSet",
")",
"MutexGroups",
"(",
")",
"map",
"[",
"string",
"]",
"MutexGroup",
"{",
"r",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"MutexGroup",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"fs",
".",
"Flags",
"{... | // MutexGroups returns a map of Flag lists which contain mutually
// exclusive flags. | [
"MutexGroups",
"returns",
"a",
"map",
"of",
"Flag",
"lists",
"which",
"contain",
"mutually",
"exclusive",
"flags",
"."
] | 58cddc247ea2f1b0d682decc39f2aec8c6ff0d00 | https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/flagset.go#L201-L215 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.