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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
6,000 | z7zmey/php-parser | node/expr/n_static_call.go | NewStaticCall | func NewStaticCall(Class node.Node, Call node.Node, ArgumentList *node.ArgumentList) *StaticCall {
return &StaticCall{
FreeFloating: nil,
Class: Class,
Call: Call,
ArgumentList: ArgumentList,
}
} | go | func NewStaticCall(Class node.Node, Call node.Node, ArgumentList *node.ArgumentList) *StaticCall {
return &StaticCall{
FreeFloating: nil,
Class: Class,
Call: Call,
ArgumentList: ArgumentList,
}
} | [
"func",
"NewStaticCall",
"(",
"Class",
"node",
".",
"Node",
",",
"Call",
"node",
".",
"Node",
",",
"ArgumentList",
"*",
"node",
".",
"ArgumentList",
")",
"*",
"StaticCall",
"{",
"return",
"&",
"StaticCall",
"{",
"FreeFloating",
":",
"nil",
",",
"Class",
":",
"Class",
",",
"Call",
":",
"Call",
",",
"ArgumentList",
":",
"ArgumentList",
",",
"}",
"\n",
"}"
] | // NewStaticCall node constructor | [
"NewStaticCall",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_static_call.go#L20-L27 |
6,001 | z7zmey/php-parser | node/expr/binary/n_not_equal.go | NewNotEqual | func NewNotEqual(Variable node.Node, Expression node.Node) *NotEqual {
return &NotEqual{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewNotEqual(Variable node.Node, Expression node.Node) *NotEqual {
return &NotEqual{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewNotEqual",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"NotEqual",
"{",
"return",
"&",
"NotEqual",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewNotEqual node constructor | [
"NewNotEqual",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_not_equal.go#L19-L25 |
6,002 | z7zmey/php-parser | node/stmt/n_alt_else_if.go | NewAltElseIf | func NewAltElseIf(Cond node.Node, Stmt node.Node) *AltElseIf {
return &AltElseIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
}
} | go | func NewAltElseIf(Cond node.Node, Stmt node.Node) *AltElseIf {
return &AltElseIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
}
} | [
"func",
"NewAltElseIf",
"(",
"Cond",
"node",
".",
"Node",
",",
"Stmt",
"node",
".",
"Node",
")",
"*",
"AltElseIf",
"{",
"return",
"&",
"AltElseIf",
"{",
"FreeFloating",
":",
"nil",
",",
"Cond",
":",
"Cond",
",",
"Stmt",
":",
"Stmt",
",",
"}",
"\n",
"}"
] | // NewAltElseIf node constructor | [
"NewAltElseIf",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_alt_else_if.go#L19-L25 |
6,003 | z7zmey/php-parser | node/stmt/n_trait_use_precedence.go | NewTraitUsePrecedence | func NewTraitUsePrecedence(Ref node.Node, Insteadof []node.Node) *TraitUsePrecedence {
return &TraitUsePrecedence{
FreeFloating: nil,
Ref: Ref,
Insteadof: Insteadof,
}
} | go | func NewTraitUsePrecedence(Ref node.Node, Insteadof []node.Node) *TraitUsePrecedence {
return &TraitUsePrecedence{
FreeFloating: nil,
Ref: Ref,
Insteadof: Insteadof,
}
} | [
"func",
"NewTraitUsePrecedence",
"(",
"Ref",
"node",
".",
"Node",
",",
"Insteadof",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"TraitUsePrecedence",
"{",
"return",
"&",
"TraitUsePrecedence",
"{",
"FreeFloating",
":",
"nil",
",",
"Ref",
":",
"Ref",
",",
"Insteadof",
":",
"Insteadof",
",",
"}",
"\n",
"}"
] | // NewTraitUsePrecedence node constructor | [
"NewTraitUsePrecedence",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_trait_use_precedence.go#L19-L25 |
6,004 | z7zmey/php-parser | node/expr/n_instance_of.go | NewInstanceOf | func NewInstanceOf(Expr node.Node, Class node.Node) *InstanceOf {
return &InstanceOf{
FreeFloating: nil,
Expr: Expr,
Class: Class,
}
} | go | func NewInstanceOf(Expr node.Node, Class node.Node) *InstanceOf {
return &InstanceOf{
FreeFloating: nil,
Expr: Expr,
Class: Class,
}
} | [
"func",
"NewInstanceOf",
"(",
"Expr",
"node",
".",
"Node",
",",
"Class",
"node",
".",
"Node",
")",
"*",
"InstanceOf",
"{",
"return",
"&",
"InstanceOf",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expr",
",",
"Class",
":",
"Class",
",",
"}",
"\n",
"}"
] | // NewInstanceOf node constructor | [
"NewInstanceOf",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_instance_of.go#L19-L25 |
6,005 | z7zmey/php-parser | node/stmt/n_alt_if.go | NewAltIf | func NewAltIf(Cond node.Node, Stmt node.Node, ElseIf []node.Node, Else node.Node) *AltIf {
return &AltIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
ElseIf: ElseIf,
Else: Else,
}
} | go | func NewAltIf(Cond node.Node, Stmt node.Node, ElseIf []node.Node, Else node.Node) *AltIf {
return &AltIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
ElseIf: ElseIf,
Else: Else,
}
} | [
"func",
"NewAltIf",
"(",
"Cond",
"node",
".",
"Node",
",",
"Stmt",
"node",
".",
"Node",
",",
"ElseIf",
"[",
"]",
"node",
".",
"Node",
",",
"Else",
"node",
".",
"Node",
")",
"*",
"AltIf",
"{",
"return",
"&",
"AltIf",
"{",
"FreeFloating",
":",
"nil",
",",
"Cond",
":",
"Cond",
",",
"Stmt",
":",
"Stmt",
",",
"ElseIf",
":",
"ElseIf",
",",
"Else",
":",
"Else",
",",
"}",
"\n",
"}"
] | // NewAltIf node constructor | [
"NewAltIf",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_alt_if.go#L21-L29 |
6,006 | z7zmey/php-parser | node/stmt/n_alt_if.go | SetElse | func (n *AltIf) SetElse(Else node.Node) node.Node {
n.Else = Else
return n
} | go | func (n *AltIf) SetElse(Else node.Node) node.Node {
n.Else = Else
return n
} | [
"func",
"(",
"n",
"*",
"AltIf",
")",
"SetElse",
"(",
"Else",
"node",
".",
"Node",
")",
"node",
".",
"Node",
"{",
"n",
".",
"Else",
"=",
"Else",
"\n\n",
"return",
"n",
"\n",
"}"
] | // SetElse set AltElse node and returns AltIf node | [
"SetElse",
"set",
"AltElse",
"node",
"and",
"returns",
"AltIf",
"node"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_alt_if.go#L62-L66 |
6,007 | z7zmey/php-parser | node/expr/n_static_property_fetch.go | NewStaticPropertyFetch | func NewStaticPropertyFetch(Class node.Node, Property node.Node) *StaticPropertyFetch {
return &StaticPropertyFetch{
FreeFloating: nil,
Class: Class,
Property: Property,
}
} | go | func NewStaticPropertyFetch(Class node.Node, Property node.Node) *StaticPropertyFetch {
return &StaticPropertyFetch{
FreeFloating: nil,
Class: Class,
Property: Property,
}
} | [
"func",
"NewStaticPropertyFetch",
"(",
"Class",
"node",
".",
"Node",
",",
"Property",
"node",
".",
"Node",
")",
"*",
"StaticPropertyFetch",
"{",
"return",
"&",
"StaticPropertyFetch",
"{",
"FreeFloating",
":",
"nil",
",",
"Class",
":",
"Class",
",",
"Property",
":",
"Property",
",",
"}",
"\n",
"}"
] | // NewStaticPropertyFetch node constructor | [
"NewStaticPropertyFetch",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_static_property_fetch.go#L19-L25 |
6,008 | z7zmey/php-parser | node/stmt/n_class_method.go | NewClassMethod | func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmt node.Node, PhpDocComment string) *ClassMethod {
return &ClassMethod{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
PhpDocComment: PhpDocComment,
MethodName: MethodName,
Modifiers: Modifiers,
Params: Params,
ReturnType: ReturnType,
Stmt: Stmt,
}
} | go | func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmt node.Node, PhpDocComment string) *ClassMethod {
return &ClassMethod{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
PhpDocComment: PhpDocComment,
MethodName: MethodName,
Modifiers: Modifiers,
Params: Params,
ReturnType: ReturnType,
Stmt: Stmt,
}
} | [
"func",
"NewClassMethod",
"(",
"MethodName",
"node",
".",
"Node",
",",
"Modifiers",
"[",
"]",
"node",
".",
"Node",
",",
"ReturnsRef",
"bool",
",",
"Params",
"[",
"]",
"node",
".",
"Node",
",",
"ReturnType",
"node",
".",
"Node",
",",
"Stmt",
"node",
".",
"Node",
",",
"PhpDocComment",
"string",
")",
"*",
"ClassMethod",
"{",
"return",
"&",
"ClassMethod",
"{",
"FreeFloating",
":",
"nil",
",",
"ReturnsRef",
":",
"ReturnsRef",
",",
"PhpDocComment",
":",
"PhpDocComment",
",",
"MethodName",
":",
"MethodName",
",",
"Modifiers",
":",
"Modifiers",
",",
"Params",
":",
"Params",
",",
"ReturnType",
":",
"ReturnType",
",",
"Stmt",
":",
"Stmt",
",",
"}",
"\n",
"}"
] | // NewClassMethod node constructor | [
"NewClassMethod",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_class_method.go#L24-L35 |
6,009 | z7zmey/php-parser | node/stmt/n_break.go | NewBreak | func NewBreak(Expr node.Node) *Break {
return &Break{
FreeFloating: nil,
Expr: Expr,
}
} | go | func NewBreak(Expr node.Node) *Break {
return &Break{
FreeFloating: nil,
Expr: Expr,
}
} | [
"func",
"NewBreak",
"(",
"Expr",
"node",
".",
"Node",
")",
"*",
"Break",
"{",
"return",
"&",
"Break",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expr",
",",
"}",
"\n",
"}"
] | // NewBreak node constructor | [
"NewBreak",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_break.go#L18-L23 |
6,010 | z7zmey/php-parser | node/expr/binary/n_greater_or_equal.go | NewGreaterOrEqual | func NewGreaterOrEqual(Variable node.Node, Expression node.Node) *GreaterOrEqual {
return &GreaterOrEqual{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewGreaterOrEqual(Variable node.Node, Expression node.Node) *GreaterOrEqual {
return &GreaterOrEqual{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewGreaterOrEqual",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"GreaterOrEqual",
"{",
"return",
"&",
"GreaterOrEqual",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewGreaterOrEqual node constructor | [
"NewGreaterOrEqual",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_greater_or_equal.go#L19-L25 |
6,011 | z7zmey/php-parser | node/expr/cast/n_cast_int.go | NewInt | func NewInt(Expr node.Node) *Int {
return &Int{
FreeFloating: nil,
Expr: Expr,
}
} | go | func NewInt(Expr node.Node) *Int {
return &Int{
FreeFloating: nil,
Expr: Expr,
}
} | [
"func",
"NewInt",
"(",
"Expr",
"node",
".",
"Node",
")",
"*",
"Int",
"{",
"return",
"&",
"Int",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expr",
",",
"}",
"\n",
"}"
] | // NewInt node constructor | [
"NewInt",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/cast/n_cast_int.go#L18-L23 |
6,012 | z7zmey/php-parser | node/expr/n_closure.go | NewClosure | func NewClosure(Params []node.Node, ClosureUse *ClosureUse, ReturnType node.Node, Stmts []node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *Closure {
return &Closure{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
Static: Static,
PhpDocComment: PhpDocComment,
Params: Params,
ClosureUse: ClosureUse,
ReturnType: ReturnType,
Stmts: Stmts,
}
} | go | func NewClosure(Params []node.Node, ClosureUse *ClosureUse, ReturnType node.Node, Stmts []node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *Closure {
return &Closure{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
Static: Static,
PhpDocComment: PhpDocComment,
Params: Params,
ClosureUse: ClosureUse,
ReturnType: ReturnType,
Stmts: Stmts,
}
} | [
"func",
"NewClosure",
"(",
"Params",
"[",
"]",
"node",
".",
"Node",
",",
"ClosureUse",
"*",
"ClosureUse",
",",
"ReturnType",
"node",
".",
"Node",
",",
"Stmts",
"[",
"]",
"node",
".",
"Node",
",",
"Static",
"bool",
",",
"ReturnsRef",
"bool",
",",
"PhpDocComment",
"string",
")",
"*",
"Closure",
"{",
"return",
"&",
"Closure",
"{",
"FreeFloating",
":",
"nil",
",",
"ReturnsRef",
":",
"ReturnsRef",
",",
"Static",
":",
"Static",
",",
"PhpDocComment",
":",
"PhpDocComment",
",",
"Params",
":",
"Params",
",",
"ClosureUse",
":",
"ClosureUse",
",",
"ReturnType",
":",
"ReturnType",
",",
"Stmts",
":",
"Stmts",
",",
"}",
"\n",
"}"
] | // NewClosure node constructor | [
"NewClosure",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_closure.go#L24-L35 |
6,013 | z7zmey/php-parser | node/expr/n_closure.go | Attributes | func (n *Closure) Attributes() map[string]interface{} {
return map[string]interface{}{
"ReturnsRef": n.ReturnsRef,
"Static": n.Static,
"PhpDocComment": n.PhpDocComment,
}
} | go | func (n *Closure) Attributes() map[string]interface{} {
return map[string]interface{}{
"ReturnsRef": n.ReturnsRef,
"Static": n.Static,
"PhpDocComment": n.PhpDocComment,
}
} | [
"func",
"(",
"n",
"*",
"Closure",
")",
"Attributes",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"return",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"n",
".",
"ReturnsRef",
",",
"\"",
"\"",
":",
"n",
".",
"Static",
",",
"\"",
"\"",
":",
"n",
".",
"PhpDocComment",
",",
"}",
"\n",
"}"
] | // Attributes returns node attributes as map | [
"Attributes",
"returns",
"node",
"attributes",
"as",
"map"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_closure.go#L52-L58 |
6,014 | z7zmey/php-parser | node/stmt/n_use.go | NewUse | func NewUse(UseType node.Node, use node.Node, Alias node.Node) *Use {
return &Use{
FreeFloating: nil,
UseType: UseType,
Use: use,
Alias: Alias,
}
} | go | func NewUse(UseType node.Node, use node.Node, Alias node.Node) *Use {
return &Use{
FreeFloating: nil,
UseType: UseType,
Use: use,
Alias: Alias,
}
} | [
"func",
"NewUse",
"(",
"UseType",
"node",
".",
"Node",
",",
"use",
"node",
".",
"Node",
",",
"Alias",
"node",
".",
"Node",
")",
"*",
"Use",
"{",
"return",
"&",
"Use",
"{",
"FreeFloating",
":",
"nil",
",",
"UseType",
":",
"UseType",
",",
"Use",
":",
"use",
",",
"Alias",
":",
"Alias",
",",
"}",
"\n",
"}"
] | // NewUse node constructor | [
"NewUse",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_use.go#L20-L27 |
6,015 | z7zmey/php-parser | node/expr/n_print.go | NewPrint | func NewPrint(Expression node.Node) *Print {
return &Print{
FreeFloating: nil,
Expr: Expression,
}
} | go | func NewPrint(Expression node.Node) *Print {
return &Print{
FreeFloating: nil,
Expr: Expression,
}
} | [
"func",
"NewPrint",
"(",
"Expression",
"node",
".",
"Node",
")",
"*",
"Print",
"{",
"return",
"&",
"Print",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewPrint node constructor | [
"NewPrint",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_print.go#L18-L23 |
6,016 | z7zmey/php-parser | node/n_argument.go | NewArgument | func NewArgument(Expression Node, Variadic bool, IsReference bool) *Argument {
return &Argument{
FreeFloating: nil,
Variadic: Variadic,
IsReference: IsReference,
Expr: Expression,
}
} | go | func NewArgument(Expression Node, Variadic bool, IsReference bool) *Argument {
return &Argument{
FreeFloating: nil,
Variadic: Variadic,
IsReference: IsReference,
Expr: Expression,
}
} | [
"func",
"NewArgument",
"(",
"Expression",
"Node",
",",
"Variadic",
"bool",
",",
"IsReference",
"bool",
")",
"*",
"Argument",
"{",
"return",
"&",
"Argument",
"{",
"FreeFloating",
":",
"nil",
",",
"Variadic",
":",
"Variadic",
",",
"IsReference",
":",
"IsReference",
",",
"Expr",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewArgument node constructor | [
"NewArgument",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/n_argument.go#L19-L26 |
6,017 | z7zmey/php-parser | node/expr/n_include_once.go | NewIncludeOnce | func NewIncludeOnce(Expression node.Node) *IncludeOnce {
return &IncludeOnce{
FreeFloating: nil,
Expr: Expression,
}
} | go | func NewIncludeOnce(Expression node.Node) *IncludeOnce {
return &IncludeOnce{
FreeFloating: nil,
Expr: Expression,
}
} | [
"func",
"NewIncludeOnce",
"(",
"Expression",
"node",
".",
"Node",
")",
"*",
"IncludeOnce",
"{",
"return",
"&",
"IncludeOnce",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewIncludeOnce node constructor | [
"NewIncludeOnce",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_include_once.go#L18-L23 |
6,018 | z7zmey/php-parser | node/stmt/n_static.go | NewStatic | func NewStatic(Vars []node.Node) *Static {
return &Static{
FreeFloating: nil,
Vars: Vars,
}
} | go | func NewStatic(Vars []node.Node) *Static {
return &Static{
FreeFloating: nil,
Vars: Vars,
}
} | [
"func",
"NewStatic",
"(",
"Vars",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"Static",
"{",
"return",
"&",
"Static",
"{",
"FreeFloating",
":",
"nil",
",",
"Vars",
":",
"Vars",
",",
"}",
"\n",
"}"
] | // NewStatic node constructor | [
"NewStatic",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_static.go#L18-L23 |
6,019 | z7zmey/php-parser | node/expr/n_yield.go | NewYield | func NewYield(Key node.Node, Value node.Node) *Yield {
return &Yield{
FreeFloating: nil,
Key: Key,
Value: Value,
}
} | go | func NewYield(Key node.Node, Value node.Node) *Yield {
return &Yield{
FreeFloating: nil,
Key: Key,
Value: Value,
}
} | [
"func",
"NewYield",
"(",
"Key",
"node",
".",
"Node",
",",
"Value",
"node",
".",
"Node",
")",
"*",
"Yield",
"{",
"return",
"&",
"Yield",
"{",
"FreeFloating",
":",
"nil",
",",
"Key",
":",
"Key",
",",
"Value",
":",
"Value",
",",
"}",
"\n",
"}"
] | // NewYield node constructor | [
"NewYield",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_yield.go#L19-L25 |
6,020 | z7zmey/php-parser | node/expr/binary/n_shift_left.go | NewShiftLeft | func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
return &ShiftLeft{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
return &ShiftLeft{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewShiftLeft",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"ShiftLeft",
"{",
"return",
"&",
"ShiftLeft",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewShiftLeft node constructor | [
"NewShiftLeft",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_shift_left.go#L19-L25 |
6,021 | z7zmey/php-parser | node/stmt/n_else.go | NewElse | func NewElse(Stmt node.Node) *Else {
return &Else{
FreeFloating: nil,
Stmt: Stmt,
}
} | go | func NewElse(Stmt node.Node) *Else {
return &Else{
FreeFloating: nil,
Stmt: Stmt,
}
} | [
"func",
"NewElse",
"(",
"Stmt",
"node",
".",
"Node",
")",
"*",
"Else",
"{",
"return",
"&",
"Else",
"{",
"FreeFloating",
":",
"nil",
",",
"Stmt",
":",
"Stmt",
",",
"}",
"\n",
"}"
] | // NewElse node constructor | [
"NewElse",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_else.go#L18-L23 |
6,022 | z7zmey/php-parser | node/expr/n_shell_exec.go | NewShellExec | func NewShellExec(Parts []node.Node) *ShellExec {
return &ShellExec{
FreeFloating: nil,
Parts: Parts,
}
} | go | func NewShellExec(Parts []node.Node) *ShellExec {
return &ShellExec{
FreeFloating: nil,
Parts: Parts,
}
} | [
"func",
"NewShellExec",
"(",
"Parts",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"ShellExec",
"{",
"return",
"&",
"ShellExec",
"{",
"FreeFloating",
":",
"nil",
",",
"Parts",
":",
"Parts",
",",
"}",
"\n",
"}"
] | // NewShellExec node constructor | [
"NewShellExec",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_shell_exec.go#L18-L23 |
6,023 | z7zmey/php-parser | node/expr/n_pre_inc.go | NewPreInc | func NewPreInc(Variable node.Node) *PreInc {
return &PreInc{
FreeFloating: nil,
Variable: Variable,
}
} | go | func NewPreInc(Variable node.Node) *PreInc {
return &PreInc{
FreeFloating: nil,
Variable: Variable,
}
} | [
"func",
"NewPreInc",
"(",
"Variable",
"node",
".",
"Node",
")",
"*",
"PreInc",
"{",
"return",
"&",
"PreInc",
"{",
"FreeFloating",
":",
"nil",
",",
"Variable",
":",
"Variable",
",",
"}",
"\n",
"}"
] | // NewPreInc node constructor | [
"NewPreInc",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_pre_inc.go#L18-L23 |
6,024 | z7zmey/php-parser | node/expr/binary/n_plus.go | NewPlus | func NewPlus(Variable node.Node, Expression node.Node) *Plus {
return &Plus{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewPlus(Variable node.Node, Expression node.Node) *Plus {
return &Plus{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewPlus",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"Plus",
"{",
"return",
"&",
"Plus",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewPlus node constructor | [
"NewPlus",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_plus.go#L19-L25 |
6,025 | z7zmey/php-parser | node/expr/cast/n_cast_bool.go | NewBool | func NewBool(Expr node.Node) *Bool {
return &Bool{
FreeFloating: nil,
Expr: Expr,
}
} | go | func NewBool(Expr node.Node) *Bool {
return &Bool{
FreeFloating: nil,
Expr: Expr,
}
} | [
"func",
"NewBool",
"(",
"Expr",
"node",
".",
"Node",
")",
"*",
"Bool",
"{",
"return",
"&",
"Bool",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expr",
",",
"}",
"\n",
"}"
] | // NewBool node constructor | [
"NewBool",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/cast/n_cast_bool.go#L18-L23 |
6,026 | z7zmey/php-parser | visitor/namespace_resolver.go | AddNamespacedName | func (nsr *NamespaceResolver) AddNamespacedName(nn node.Node, nodeName string) {
if nsr.Namespace.Namespace == "" {
nsr.ResolvedNames[nn] = nodeName
} else {
nsr.ResolvedNames[nn] = nsr.Namespace.Namespace + "\\" + nodeName
}
} | go | func (nsr *NamespaceResolver) AddNamespacedName(nn node.Node, nodeName string) {
if nsr.Namespace.Namespace == "" {
nsr.ResolvedNames[nn] = nodeName
} else {
nsr.ResolvedNames[nn] = nsr.Namespace.Namespace + "\\" + nodeName
}
} | [
"func",
"(",
"nsr",
"*",
"NamespaceResolver",
")",
"AddNamespacedName",
"(",
"nn",
"node",
".",
"Node",
",",
"nodeName",
"string",
")",
"{",
"if",
"nsr",
".",
"Namespace",
".",
"Namespace",
"==",
"\"",
"\"",
"{",
"nsr",
".",
"ResolvedNames",
"[",
"nn",
"]",
"=",
"nodeName",
"\n",
"}",
"else",
"{",
"nsr",
".",
"ResolvedNames",
"[",
"nn",
"]",
"=",
"nsr",
".",
"Namespace",
".",
"Namespace",
"+",
"\"",
"\\\\",
"\"",
"+",
"nodeName",
"\n",
"}",
"\n",
"}"
] | // AddNamespacedName adds namespaced name by node | [
"AddNamespacedName",
"adds",
"namespaced",
"name",
"by",
"node"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/visitor/namespace_resolver.go#L231-L237 |
6,027 | z7zmey/php-parser | visitor/namespace_resolver.go | ResolveName | func (nsr *NamespaceResolver) ResolveName(nameNode node.Node, aliasType string) {
resolved, err := nsr.Namespace.ResolveName(nameNode, aliasType)
if err == nil {
nsr.ResolvedNames[nameNode] = resolved
}
} | go | func (nsr *NamespaceResolver) ResolveName(nameNode node.Node, aliasType string) {
resolved, err := nsr.Namespace.ResolveName(nameNode, aliasType)
if err == nil {
nsr.ResolvedNames[nameNode] = resolved
}
} | [
"func",
"(",
"nsr",
"*",
"NamespaceResolver",
")",
"ResolveName",
"(",
"nameNode",
"node",
".",
"Node",
",",
"aliasType",
"string",
")",
"{",
"resolved",
",",
"err",
":=",
"nsr",
".",
"Namespace",
".",
"ResolveName",
"(",
"nameNode",
",",
"aliasType",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"nsr",
".",
"ResolvedNames",
"[",
"nameNode",
"]",
"=",
"resolved",
"\n",
"}",
"\n",
"}"
] | // ResolveName adds a resolved fully qualified name by node | [
"ResolveName",
"adds",
"a",
"resolved",
"fully",
"qualified",
"name",
"by",
"node"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/visitor/namespace_resolver.go#L240-L245 |
6,028 | z7zmey/php-parser | visitor/namespace_resolver.go | ResolveType | func (nsr *NamespaceResolver) ResolveType(n node.Node) {
switch nn := n.(type) {
case *node.Nullable:
nsr.ResolveType(nn.Expr)
case name.Names:
nsr.ResolveName(n, "")
}
} | go | func (nsr *NamespaceResolver) ResolveType(n node.Node) {
switch nn := n.(type) {
case *node.Nullable:
nsr.ResolveType(nn.Expr)
case name.Names:
nsr.ResolveName(n, "")
}
} | [
"func",
"(",
"nsr",
"*",
"NamespaceResolver",
")",
"ResolveType",
"(",
"n",
"node",
".",
"Node",
")",
"{",
"switch",
"nn",
":=",
"n",
".",
"(",
"type",
")",
"{",
"case",
"*",
"node",
".",
"Nullable",
":",
"nsr",
".",
"ResolveType",
"(",
"nn",
".",
"Expr",
")",
"\n",
"case",
"name",
".",
"Names",
":",
"nsr",
".",
"ResolveName",
"(",
"n",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // ResolveType adds a resolved fully qualified type name | [
"ResolveType",
"adds",
"a",
"resolved",
"fully",
"qualified",
"type",
"name"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/visitor/namespace_resolver.go#L248-L255 |
6,029 | z7zmey/php-parser | visitor/namespace_resolver.go | ResolveName | func (ns *Namespace) ResolveName(nameNode node.Node, aliasType string) (string, error) {
switch n := nameNode.(type) {
case *name.FullyQualified:
// Fully qualifid name is already resolved
return concatNameParts(n.Parts), nil
case *name.Relative:
if ns.Namespace == "" {
return concatNameParts(n.Parts), nil
}
return ns.Namespace + "\\" + concatNameParts(n.Parts), nil
case *name.Name:
if aliasType == "const" && len(n.Parts) == 1 {
part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
if part == "true" || part == "false" || part == "null" {
return part, nil
}
}
if aliasType == "" && len(n.Parts) == 1 {
part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
switch part {
case "self":
fallthrough
case "static":
fallthrough
case "parent":
fallthrough
case "int":
fallthrough
case "float":
fallthrough
case "bool":
fallthrough
case "string":
fallthrough
case "void":
fallthrough
case "iterable":
fallthrough
case "object":
return part, nil
}
}
aliasName, err := ns.ResolveAlias(nameNode, aliasType)
if err != nil {
// resolve as relative name if alias not found
if ns.Namespace == "" {
return concatNameParts(n.Parts), nil
}
return ns.Namespace + "\\" + concatNameParts(n.Parts), nil
}
if len(n.Parts) > 1 {
// if name qualified, replace first part by alias
return aliasName + "\\" + concatNameParts(n.Parts[1:]), nil
}
return aliasName, nil
}
return "", errors.New("must be instance of name.Names")
} | go | func (ns *Namespace) ResolveName(nameNode node.Node, aliasType string) (string, error) {
switch n := nameNode.(type) {
case *name.FullyQualified:
// Fully qualifid name is already resolved
return concatNameParts(n.Parts), nil
case *name.Relative:
if ns.Namespace == "" {
return concatNameParts(n.Parts), nil
}
return ns.Namespace + "\\" + concatNameParts(n.Parts), nil
case *name.Name:
if aliasType == "const" && len(n.Parts) == 1 {
part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
if part == "true" || part == "false" || part == "null" {
return part, nil
}
}
if aliasType == "" && len(n.Parts) == 1 {
part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
switch part {
case "self":
fallthrough
case "static":
fallthrough
case "parent":
fallthrough
case "int":
fallthrough
case "float":
fallthrough
case "bool":
fallthrough
case "string":
fallthrough
case "void":
fallthrough
case "iterable":
fallthrough
case "object":
return part, nil
}
}
aliasName, err := ns.ResolveAlias(nameNode, aliasType)
if err != nil {
// resolve as relative name if alias not found
if ns.Namespace == "" {
return concatNameParts(n.Parts), nil
}
return ns.Namespace + "\\" + concatNameParts(n.Parts), nil
}
if len(n.Parts) > 1 {
// if name qualified, replace first part by alias
return aliasName + "\\" + concatNameParts(n.Parts[1:]), nil
}
return aliasName, nil
}
return "", errors.New("must be instance of name.Names")
} | [
"func",
"(",
"ns",
"*",
"Namespace",
")",
"ResolveName",
"(",
"nameNode",
"node",
".",
"Node",
",",
"aliasType",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"switch",
"n",
":=",
"nameNode",
".",
"(",
"type",
")",
"{",
"case",
"*",
"name",
".",
"FullyQualified",
":",
"// Fully qualifid name is already resolved",
"return",
"concatNameParts",
"(",
"n",
".",
"Parts",
")",
",",
"nil",
"\n\n",
"case",
"*",
"name",
".",
"Relative",
":",
"if",
"ns",
".",
"Namespace",
"==",
"\"",
"\"",
"{",
"return",
"concatNameParts",
"(",
"n",
".",
"Parts",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"ns",
".",
"Namespace",
"+",
"\"",
"\\\\",
"\"",
"+",
"concatNameParts",
"(",
"n",
".",
"Parts",
")",
",",
"nil",
"\n\n",
"case",
"*",
"name",
".",
"Name",
":",
"if",
"aliasType",
"==",
"\"",
"\"",
"&&",
"len",
"(",
"n",
".",
"Parts",
")",
"==",
"1",
"{",
"part",
":=",
"strings",
".",
"ToLower",
"(",
"n",
".",
"Parts",
"[",
"0",
"]",
".",
"(",
"*",
"name",
".",
"NamePart",
")",
".",
"Value",
")",
"\n",
"if",
"part",
"==",
"\"",
"\"",
"||",
"part",
"==",
"\"",
"\"",
"||",
"part",
"==",
"\"",
"\"",
"{",
"return",
"part",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"aliasType",
"==",
"\"",
"\"",
"&&",
"len",
"(",
"n",
".",
"Parts",
")",
"==",
"1",
"{",
"part",
":=",
"strings",
".",
"ToLower",
"(",
"n",
".",
"Parts",
"[",
"0",
"]",
".",
"(",
"*",
"name",
".",
"NamePart",
")",
".",
"Value",
")",
"\n\n",
"switch",
"part",
"{",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"return",
"part",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"aliasName",
",",
"err",
":=",
"ns",
".",
"ResolveAlias",
"(",
"nameNode",
",",
"aliasType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// resolve as relative name if alias not found",
"if",
"ns",
".",
"Namespace",
"==",
"\"",
"\"",
"{",
"return",
"concatNameParts",
"(",
"n",
".",
"Parts",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"ns",
".",
"Namespace",
"+",
"\"",
"\\\\",
"\"",
"+",
"concatNameParts",
"(",
"n",
".",
"Parts",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"n",
".",
"Parts",
")",
">",
"1",
"{",
"// if name qualified, replace first part by alias",
"return",
"aliasName",
"+",
"\"",
"\\\\",
"\"",
"+",
"concatNameParts",
"(",
"n",
".",
"Parts",
"[",
"1",
":",
"]",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"aliasName",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ResolveName returns a resolved fully qualified name | [
"ResolveName",
"returns",
"a",
"resolved",
"fully",
"qualified",
"name"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/visitor/namespace_resolver.go#L287-L352 |
6,030 | z7zmey/php-parser | visitor/namespace_resolver.go | ResolveAlias | func (ns *Namespace) ResolveAlias(nameNode node.Node, aliasType string) (string, error) {
aliasType = strings.ToLower(aliasType)
nameParts := nameNode.(*name.Name).Parts
firstPartStr := nameParts[0].(*name.NamePart).Value
if len(nameParts) > 1 { // resolve aliases for qualified names, always against class alias type
firstPartStr = strings.ToLower(firstPartStr)
aliasType = ""
} else {
if aliasType != "const" { // constants are case-sensitive
firstPartStr = strings.ToLower(firstPartStr)
}
}
aliasName, ok := ns.Aliases[aliasType][firstPartStr]
if !ok {
return "", errors.New("Not found")
}
return aliasName, nil
} | go | func (ns *Namespace) ResolveAlias(nameNode node.Node, aliasType string) (string, error) {
aliasType = strings.ToLower(aliasType)
nameParts := nameNode.(*name.Name).Parts
firstPartStr := nameParts[0].(*name.NamePart).Value
if len(nameParts) > 1 { // resolve aliases for qualified names, always against class alias type
firstPartStr = strings.ToLower(firstPartStr)
aliasType = ""
} else {
if aliasType != "const" { // constants are case-sensitive
firstPartStr = strings.ToLower(firstPartStr)
}
}
aliasName, ok := ns.Aliases[aliasType][firstPartStr]
if !ok {
return "", errors.New("Not found")
}
return aliasName, nil
} | [
"func",
"(",
"ns",
"*",
"Namespace",
")",
"ResolveAlias",
"(",
"nameNode",
"node",
".",
"Node",
",",
"aliasType",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"aliasType",
"=",
"strings",
".",
"ToLower",
"(",
"aliasType",
")",
"\n",
"nameParts",
":=",
"nameNode",
".",
"(",
"*",
"name",
".",
"Name",
")",
".",
"Parts",
"\n\n",
"firstPartStr",
":=",
"nameParts",
"[",
"0",
"]",
".",
"(",
"*",
"name",
".",
"NamePart",
")",
".",
"Value",
"\n\n",
"if",
"len",
"(",
"nameParts",
")",
">",
"1",
"{",
"// resolve aliases for qualified names, always against class alias type",
"firstPartStr",
"=",
"strings",
".",
"ToLower",
"(",
"firstPartStr",
")",
"\n",
"aliasType",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"if",
"aliasType",
"!=",
"\"",
"\"",
"{",
"// constants are case-sensitive",
"firstPartStr",
"=",
"strings",
".",
"ToLower",
"(",
"firstPartStr",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"aliasName",
",",
"ok",
":=",
"ns",
".",
"Aliases",
"[",
"aliasType",
"]",
"[",
"firstPartStr",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"aliasName",
",",
"nil",
"\n",
"}"
] | // ResolveAlias returns alias or error if not found | [
"ResolveAlias",
"returns",
"alias",
"or",
"error",
"if",
"not",
"found"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/visitor/namespace_resolver.go#L355-L376 |
6,031 | z7zmey/php-parser | node/stmt/n_trait_use_alias.go | NewTraitUseAlias | func NewTraitUseAlias(Ref node.Node, Modifier node.Node, Alias node.Node) *TraitUseAlias {
return &TraitUseAlias{
FreeFloating: nil,
Ref: Ref,
Modifier: Modifier,
Alias: Alias,
}
} | go | func NewTraitUseAlias(Ref node.Node, Modifier node.Node, Alias node.Node) *TraitUseAlias {
return &TraitUseAlias{
FreeFloating: nil,
Ref: Ref,
Modifier: Modifier,
Alias: Alias,
}
} | [
"func",
"NewTraitUseAlias",
"(",
"Ref",
"node",
".",
"Node",
",",
"Modifier",
"node",
".",
"Node",
",",
"Alias",
"node",
".",
"Node",
")",
"*",
"TraitUseAlias",
"{",
"return",
"&",
"TraitUseAlias",
"{",
"FreeFloating",
":",
"nil",
",",
"Ref",
":",
"Ref",
",",
"Modifier",
":",
"Modifier",
",",
"Alias",
":",
"Alias",
",",
"}",
"\n",
"}"
] | // NewTraitUseAlias node constructor | [
"NewTraitUseAlias",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_trait_use_alias.go#L20-L27 |
6,032 | z7zmey/php-parser | node/expr/binary/n_equal.go | NewEqual | func NewEqual(Variable node.Node, Expression node.Node) *Equal {
return &Equal{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewEqual(Variable node.Node, Expression node.Node) *Equal {
return &Equal{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewEqual",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"Equal",
"{",
"return",
"&",
"Equal",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewEqual node constructor | [
"NewEqual",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_equal.go#L19-L25 |
6,033 | z7zmey/php-parser | node/expr/n_clone.go | NewClone | func NewClone(Expression node.Node) *Clone {
return &Clone{
FreeFloating: nil,
Expr: Expression,
}
} | go | func NewClone(Expression node.Node) *Clone {
return &Clone{
FreeFloating: nil,
Expr: Expression,
}
} | [
"func",
"NewClone",
"(",
"Expression",
"node",
".",
"Node",
")",
"*",
"Clone",
"{",
"return",
"&",
"Clone",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewClone node constructor | [
"NewClone",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_clone.go#L18-L23 |
6,034 | z7zmey/php-parser | node/expr/binary/n_mul.go | NewMul | func NewMul(Variable node.Node, Expression node.Node) *Mul {
return &Mul{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewMul(Variable node.Node, Expression node.Node) *Mul {
return &Mul{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewMul",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"Mul",
"{",
"return",
"&",
"Mul",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewMul node constructor | [
"NewMul",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_mul.go#L19-L25 |
6,035 | z7zmey/php-parser | node/expr/n_eval.go | NewEval | func NewEval(Expression node.Node) *Eval {
return &Eval{
FreeFloating: nil,
Expr: Expression,
}
} | go | func NewEval(Expression node.Node) *Eval {
return &Eval{
FreeFloating: nil,
Expr: Expression,
}
} | [
"func",
"NewEval",
"(",
"Expression",
"node",
".",
"Node",
")",
"*",
"Eval",
"{",
"return",
"&",
"Eval",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewEval node constructor | [
"NewEval",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_eval.go#L18-L23 |
6,036 | z7zmey/php-parser | node/stmt/n_case_list.go | NewCaseList | func NewCaseList(Cases []node.Node) *CaseList {
return &CaseList{
FreeFloating: nil,
Cases: Cases,
}
} | go | func NewCaseList(Cases []node.Node) *CaseList {
return &CaseList{
FreeFloating: nil,
Cases: Cases,
}
} | [
"func",
"NewCaseList",
"(",
"Cases",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"CaseList",
"{",
"return",
"&",
"CaseList",
"{",
"FreeFloating",
":",
"nil",
",",
"Cases",
":",
"Cases",
",",
"}",
"\n",
"}"
] | // NewCaseList node constructor | [
"NewCaseList",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_case_list.go#L18-L23 |
6,037 | z7zmey/php-parser | scanner/lexer.go | Rune2Class | func Rune2Class(r rune) int {
if r >= 0 && r < 0x80 { // Keep ASCII as it is.
return int(r)
}
if unicode.IsLetter(r) {
return classUnicodeLeter
}
if unicode.IsDigit(r) {
return classUnicodeDigit
}
if unicode.IsGraphic(r) {
return classUnicodeGraphic
}
if r == lex.RuneEOF {
return int(r)
}
return classOther
} | go | func Rune2Class(r rune) int {
if r >= 0 && r < 0x80 { // Keep ASCII as it is.
return int(r)
}
if unicode.IsLetter(r) {
return classUnicodeLeter
}
if unicode.IsDigit(r) {
return classUnicodeDigit
}
if unicode.IsGraphic(r) {
return classUnicodeGraphic
}
if r == lex.RuneEOF {
return int(r)
}
return classOther
} | [
"func",
"Rune2Class",
"(",
"r",
"rune",
")",
"int",
"{",
"if",
"r",
">=",
"0",
"&&",
"r",
"<",
"0x80",
"{",
"// Keep ASCII as it is.",
"return",
"int",
"(",
"r",
")",
"\n",
"}",
"\n",
"if",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"{",
"return",
"classUnicodeLeter",
"\n",
"}",
"\n",
"if",
"unicode",
".",
"IsDigit",
"(",
"r",
")",
"{",
"return",
"classUnicodeDigit",
"\n",
"}",
"\n",
"if",
"unicode",
".",
"IsGraphic",
"(",
"r",
")",
"{",
"return",
"classUnicodeGraphic",
"\n",
"}",
"\n",
"if",
"r",
"==",
"lex",
".",
"RuneEOF",
"{",
"return",
"int",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"classOther",
"\n",
"}"
] | // Rune2Class returns the rune integer id | [
"Rune2Class",
"returns",
"the",
"rune",
"integer",
"id"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/scanner/lexer.go#L46-L63 |
6,038 | z7zmey/php-parser | scanner/lexer.go | NewLexer | func NewLexer(src io.Reader, fName string) *Lexer {
file := t.NewFileSet().AddFile(fName, -1, 1<<31-3)
lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(Rune2Class))
if err != nil {
panic(err)
}
return &Lexer{
Lexer: lx,
StateStack: []int{0},
PhpDocComment: "",
FreeFloating: nil,
heredocLabel: "",
tokenBytesBuf: &bytes.Buffer{},
TokenPool: &TokenPool{},
}
} | go | func NewLexer(src io.Reader, fName string) *Lexer {
file := t.NewFileSet().AddFile(fName, -1, 1<<31-3)
lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(Rune2Class))
if err != nil {
panic(err)
}
return &Lexer{
Lexer: lx,
StateStack: []int{0},
PhpDocComment: "",
FreeFloating: nil,
heredocLabel: "",
tokenBytesBuf: &bytes.Buffer{},
TokenPool: &TokenPool{},
}
} | [
"func",
"NewLexer",
"(",
"src",
"io",
".",
"Reader",
",",
"fName",
"string",
")",
"*",
"Lexer",
"{",
"file",
":=",
"t",
".",
"NewFileSet",
"(",
")",
".",
"AddFile",
"(",
"fName",
",",
"-",
"1",
",",
"1",
"<<",
"31",
"-",
"3",
")",
"\n",
"lx",
",",
"err",
":=",
"lex",
".",
"New",
"(",
"file",
",",
"bufio",
".",
"NewReader",
"(",
"src",
")",
",",
"lex",
".",
"RuneClass",
"(",
"Rune2Class",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Lexer",
"{",
"Lexer",
":",
"lx",
",",
"StateStack",
":",
"[",
"]",
"int",
"{",
"0",
"}",
",",
"PhpDocComment",
":",
"\"",
"\"",
",",
"FreeFloating",
":",
"nil",
",",
"heredocLabel",
":",
"\"",
"\"",
",",
"tokenBytesBuf",
":",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
",",
"TokenPool",
":",
"&",
"TokenPool",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewLexer the Lexer constructor | [
"NewLexer",
"the",
"Lexer",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/scanner/lexer.go#L66-L82 |
6,039 | z7zmey/php-parser | scanner/lexer.go | addFreeFloating | func (l *Lexer) addFreeFloating(t freefloating.StringType, chars []lex.Char) {
if !l.WithFreeFloating {
return
}
firstChar := chars[0]
lastChar := chars[len(chars)-1]
pos := position.NewPosition(
l.File.Line(firstChar.Pos()),
l.File.Line(lastChar.Pos()),
int(firstChar.Pos()),
int(lastChar.Pos()),
)
l.FreeFloating = append(l.FreeFloating, freefloating.String{
StringType: t,
Value: l.tokenString(chars),
Position: pos,
})
} | go | func (l *Lexer) addFreeFloating(t freefloating.StringType, chars []lex.Char) {
if !l.WithFreeFloating {
return
}
firstChar := chars[0]
lastChar := chars[len(chars)-1]
pos := position.NewPosition(
l.File.Line(firstChar.Pos()),
l.File.Line(lastChar.Pos()),
int(firstChar.Pos()),
int(lastChar.Pos()),
)
l.FreeFloating = append(l.FreeFloating, freefloating.String{
StringType: t,
Value: l.tokenString(chars),
Position: pos,
})
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"addFreeFloating",
"(",
"t",
"freefloating",
".",
"StringType",
",",
"chars",
"[",
"]",
"lex",
".",
"Char",
")",
"{",
"if",
"!",
"l",
".",
"WithFreeFloating",
"{",
"return",
"\n",
"}",
"\n\n",
"firstChar",
":=",
"chars",
"[",
"0",
"]",
"\n",
"lastChar",
":=",
"chars",
"[",
"len",
"(",
"chars",
")",
"-",
"1",
"]",
"\n\n",
"pos",
":=",
"position",
".",
"NewPosition",
"(",
"l",
".",
"File",
".",
"Line",
"(",
"firstChar",
".",
"Pos",
"(",
")",
")",
",",
"l",
".",
"File",
".",
"Line",
"(",
"lastChar",
".",
"Pos",
"(",
")",
")",
",",
"int",
"(",
"firstChar",
".",
"Pos",
"(",
")",
")",
",",
"int",
"(",
"lastChar",
".",
"Pos",
"(",
")",
")",
",",
")",
"\n\n",
"l",
".",
"FreeFloating",
"=",
"append",
"(",
"l",
".",
"FreeFloating",
",",
"freefloating",
".",
"String",
"{",
"StringType",
":",
"t",
",",
"Value",
":",
"l",
".",
"tokenString",
"(",
"chars",
")",
",",
"Position",
":",
"pos",
",",
"}",
")",
"\n",
"}"
] | // free-floating | [
"free",
"-",
"floating"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/scanner/lexer.go#L168-L188 |
6,040 | z7zmey/php-parser | node/expr/n_list.go | NewList | func NewList(Items []node.Node) *List {
return &List{
FreeFloating: nil,
Items: Items,
}
} | go | func NewList(Items []node.Node) *List {
return &List{
FreeFloating: nil,
Items: Items,
}
} | [
"func",
"NewList",
"(",
"Items",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"List",
"{",
"return",
"&",
"List",
"{",
"FreeFloating",
":",
"nil",
",",
"Items",
":",
"Items",
",",
"}",
"\n",
"}"
] | // NewList node constructor | [
"NewList",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_list.go#L18-L23 |
6,041 | z7zmey/php-parser | node/expr/binary/n_bitwise_and.go | NewBitwiseAnd | func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
return &BitwiseAnd{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
return &BitwiseAnd{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewBitwiseAnd",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"BitwiseAnd",
"{",
"return",
"&",
"BitwiseAnd",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewBitwiseAnd node constructor | [
"NewBitwiseAnd",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_bitwise_and.go#L19-L25 |
6,042 | z7zmey/php-parser | node/expr/n_ternary.go | NewTernary | func NewTernary(Condition node.Node, IfTrue node.Node, IfFalse node.Node) *Ternary {
return &Ternary{
FreeFloating: nil,
Condition: Condition,
IfTrue: IfTrue,
IfFalse: IfFalse,
}
} | go | func NewTernary(Condition node.Node, IfTrue node.Node, IfFalse node.Node) *Ternary {
return &Ternary{
FreeFloating: nil,
Condition: Condition,
IfTrue: IfTrue,
IfFalse: IfFalse,
}
} | [
"func",
"NewTernary",
"(",
"Condition",
"node",
".",
"Node",
",",
"IfTrue",
"node",
".",
"Node",
",",
"IfFalse",
"node",
".",
"Node",
")",
"*",
"Ternary",
"{",
"return",
"&",
"Ternary",
"{",
"FreeFloating",
":",
"nil",
",",
"Condition",
":",
"Condition",
",",
"IfTrue",
":",
"IfTrue",
",",
"IfFalse",
":",
"IfFalse",
",",
"}",
"\n",
"}"
] | // NewTernary node constructor | [
"NewTernary",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_ternary.go#L20-L27 |
6,043 | z7zmey/php-parser | printer/pretty_printer.go | NewPrettyPrinter | func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter {
return &PrettyPrinter{
w: w,
indentStr: indentStr,
indentDepth: 0,
}
} | go | func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter {
return &PrettyPrinter{
w: w,
indentStr: indentStr,
indentDepth: 0,
}
} | [
"func",
"NewPrettyPrinter",
"(",
"w",
"io",
".",
"Writer",
",",
"indentStr",
"string",
")",
"*",
"PrettyPrinter",
"{",
"return",
"&",
"PrettyPrinter",
"{",
"w",
":",
"w",
",",
"indentStr",
":",
"indentStr",
",",
"indentDepth",
":",
"0",
",",
"}",
"\n",
"}"
] | // NewPrettyPrinter - Constructor for PrettyPrinter | [
"NewPrettyPrinter",
"-",
"Constructor",
"for",
"PrettyPrinter"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/printer/pretty_printer.go#L25-L31 |
6,044 | z7zmey/php-parser | node/stmt/n_namespace.go | NewNamespace | func NewNamespace(NamespaceName node.Node, Stmts []node.Node) *Namespace {
return &Namespace{
FreeFloating: nil,
NamespaceName: NamespaceName,
Stmts: Stmts,
}
} | go | func NewNamespace(NamespaceName node.Node, Stmts []node.Node) *Namespace {
return &Namespace{
FreeFloating: nil,
NamespaceName: NamespaceName,
Stmts: Stmts,
}
} | [
"func",
"NewNamespace",
"(",
"NamespaceName",
"node",
".",
"Node",
",",
"Stmts",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"Namespace",
"{",
"return",
"&",
"Namespace",
"{",
"FreeFloating",
":",
"nil",
",",
"NamespaceName",
":",
"NamespaceName",
",",
"Stmts",
":",
"Stmts",
",",
"}",
"\n",
"}"
] | // NewNamespace node constructor | [
"NewNamespace",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_namespace.go#L19-L25 |
6,045 | z7zmey/php-parser | node/expr/n_require.go | NewRequire | func NewRequire(Expression node.Node) *Require {
return &Require{
FreeFloating: nil,
Expr: Expression,
}
} | go | func NewRequire(Expression node.Node) *Require {
return &Require{
FreeFloating: nil,
Expr: Expression,
}
} | [
"func",
"NewRequire",
"(",
"Expression",
"node",
".",
"Node",
")",
"*",
"Require",
"{",
"return",
"&",
"Require",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewRequire node constructor | [
"NewRequire",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_require.go#L18-L23 |
6,046 | z7zmey/php-parser | node/stmt/n_foreach.go | NewForeach | func NewForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *Foreach {
return &Foreach{
FreeFloating: nil,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
} | go | func NewForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *Foreach {
return &Foreach{
FreeFloating: nil,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
} | [
"func",
"NewForeach",
"(",
"Expr",
"node",
".",
"Node",
",",
"Key",
"node",
".",
"Node",
",",
"Variable",
"node",
".",
"Node",
",",
"Stmt",
"node",
".",
"Node",
")",
"*",
"Foreach",
"{",
"return",
"&",
"Foreach",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expr",
",",
"Key",
":",
"Key",
",",
"Variable",
":",
"Variable",
",",
"Stmt",
":",
"Stmt",
",",
"}",
"\n",
"}"
] | // NewForeach node constructor | [
"NewForeach",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_foreach.go#L21-L29 |
6,047 | z7zmey/php-parser | node/expr/binary/n_coalesce.go | NewCoalesce | func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
return &Coalesce{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
return &Coalesce{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewCoalesce",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"Coalesce",
"{",
"return",
"&",
"Coalesce",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewCoalesce node constructor | [
"NewCoalesce",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_coalesce.go#L19-L25 |
6,048 | z7zmey/php-parser | node/expr/binary/n_smaller.go | NewSmaller | func NewSmaller(Variable node.Node, Expression node.Node) *Smaller {
return &Smaller{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewSmaller(Variable node.Node, Expression node.Node) *Smaller {
return &Smaller{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewSmaller",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"Smaller",
"{",
"return",
"&",
"Smaller",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewSmaller node constructor | [
"NewSmaller",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_smaller.go#L19-L25 |
6,049 | z7zmey/php-parser | node/stmt/n_stmt_list.go | NewStmtList | func NewStmtList(Stmts []node.Node) *StmtList {
return &StmtList{
FreeFloating: nil,
Stmts: Stmts,
}
} | go | func NewStmtList(Stmts []node.Node) *StmtList {
return &StmtList{
FreeFloating: nil,
Stmts: Stmts,
}
} | [
"func",
"NewStmtList",
"(",
"Stmts",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"StmtList",
"{",
"return",
"&",
"StmtList",
"{",
"FreeFloating",
":",
"nil",
",",
"Stmts",
":",
"Stmts",
",",
"}",
"\n",
"}"
] | // NewStmtList node constructor | [
"NewStmtList",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_stmt_list.go#L18-L23 |
6,050 | z7zmey/php-parser | node/expr/binary/n_concat.go | NewConcat | func NewConcat(Variable node.Node, Expression node.Node) *Concat {
return &Concat{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewConcat(Variable node.Node, Expression node.Node) *Concat {
return &Concat{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewConcat",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"Concat",
"{",
"return",
"&",
"Concat",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewConcat node constructor | [
"NewConcat",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_concat.go#L19-L25 |
6,051 | z7zmey/php-parser | node/stmt/n_alt_switch.go | NewAltSwitch | func NewAltSwitch(Cond node.Node, CaseList *CaseList) *AltSwitch {
return &AltSwitch{
FreeFloating: nil,
Cond: Cond,
CaseList: CaseList,
}
} | go | func NewAltSwitch(Cond node.Node, CaseList *CaseList) *AltSwitch {
return &AltSwitch{
FreeFloating: nil,
Cond: Cond,
CaseList: CaseList,
}
} | [
"func",
"NewAltSwitch",
"(",
"Cond",
"node",
".",
"Node",
",",
"CaseList",
"*",
"CaseList",
")",
"*",
"AltSwitch",
"{",
"return",
"&",
"AltSwitch",
"{",
"FreeFloating",
":",
"nil",
",",
"Cond",
":",
"Cond",
",",
"CaseList",
":",
"CaseList",
",",
"}",
"\n",
"}"
] | // NewAltSwitch node constructor | [
"NewAltSwitch",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_alt_switch.go#L19-L25 |
6,052 | z7zmey/php-parser | node/stmt/n_else_if.go | NewElseIf | func NewElseIf(Cond node.Node, Stmt node.Node) *ElseIf {
return &ElseIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
}
} | go | func NewElseIf(Cond node.Node, Stmt node.Node) *ElseIf {
return &ElseIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
}
} | [
"func",
"NewElseIf",
"(",
"Cond",
"node",
".",
"Node",
",",
"Stmt",
"node",
".",
"Node",
")",
"*",
"ElseIf",
"{",
"return",
"&",
"ElseIf",
"{",
"FreeFloating",
":",
"nil",
",",
"Cond",
":",
"Cond",
",",
"Stmt",
":",
"Stmt",
",",
"}",
"\n",
"}"
] | // NewElseIf node constructor | [
"NewElseIf",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_else_if.go#L19-L25 |
6,053 | z7zmey/php-parser | node/stmt/n_declare.go | NewDeclare | func NewDeclare(Consts []node.Node, Stmt node.Node, alt bool) *Declare {
return &Declare{
FreeFloating: nil,
Consts: Consts,
Stmt: Stmt,
Alt: alt,
}
} | go | func NewDeclare(Consts []node.Node, Stmt node.Node, alt bool) *Declare {
return &Declare{
FreeFloating: nil,
Consts: Consts,
Stmt: Stmt,
Alt: alt,
}
} | [
"func",
"NewDeclare",
"(",
"Consts",
"[",
"]",
"node",
".",
"Node",
",",
"Stmt",
"node",
".",
"Node",
",",
"alt",
"bool",
")",
"*",
"Declare",
"{",
"return",
"&",
"Declare",
"{",
"FreeFloating",
":",
"nil",
",",
"Consts",
":",
"Consts",
",",
"Stmt",
":",
"Stmt",
",",
"Alt",
":",
"alt",
",",
"}",
"\n",
"}"
] | // NewDeclare node constructor | [
"NewDeclare",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_declare.go#L20-L27 |
6,054 | z7zmey/php-parser | node/expr/binary/n_minus.go | NewMinus | func NewMinus(Variable node.Node, Expression node.Node) *Minus {
return &Minus{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | go | func NewMinus(Variable node.Node, Expression node.Node) *Minus {
return &Minus{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
} | [
"func",
"NewMinus",
"(",
"Variable",
"node",
".",
"Node",
",",
"Expression",
"node",
".",
"Node",
")",
"*",
"Minus",
"{",
"return",
"&",
"Minus",
"{",
"FreeFloating",
":",
"nil",
",",
"Left",
":",
"Variable",
",",
"Right",
":",
"Expression",
",",
"}",
"\n",
"}"
] | // NewMinus node constructor | [
"NewMinus",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/binary/n_minus.go#L19-L25 |
6,055 | z7zmey/php-parser | node/name/n_relative.go | NewRelative | func NewRelative(Parts []node.Node) *Relative {
return &Relative{
FreeFloating: nil,
Parts: Parts,
}
} | go | func NewRelative(Parts []node.Node) *Relative {
return &Relative{
FreeFloating: nil,
Parts: Parts,
}
} | [
"func",
"NewRelative",
"(",
"Parts",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"Relative",
"{",
"return",
"&",
"Relative",
"{",
"FreeFloating",
":",
"nil",
",",
"Parts",
":",
"Parts",
",",
"}",
"\n",
"}"
] | // NewRelative node constructor | [
"NewRelative",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/name/n_relative.go#L18-L23 |
6,056 | z7zmey/php-parser | node/stmt/n_continue.go | NewContinue | func NewContinue(Expr node.Node) *Continue {
return &Continue{
FreeFloating: nil,
Expr: Expr,
}
} | go | func NewContinue(Expr node.Node) *Continue {
return &Continue{
FreeFloating: nil,
Expr: Expr,
}
} | [
"func",
"NewContinue",
"(",
"Expr",
"node",
".",
"Node",
")",
"*",
"Continue",
"{",
"return",
"&",
"Continue",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expr",
",",
"}",
"\n",
"}"
] | // NewContinue node constructor | [
"NewContinue",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_continue.go#L18-L23 |
6,057 | z7zmey/php-parser | node/expr/n_array_dim_fetch.go | NewArrayDimFetch | func NewArrayDimFetch(Variable node.Node, Dim node.Node) *ArrayDimFetch {
return &ArrayDimFetch{
FreeFloating: nil,
Variable: Variable,
Dim: Dim,
}
} | go | func NewArrayDimFetch(Variable node.Node, Dim node.Node) *ArrayDimFetch {
return &ArrayDimFetch{
FreeFloating: nil,
Variable: Variable,
Dim: Dim,
}
} | [
"func",
"NewArrayDimFetch",
"(",
"Variable",
"node",
".",
"Node",
",",
"Dim",
"node",
".",
"Node",
")",
"*",
"ArrayDimFetch",
"{",
"return",
"&",
"ArrayDimFetch",
"{",
"FreeFloating",
":",
"nil",
",",
"Variable",
":",
"Variable",
",",
"Dim",
":",
"Dim",
",",
"}",
"\n",
"}"
] | // NewArrayDimFetch node constructor | [
"NewArrayDimFetch",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_array_dim_fetch.go#L19-L25 |
6,058 | z7zmey/php-parser | node/stmt/n_global.go | NewGlobal | func NewGlobal(Vars []node.Node) *Global {
return &Global{
FreeFloating: nil,
Vars: Vars,
}
} | go | func NewGlobal(Vars []node.Node) *Global {
return &Global{
FreeFloating: nil,
Vars: Vars,
}
} | [
"func",
"NewGlobal",
"(",
"Vars",
"[",
"]",
"node",
".",
"Node",
")",
"*",
"Global",
"{",
"return",
"&",
"Global",
"{",
"FreeFloating",
":",
"nil",
",",
"Vars",
":",
"Vars",
",",
"}",
"\n",
"}"
] | // NewGlobal node constructor | [
"NewGlobal",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_global.go#L18-L23 |
6,059 | z7zmey/php-parser | position/position.go | NewPosition | func NewPosition(StartLine int, EndLine int, StartPos int, EndPos int) *Position {
return &Position{
StartLine: StartLine,
EndLine: EndLine,
StartPos: StartPos,
EndPos: EndPos,
}
} | go | func NewPosition(StartLine int, EndLine int, StartPos int, EndPos int) *Position {
return &Position{
StartLine: StartLine,
EndLine: EndLine,
StartPos: StartPos,
EndPos: EndPos,
}
} | [
"func",
"NewPosition",
"(",
"StartLine",
"int",
",",
"EndLine",
"int",
",",
"StartPos",
"int",
",",
"EndPos",
"int",
")",
"*",
"Position",
"{",
"return",
"&",
"Position",
"{",
"StartLine",
":",
"StartLine",
",",
"EndLine",
":",
"EndLine",
",",
"StartPos",
":",
"StartPos",
",",
"EndPos",
":",
"EndPos",
",",
"}",
"\n",
"}"
] | // NewPosition Position constructor | [
"NewPosition",
"Position",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/position/position.go#L16-L23 |
6,060 | z7zmey/php-parser | node/expr/n_post_inc.go | NewPostInc | func NewPostInc(Variable node.Node) *PostInc {
return &PostInc{
FreeFloating: nil,
Variable: Variable,
}
} | go | func NewPostInc(Variable node.Node) *PostInc {
return &PostInc{
FreeFloating: nil,
Variable: Variable,
}
} | [
"func",
"NewPostInc",
"(",
"Variable",
"node",
".",
"Node",
")",
"*",
"PostInc",
"{",
"return",
"&",
"PostInc",
"{",
"FreeFloating",
":",
"nil",
",",
"Variable",
":",
"Variable",
",",
"}",
"\n",
"}"
] | // NewPostInc node constructor | [
"NewPostInc",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/expr/n_post_inc.go#L18-L23 |
6,061 | z7zmey/php-parser | node/stmt/n_alt_foreach.go | NewAltForeach | func NewAltForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *AltForeach {
return &AltForeach{
FreeFloating: nil,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
} | go | func NewAltForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *AltForeach {
return &AltForeach{
FreeFloating: nil,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
} | [
"func",
"NewAltForeach",
"(",
"Expr",
"node",
".",
"Node",
",",
"Key",
"node",
".",
"Node",
",",
"Variable",
"node",
".",
"Node",
",",
"Stmt",
"node",
".",
"Node",
")",
"*",
"AltForeach",
"{",
"return",
"&",
"AltForeach",
"{",
"FreeFloating",
":",
"nil",
",",
"Expr",
":",
"Expr",
",",
"Key",
":",
"Key",
",",
"Variable",
":",
"Variable",
",",
"Stmt",
":",
"Stmt",
",",
"}",
"\n",
"}"
] | // NewAltForeach node constructor | [
"NewAltForeach",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_alt_foreach.go#L21-L29 |
6,062 | z7zmey/php-parser | node/stmt/n_goto.go | NewGoto | func NewGoto(Label node.Node) *Goto {
return &Goto{
FreeFloating: nil,
Label: Label,
}
} | go | func NewGoto(Label node.Node) *Goto {
return &Goto{
FreeFloating: nil,
Label: Label,
}
} | [
"func",
"NewGoto",
"(",
"Label",
"node",
".",
"Node",
")",
"*",
"Goto",
"{",
"return",
"&",
"Goto",
"{",
"FreeFloating",
":",
"nil",
",",
"Label",
":",
"Label",
",",
"}",
"\n",
"}"
] | // NewGoto node constructor | [
"NewGoto",
"node",
"constructor"
] | 394f8821001f38fe5b4c4aaffd4fa20e50927a3f | https://github.com/z7zmey/php-parser/blob/394f8821001f38fe5b4c4aaffd4fa20e50927a3f/node/stmt/n_goto.go#L18-L23 |
6,063 | disintegration/gift | colors.go | Invert | func Invert() Filter {
return &colorchanFilter{
fn: func(x float32) float32 {
return 1 - x
},
lut: false,
}
} | go | func Invert() Filter {
return &colorchanFilter{
fn: func(x float32) float32 {
return 1 - x
},
lut: false,
}
} | [
"func",
"Invert",
"(",
")",
"Filter",
"{",
"return",
"&",
"colorchanFilter",
"{",
"fn",
":",
"func",
"(",
"x",
"float32",
")",
"float32",
"{",
"return",
"1",
"-",
"x",
"\n",
"}",
",",
"lut",
":",
"false",
",",
"}",
"\n",
"}"
] | // Invert creates a filter that negates the colors of an image. | [
"Invert",
"creates",
"a",
"filter",
"that",
"negates",
"the",
"colors",
"of",
"an",
"image",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/colors.go#L85-L92 |
6,064 | disintegration/gift | colors.go | ColorspaceSRGBToLinear | func ColorspaceSRGBToLinear() Filter {
return &colorchanFilter{
fn: func(x float32) float32 {
if x <= 0.04045 {
return x / 12.92
}
return float32(math.Pow(float64((x+0.055)/1.055), 2.4))
},
lut: true,
}
} | go | func ColorspaceSRGBToLinear() Filter {
return &colorchanFilter{
fn: func(x float32) float32 {
if x <= 0.04045 {
return x / 12.92
}
return float32(math.Pow(float64((x+0.055)/1.055), 2.4))
},
lut: true,
}
} | [
"func",
"ColorspaceSRGBToLinear",
"(",
")",
"Filter",
"{",
"return",
"&",
"colorchanFilter",
"{",
"fn",
":",
"func",
"(",
"x",
"float32",
")",
"float32",
"{",
"if",
"x",
"<=",
"0.04045",
"{",
"return",
"x",
"/",
"12.92",
"\n",
"}",
"\n",
"return",
"float32",
"(",
"math",
".",
"Pow",
"(",
"float64",
"(",
"(",
"x",
"+",
"0.055",
")",
"/",
"1.055",
")",
",",
"2.4",
")",
")",
"\n",
"}",
",",
"lut",
":",
"true",
",",
"}",
"\n",
"}"
] | // ColorspaceSRGBToLinear creates a filter that converts the colors of an image from sRGB to linear RGB. | [
"ColorspaceSRGBToLinear",
"creates",
"a",
"filter",
"that",
"converts",
"the",
"colors",
"of",
"an",
"image",
"from",
"sRGB",
"to",
"linear",
"RGB",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/colors.go#L95-L105 |
6,065 | disintegration/gift | colors.go | Gamma | func Gamma(gamma float32) Filter {
e := 1 / maxf32(gamma, 1.0e-5)
return &colorchanFilter{
fn: func(x float32) float32 {
return powf32(x, e)
},
lut: true,
}
} | go | func Gamma(gamma float32) Filter {
e := 1 / maxf32(gamma, 1.0e-5)
return &colorchanFilter{
fn: func(x float32) float32 {
return powf32(x, e)
},
lut: true,
}
} | [
"func",
"Gamma",
"(",
"gamma",
"float32",
")",
"Filter",
"{",
"e",
":=",
"1",
"/",
"maxf32",
"(",
"gamma",
",",
"1.0e-5",
")",
"\n",
"return",
"&",
"colorchanFilter",
"{",
"fn",
":",
"func",
"(",
"x",
"float32",
")",
"float32",
"{",
"return",
"powf32",
"(",
"x",
",",
"e",
")",
"\n",
"}",
",",
"lut",
":",
"true",
",",
"}",
"\n",
"}"
] | // Gamma creates a filter that performs a gamma correction on an image.
// The gamma parameter must be positive. Gamma = 1 gives the original image.
// Gamma less than 1 darkens the image and gamma greater than 1 lightens it. | [
"Gamma",
"creates",
"a",
"filter",
"that",
"performs",
"a",
"gamma",
"correction",
"on",
"an",
"image",
".",
"The",
"gamma",
"parameter",
"must",
"be",
"positive",
".",
"Gamma",
"=",
"1",
"gives",
"the",
"original",
"image",
".",
"Gamma",
"less",
"than",
"1",
"darkens",
"the",
"image",
"and",
"gamma",
"greater",
"than",
"1",
"lightens",
"it",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/colors.go#L123-L131 |
6,066 | disintegration/gift | colors.go | Grayscale | func Grayscale() Filter {
return &colorFilter{
fn: func(px pixel) pixel {
y := 0.299*px.r + 0.587*px.g + 0.114*px.b
return pixel{y, y, y, px.a}
},
}
} | go | func Grayscale() Filter {
return &colorFilter{
fn: func(px pixel) pixel {
y := 0.299*px.r + 0.587*px.g + 0.114*px.b
return pixel{y, y, y, px.a}
},
}
} | [
"func",
"Grayscale",
"(",
")",
"Filter",
"{",
"return",
"&",
"colorFilter",
"{",
"fn",
":",
"func",
"(",
"px",
"pixel",
")",
"pixel",
"{",
"y",
":=",
"0.299",
"*",
"px",
".",
"r",
"+",
"0.587",
"*",
"px",
".",
"g",
"+",
"0.114",
"*",
"px",
".",
"b",
"\n",
"return",
"pixel",
"{",
"y",
",",
"y",
",",
"y",
",",
"px",
".",
"a",
"}",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // Grayscale creates a filter that produces a grayscale version of an image. | [
"Grayscale",
"creates",
"a",
"filter",
"that",
"produces",
"a",
"grayscale",
"version",
"of",
"an",
"image",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/colors.go#L249-L256 |
6,067 | disintegration/gift | gift.go | Add | func (g *GIFT) Add(filters ...Filter) {
g.Filters = append(g.Filters, filters...)
} | go | func (g *GIFT) Add(filters ...Filter) {
g.Filters = append(g.Filters, filters...)
} | [
"func",
"(",
"g",
"*",
"GIFT",
")",
"Add",
"(",
"filters",
"...",
"Filter",
")",
"{",
"g",
".",
"Filters",
"=",
"append",
"(",
"g",
".",
"Filters",
",",
"filters",
"...",
")",
"\n",
"}"
] | // Add appends the given filters to the list of filters. | [
"Add",
"appends",
"the",
"given",
"filters",
"to",
"the",
"list",
"of",
"filters",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/gift.go#L70-L72 |
6,068 | disintegration/gift | gift.go | Draw | func (g *GIFT) Draw(dst draw.Image, src image.Image) {
if len(g.Filters) == 0 {
copyimage(dst, src, &g.Options)
return
}
first, last := 0, len(g.Filters)-1
var tmpIn image.Image
var tmpOut draw.Image
for i, f := range g.Filters {
if i == first {
tmpIn = src
} else {
tmpIn = tmpOut
}
if i == last {
tmpOut = dst
} else {
tmpOut = createTempImage(f.Bounds(tmpIn.Bounds()))
}
f.Draw(tmpOut, tmpIn, &g.Options)
}
} | go | func (g *GIFT) Draw(dst draw.Image, src image.Image) {
if len(g.Filters) == 0 {
copyimage(dst, src, &g.Options)
return
}
first, last := 0, len(g.Filters)-1
var tmpIn image.Image
var tmpOut draw.Image
for i, f := range g.Filters {
if i == first {
tmpIn = src
} else {
tmpIn = tmpOut
}
if i == last {
tmpOut = dst
} else {
tmpOut = createTempImage(f.Bounds(tmpIn.Bounds()))
}
f.Draw(tmpOut, tmpIn, &g.Options)
}
} | [
"func",
"(",
"g",
"*",
"GIFT",
")",
"Draw",
"(",
"dst",
"draw",
".",
"Image",
",",
"src",
"image",
".",
"Image",
")",
"{",
"if",
"len",
"(",
"g",
".",
"Filters",
")",
"==",
"0",
"{",
"copyimage",
"(",
"dst",
",",
"src",
",",
"&",
"g",
".",
"Options",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"first",
",",
"last",
":=",
"0",
",",
"len",
"(",
"g",
".",
"Filters",
")",
"-",
"1",
"\n",
"var",
"tmpIn",
"image",
".",
"Image",
"\n",
"var",
"tmpOut",
"draw",
".",
"Image",
"\n\n",
"for",
"i",
",",
"f",
":=",
"range",
"g",
".",
"Filters",
"{",
"if",
"i",
"==",
"first",
"{",
"tmpIn",
"=",
"src",
"\n",
"}",
"else",
"{",
"tmpIn",
"=",
"tmpOut",
"\n",
"}",
"\n\n",
"if",
"i",
"==",
"last",
"{",
"tmpOut",
"=",
"dst",
"\n",
"}",
"else",
"{",
"tmpOut",
"=",
"createTempImage",
"(",
"f",
".",
"Bounds",
"(",
"tmpIn",
".",
"Bounds",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"f",
".",
"Draw",
"(",
"tmpOut",
",",
"tmpIn",
",",
"&",
"g",
".",
"Options",
")",
"\n",
"}",
"\n",
"}"
] | // Draw applies all the added filters to the src image and outputs the result to the dst image. | [
"Draw",
"applies",
"all",
"the",
"added",
"filters",
"to",
"the",
"src",
"image",
"and",
"outputs",
"the",
"result",
"to",
"the",
"dst",
"image",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/gift.go#L101-L126 |
6,069 | disintegration/gift | convolution.go | prepareConvolutionWeights1d | func prepareConvolutionWeights1d(kernel []float32) (int, []uweight) {
size := len(kernel)
if size%2 == 0 {
size--
}
if size < 1 {
return 0, []uweight{}
}
center := size / 2
weights := []uweight{}
for i := 0; i < size; i++ {
w := float32(0)
if i < len(kernel) {
w = kernel[i]
}
if w != 0 {
weights = append(weights, uweight{i - center, w})
}
}
return size, weights
} | go | func prepareConvolutionWeights1d(kernel []float32) (int, []uweight) {
size := len(kernel)
if size%2 == 0 {
size--
}
if size < 1 {
return 0, []uweight{}
}
center := size / 2
weights := []uweight{}
for i := 0; i < size; i++ {
w := float32(0)
if i < len(kernel) {
w = kernel[i]
}
if w != 0 {
weights = append(weights, uweight{i - center, w})
}
}
return size, weights
} | [
"func",
"prepareConvolutionWeights1d",
"(",
"kernel",
"[",
"]",
"float32",
")",
"(",
"int",
",",
"[",
"]",
"uweight",
")",
"{",
"size",
":=",
"len",
"(",
"kernel",
")",
"\n",
"if",
"size",
"%",
"2",
"==",
"0",
"{",
"size",
"--",
"\n",
"}",
"\n",
"if",
"size",
"<",
"1",
"{",
"return",
"0",
",",
"[",
"]",
"uweight",
"{",
"}",
"\n",
"}",
"\n",
"center",
":=",
"size",
"/",
"2",
"\n",
"weights",
":=",
"[",
"]",
"uweight",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
"{",
"w",
":=",
"float32",
"(",
"0",
")",
"\n",
"if",
"i",
"<",
"len",
"(",
"kernel",
")",
"{",
"w",
"=",
"kernel",
"[",
"i",
"]",
"\n",
"}",
"\n",
"if",
"w",
"!=",
"0",
"{",
"weights",
"=",
"append",
"(",
"weights",
",",
"uweight",
"{",
"i",
"-",
"center",
",",
"w",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"size",
",",
"weights",
"\n",
"}"
] | // prepareConvolutionWeights1d prepares pixel weights using a convolution kernel.
// Weights equal to 0 are excluded. | [
"prepareConvolutionWeights1d",
"prepares",
"pixel",
"weights",
"using",
"a",
"convolution",
"kernel",
".",
"Weights",
"equal",
"to",
"0",
"are",
"excluded",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/convolution.go#L221-L241 |
6,070 | disintegration/gift | convolution.go | convolveLine | func convolveLine(dstBuf []pixel, srcBuf []pixel, weights []uweight) {
max := len(srcBuf) - 1
if max < 0 {
return
}
for dstu := 0; dstu < len(srcBuf); dstu++ {
var r, g, b, a float32
for _, w := range weights {
k := dstu + w.u
if k < 0 {
k = 0
} else if k > max {
k = max
}
c := srcBuf[k]
wa := c.a * w.weight
r += c.r * wa
g += c.g * wa
b += c.b * wa
a += wa
}
if a != 0 {
r /= a
g /= a
b /= a
}
dstBuf[dstu] = pixel{r, g, b, a}
}
} | go | func convolveLine(dstBuf []pixel, srcBuf []pixel, weights []uweight) {
max := len(srcBuf) - 1
if max < 0 {
return
}
for dstu := 0; dstu < len(srcBuf); dstu++ {
var r, g, b, a float32
for _, w := range weights {
k := dstu + w.u
if k < 0 {
k = 0
} else if k > max {
k = max
}
c := srcBuf[k]
wa := c.a * w.weight
r += c.r * wa
g += c.g * wa
b += c.b * wa
a += wa
}
if a != 0 {
r /= a
g /= a
b /= a
}
dstBuf[dstu] = pixel{r, g, b, a}
}
} | [
"func",
"convolveLine",
"(",
"dstBuf",
"[",
"]",
"pixel",
",",
"srcBuf",
"[",
"]",
"pixel",
",",
"weights",
"[",
"]",
"uweight",
")",
"{",
"max",
":=",
"len",
"(",
"srcBuf",
")",
"-",
"1",
"\n",
"if",
"max",
"<",
"0",
"{",
"return",
"\n",
"}",
"\n",
"for",
"dstu",
":=",
"0",
";",
"dstu",
"<",
"len",
"(",
"srcBuf",
")",
";",
"dstu",
"++",
"{",
"var",
"r",
",",
"g",
",",
"b",
",",
"a",
"float32",
"\n",
"for",
"_",
",",
"w",
":=",
"range",
"weights",
"{",
"k",
":=",
"dstu",
"+",
"w",
".",
"u",
"\n",
"if",
"k",
"<",
"0",
"{",
"k",
"=",
"0",
"\n",
"}",
"else",
"if",
"k",
">",
"max",
"{",
"k",
"=",
"max",
"\n",
"}",
"\n",
"c",
":=",
"srcBuf",
"[",
"k",
"]",
"\n",
"wa",
":=",
"c",
".",
"a",
"*",
"w",
".",
"weight",
"\n",
"r",
"+=",
"c",
".",
"r",
"*",
"wa",
"\n",
"g",
"+=",
"c",
".",
"g",
"*",
"wa",
"\n",
"b",
"+=",
"c",
".",
"b",
"*",
"wa",
"\n",
"a",
"+=",
"wa",
"\n",
"}",
"\n",
"if",
"a",
"!=",
"0",
"{",
"r",
"/=",
"a",
"\n",
"g",
"/=",
"a",
"\n",
"b",
"/=",
"a",
"\n",
"}",
"\n",
"dstBuf",
"[",
"dstu",
"]",
"=",
"pixel",
"{",
"r",
",",
"g",
",",
"b",
",",
"a",
"}",
"\n",
"}",
"\n",
"}"
] | // convolveLine convolves a single line of pixels according to the given weights. | [
"convolveLine",
"convolves",
"a",
"single",
"line",
"of",
"pixels",
"according",
"to",
"the",
"given",
"weights",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/convolution.go#L244-L272 |
6,071 | disintegration/gift | convolution.go | convolve1dv | func convolve1dv(dst draw.Image, src image.Image, kernel []float32, options *Options) {
srcb := src.Bounds()
dstb := dst.Bounds()
if srcb.Dx() <= 0 || srcb.Dy() <= 0 {
return
}
if kernel == nil || len(kernel) < 1 {
copyimage(dst, src, options)
return
}
_, weights := prepareConvolutionWeights1d(kernel)
pixGetter := newPixelGetter(src)
pixSetter := newPixelSetter(dst)
parallelize(options.Parallelization, srcb.Min.X, srcb.Max.X, func(start, stop int) {
srcBuf := make([]pixel, srcb.Dy())
dstBuf := make([]pixel, srcb.Dy())
for x := start; x < stop; x++ {
pixGetter.getPixelColumn(x, &srcBuf)
convolveLine(dstBuf, srcBuf, weights)
pixSetter.setPixelColumn(dstb.Min.X+x-srcb.Min.X, dstBuf)
}
})
} | go | func convolve1dv(dst draw.Image, src image.Image, kernel []float32, options *Options) {
srcb := src.Bounds()
dstb := dst.Bounds()
if srcb.Dx() <= 0 || srcb.Dy() <= 0 {
return
}
if kernel == nil || len(kernel) < 1 {
copyimage(dst, src, options)
return
}
_, weights := prepareConvolutionWeights1d(kernel)
pixGetter := newPixelGetter(src)
pixSetter := newPixelSetter(dst)
parallelize(options.Parallelization, srcb.Min.X, srcb.Max.X, func(start, stop int) {
srcBuf := make([]pixel, srcb.Dy())
dstBuf := make([]pixel, srcb.Dy())
for x := start; x < stop; x++ {
pixGetter.getPixelColumn(x, &srcBuf)
convolveLine(dstBuf, srcBuf, weights)
pixSetter.setPixelColumn(dstb.Min.X+x-srcb.Min.X, dstBuf)
}
})
} | [
"func",
"convolve1dv",
"(",
"dst",
"draw",
".",
"Image",
",",
"src",
"image",
".",
"Image",
",",
"kernel",
"[",
"]",
"float32",
",",
"options",
"*",
"Options",
")",
"{",
"srcb",
":=",
"src",
".",
"Bounds",
"(",
")",
"\n",
"dstb",
":=",
"dst",
".",
"Bounds",
"(",
")",
"\n",
"if",
"srcb",
".",
"Dx",
"(",
")",
"<=",
"0",
"||",
"srcb",
".",
"Dy",
"(",
")",
"<=",
"0",
"{",
"return",
"\n",
"}",
"\n",
"if",
"kernel",
"==",
"nil",
"||",
"len",
"(",
"kernel",
")",
"<",
"1",
"{",
"copyimage",
"(",
"dst",
",",
"src",
",",
"options",
")",
"\n",
"return",
"\n",
"}",
"\n",
"_",
",",
"weights",
":=",
"prepareConvolutionWeights1d",
"(",
"kernel",
")",
"\n",
"pixGetter",
":=",
"newPixelGetter",
"(",
"src",
")",
"\n",
"pixSetter",
":=",
"newPixelSetter",
"(",
"dst",
")",
"\n",
"parallelize",
"(",
"options",
".",
"Parallelization",
",",
"srcb",
".",
"Min",
".",
"X",
",",
"srcb",
".",
"Max",
".",
"X",
",",
"func",
"(",
"start",
",",
"stop",
"int",
")",
"{",
"srcBuf",
":=",
"make",
"(",
"[",
"]",
"pixel",
",",
"srcb",
".",
"Dy",
"(",
")",
")",
"\n",
"dstBuf",
":=",
"make",
"(",
"[",
"]",
"pixel",
",",
"srcb",
".",
"Dy",
"(",
")",
")",
"\n",
"for",
"x",
":=",
"start",
";",
"x",
"<",
"stop",
";",
"x",
"++",
"{",
"pixGetter",
".",
"getPixelColumn",
"(",
"x",
",",
"&",
"srcBuf",
")",
"\n",
"convolveLine",
"(",
"dstBuf",
",",
"srcBuf",
",",
"weights",
")",
"\n",
"pixSetter",
".",
"setPixelColumn",
"(",
"dstb",
".",
"Min",
".",
"X",
"+",
"x",
"-",
"srcb",
".",
"Min",
".",
"X",
",",
"dstBuf",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // convolve1dv performs a fast vertical 1d convolution. | [
"convolve1dv",
"performs",
"a",
"fast",
"vertical",
"1d",
"convolution",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/convolution.go#L275-L297 |
6,072 | disintegration/gift | convolution.go | convolve1dh | func convolve1dh(dst draw.Image, src image.Image, kernel []float32, options *Options) {
srcb := src.Bounds()
dstb := dst.Bounds()
if srcb.Dx() <= 0 || srcb.Dy() <= 0 {
return
}
if kernel == nil || len(kernel) < 1 {
copyimage(dst, src, options)
return
}
_, weights := prepareConvolutionWeights1d(kernel)
pixGetter := newPixelGetter(src)
pixSetter := newPixelSetter(dst)
parallelize(options.Parallelization, srcb.Min.Y, srcb.Max.Y, func(start, stop int) {
srcBuf := make([]pixel, srcb.Dx())
dstBuf := make([]pixel, srcb.Dx())
for y := start; y < stop; y++ {
pixGetter.getPixelRow(y, &srcBuf)
convolveLine(dstBuf, srcBuf, weights)
pixSetter.setPixelRow(dstb.Min.Y+y-srcb.Min.Y, dstBuf)
}
})
} | go | func convolve1dh(dst draw.Image, src image.Image, kernel []float32, options *Options) {
srcb := src.Bounds()
dstb := dst.Bounds()
if srcb.Dx() <= 0 || srcb.Dy() <= 0 {
return
}
if kernel == nil || len(kernel) < 1 {
copyimage(dst, src, options)
return
}
_, weights := prepareConvolutionWeights1d(kernel)
pixGetter := newPixelGetter(src)
pixSetter := newPixelSetter(dst)
parallelize(options.Parallelization, srcb.Min.Y, srcb.Max.Y, func(start, stop int) {
srcBuf := make([]pixel, srcb.Dx())
dstBuf := make([]pixel, srcb.Dx())
for y := start; y < stop; y++ {
pixGetter.getPixelRow(y, &srcBuf)
convolveLine(dstBuf, srcBuf, weights)
pixSetter.setPixelRow(dstb.Min.Y+y-srcb.Min.Y, dstBuf)
}
})
} | [
"func",
"convolve1dh",
"(",
"dst",
"draw",
".",
"Image",
",",
"src",
"image",
".",
"Image",
",",
"kernel",
"[",
"]",
"float32",
",",
"options",
"*",
"Options",
")",
"{",
"srcb",
":=",
"src",
".",
"Bounds",
"(",
")",
"\n",
"dstb",
":=",
"dst",
".",
"Bounds",
"(",
")",
"\n",
"if",
"srcb",
".",
"Dx",
"(",
")",
"<=",
"0",
"||",
"srcb",
".",
"Dy",
"(",
")",
"<=",
"0",
"{",
"return",
"\n",
"}",
"\n",
"if",
"kernel",
"==",
"nil",
"||",
"len",
"(",
"kernel",
")",
"<",
"1",
"{",
"copyimage",
"(",
"dst",
",",
"src",
",",
"options",
")",
"\n",
"return",
"\n",
"}",
"\n",
"_",
",",
"weights",
":=",
"prepareConvolutionWeights1d",
"(",
"kernel",
")",
"\n",
"pixGetter",
":=",
"newPixelGetter",
"(",
"src",
")",
"\n",
"pixSetter",
":=",
"newPixelSetter",
"(",
"dst",
")",
"\n",
"parallelize",
"(",
"options",
".",
"Parallelization",
",",
"srcb",
".",
"Min",
".",
"Y",
",",
"srcb",
".",
"Max",
".",
"Y",
",",
"func",
"(",
"start",
",",
"stop",
"int",
")",
"{",
"srcBuf",
":=",
"make",
"(",
"[",
"]",
"pixel",
",",
"srcb",
".",
"Dx",
"(",
")",
")",
"\n",
"dstBuf",
":=",
"make",
"(",
"[",
"]",
"pixel",
",",
"srcb",
".",
"Dx",
"(",
")",
")",
"\n",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"stop",
";",
"y",
"++",
"{",
"pixGetter",
".",
"getPixelRow",
"(",
"y",
",",
"&",
"srcBuf",
")",
"\n",
"convolveLine",
"(",
"dstBuf",
",",
"srcBuf",
",",
"weights",
")",
"\n",
"pixSetter",
".",
"setPixelRow",
"(",
"dstb",
".",
"Min",
".",
"Y",
"+",
"y",
"-",
"srcb",
".",
"Min",
".",
"Y",
",",
"dstBuf",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // convolve1dh performs afast horizontal 1d convolution. | [
"convolve1dh",
"performs",
"afast",
"horizontal",
"1d",
"convolution",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/convolution.go#L300-L322 |
6,073 | disintegration/gift | transform.go | CropToSize | func CropToSize(width, height int, anchor Anchor) Filter {
return &cropToSizeFilter{
w: width,
h: height,
anchor: anchor,
}
} | go | func CropToSize(width, height int, anchor Anchor) Filter {
return &cropToSizeFilter{
w: width,
h: height,
anchor: anchor,
}
} | [
"func",
"CropToSize",
"(",
"width",
",",
"height",
"int",
",",
"anchor",
"Anchor",
")",
"Filter",
"{",
"return",
"&",
"cropToSizeFilter",
"{",
"w",
":",
"width",
",",
"h",
":",
"height",
",",
"anchor",
":",
"anchor",
",",
"}",
"\n",
"}"
] | // CropToSize creates a filter that crops an image to the specified size using the specified anchor point. | [
"CropToSize",
"creates",
"a",
"filter",
"that",
"crops",
"an",
"image",
"to",
"the",
"specified",
"size",
"using",
"the",
"specified",
"anchor",
"point",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/transform.go#L492-L498 |
6,074 | disintegration/gift | utils.go | parallelize | func parallelize(enabled bool, start, stop int, fn func(start, stop int)) {
procs := 1
if enabled {
procs = runtime.GOMAXPROCS(0)
}
var wg sync.WaitGroup
splitRange(start, stop, procs, func(pstart, pstop int) {
wg.Add(1)
go func() {
defer wg.Done()
fn(pstart, pstop)
}()
})
wg.Wait()
} | go | func parallelize(enabled bool, start, stop int, fn func(start, stop int)) {
procs := 1
if enabled {
procs = runtime.GOMAXPROCS(0)
}
var wg sync.WaitGroup
splitRange(start, stop, procs, func(pstart, pstop int) {
wg.Add(1)
go func() {
defer wg.Done()
fn(pstart, pstop)
}()
})
wg.Wait()
} | [
"func",
"parallelize",
"(",
"enabled",
"bool",
",",
"start",
",",
"stop",
"int",
",",
"fn",
"func",
"(",
"start",
",",
"stop",
"int",
")",
")",
"{",
"procs",
":=",
"1",
"\n",
"if",
"enabled",
"{",
"procs",
"=",
"runtime",
".",
"GOMAXPROCS",
"(",
"0",
")",
"\n",
"}",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"splitRange",
"(",
"start",
",",
"stop",
",",
"procs",
",",
"func",
"(",
"pstart",
",",
"pstop",
"int",
")",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"fn",
"(",
"pstart",
",",
"pstop",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
")",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // parallelize parallelizes the data processing. | [
"parallelize",
"parallelizes",
"the",
"data",
"processing",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/utils.go#L12-L26 |
6,075 | disintegration/gift | utils.go | splitRange | func splitRange(start, stop, n int, fn func(pstart, pstop int)) {
count := stop - start
if count < 1 {
return
}
if n < 1 {
n = 1
}
if n > count {
n = count
}
div := count / n
mod := count % n
for i := 0; i < n; i++ {
fn(
start+i*div+minint(i, mod),
start+(i+1)*div+minint(i+1, mod),
)
}
} | go | func splitRange(start, stop, n int, fn func(pstart, pstop int)) {
count := stop - start
if count < 1 {
return
}
if n < 1 {
n = 1
}
if n > count {
n = count
}
div := count / n
mod := count % n
for i := 0; i < n; i++ {
fn(
start+i*div+minint(i, mod),
start+(i+1)*div+minint(i+1, mod),
)
}
} | [
"func",
"splitRange",
"(",
"start",
",",
"stop",
",",
"n",
"int",
",",
"fn",
"func",
"(",
"pstart",
",",
"pstop",
"int",
")",
")",
"{",
"count",
":=",
"stop",
"-",
"start",
"\n",
"if",
"count",
"<",
"1",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"n",
"<",
"1",
"{",
"n",
"=",
"1",
"\n",
"}",
"\n",
"if",
"n",
">",
"count",
"{",
"n",
"=",
"count",
"\n",
"}",
"\n\n",
"div",
":=",
"count",
"/",
"n",
"\n",
"mod",
":=",
"count",
"%",
"n",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"fn",
"(",
"start",
"+",
"i",
"*",
"div",
"+",
"minint",
"(",
"i",
",",
"mod",
")",
",",
"start",
"+",
"(",
"i",
"+",
"1",
")",
"*",
"div",
"+",
"minint",
"(",
"i",
"+",
"1",
",",
"mod",
")",
",",
")",
"\n",
"}",
"\n",
"}"
] | // splitRange splits a range into n parts and calls a function for each of them. | [
"splitRange",
"splits",
"a",
"range",
"into",
"n",
"parts",
"and",
"calls",
"a",
"function",
"for",
"each",
"of",
"them",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/utils.go#L29-L51 |
6,076 | disintegration/gift | utils.go | isOpaque | func isOpaque(img image.Image) bool {
type opaquer interface {
Opaque() bool
}
if o, ok := img.(opaquer); ok {
return o.Opaque()
}
return false
} | go | func isOpaque(img image.Image) bool {
type opaquer interface {
Opaque() bool
}
if o, ok := img.(opaquer); ok {
return o.Opaque()
}
return false
} | [
"func",
"isOpaque",
"(",
"img",
"image",
".",
"Image",
")",
"bool",
"{",
"type",
"opaquer",
"interface",
"{",
"Opaque",
"(",
")",
"bool",
"\n",
"}",
"\n",
"if",
"o",
",",
"ok",
":=",
"img",
".",
"(",
"opaquer",
")",
";",
"ok",
"{",
"return",
"o",
".",
"Opaque",
"(",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // isOpaque checks if the given image is opaque. | [
"isOpaque",
"checks",
"if",
"the",
"given",
"image",
"is",
"opaque",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/utils.go#L162-L170 |
6,077 | disintegration/gift | utils.go | genDisk | func genDisk(ksize int) []float32 {
if ksize%2 == 0 {
ksize--
}
if ksize < 1 {
return []float32{}
}
disk := make([]float32, ksize*ksize)
kcenter := ksize / 2
for i := 0; i < ksize; i++ {
for j := 0; j < ksize; j++ {
x := kcenter - i
y := kcenter - j
r := math.Sqrt(float64(x*x + y*y))
if r <= float64(ksize/2) {
disk[j*ksize+i] = 1
}
}
}
return disk
} | go | func genDisk(ksize int) []float32 {
if ksize%2 == 0 {
ksize--
}
if ksize < 1 {
return []float32{}
}
disk := make([]float32, ksize*ksize)
kcenter := ksize / 2
for i := 0; i < ksize; i++ {
for j := 0; j < ksize; j++ {
x := kcenter - i
y := kcenter - j
r := math.Sqrt(float64(x*x + y*y))
if r <= float64(ksize/2) {
disk[j*ksize+i] = 1
}
}
}
return disk
} | [
"func",
"genDisk",
"(",
"ksize",
"int",
")",
"[",
"]",
"float32",
"{",
"if",
"ksize",
"%",
"2",
"==",
"0",
"{",
"ksize",
"--",
"\n",
"}",
"\n",
"if",
"ksize",
"<",
"1",
"{",
"return",
"[",
"]",
"float32",
"{",
"}",
"\n",
"}",
"\n",
"disk",
":=",
"make",
"(",
"[",
"]",
"float32",
",",
"ksize",
"*",
"ksize",
")",
"\n",
"kcenter",
":=",
"ksize",
"/",
"2",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"ksize",
";",
"i",
"++",
"{",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"ksize",
";",
"j",
"++",
"{",
"x",
":=",
"kcenter",
"-",
"i",
"\n",
"y",
":=",
"kcenter",
"-",
"j",
"\n",
"r",
":=",
"math",
".",
"Sqrt",
"(",
"float64",
"(",
"x",
"*",
"x",
"+",
"y",
"*",
"y",
")",
")",
"\n",
"if",
"r",
"<=",
"float64",
"(",
"ksize",
"/",
"2",
")",
"{",
"disk",
"[",
"j",
"*",
"ksize",
"+",
"i",
"]",
"=",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"disk",
"\n",
"}"
] | // genDisk generates a disk-shaped kernel. | [
"genDisk",
"generates",
"a",
"disk",
"-",
"shaped",
"kernel",
"."
] | 5c2e6f4a91b12ffcb309b7602c01be3a2ba55543 | https://github.com/disintegration/gift/blob/5c2e6f4a91b12ffcb309b7602c01be3a2ba55543/utils.go#L173-L193 |
6,078 | creasty/defaults | defaults.go | Set | func Set(ptr interface{}) error {
if reflect.TypeOf(ptr).Kind() != reflect.Ptr {
return errInvalidType
}
v := reflect.ValueOf(ptr).Elem()
t := v.Type()
if t.Kind() != reflect.Struct {
return errInvalidType
}
for i := 0; i < t.NumField(); i++ {
if defaultVal := t.Field(i).Tag.Get(fieldName); defaultVal != "-" {
if err := setField(v.Field(i), defaultVal); err != nil {
return err
}
}
}
return nil
} | go | func Set(ptr interface{}) error {
if reflect.TypeOf(ptr).Kind() != reflect.Ptr {
return errInvalidType
}
v := reflect.ValueOf(ptr).Elem()
t := v.Type()
if t.Kind() != reflect.Struct {
return errInvalidType
}
for i := 0; i < t.NumField(); i++ {
if defaultVal := t.Field(i).Tag.Get(fieldName); defaultVal != "-" {
if err := setField(v.Field(i), defaultVal); err != nil {
return err
}
}
}
return nil
} | [
"func",
"Set",
"(",
"ptr",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"reflect",
".",
"TypeOf",
"(",
"ptr",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"return",
"errInvalidType",
"\n",
"}",
"\n\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"ptr",
")",
".",
"Elem",
"(",
")",
"\n",
"t",
":=",
"v",
".",
"Type",
"(",
")",
"\n\n",
"if",
"t",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Struct",
"{",
"return",
"errInvalidType",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"t",
".",
"NumField",
"(",
")",
";",
"i",
"++",
"{",
"if",
"defaultVal",
":=",
"t",
".",
"Field",
"(",
"i",
")",
".",
"Tag",
".",
"Get",
"(",
"fieldName",
")",
";",
"defaultVal",
"!=",
"\"",
"\"",
"{",
"if",
"err",
":=",
"setField",
"(",
"v",
".",
"Field",
"(",
"i",
")",
",",
"defaultVal",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Set initializes members in a struct referenced by a pointer.
// Maps and slices are initialized by `make` and other primitive types are set with default values.
// `ptr` should be a struct pointer | [
"Set",
"initializes",
"members",
"in",
"a",
"struct",
"referenced",
"by",
"a",
"pointer",
".",
"Maps",
"and",
"slices",
"are",
"initialized",
"by",
"make",
"and",
"other",
"primitive",
"types",
"are",
"set",
"with",
"default",
"values",
".",
"ptr",
"should",
"be",
"a",
"struct",
"pointer"
] | edf4f6a95a3223dfff4eff2c404103e756fef68d | https://github.com/creasty/defaults/blob/edf4f6a95a3223dfff4eff2c404103e756fef68d/defaults.go#L22-L43 |
6,079 | mat/besticon | besticon/besticon.go | SetLogOutput | func SetLogOutput(w io.Writer) {
logger = log.New(w, "http: ", log.LstdFlags|log.Lmicroseconds)
} | go | func SetLogOutput(w io.Writer) {
logger = log.New(w, "http: ", log.LstdFlags|log.Lmicroseconds)
} | [
"func",
"SetLogOutput",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"logger",
"=",
"log",
".",
"New",
"(",
"w",
",",
"\"",
"\"",
",",
"log",
".",
"LstdFlags",
"|",
"log",
".",
"Lmicroseconds",
")",
"\n",
"}"
] | // SetLogOutput sets the output for the package's logger. | [
"SetLogOutput",
"sets",
"the",
"output",
"for",
"the",
"package",
"s",
"logger",
"."
] | 8d6f841790b47dbcab3399592f065e53a56ec2b7 | https://github.com/mat/besticon/blob/8d6f841790b47dbcab3399592f065e53a56ec2b7/besticon/besticon.go#L553-L555 |
6,080 | mat/besticon | besticon/caching.go | SetCacheMaxSize | func SetCacheMaxSize(sizeInMB int64) {
if sizeInMB > 0 {
iconCache = groupcache.NewGroup("icons", sizeInMB<<20, groupcache.GetterFunc(generatorFunc))
} else {
iconCache = nil
}
} | go | func SetCacheMaxSize(sizeInMB int64) {
if sizeInMB > 0 {
iconCache = groupcache.NewGroup("icons", sizeInMB<<20, groupcache.GetterFunc(generatorFunc))
} else {
iconCache = nil
}
} | [
"func",
"SetCacheMaxSize",
"(",
"sizeInMB",
"int64",
")",
"{",
"if",
"sizeInMB",
">",
"0",
"{",
"iconCache",
"=",
"groupcache",
".",
"NewGroup",
"(",
"\"",
"\"",
",",
"sizeInMB",
"<<",
"20",
",",
"groupcache",
".",
"GetterFunc",
"(",
"generatorFunc",
")",
")",
"\n",
"}",
"else",
"{",
"iconCache",
"=",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetCacheMaxSize enables icon caching if sizeInMB > 0. | [
"SetCacheMaxSize",
"enables",
"icon",
"caching",
"if",
"sizeInMB",
">",
"0",
"."
] | 8d6f841790b47dbcab3399592f065e53a56ec2b7 | https://github.com/mat/besticon/blob/8d6f841790b47dbcab3399592f065e53a56ec2b7/besticon/caching.go#L72-L78 |
6,081 | mat/besticon | besticon/size_range.go | ParseSizeRange | func ParseSizeRange(s string) (*SizeRange, error) {
parts := strings.SplitN(s, "..", 3)
switch len(parts) {
case 1:
size, ok := parseSize(parts[0])
if !ok {
return nil, errBadSize
}
return &SizeRange{size, size, MaxIconSize}, nil
case 3:
n1, ok1 := parseSize(parts[0])
n2, ok2 := parseSize(parts[1])
n3, ok3 := parseSize(parts[2])
if !ok1 || !ok2 || !ok3 {
return nil, errBadSize
}
if !((n1 <= n2) && (n2 <= n3)) {
return nil, errBadSize
}
return &SizeRange{n1, n2, n3}, nil
}
return nil, errBadSize
} | go | func ParseSizeRange(s string) (*SizeRange, error) {
parts := strings.SplitN(s, "..", 3)
switch len(parts) {
case 1:
size, ok := parseSize(parts[0])
if !ok {
return nil, errBadSize
}
return &SizeRange{size, size, MaxIconSize}, nil
case 3:
n1, ok1 := parseSize(parts[0])
n2, ok2 := parseSize(parts[1])
n3, ok3 := parseSize(parts[2])
if !ok1 || !ok2 || !ok3 {
return nil, errBadSize
}
if !((n1 <= n2) && (n2 <= n3)) {
return nil, errBadSize
}
return &SizeRange{n1, n2, n3}, nil
}
return nil, errBadSize
} | [
"func",
"ParseSizeRange",
"(",
"s",
"string",
")",
"(",
"*",
"SizeRange",
",",
"error",
")",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"s",
",",
"\"",
"\"",
",",
"3",
")",
"\n",
"switch",
"len",
"(",
"parts",
")",
"{",
"case",
"1",
":",
"size",
",",
"ok",
":=",
"parseSize",
"(",
"parts",
"[",
"0",
"]",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errBadSize",
"\n",
"}",
"\n",
"return",
"&",
"SizeRange",
"{",
"size",
",",
"size",
",",
"MaxIconSize",
"}",
",",
"nil",
"\n",
"case",
"3",
":",
"n1",
",",
"ok1",
":=",
"parseSize",
"(",
"parts",
"[",
"0",
"]",
")",
"\n",
"n2",
",",
"ok2",
":=",
"parseSize",
"(",
"parts",
"[",
"1",
"]",
")",
"\n",
"n3",
",",
"ok3",
":=",
"parseSize",
"(",
"parts",
"[",
"2",
"]",
")",
"\n",
"if",
"!",
"ok1",
"||",
"!",
"ok2",
"||",
"!",
"ok3",
"{",
"return",
"nil",
",",
"errBadSize",
"\n",
"}",
"\n",
"if",
"!",
"(",
"(",
"n1",
"<=",
"n2",
")",
"&&",
"(",
"n2",
"<=",
"n3",
")",
")",
"{",
"return",
"nil",
",",
"errBadSize",
"\n",
"}",
"\n",
"return",
"&",
"SizeRange",
"{",
"n1",
",",
"n2",
",",
"n3",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"errBadSize",
"\n",
"}"
] | // ParseSizeRange parses a string like 60..100..200 into a SizeRange | [
"ParseSizeRange",
"parses",
"a",
"string",
"like",
"60",
"..",
"100",
"..",
"200",
"into",
"a",
"SizeRange"
] | 8d6f841790b47dbcab3399592f065e53a56ec2b7 | https://github.com/mat/besticon/blob/8d6f841790b47dbcab3399592f065e53a56ec2b7/besticon/size_range.go#L19-L42 |
6,082 | mat/besticon | colorfinder/colorfinder.go | FindMainColor | func (cf *ColorFinder) FindMainColor(img image.Image) (color.RGBA, error) {
cf.img = img
colorMap := cf.buildColorMap()
sRGB := cf.findMainColor(colorMap, 6, nil)
sRGB = cf.findMainColor(colorMap, 4, &sRGB)
sRGB = cf.findMainColor(colorMap, 2, &sRGB)
sRGB = cf.findMainColor(colorMap, 0, &sRGB)
return sRGB.rgb, nil
} | go | func (cf *ColorFinder) FindMainColor(img image.Image) (color.RGBA, error) {
cf.img = img
colorMap := cf.buildColorMap()
sRGB := cf.findMainColor(colorMap, 6, nil)
sRGB = cf.findMainColor(colorMap, 4, &sRGB)
sRGB = cf.findMainColor(colorMap, 2, &sRGB)
sRGB = cf.findMainColor(colorMap, 0, &sRGB)
return sRGB.rgb, nil
} | [
"func",
"(",
"cf",
"*",
"ColorFinder",
")",
"FindMainColor",
"(",
"img",
"image",
".",
"Image",
")",
"(",
"color",
".",
"RGBA",
",",
"error",
")",
"{",
"cf",
".",
"img",
"=",
"img",
"\n\n",
"colorMap",
":=",
"cf",
".",
"buildColorMap",
"(",
")",
"\n\n",
"sRGB",
":=",
"cf",
".",
"findMainColor",
"(",
"colorMap",
",",
"6",
",",
"nil",
")",
"\n",
"sRGB",
"=",
"cf",
".",
"findMainColor",
"(",
"colorMap",
",",
"4",
",",
"&",
"sRGB",
")",
"\n",
"sRGB",
"=",
"cf",
".",
"findMainColor",
"(",
"colorMap",
",",
"2",
",",
"&",
"sRGB",
")",
"\n",
"sRGB",
"=",
"cf",
".",
"findMainColor",
"(",
"colorMap",
",",
"0",
",",
"&",
"sRGB",
")",
"\n\n",
"return",
"sRGB",
".",
"rgb",
",",
"nil",
"\n",
"}"
] | // FindMainColor tries to identify the most important color in the given logo. | [
"FindMainColor",
"tries",
"to",
"identify",
"the",
"most",
"important",
"color",
"in",
"the",
"given",
"logo",
"."
] | 8d6f841790b47dbcab3399592f065e53a56ec2b7 | https://github.com/mat/besticon/blob/8d6f841790b47dbcab3399592f065e53a56ec2b7/colorfinder/colorfinder.go#L64-L75 |
6,083 | mat/besticon | ico/ico.go | ParseIco | func ParseIco(r io.Reader) (*icondir, error) {
dir := icondir{}
var err error
err = binary.Read(r, binary.LittleEndian, &dir.Reserved)
if err != nil {
return nil, err
}
err = binary.Read(r, binary.LittleEndian, &dir.Type)
if err != nil {
return nil, err
}
err = binary.Read(r, binary.LittleEndian, &dir.Count)
if err != nil {
return nil, err
}
for i := uint16(0); i < dir.Count; i++ {
entry := icondirEntry{}
e := parseIcondirEntry(r, &entry)
if e != nil {
return nil, e
}
dir.Entries = append(dir.Entries, entry)
}
return &dir, err
} | go | func ParseIco(r io.Reader) (*icondir, error) {
dir := icondir{}
var err error
err = binary.Read(r, binary.LittleEndian, &dir.Reserved)
if err != nil {
return nil, err
}
err = binary.Read(r, binary.LittleEndian, &dir.Type)
if err != nil {
return nil, err
}
err = binary.Read(r, binary.LittleEndian, &dir.Count)
if err != nil {
return nil, err
}
for i := uint16(0); i < dir.Count; i++ {
entry := icondirEntry{}
e := parseIcondirEntry(r, &entry)
if e != nil {
return nil, e
}
dir.Entries = append(dir.Entries, entry)
}
return &dir, err
} | [
"func",
"ParseIco",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"icondir",
",",
"error",
")",
"{",
"dir",
":=",
"icondir",
"{",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"dir",
".",
"Reserved",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"dir",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"dir",
".",
"Count",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"uint16",
"(",
"0",
")",
";",
"i",
"<",
"dir",
".",
"Count",
";",
"i",
"++",
"{",
"entry",
":=",
"icondirEntry",
"{",
"}",
"\n",
"e",
":=",
"parseIcondirEntry",
"(",
"r",
",",
"&",
"entry",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"nil",
",",
"e",
"\n",
"}",
"\n",
"dir",
".",
"Entries",
"=",
"append",
"(",
"dir",
".",
"Entries",
",",
"entry",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"dir",
",",
"err",
"\n",
"}"
] | // ParseIco parses the icon and returns meta information for the icons as icondir. | [
"ParseIco",
"parses",
"the",
"icon",
"and",
"returns",
"meta",
"information",
"for",
"the",
"icons",
"as",
"icondir",
"."
] | 8d6f841790b47dbcab3399592f065e53a56ec2b7 | https://github.com/mat/besticon/blob/8d6f841790b47dbcab3399592f065e53a56ec2b7/ico/ico.go#L51-L80 |
6,084 | mat/besticon | ico/ico.go | DecodeConfig | func DecodeConfig(r io.Reader) (image.Config, error) {
dir, err := ParseIco(r)
if err != nil {
return image.Config{}, err
}
best := dir.FindBestIcon()
if best == nil {
return image.Config{}, errInvalid
}
return image.Config{Width: best.width(), Height: best.height()}, nil
} | go | func DecodeConfig(r io.Reader) (image.Config, error) {
dir, err := ParseIco(r)
if err != nil {
return image.Config{}, err
}
best := dir.FindBestIcon()
if best == nil {
return image.Config{}, errInvalid
}
return image.Config{Width: best.width(), Height: best.height()}, nil
} | [
"func",
"DecodeConfig",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"image",
".",
"Config",
",",
"error",
")",
"{",
"dir",
",",
"err",
":=",
"ParseIco",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"image",
".",
"Config",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"best",
":=",
"dir",
".",
"FindBestIcon",
"(",
")",
"\n",
"if",
"best",
"==",
"nil",
"{",
"return",
"image",
".",
"Config",
"{",
"}",
",",
"errInvalid",
"\n",
"}",
"\n",
"return",
"image",
".",
"Config",
"{",
"Width",
":",
"best",
".",
"width",
"(",
")",
",",
"Height",
":",
"best",
".",
"height",
"(",
")",
"}",
",",
"nil",
"\n",
"}"
] | // DecodeConfig returns just the dimensions of the largest image
// contained in the icon withou decoding the entire icon file. | [
"DecodeConfig",
"returns",
"just",
"the",
"dimensions",
"of",
"the",
"largest",
"image",
"contained",
"in",
"the",
"icon",
"withou",
"decoding",
"the",
"entire",
"icon",
"file",
"."
] | 8d6f841790b47dbcab3399592f065e53a56ec2b7 | https://github.com/mat/besticon/blob/8d6f841790b47dbcab3399592f065e53a56ec2b7/ico/ico.go#L120-L131 |
6,085 | mat/besticon | ico/ico.go | Decode | func Decode(r io.Reader) (image.Image, error) {
icoBytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
r = bytes.NewReader(icoBytes)
dir, err := ParseIco(r)
if err != nil {
return nil, errInvalid
}
best := dir.FindBestIcon()
if best == nil {
return nil, errInvalid
}
return parseImage(best, icoBytes)
} | go | func Decode(r io.Reader) (image.Image, error) {
icoBytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
r = bytes.NewReader(icoBytes)
dir, err := ParseIco(r)
if err != nil {
return nil, errInvalid
}
best := dir.FindBestIcon()
if best == nil {
return nil, errInvalid
}
return parseImage(best, icoBytes)
} | [
"func",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"image",
".",
"Image",
",",
"error",
")",
"{",
"icoBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"r",
"=",
"bytes",
".",
"NewReader",
"(",
"icoBytes",
")",
"\n",
"dir",
",",
"err",
":=",
"ParseIco",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errInvalid",
"\n",
"}",
"\n\n",
"best",
":=",
"dir",
".",
"FindBestIcon",
"(",
")",
"\n",
"if",
"best",
"==",
"nil",
"{",
"return",
"nil",
",",
"errInvalid",
"\n",
"}",
"\n\n",
"return",
"parseImage",
"(",
"best",
",",
"icoBytes",
")",
"\n",
"}"
] | // Decode returns the largest image contained in the icon
// which might be a bmp or png | [
"Decode",
"returns",
"the",
"largest",
"image",
"contained",
"in",
"the",
"icon",
"which",
"might",
"be",
"a",
"bmp",
"or",
"png"
] | 8d6f841790b47dbcab3399592f065e53a56ec2b7 | https://github.com/mat/besticon/blob/8d6f841790b47dbcab3399592f065e53a56ec2b7/ico/ico.go#L171-L189 |
6,086 | google/gofuzz | fuzz.go | RandSource | func (f *Fuzzer) RandSource(s rand.Source) *Fuzzer {
f.r = rand.New(s)
return f
} | go | func (f *Fuzzer) RandSource(s rand.Source) *Fuzzer {
f.r = rand.New(s)
return f
} | [
"func",
"(",
"f",
"*",
"Fuzzer",
")",
"RandSource",
"(",
"s",
"rand",
".",
"Source",
")",
"*",
"Fuzzer",
"{",
"f",
".",
"r",
"=",
"rand",
".",
"New",
"(",
"s",
")",
"\n",
"return",
"f",
"\n",
"}"
] | // RandSource causes f to get values from the given source of randomness.
// Use if you want deterministic fuzzing. | [
"RandSource",
"causes",
"f",
"to",
"get",
"values",
"from",
"the",
"given",
"source",
"of",
"randomness",
".",
"Use",
"if",
"you",
"want",
"deterministic",
"fuzzing",
"."
] | f140a6486e521aad38f5917de355cbf147cc0496 | https://github.com/google/gofuzz/blob/f140a6486e521aad38f5917de355cbf147cc0496/fuzz.go#L105-L108 |
6,087 | google/gofuzz | fuzz.go | NumElements | func (f *Fuzzer) NumElements(atLeast, atMost int) *Fuzzer {
if atLeast > atMost {
panic("atLeast must be <= atMost")
}
if atLeast < 0 {
panic("atLeast must be >= 0")
}
f.minElements = atLeast
f.maxElements = atMost
return f
} | go | func (f *Fuzzer) NumElements(atLeast, atMost int) *Fuzzer {
if atLeast > atMost {
panic("atLeast must be <= atMost")
}
if atLeast < 0 {
panic("atLeast must be >= 0")
}
f.minElements = atLeast
f.maxElements = atMost
return f
} | [
"func",
"(",
"f",
"*",
"Fuzzer",
")",
"NumElements",
"(",
"atLeast",
",",
"atMost",
"int",
")",
"*",
"Fuzzer",
"{",
"if",
"atLeast",
">",
"atMost",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"atLeast",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"f",
".",
"minElements",
"=",
"atLeast",
"\n",
"f",
".",
"maxElements",
"=",
"atMost",
"\n",
"return",
"f",
"\n",
"}"
] | // NumElements sets the minimum and maximum number of elements that will be
// added to a non-nil map or slice. | [
"NumElements",
"sets",
"the",
"minimum",
"and",
"maximum",
"number",
"of",
"elements",
"that",
"will",
"be",
"added",
"to",
"a",
"non",
"-",
"nil",
"map",
"or",
"slice",
"."
] | f140a6486e521aad38f5917de355cbf147cc0496 | https://github.com/google/gofuzz/blob/f140a6486e521aad38f5917de355cbf147cc0496/fuzz.go#L122-L132 |
6,088 | google/gofuzz | fuzz.go | MaxDepth | func (f *Fuzzer) MaxDepth(d int) *Fuzzer {
f.maxDepth = d
return f
} | go | func (f *Fuzzer) MaxDepth(d int) *Fuzzer {
f.maxDepth = d
return f
} | [
"func",
"(",
"f",
"*",
"Fuzzer",
")",
"MaxDepth",
"(",
"d",
"int",
")",
"*",
"Fuzzer",
"{",
"f",
".",
"maxDepth",
"=",
"d",
"\n",
"return",
"f",
"\n",
"}"
] | // MaxDepth sets the maximum number of recursive fuzz calls that will be made
// before stopping. This includes struct members, pointers, and map and slice
// elements. | [
"MaxDepth",
"sets",
"the",
"maximum",
"number",
"of",
"recursive",
"fuzz",
"calls",
"that",
"will",
"be",
"made",
"before",
"stopping",
".",
"This",
"includes",
"struct",
"members",
"pointers",
"and",
"map",
"and",
"slice",
"elements",
"."
] | f140a6486e521aad38f5917de355cbf147cc0496 | https://github.com/google/gofuzz/blob/f140a6486e521aad38f5917de355cbf147cc0496/fuzz.go#L148-L151 |
6,089 | google/gofuzz | fuzz.go | tryCustom | func (fc *fuzzerContext) tryCustom(v reflect.Value) bool {
// First: see if we have a fuzz function for it.
doCustom, ok := fc.fuzzer.fuzzFuncs[v.Type()]
if !ok {
// Second: see if it can fuzz itself.
if v.CanInterface() {
intf := v.Interface()
if fuzzable, ok := intf.(Interface); ok {
fuzzable.Fuzz(Continue{fc: fc, Rand: fc.fuzzer.r})
return true
}
}
// Finally: see if there is a default fuzz function.
doCustom, ok = fc.fuzzer.defaultFuzzFuncs[v.Type()]
if !ok {
return false
}
}
switch v.Kind() {
case reflect.Ptr:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.New(v.Type().Elem()))
}
case reflect.Map:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.MakeMap(v.Type()))
}
default:
return false
}
doCustom.Call([]reflect.Value{v, reflect.ValueOf(Continue{
fc: fc,
Rand: fc.fuzzer.r,
})})
return true
} | go | func (fc *fuzzerContext) tryCustom(v reflect.Value) bool {
// First: see if we have a fuzz function for it.
doCustom, ok := fc.fuzzer.fuzzFuncs[v.Type()]
if !ok {
// Second: see if it can fuzz itself.
if v.CanInterface() {
intf := v.Interface()
if fuzzable, ok := intf.(Interface); ok {
fuzzable.Fuzz(Continue{fc: fc, Rand: fc.fuzzer.r})
return true
}
}
// Finally: see if there is a default fuzz function.
doCustom, ok = fc.fuzzer.defaultFuzzFuncs[v.Type()]
if !ok {
return false
}
}
switch v.Kind() {
case reflect.Ptr:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.New(v.Type().Elem()))
}
case reflect.Map:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.MakeMap(v.Type()))
}
default:
return false
}
doCustom.Call([]reflect.Value{v, reflect.ValueOf(Continue{
fc: fc,
Rand: fc.fuzzer.r,
})})
return true
} | [
"func",
"(",
"fc",
"*",
"fuzzerContext",
")",
"tryCustom",
"(",
"v",
"reflect",
".",
"Value",
")",
"bool",
"{",
"// First: see if we have a fuzz function for it.",
"doCustom",
",",
"ok",
":=",
"fc",
".",
"fuzzer",
".",
"fuzzFuncs",
"[",
"v",
".",
"Type",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// Second: see if it can fuzz itself.",
"if",
"v",
".",
"CanInterface",
"(",
")",
"{",
"intf",
":=",
"v",
".",
"Interface",
"(",
")",
"\n",
"if",
"fuzzable",
",",
"ok",
":=",
"intf",
".",
"(",
"Interface",
")",
";",
"ok",
"{",
"fuzzable",
".",
"Fuzz",
"(",
"Continue",
"{",
"fc",
":",
"fc",
",",
"Rand",
":",
"fc",
".",
"fuzzer",
".",
"r",
"}",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"// Finally: see if there is a default fuzz function.",
"doCustom",
",",
"ok",
"=",
"fc",
".",
"fuzzer",
".",
"defaultFuzzFuncs",
"[",
"v",
".",
"Type",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Ptr",
":",
"if",
"v",
".",
"IsNil",
"(",
")",
"{",
"if",
"!",
"v",
".",
"CanSet",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"v",
".",
"Set",
"(",
"reflect",
".",
"New",
"(",
"v",
".",
"Type",
"(",
")",
".",
"Elem",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"case",
"reflect",
".",
"Map",
":",
"if",
"v",
".",
"IsNil",
"(",
")",
"{",
"if",
"!",
"v",
".",
"CanSet",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"v",
".",
"Set",
"(",
"reflect",
".",
"MakeMap",
"(",
"v",
".",
"Type",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n\n",
"doCustom",
".",
"Call",
"(",
"[",
"]",
"reflect",
".",
"Value",
"{",
"v",
",",
"reflect",
".",
"ValueOf",
"(",
"Continue",
"{",
"fc",
":",
"fc",
",",
"Rand",
":",
"fc",
".",
"fuzzer",
".",
"r",
",",
"}",
")",
"}",
")",
"\n",
"return",
"true",
"\n",
"}"
] | // tryCustom searches for custom handlers, and returns true iff it finds a match
// and successfully randomizes v. | [
"tryCustom",
"searches",
"for",
"custom",
"handlers",
"and",
"returns",
"true",
"iff",
"it",
"finds",
"a",
"match",
"and",
"successfully",
"randomizes",
"v",
"."
] | f140a6486e521aad38f5917de355cbf147cc0496 | https://github.com/google/gofuzz/blob/f140a6486e521aad38f5917de355cbf147cc0496/fuzz.go#L292-L335 |
6,090 | google/gofuzz | fuzz.go | Fuzz | func (c Continue) Fuzz(obj interface{}) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
panic("needed ptr!")
}
v = v.Elem()
c.fc.doFuzz(v, 0)
} | go | func (c Continue) Fuzz(obj interface{}) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
panic("needed ptr!")
}
v = v.Elem()
c.fc.doFuzz(v, 0)
} | [
"func",
"(",
"c",
"Continue",
")",
"Fuzz",
"(",
"obj",
"interface",
"{",
"}",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"obj",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"v",
"=",
"v",
".",
"Elem",
"(",
")",
"\n",
"c",
".",
"fc",
".",
"doFuzz",
"(",
"v",
",",
"0",
")",
"\n",
"}"
] | // Fuzz continues fuzzing obj. obj must be a pointer. | [
"Fuzz",
"continues",
"fuzzing",
"obj",
".",
"obj",
"must",
"be",
"a",
"pointer",
"."
] | f140a6486e521aad38f5917de355cbf147cc0496 | https://github.com/google/gofuzz/blob/f140a6486e521aad38f5917de355cbf147cc0496/fuzz.go#L356-L363 |
6,091 | google/gofuzz | fuzz.go | choose | func (r *charRange) choose(rand *rand.Rand) rune {
count := int64(r.last - r.first)
return r.first + rune(rand.Int63n(count))
} | go | func (r *charRange) choose(rand *rand.Rand) rune {
count := int64(r.last - r.first)
return r.first + rune(rand.Int63n(count))
} | [
"func",
"(",
"r",
"*",
"charRange",
")",
"choose",
"(",
"rand",
"*",
"rand",
".",
"Rand",
")",
"rune",
"{",
"count",
":=",
"int64",
"(",
"r",
".",
"last",
"-",
"r",
".",
"first",
")",
"\n",
"return",
"r",
".",
"first",
"+",
"rune",
"(",
"rand",
".",
"Int63n",
"(",
"count",
")",
")",
"\n",
"}"
] | // choose returns a random unicode character from the given range, using the
// given randomness source. | [
"choose",
"returns",
"a",
"random",
"unicode",
"character",
"from",
"the",
"given",
"range",
"using",
"the",
"given",
"randomness",
"source",
"."
] | f140a6486e521aad38f5917de355cbf147cc0496 | https://github.com/google/gofuzz/blob/f140a6486e521aad38f5917de355cbf147cc0496/fuzz.go#L461-L464 |
6,092 | google/gofuzz | fuzz.go | randUint64 | func randUint64(r *rand.Rand) uint64 {
return uint64(r.Uint32())<<32 | uint64(r.Uint32())
} | go | func randUint64(r *rand.Rand) uint64 {
return uint64(r.Uint32())<<32 | uint64(r.Uint32())
} | [
"func",
"randUint64",
"(",
"r",
"*",
"rand",
".",
"Rand",
")",
"uint64",
"{",
"return",
"uint64",
"(",
"r",
".",
"Uint32",
"(",
")",
")",
"<<",
"32",
"|",
"uint64",
"(",
"r",
".",
"Uint32",
"(",
")",
")",
"\n",
"}"
] | // randUint64 makes random 64 bit numbers.
// Weirdly, rand doesn't have a function that gives you 64 random bits. | [
"randUint64",
"makes",
"random",
"64",
"bit",
"numbers",
".",
"Weirdly",
"rand",
"doesn",
"t",
"have",
"a",
"function",
"that",
"gives",
"you",
"64",
"random",
"bits",
"."
] | f140a6486e521aad38f5917de355cbf147cc0496 | https://github.com/google/gofuzz/blob/f140a6486e521aad38f5917de355cbf147cc0496/fuzz.go#L485-L487 |
6,093 | google/safebrowsing | cache.go | Update | func (c *cache) Update(req *pb.FindFullHashesRequest, resp *pb.FindFullHashesResponse) {
c.Lock()
defer c.Unlock()
now := c.now()
if c.pttls == nil {
c.pttls = make(map[hashPrefix]map[ThreatDescriptor]time.Time)
c.nttls = make(map[hashPrefix]time.Time)
}
// Insert each threat match into the cache by full hash.
for _, tm := range resp.GetMatches() {
fullHash := hashPrefix(tm.GetThreat().Hash)
if !fullHash.IsFull() {
continue
}
if c.pttls[fullHash] == nil {
c.pttls[fullHash] = make(map[ThreatDescriptor]time.Time)
}
var dur time.Duration
if tmCacheDur := tm.GetCacheDuration(); tmCacheDur != nil {
dur = time.Duration(tm.GetCacheDuration().Seconds) * time.Second
} else {
dur = 0
}
td := ThreatDescriptor{
ThreatType: ThreatType(tm.ThreatType),
PlatformType: PlatformType(tm.PlatformType),
ThreatEntryType: ThreatEntryType(tm.ThreatEntryType),
}
c.pttls[fullHash][td] = now.Add(dur)
}
// Insert negative TTLs for partial hashes.
if resp.GetNegativeCacheDuration() != nil {
dur := time.Duration(resp.GetNegativeCacheDuration().Seconds) * time.Second
nttl := now.Add(dur)
for _, te := range req.GetThreatInfo().GetThreatEntries() {
partialHash := hashPrefix(te.Hash)
c.nttls[partialHash] = nttl
}
}
} | go | func (c *cache) Update(req *pb.FindFullHashesRequest, resp *pb.FindFullHashesResponse) {
c.Lock()
defer c.Unlock()
now := c.now()
if c.pttls == nil {
c.pttls = make(map[hashPrefix]map[ThreatDescriptor]time.Time)
c.nttls = make(map[hashPrefix]time.Time)
}
// Insert each threat match into the cache by full hash.
for _, tm := range resp.GetMatches() {
fullHash := hashPrefix(tm.GetThreat().Hash)
if !fullHash.IsFull() {
continue
}
if c.pttls[fullHash] == nil {
c.pttls[fullHash] = make(map[ThreatDescriptor]time.Time)
}
var dur time.Duration
if tmCacheDur := tm.GetCacheDuration(); tmCacheDur != nil {
dur = time.Duration(tm.GetCacheDuration().Seconds) * time.Second
} else {
dur = 0
}
td := ThreatDescriptor{
ThreatType: ThreatType(tm.ThreatType),
PlatformType: PlatformType(tm.PlatformType),
ThreatEntryType: ThreatEntryType(tm.ThreatEntryType),
}
c.pttls[fullHash][td] = now.Add(dur)
}
// Insert negative TTLs for partial hashes.
if resp.GetNegativeCacheDuration() != nil {
dur := time.Duration(resp.GetNegativeCacheDuration().Seconds) * time.Second
nttl := now.Add(dur)
for _, te := range req.GetThreatInfo().GetThreatEntries() {
partialHash := hashPrefix(te.Hash)
c.nttls[partialHash] = nttl
}
}
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"Update",
"(",
"req",
"*",
"pb",
".",
"FindFullHashesRequest",
",",
"resp",
"*",
"pb",
".",
"FindFullHashesResponse",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"now",
":=",
"c",
".",
"now",
"(",
")",
"\n\n",
"if",
"c",
".",
"pttls",
"==",
"nil",
"{",
"c",
".",
"pttls",
"=",
"make",
"(",
"map",
"[",
"hashPrefix",
"]",
"map",
"[",
"ThreatDescriptor",
"]",
"time",
".",
"Time",
")",
"\n",
"c",
".",
"nttls",
"=",
"make",
"(",
"map",
"[",
"hashPrefix",
"]",
"time",
".",
"Time",
")",
"\n",
"}",
"\n\n",
"// Insert each threat match into the cache by full hash.",
"for",
"_",
",",
"tm",
":=",
"range",
"resp",
".",
"GetMatches",
"(",
")",
"{",
"fullHash",
":=",
"hashPrefix",
"(",
"tm",
".",
"GetThreat",
"(",
")",
".",
"Hash",
")",
"\n",
"if",
"!",
"fullHash",
".",
"IsFull",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"c",
".",
"pttls",
"[",
"fullHash",
"]",
"==",
"nil",
"{",
"c",
".",
"pttls",
"[",
"fullHash",
"]",
"=",
"make",
"(",
"map",
"[",
"ThreatDescriptor",
"]",
"time",
".",
"Time",
")",
"\n",
"}",
"\n",
"var",
"dur",
"time",
".",
"Duration",
"\n",
"if",
"tmCacheDur",
":=",
"tm",
".",
"GetCacheDuration",
"(",
")",
";",
"tmCacheDur",
"!=",
"nil",
"{",
"dur",
"=",
"time",
".",
"Duration",
"(",
"tm",
".",
"GetCacheDuration",
"(",
")",
".",
"Seconds",
")",
"*",
"time",
".",
"Second",
"\n",
"}",
"else",
"{",
"dur",
"=",
"0",
"\n",
"}",
"\n",
"td",
":=",
"ThreatDescriptor",
"{",
"ThreatType",
":",
"ThreatType",
"(",
"tm",
".",
"ThreatType",
")",
",",
"PlatformType",
":",
"PlatformType",
"(",
"tm",
".",
"PlatformType",
")",
",",
"ThreatEntryType",
":",
"ThreatEntryType",
"(",
"tm",
".",
"ThreatEntryType",
")",
",",
"}",
"\n",
"c",
".",
"pttls",
"[",
"fullHash",
"]",
"[",
"td",
"]",
"=",
"now",
".",
"Add",
"(",
"dur",
")",
"\n",
"}",
"\n\n",
"// Insert negative TTLs for partial hashes.",
"if",
"resp",
".",
"GetNegativeCacheDuration",
"(",
")",
"!=",
"nil",
"{",
"dur",
":=",
"time",
".",
"Duration",
"(",
"resp",
".",
"GetNegativeCacheDuration",
"(",
")",
".",
"Seconds",
")",
"*",
"time",
".",
"Second",
"\n",
"nttl",
":=",
"now",
".",
"Add",
"(",
"dur",
")",
"\n",
"for",
"_",
",",
"te",
":=",
"range",
"req",
".",
"GetThreatInfo",
"(",
")",
".",
"GetThreatEntries",
"(",
")",
"{",
"partialHash",
":=",
"hashPrefix",
"(",
"te",
".",
"Hash",
")",
"\n",
"c",
".",
"nttls",
"[",
"partialHash",
"]",
"=",
"nttl",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Update updates the cache according to the request that was made to the server
// and the response given back. | [
"Update",
"updates",
"the",
"cache",
"according",
"to",
"the",
"request",
"that",
"was",
"made",
"to",
"the",
"server",
"and",
"the",
"response",
"given",
"back",
"."
] | 92a16cf6d02871018d6a426fb7886e34022c5c59 | https://github.com/google/safebrowsing/blob/92a16cf6d02871018d6a426fb7886e34022c5c59/cache.go#L64-L106 |
6,094 | google/safebrowsing | cache.go | Lookup | func (c *cache) Lookup(hash hashPrefix) (map[ThreatDescriptor]bool, cacheResult) {
if !hash.IsFull() {
panic("hash is not full")
}
c.Lock()
defer c.Unlock()
now := c.now()
// Check all entries to see if there *is* a threat.
threats := make(map[ThreatDescriptor]bool)
threatTTLs := c.pttls[hash]
for td, pttl := range threatTTLs {
if pttl.After(now) {
threats[td] = true
} else {
// The PTTL has expired, we should ask the server what's going on.
return nil, cacheMiss
}
}
if len(threats) > 0 {
// So long as there are valid threats, we report them. The positive TTL
// takes precedence over the negative TTL at the partial hash level.
return threats, positiveCacheHit
}
// Check the negative TTLs to see if there are *no* threats.
for i := minHashPrefixLength; i <= maxHashPrefixLength; i++ {
if nttl, ok := c.nttls[hash[:i]]; ok {
if nttl.After(now) {
return nil, negativeCacheHit
}
}
}
// The cache has no information; it is a *possible* threat.
return nil, cacheMiss
} | go | func (c *cache) Lookup(hash hashPrefix) (map[ThreatDescriptor]bool, cacheResult) {
if !hash.IsFull() {
panic("hash is not full")
}
c.Lock()
defer c.Unlock()
now := c.now()
// Check all entries to see if there *is* a threat.
threats := make(map[ThreatDescriptor]bool)
threatTTLs := c.pttls[hash]
for td, pttl := range threatTTLs {
if pttl.After(now) {
threats[td] = true
} else {
// The PTTL has expired, we should ask the server what's going on.
return nil, cacheMiss
}
}
if len(threats) > 0 {
// So long as there are valid threats, we report them. The positive TTL
// takes precedence over the negative TTL at the partial hash level.
return threats, positiveCacheHit
}
// Check the negative TTLs to see if there are *no* threats.
for i := minHashPrefixLength; i <= maxHashPrefixLength; i++ {
if nttl, ok := c.nttls[hash[:i]]; ok {
if nttl.After(now) {
return nil, negativeCacheHit
}
}
}
// The cache has no information; it is a *possible* threat.
return nil, cacheMiss
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"Lookup",
"(",
"hash",
"hashPrefix",
")",
"(",
"map",
"[",
"ThreatDescriptor",
"]",
"bool",
",",
"cacheResult",
")",
"{",
"if",
"!",
"hash",
".",
"IsFull",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"now",
":=",
"c",
".",
"now",
"(",
")",
"\n\n",
"// Check all entries to see if there *is* a threat.",
"threats",
":=",
"make",
"(",
"map",
"[",
"ThreatDescriptor",
"]",
"bool",
")",
"\n",
"threatTTLs",
":=",
"c",
".",
"pttls",
"[",
"hash",
"]",
"\n",
"for",
"td",
",",
"pttl",
":=",
"range",
"threatTTLs",
"{",
"if",
"pttl",
".",
"After",
"(",
"now",
")",
"{",
"threats",
"[",
"td",
"]",
"=",
"true",
"\n",
"}",
"else",
"{",
"// The PTTL has expired, we should ask the server what's going on.",
"return",
"nil",
",",
"cacheMiss",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"threats",
")",
">",
"0",
"{",
"// So long as there are valid threats, we report them. The positive TTL",
"// takes precedence over the negative TTL at the partial hash level.",
"return",
"threats",
",",
"positiveCacheHit",
"\n",
"}",
"\n\n",
"// Check the negative TTLs to see if there are *no* threats.",
"for",
"i",
":=",
"minHashPrefixLength",
";",
"i",
"<=",
"maxHashPrefixLength",
";",
"i",
"++",
"{",
"if",
"nttl",
",",
"ok",
":=",
"c",
".",
"nttls",
"[",
"hash",
"[",
":",
"i",
"]",
"]",
";",
"ok",
"{",
"if",
"nttl",
".",
"After",
"(",
"now",
")",
"{",
"return",
"nil",
",",
"negativeCacheHit",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// The cache has no information; it is a *possible* threat.",
"return",
"nil",
",",
"cacheMiss",
"\n",
"}"
] | // Lookup looks up a full hash and returns a set of ThreatDescriptors and the
// validity of the result. | [
"Lookup",
"looks",
"up",
"a",
"full",
"hash",
"and",
"returns",
"a",
"set",
"of",
"ThreatDescriptors",
"and",
"the",
"validity",
"of",
"the",
"result",
"."
] | 92a16cf6d02871018d6a426fb7886e34022c5c59 | https://github.com/google/safebrowsing/blob/92a16cf6d02871018d6a426fb7886e34022c5c59/cache.go#L110-L147 |
6,095 | google/safebrowsing | cache.go | Purge | func (c *cache) Purge() {
c.Lock()
defer c.Unlock()
now := c.now()
// Nuke all threat entries based on their positive TTL.
for fullHash, threatTTLs := range c.pttls {
for td, pttl := range threatTTLs {
if now.After(pttl) {
del := true
for i := minHashPrefixLength; i <= maxHashPrefixLength; i++ {
if nttl, ok := c.nttls[fullHash[:i]]; ok {
if nttl.After(pttl) {
del = false
break
}
}
}
if del {
delete(threatTTLs, td)
}
}
}
if len(threatTTLs) == 0 {
delete(c.pttls, fullHash)
}
}
// Nuke all partial hashes based on their negative TTL.
for partialHash, nttl := range c.nttls {
if now.After(nttl) {
delete(c.nttls, partialHash)
}
}
} | go | func (c *cache) Purge() {
c.Lock()
defer c.Unlock()
now := c.now()
// Nuke all threat entries based on their positive TTL.
for fullHash, threatTTLs := range c.pttls {
for td, pttl := range threatTTLs {
if now.After(pttl) {
del := true
for i := minHashPrefixLength; i <= maxHashPrefixLength; i++ {
if nttl, ok := c.nttls[fullHash[:i]]; ok {
if nttl.After(pttl) {
del = false
break
}
}
}
if del {
delete(threatTTLs, td)
}
}
}
if len(threatTTLs) == 0 {
delete(c.pttls, fullHash)
}
}
// Nuke all partial hashes based on their negative TTL.
for partialHash, nttl := range c.nttls {
if now.After(nttl) {
delete(c.nttls, partialHash)
}
}
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"Purge",
"(",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"now",
":=",
"c",
".",
"now",
"(",
")",
"\n\n",
"// Nuke all threat entries based on their positive TTL.",
"for",
"fullHash",
",",
"threatTTLs",
":=",
"range",
"c",
".",
"pttls",
"{",
"for",
"td",
",",
"pttl",
":=",
"range",
"threatTTLs",
"{",
"if",
"now",
".",
"After",
"(",
"pttl",
")",
"{",
"del",
":=",
"true",
"\n",
"for",
"i",
":=",
"minHashPrefixLength",
";",
"i",
"<=",
"maxHashPrefixLength",
";",
"i",
"++",
"{",
"if",
"nttl",
",",
"ok",
":=",
"c",
".",
"nttls",
"[",
"fullHash",
"[",
":",
"i",
"]",
"]",
";",
"ok",
"{",
"if",
"nttl",
".",
"After",
"(",
"pttl",
")",
"{",
"del",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"del",
"{",
"delete",
"(",
"threatTTLs",
",",
"td",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"threatTTLs",
")",
"==",
"0",
"{",
"delete",
"(",
"c",
".",
"pttls",
",",
"fullHash",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Nuke all partial hashes based on their negative TTL.",
"for",
"partialHash",
",",
"nttl",
":=",
"range",
"c",
".",
"nttls",
"{",
"if",
"now",
".",
"After",
"(",
"nttl",
")",
"{",
"delete",
"(",
"c",
".",
"nttls",
",",
"partialHash",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Purge purges all expired entries from the cache. | [
"Purge",
"purges",
"all",
"expired",
"entries",
"from",
"the",
"cache",
"."
] | 92a16cf6d02871018d6a426fb7886e34022c5c59 | https://github.com/google/safebrowsing/blob/92a16cf6d02871018d6a426fb7886e34022c5c59/cache.go#L150-L184 |
6,096 | google/safebrowsing | database.go | Init | func (db *database) Init(config *Config, logger *log.Logger) bool {
db.mu.Lock()
defer db.mu.Unlock()
db.setError(errors.New("not intialized"))
db.config = config
db.log = logger
if db.config.DBPath == "" {
db.log.Printf("no database file specified")
db.setError(errors.New("no database loaded"))
return false
}
dbf, err := loadDatabase(db.config.DBPath)
if err != nil {
db.log.Printf("load failure: %v", err)
db.setError(err)
return false
}
// Validate that the database threat list stored on disk is not too stale.
if db.isStale(dbf.Time) {
db.log.Printf("database loaded is stale")
db.ml.Lock()
defer db.ml.Unlock()
db.setStale()
return false
}
// Validate that the database threat list stored on disk is at least a
// superset of the specified configuration.
tfuNew := make(threatsForUpdate)
for _, td := range db.config.ThreatLists {
if row, ok := dbf.Table[td]; ok {
tfuNew[td] = row
} else {
db.log.Printf("database configuration mismatch, missing %v", td)
db.setError(errors.New("database configuration mismatch"))
return false
}
}
db.tfu = tfuNew
db.generateThreatsForLookups(dbf.Time)
return true
} | go | func (db *database) Init(config *Config, logger *log.Logger) bool {
db.mu.Lock()
defer db.mu.Unlock()
db.setError(errors.New("not intialized"))
db.config = config
db.log = logger
if db.config.DBPath == "" {
db.log.Printf("no database file specified")
db.setError(errors.New("no database loaded"))
return false
}
dbf, err := loadDatabase(db.config.DBPath)
if err != nil {
db.log.Printf("load failure: %v", err)
db.setError(err)
return false
}
// Validate that the database threat list stored on disk is not too stale.
if db.isStale(dbf.Time) {
db.log.Printf("database loaded is stale")
db.ml.Lock()
defer db.ml.Unlock()
db.setStale()
return false
}
// Validate that the database threat list stored on disk is at least a
// superset of the specified configuration.
tfuNew := make(threatsForUpdate)
for _, td := range db.config.ThreatLists {
if row, ok := dbf.Table[td]; ok {
tfuNew[td] = row
} else {
db.log.Printf("database configuration mismatch, missing %v", td)
db.setError(errors.New("database configuration mismatch"))
return false
}
}
db.tfu = tfuNew
db.generateThreatsForLookups(dbf.Time)
return true
} | [
"func",
"(",
"db",
"*",
"database",
")",
"Init",
"(",
"config",
"*",
"Config",
",",
"logger",
"*",
"log",
".",
"Logger",
")",
"bool",
"{",
"db",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"db",
".",
"setError",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"db",
".",
"config",
"=",
"config",
"\n",
"db",
".",
"log",
"=",
"logger",
"\n",
"if",
"db",
".",
"config",
".",
"DBPath",
"==",
"\"",
"\"",
"{",
"db",
".",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"db",
".",
"setError",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"dbf",
",",
"err",
":=",
"loadDatabase",
"(",
"db",
".",
"config",
".",
"DBPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"db",
".",
"setError",
"(",
"err",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"// Validate that the database threat list stored on disk is not too stale.",
"if",
"db",
".",
"isStale",
"(",
"dbf",
".",
"Time",
")",
"{",
"db",
".",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"db",
".",
"ml",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"ml",
".",
"Unlock",
"(",
")",
"\n",
"db",
".",
"setStale",
"(",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"// Validate that the database threat list stored on disk is at least a",
"// superset of the specified configuration.",
"tfuNew",
":=",
"make",
"(",
"threatsForUpdate",
")",
"\n",
"for",
"_",
",",
"td",
":=",
"range",
"db",
".",
"config",
".",
"ThreatLists",
"{",
"if",
"row",
",",
"ok",
":=",
"dbf",
".",
"Table",
"[",
"td",
"]",
";",
"ok",
"{",
"tfuNew",
"[",
"td",
"]",
"=",
"row",
"\n",
"}",
"else",
"{",
"db",
".",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"td",
")",
"\n",
"db",
".",
"setError",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"db",
".",
"tfu",
"=",
"tfuNew",
"\n",
"db",
".",
"generateThreatsForLookups",
"(",
"dbf",
".",
"Time",
")",
"\n",
"return",
"true",
"\n",
"}"
] | // Init initializes the database from the specified file in config.DBPath.
// It reports true if the database was successfully loaded. | [
"Init",
"initializes",
"the",
"database",
"from",
"the",
"specified",
"file",
"in",
"config",
".",
"DBPath",
".",
"It",
"reports",
"true",
"if",
"the",
"database",
"was",
"successfully",
"loaded",
"."
] | 92a16cf6d02871018d6a426fb7886e34022c5c59 | https://github.com/google/safebrowsing/blob/92a16cf6d02871018d6a426fb7886e34022c5c59/database.go#L104-L144 |
6,097 | google/safebrowsing | database.go | Status | func (db *database) Status() error {
db.ml.RLock()
defer db.ml.RUnlock()
if db.err != nil {
return db.err
}
if db.isStale(db.last) {
db.setStale()
return db.err
}
return nil
} | go | func (db *database) Status() error {
db.ml.RLock()
defer db.ml.RUnlock()
if db.err != nil {
return db.err
}
if db.isStale(db.last) {
db.setStale()
return db.err
}
return nil
} | [
"func",
"(",
"db",
"*",
"database",
")",
"Status",
"(",
")",
"error",
"{",
"db",
".",
"ml",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"ml",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"db",
".",
"err",
"!=",
"nil",
"{",
"return",
"db",
".",
"err",
"\n",
"}",
"\n",
"if",
"db",
".",
"isStale",
"(",
"db",
".",
"last",
")",
"{",
"db",
".",
"setStale",
"(",
")",
"\n",
"return",
"db",
".",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Status reports the health of the database. The database is considered faulted
// if there was an error during update or if the last update has gone stale. If
// in a faulted state, the db may repair itself on the next Update. | [
"Status",
"reports",
"the",
"health",
"of",
"the",
"database",
".",
"The",
"database",
"is",
"considered",
"faulted",
"if",
"there",
"was",
"an",
"error",
"during",
"update",
"or",
"if",
"the",
"last",
"update",
"has",
"gone",
"stale",
".",
"If",
"in",
"a",
"faulted",
"state",
"the",
"db",
"may",
"repair",
"itself",
"on",
"the",
"next",
"Update",
"."
] | 92a16cf6d02871018d6a426fb7886e34022c5c59 | https://github.com/google/safebrowsing/blob/92a16cf6d02871018d6a426fb7886e34022c5c59/database.go#L149-L161 |
6,098 | google/safebrowsing | database.go | UpdateLag | func (db *database) UpdateLag() time.Duration {
lag := db.SinceLastUpdate()
if lag < db.config.UpdatePeriod {
return 0
}
return lag - db.config.UpdatePeriod
} | go | func (db *database) UpdateLag() time.Duration {
lag := db.SinceLastUpdate()
if lag < db.config.UpdatePeriod {
return 0
}
return lag - db.config.UpdatePeriod
} | [
"func",
"(",
"db",
"*",
"database",
")",
"UpdateLag",
"(",
")",
"time",
".",
"Duration",
"{",
"lag",
":=",
"db",
".",
"SinceLastUpdate",
"(",
")",
"\n",
"if",
"lag",
"<",
"db",
".",
"config",
".",
"UpdatePeriod",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"lag",
"-",
"db",
".",
"config",
".",
"UpdatePeriod",
"\n",
"}"
] | // UpdateLag reports the amount of time in between when we expected to run
// a database update and the current time | [
"UpdateLag",
"reports",
"the",
"amount",
"of",
"time",
"in",
"between",
"when",
"we",
"expected",
"to",
"run",
"a",
"database",
"update",
"and",
"the",
"current",
"time"
] | 92a16cf6d02871018d6a426fb7886e34022c5c59 | https://github.com/google/safebrowsing/blob/92a16cf6d02871018d6a426fb7886e34022c5c59/database.go#L165-L171 |
6,099 | google/safebrowsing | database.go | SinceLastUpdate | func (db *database) SinceLastUpdate() time.Duration {
db.ml.RLock()
defer db.ml.RUnlock()
return db.config.now().Sub(db.last)
} | go | func (db *database) SinceLastUpdate() time.Duration {
db.ml.RLock()
defer db.ml.RUnlock()
return db.config.now().Sub(db.last)
} | [
"func",
"(",
"db",
"*",
"database",
")",
"SinceLastUpdate",
"(",
")",
"time",
".",
"Duration",
"{",
"db",
".",
"ml",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"ml",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"db",
".",
"config",
".",
"now",
"(",
")",
".",
"Sub",
"(",
"db",
".",
"last",
")",
"\n",
"}"
] | // SinceLastUpdate gives the duration since the last database update | [
"SinceLastUpdate",
"gives",
"the",
"duration",
"since",
"the",
"last",
"database",
"update"
] | 92a16cf6d02871018d6a426fb7886e34022c5c59 | https://github.com/google/safebrowsing/blob/92a16cf6d02871018d6a426fb7886e34022c5c59/database.go#L174-L179 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.