id stringlengths 2 7 | text stringlengths 17 51.2k | title stringclasses 1 value |
|---|---|---|
c171900 | parsed, err := parser.ParseFile(fset, fileName, src, 0)
if err != nil {
log.Printf("Failed to parse %s: %s", fileName, err)
return
}
// Convert the line number into raw file offset.
offsets := []int{0, 0}
start := 0
for l := 1; start < len(src); l++ {
start += bytes.IndexByte(src[start:], '\n') + 1
offsets = append(offsets, start)
}
c.parsed[fileName] = &parsedFile{offsets, parsed}
} | |
c171901 | {
return true
}
if found != nil {
// We are walking up.
}
if int(n.Pos()) >= p.lineToByteOffset[l] {
// We are expecting a ast.CallExpr node. It can be harder to figure out
// when there are multiple calls on a single line, as the stack trace
// doesn't have file byte offset information, only line based.
// gofmt will always format to one function call per line but there can
// be edge cases, like:
// a = A{Foo(), Bar()}
d = lastFunc
//p.processNode(call, n)
return false
} else if f, ok := n.(*ast.FuncDecl); ok {
lastFunc = f
}
return true
})
return
} | |
c171902 | return fmt.Sprintf("map[%s]%s", name(arg.Key), name(arg.Value)), false
case *ast.ChanType:
return fmt.Sprintf("chan %s", name(arg.Value)), false
default:
// TODO(maruel): Implement anything missing.
return "<unknown>", false
}
} | |
c171903 | arg := range append(fields, f.Type.Params.List...) {
// Assert that extra is only set on the last item of fields?
var t string
t, extra = fieldToType(arg)
mult := len(arg.Names)
if mult == 0 {
mult = 1
}
for i := 0; i < mult; i++ {
types = append(types, t)
}
}
return types, extra
} | |
c171904 | t.texts = append(t.texts, s)
break
}
t.texts = append(t.texts, s[:n])
s = s[n+len(a):]
n = bytes.Index(s, b)
if n < 0 {
return fmt.Errorf("Cannot find end tag=%q in the template=%q starting from %q", endTag, template, s)
}
t.tags = append(t.tags, unsafeBytes2String(s[:n]))
s = s[n+len(b):]
}
return nil
} | |
c171905 | !Opts.Disable {
postUnlock(m)
}
} | |
c171906 | !Opts.Disable {
postUnlock(m)
}
} | |
c171907 | {
continue
}
fmt.Fprintf(Opts.LogBuf, "goroutine %v lock %p\n", pp.gid, k)
printStack(Opts.LogBuf, pp.stack)
}
fmt.Fprintln(Opts.LogBuf)
} | |
c171908 | text, _ := ioutil.ReadFile(file)
fileSources.lines[file] = bytes.Split(text, []byte{'\n'})
return fileSources.lines[file]
} | |
c171909 | return buf[:n]
}
buf = make([]byte, 2*len(buf))
}
} | |
c171910 | enc := base57{newAlphabet(abc)}
return enc.Encode(uuid.New())
} | |
c171911 | remainder := math.Max(float64(padToLen-len(out)), 0)
out = out + strings.Repeat(b.alphabet.chars[0], int(remainder))
}
return out
} | |
c171912 | x = strings.Repeat("0", 32-len(x)) + x
} else if len(x) > 32 {
return "", fmt.Errorf("UUID length overflow for %q", s)
}
return fmt.Sprintf("%s-%s-%s-%s-%s", x[0:8], x[8:12], x[12:16], x[16:20], x[20:32]), nil
} | |
c171913 |
sort.Strings(abc)
a := alphabet{
len: int64(len(abc)),
}
copy(a.chars[:], abc)
return a
} | |
c171914 | }
return 0, fmt.Errorf("Element '%v' is not part of the alphabet", t)
} | |
c171915 | m[char] = true
out = append(out, char)
}
}
return out
} | |
c171916 | {
return Is(e.Err, original)
}
if original, ok := original.(*Error); ok {
return Is(e, original.Err)
}
return false
} | |
c171917 | = fmt.Sprintf("%s: %s", err.prefix, msg)
}
return msg
} | |
c171918 | + err.Error() + "\n" + string(err.Stack())
} | |
c171919 | return fmt.Sprintf("%s%s%s", t.start, val, t.stop)
} | |
c171920 | return &PointsIndex{newGeoIndex(resolution, newSet), make(map[string]Point)}
} | |
c171921 | delete(currentPosition, point.Id())
})
return set
}
return &PointsIndex{newGeoIndex(resolution, newExpiringSet), currentPosition}
} | |
c171922 | nil if a point has expired
if result, resultOk := points.index.GetEntryAt(point).(set).Get(id); resultOk {
return result.(Point)
}
}
return nil
} | |
c171923 | 0)
for i, p := range points.currentPosition {
newpoints[i] = p
}
return newpoints
} | |
c171924 | := points.index.AddEntryAt(point).(set)
newSet.Add(point.Id(), point)
points.currentPosition[point.Id()] = point
} | |
c171925 | set.Remove(prevPoint.Id())
delete(points.currentPosition, prevPoint.Id())
}
} | |
c171926 | bottomRight.Lat(), topLeft.Lat()) &&
between(point.Lon(), topLeft.Lon(), bottomRight.Lon())
}
return getPoints(entries, accept)
} | |
c171927 | idx.x-d, idx.y-d+1, idx.y+d-1), accept)
nearbyPoints = getPointsAppend(nearbyPoints, points.index.get(idx.x+d, idx.x+d, idx.y-d+1, idx.y+d-1), accept)
totalCount += len(nearbyPoints) - oldCount
if totalCount > k {
break
}
}
sortedPoints := &sortedPoints{nearbyPoints, point}
sort.Sort(sortedPoints)
k = min(k, len(sortedPoints.points))
// filter points which longer than maxDistance away from point.
for i, nearbyPoint := range sortedPoints.points {
if Distance(point, nearbyPoint) > maxDistance || i == k {
k = i
break
}
}
return sortedPoints.points[0:k]
} | |
c171928 | maxDistance away from point.
withinPoints := make([]Point, 0)
for _, nearbyPoint := range nearbyPoints {
if Distance(point, nearbyPoint) < distance {
withinPoints = append(withinPoints, nearbyPoint)
}
}
return withinPoints
} | |
c171929 | = 1
return &multiValueAccumulatingCounter{
newSingleValueAccumulatingCounter(point).(*singleValueAccumulatingCounter),
values,
}
} | |
c171930 | newSingleValueAccumulatingCounter(point).(*singleValueAccumulatingCounter),
point.(*CountPoint).Count.(float64),
}
} | |
c171931 | &geoIndex{resolution, make(map[cell]interface{}), newEntry}
} | |
c171932 |
geoIndex.index[square] = geoIndex.newEntry()
}
return geoIndex.index[square]
} | |
c171933 | ok := geoIndex.index[square]
if !ok {
return geoIndex.newEntry()
}
return entries
} | |
c171934 |
bottomRightIndex := cellOf(bottomRight, geoIndex.resolution)
return geoIndex.get(bottomRightIndex.x, topLeftIndex.x, topLeftIndex.y, bottomRightIndex.y)
} | |
c171935 | = NewCountIndex(Km(10))
index.worldLevel = NewCountIndex(Km(500))
return index
} | |
c171936 | NewExpiringCountIndex(Km(10), expiration)
index.worldLevel = NewExpiringCountIndex(Km(500), expiration)
return index
} | |
c171937 |
return index.streetLevel.Range(topLeft, bottomRight)
} else if dist < cityLevel {
return index.cityLevel.Range(topLeft, bottomRight)
} else {
return index.worldLevel.Range(topLeft, bottomRight)
}
} | |
c171938 | accept func(p Point) bool) []Point {
return index.streetLevel.KNearest(point, k, maxDistance, accept)
} | |
c171939 | queue.elements[queue.end%int64(queue.cap)] = element
queue.end++
queue.size++
} | |
c171940 | queue.size > 4 {
queue.resize(queue.cap / 2)
}
result := queue.elements[queue.start%int64(queue.cap)]
queue.start++
queue.size--
return result
} | |
c171941 |
return queue.elements[queue.start%int64(queue.cap)]
} | |
c171942 |
return queue.elements[(queue.end-1)%int64(queue.cap)]
} | |
c171943 | process(queue.elements[i%int64(queue.cap)])
}
} | |
c171944 | := range set {
clone[k] = v
}
return clone
} | |
c171945 | &CountIndex{newGeoIndex(resolution, newCounter), make(map[string]Point)}
} | |
c171946 |
return &CountIndex{newGeoIndex(resolution, newExpiringCounter), make(map[string]Point)}
} | |
c171947 | if c.(counter).Point() != nil {
points = append(points, c.(counter).Point())
}
}
return points
} | |
c171948 | bool) []Point {
panic("Unsupported operation")
} | |
c171949 |
indexInt := int(index / 45.0)
return Direction(indexInt)
} | |
c171950 | := math.Cos(lat1)*math.Sin(lat2) -
math.Sin(lat1)*math.Cos(lat2)*math.Cos(dLon)
brng := toDegrees(math.Atan2(y, x))
return brng
} | |
c171951 | := math.Abs(p1.Lon()-p2.Lon()) * float64(lonLength.get(avgLat))
return Meters(latLen*latLen + lonLen*lonLen)
} | |
c171952 | base,
inner: inner,
includes: includes,
}
} | |
c171953 | base,
inner: inner,
includes: includes,
}
} | |
c171954 | fmt.Errorf("no template name is specified [file: %s][line: %d]", ln.fileName(), ln.no)
}
e := &helperMethodYield{
elementBase: newElementBase(ln, rslt, src, parent, opts),
templateName: ln.tokens[2],
}
return e, nil
} | |
c171955 |
return nil, fmt.Errorf("doctype is invalid [file: %s][line: %d][doctype: %s]", ln.fileName(), ln.no, doctype)
}
e := &helperMethodDoctype{
elementBase: newElementBase(ln, rslt, src, parent, opts),
doctype: doctype,
}
return e, nil
} | |
c171956 | *File {
return &File{
path: path,
data: data,
}
} | |
c171957 |
rslt, err := ParseSource(src, opts)
if err != nil {
return nil, err
}
// Compile the parsed result.
tpl, err := CompileResult(name, rslt, opts)
if err != nil {
return nil, err
}
if !opts.DynamicReload {
setCache(name, *tpl)
}
return tpl, nil
} | |
c171958 | := cache[name]
cacheMutex.RUnlock()
return tpl, ok
} | |
c171959 | cache[name] = tpl
cacheMutex.Unlock()
} | |
c171960 | = make(map[string]template.Template)
cacheMutex.Unlock()
} | |
c171961 | newElementBase(ln, rslt, src, parent, opts),
insertBr: insertBr,
}
} | |
c171962 | *Options) *emptyElement {
return &emptyElement{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
} | |
c171963 | *Options) *comment {
return &comment{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
} | |
c171964 | return &helperMethodJavascript{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
} | |
c171965 | := range src.includes {
includes[f.path], err = parseBytes(f.data, rslt, src, opts, f)
if err != nil {
return nil, err
}
}
rslt.base = base
rslt.inner = inner
rslt.includes = includes
return rslt, nil
} | |
c171966 | ln := newLine(i+1, lines[i], opts, f)
i++
// Ignore the empty line.
if ln.isEmpty() {
continue
}
if ln.isTopIndent() {
e, err := newElement(ln, rslt, src, nil, opts)
if err != nil {
return nil, err
}
// Append child elements to the element.
if err := appendChildren(e, rslt, lines, &i, l, src, opts, f); err != nil {
return nil, err
}
elements = append(elements, e)
}
}
return elements, nil
} | |
c171967 | child, err := newElement(ln, rslt, src, parent, opts)
if err != nil {
return err
}
parent.AppendChild(child)
*i++
if child.CanHaveChildren() {
if err := appendChildren(child, rslt, lines, i, l, src, opts, f); err != nil {
return err
}
}
}
return nil
} | |
c171968 | *Options) *htmlComment {
return &htmlComment{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
} | |
c171969 | %d]", ln.fileName(), ln.no)
}
var pipeline string
if len(ln.tokens) > 3 {
pipeline = strings.Join(ln.tokens[3:], space)
}
e := &helperMethodInclude{
elementBase: newElementBase(ln, rslt, src, parent, opts),
templateName: ln.tokens[2],
pipeline: pipeline,
}
return e, nil
} | |
c171970 | %s][line: %d]", ln.fileName(), ln.no)
}
e := &helperMethodConditionalComment{
elementBase: newElementBase(ln, rslt, src, parent, opts),
commentType: commentType,
condition: strings.Join(ln.tokens[3:], space),
}
return e, nil
} | |
c171971 | Create a template.
t := template.New(name)
return CompileResultWithTemplate(t, rslt, opts)
} | |
c171972 |
}
// Set Delimiters.
t.Delims(opts.DelimLeft, opts.DelimRight)
// Set FuncMaps.
t.Funcs(template.FuncMap{
preDefinedFuncNameHTML: func(s string) template.HTML {
return template.HTML(s)
},
})
t.Funcs(opts.FuncMap)
// Parse a string to the template.
t, err = t.Parse(baseBf.String())
if err != nil {
return nil, err
}
t, err = t.Parse(innerBf.String())
if err != nil {
return nil, err
}
for _, bf := range includeBfs {
t, err = t.Parse(bf.String())
if err != nil {
return nil, err
}
}
return t, nil
} | |
c171973 | = append(e.children, child)
} | |
c171974 | e.opts.formatter.OpeningElement(bf, child); err != nil {
return int64(i), err
}
}
if i, err := child.WriteTo(bf); err != nil {
return int64(i), err
}
}
return 0, nil
} | |
c171975 | {
return elementBase{
ln: ln,
rslt: rslt,
src: src,
parent: parent,
opts: opts,
}
} | |
c171976 | {
return nil, err
}
// Find include files from the inner file.
if err := findIncludes(inner.data, opts, &includes, inner); err != nil {
return nil, err
}
return NewSource(base, inner, includes), nil
} | |
c171977 | } else {
data, err = ioutil.ReadFile(name)
}
if err != nil {
return nil, err
}
}
return NewFile(path, data), nil
} | |
c171978 | includePaths {
if !hasFile(*includes, includePath) {
f, err := readFile(includePath, opts)
if err != nil {
return err
}
*includes = append(*includes, f)
if err := findIncludes(f.data, opts, includes, f); err != nil {
return err
}
}
}
return nil
} | |
c171979 | return nil, fmt.Errorf("no template name is specified [file: %s][line: %d]", ln.fileName(), ln.no)
}
includePaths = append(includePaths, ln.tokens[2])
}
}
return includePaths, nil
} | |
c171980 | == path {
return true
}
}
return false
} | |
c171981 | *Options) *helperMethodCSS {
return &helperMethodCSS{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
} | |
c171982 | err = newHelperMethodContent(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameCSS):
e = newHelperMethodCSS(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameDoctype):
e, err = newHelperMethodDoctype(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameInclude):
e, err = newHelperMethodInclude(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameJavascript):
e = newHelperMethodJavascript(ln, rslt, src, parent, opts)
case ln.isHelperMethodOf(helperMethodNameYield):
e, err = newHelperMethodYield(ln, rslt, src, parent, opts)
default:
err = fmt.Errorf("the helper method name is invalid [file: %s][line: %d]", ln.fileName(), ln.no)
}
case ln.isPlainText():
e = newPlainText(ln, rslt, src, parent, opts)
case ln.isAction():
e = newAction(ln, rslt, src, parent, opts)
default:
e, err = newHTMLTag(ln, rslt, src, parent, opts)
}
return e, err
} | |
c171983 |
e := &helperMethodContent{
elementBase: newElementBase(ln, rslt, src, parent, opts),
name: ln.tokens[2],
}
return e, nil
} | |
c171984 | > 1 && strings.HasPrefix(v, doubleQuote) && strings.HasSuffix(v, doubleQuote) {
v = v[1 : len(v)-1]
}
switch k {
case attributeNameID:
if e.id != "" {
return fmt.Errorf("multiple IDs are specified [file: %s][line: %d]", e.ln.fileName(), e.ln.no)
}
e.id = v
case e.opts.AttributeNameClass:
e.classes = append(e.classes, strings.Split(v, space)...)
default:
e.attributes = append(e.attributes, htmlAttribute{k, v})
}
}
// Set a text value to the element.
if setTextValue {
e.textValue = strings.Join(parsedTokens[i:], space)
}
return nil
} | |
c171985 | e.opts.NoCloseTagNames {
if e.tagName == name {
return true
}
}
return false
} | |
c171986 |
return !inline
} else {
return true
}
} | |
c171987 | classes,
containPlainText: strings.HasSuffix(s, dot),
insertBr: strings.HasSuffix(s, doubleDot),
attributes: make([]htmlAttribute, 0, 2),
}
if err := e.setAttributes(); err != nil {
return nil, err
}
return e, nil
} | |
c171988 | sharp)[0], dot)[0]
if tagName == "" {
tagName = tagNameDiv
}
return tagName
} | |
c171989 | IDs are specified [file: %s][line: %d]", ln.fileName(), ln.no)
}
return strings.Split(tokens[1], dot)[0], nil
} | |
c171990 | := strings.Split(token, sharp)[0]
if class == "" {
continue
}
classes = append(classes, class)
}
return classes
} | |
c171991 | token += c
if inDelim {
if strings.HasSuffix(token, e.opts.DelimRight) {
inDelim = false
}
} else {
if strings.HasSuffix(token, e.opts.DelimLeft) {
inDelim = true
}
}
}
}
if len(token) > 0 {
tokens = append(tokens, token)
}
return tokens
} | |
c171992 | src, parent, opts),
insertBr: ln.tokens[0] == doublePipe,
}
} | |
c171993 | > 1 && l.tokens[0] == equal
} | |
c171994 | l.isHelperMethod() && l.tokens[1] == name
} | |
c171995 | == pipe || l.tokens[0] == doublePipe)
} | |
c171996 | && l.tokens[0] == slash
} | |
c171997 | && l.tokens[0] == slash+slash
} | |
c171998 |
return strings.HasPrefix(str, l.opts.DelimLeft) && strings.HasSuffix(str, l.opts.DelimRight)
} | |
c171999 | + dot + l.opts.Extension
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.