_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q171900
load
validation
func (c *cache) load(fileName string) { if _, ok := c.parsed[fileName]; ok { return } c.parsed[fileName] = nil if !strings.HasSuffix(fileName, ".go") { // Ignore C and assembly. c.files[fileName] = nil return } log.Printf("load(%s)", fileName) if _, ok := c.files[fileName]; !ok { var err error if c.f...
go
{ "resource": "" }
q171901
getFuncAST
validation
func (p *parsedFile) getFuncAST(f string, l int) (d *ast.FuncDecl) { if len(p.lineToByteOffset) <= l { // The line number in the stack trace line does not exist in the file. That // can only mean that the sources on disk do not match the sources used to // build the binary. // TODO(maruel): This should be surf...
go
{ "resource": "" }
q171902
fieldToType
validation
func fieldToType(f *ast.Field) (string, bool) { switch arg := f.Type.(type) { case *ast.ArrayType: return "[]" + name(arg.Elt), false case *ast.Ellipsis: return name(arg.Elt), true case *ast.FuncType: // Do not print the function signature to not overload the trace. return "func", false case *ast.Ident: ...
go
{ "resource": "" }
q171903
extractArgumentsType
validation
func extractArgumentsType(f *ast.FuncDecl) ([]string, bool) { var fields []*ast.Field if f.Recv != nil { if len(f.Recv.List) != 1 { panic("Expect only one receiver; please fix panicparse's code") } // If it is an object receiver (vs a pointer receiver), its address is not // printed in the stack trace so i...
go
{ "resource": "" }
q171904
Reset
validation
func (t *Template) Reset(template, startTag, endTag string) error { // Keep these vars in t, so GC won't collect them and won't break // vars derived via unsafe* t.template = template t.startTag = startTag t.endTag = endTag t.texts = t.texts[:0] t.tags = t.tags[:0] if len(startTag) == 0 { panic("startTag can...
go
{ "resource": "" }
q171905
Unlock
validation
func (m *Mutex) Unlock() { m.mu.Unlock() if !Opts.Disable { postUnlock(m) } }
go
{ "resource": "" }
q171906
RUnlock
validation
func (m *RWMutex) RUnlock() { m.mu.RUnlock() if !Opts.Disable { postUnlock(m) } }
go
{ "resource": "" }
q171907
other
validation
func (l *lockOrder) other(ptr interface{}) { empty := true for k := range l.cur { if k == ptr { continue } empty = false } if empty { return } fmt.Fprintln(Opts.LogBuf, "Other goroutines holding locks:") for k, pp := range l.cur { if k == ptr { continue } fmt.Fprintf(Opts.LogBuf, "goroutine %...
go
{ "resource": "" }
q171908
getSourceLines
validation
func getSourceLines(file string) [][]byte { fileSources.Lock() defer fileSources.Unlock() if fileSources.lines == nil { fileSources.lines = map[string][][]byte{} } if lines, ok := fileSources.lines[file]; ok { return lines } text, _ := ioutil.ReadFile(file) fileSources.lines[file] = bytes.Split(text, []byte...
go
{ "resource": "" }
q171909
stacks
validation
func stacks() []byte { buf := make([]byte, 1024*16) for { n := runtime.Stack(buf, true) if n < len(buf) { return buf[:n] } buf = make([]byte, 2*len(buf)) } }
go
{ "resource": "" }
q171910
NewWithAlphabet
validation
func NewWithAlphabet(abc string) string { enc := base57{newAlphabet(abc)} return enc.Encode(uuid.New()) }
go
{ "resource": "" }
q171911
numToString
validation
func (b *base57) numToString(number *big.Int, padToLen int) string { var ( out string digit *big.Int ) for number.Uint64() > 0 { number, digit = new(big.Int).DivMod(number, big.NewInt(b.alphabet.Length()), new(big.Int)) out += b.alphabet.chars[digit.Int64()] } if padToLen > 0 { remainder := math.Max(...
go
{ "resource": "" }
q171912
stringToNum
validation
func (b *base57) stringToNum(s string) (string, error) { n := big.NewInt(0) for i := len(s) - 1; i >= 0; i-- { n.Mul(n, big.NewInt(b.alphabet.Length())) index, err := b.alphabet.Index(string(s[i])) if err != nil { return "", err } n.Add(n, big.NewInt(index)) } x := fmt.Sprintf("%x", n) if len(x) ...
go
{ "resource": "" }
q171913
newAlphabet
validation
func newAlphabet(s string) alphabet { abc := dedupe(strings.Split(s, "")) if len(abc) != 57 { panic("encoding alphabet is not 57-bytes long") } sort.Strings(abc) a := alphabet{ len: int64(len(abc)), } copy(a.chars[:], abc) return a }
go
{ "resource": "" }
q171914
Index
validation
func (a *alphabet) Index(t string) (int64, error) { for i, char := range a.chars { if char == t { return int64(i), nil } } return 0, fmt.Errorf("Element '%v' is not part of the alphabet", t) }
go
{ "resource": "" }
q171915
dedupe
validation
func dedupe(s []string) []string { var out []string m := make(map[string]bool) for _, char := range s { if _, ok := m[char]; !ok { m[char] = true out = append(out, char) } } return out }
go
{ "resource": "" }
q171916
Is
validation
func Is(e error, original error) bool { if e == original { return true } if e, ok := e.(*Error); ok { return Is(e.Err, original) } if original, ok := original.(*Error); ok { return Is(e, original.Err) } return false }
go
{ "resource": "" }
q171917
Error
validation
func (err *Error) Error() string { msg := err.Err.Error() if err.prefix != "" { msg = fmt.Sprintf("%s: %s", err.prefix, msg) } return msg }
go
{ "resource": "" }
q171918
ErrorStack
validation
func (err *Error) ErrorStack() string { return err.TypeName() + " " + err.Error() + "\n" + string(err.Stack()) }
go
{ "resource": "" }
q171919
TextStyle
validation
func (t TextStyle) TextStyle(val string) string { if t == emptyTextStyle { return val } return fmt.Sprintf("%s%s%s", t.start, val, t.stop) }
go
{ "resource": "" }
q171920
NewPointsIndex
validation
func NewPointsIndex(resolution Meters) *PointsIndex { newSet := func() interface{} { return newSet() } return &PointsIndex{newGeoIndex(resolution, newSet), make(map[string]Point)} }
go
{ "resource": "" }
q171921
NewExpiringPointsIndex
validation
func NewExpiringPointsIndex(resolution Meters, expiration Minutes) *PointsIndex { currentPosition := make(map[string]Point) newExpiringSet := func() interface{} { set := newExpiringSet(expiration) set.OnExpire(func(id string, value interface{}) { point := value.(Point) delete(currentPosition, point.Id()) ...
go
{ "resource": "" }
q171922
Get
validation
func (points *PointsIndex) Get(id string) Point { if point, ok := points.currentPosition[id]; ok { // first it gets the set of the currentPosition and then gets the point from the set // this is done so it triggers expiration on expiringSet, and returns nil if a point has expired if result, resultOk := points.in...
go
{ "resource": "" }
q171923
GetAll
validation
func (points *PointsIndex) GetAll() map[string]Point { newpoints := make(map[string]Point, 0) for i, p := range points.currentPosition { newpoints[i] = p } return newpoints }
go
{ "resource": "" }
q171924
Add
validation
func (points *PointsIndex) Add(point Point) { points.Remove(point.Id()) newSet := points.index.AddEntryAt(point).(set) newSet.Add(point.Id(), point) points.currentPosition[point.Id()] = point }
go
{ "resource": "" }
q171925
Remove
validation
func (points *PointsIndex) Remove(id string) { if prevPoint, ok := points.currentPosition[id]; ok { set := points.index.GetEntryAt(prevPoint).(set) set.Remove(prevPoint.Id()) delete(points.currentPosition, prevPoint.Id()) } }
go
{ "resource": "" }
q171926
Range
validation
func (points *PointsIndex) Range(topLeft Point, bottomRight Point) []Point { entries := points.index.Range(topLeft, bottomRight) accept := func(point Point) bool { return between(point.Lat(), bottomRight.Lat(), topLeft.Lat()) && between(point.Lon(), topLeft.Lon(), bottomRight.Lon()) } return getPoints(entries...
go
{ "resource": "" }
q171927
KNearest
validation
func (points *PointsIndex) KNearest(point Point, k int, maxDistance Meters, accept func(p Point) bool) []Point { nearbyPoints := make([]Point, 0) pointEntry := points.index.GetEntryAt(point).(set) nearbyPoints = append(nearbyPoints, getPoints([]interface{}{pointEntry}, accept)...) totalCount := 0 idx := cellOf(po...
go
{ "resource": "" }
q171928
PointsWithin
validation
func (points *PointsIndex) PointsWithin(point Point, distance Meters, accept func(p Point) bool) []Point { d := int(distance / points.index.resolution) if d == 0 { d = 1 } idx := cellOf(point, points.index.resolution) nearbyPoints := make([]Point, 0) nearbyPoints = getPointsAppend(nearbyPoints, points.index...
go
{ "resource": "" }
q171929
newMultiValueCounter
validation
func newMultiValueCounter(point Point) accumulatingCounter { values := make(map[string]int) values[point.Id()] = 1 return &multiValueAccumulatingCounter{ newSingleValueAccumulatingCounter(point).(*singleValueAccumulatingCounter), values, } }
go
{ "resource": "" }
q171930
newAverageAccumulatingCounter
validation
func newAverageAccumulatingCounter(point Point) accumulatingCounter { return &averageAccumulatingCounter{ newSingleValueAccumulatingCounter(point).(*singleValueAccumulatingCounter), point.(*CountPoint).Count.(float64), } }
go
{ "resource": "" }
q171931
newGeoIndex
validation
func newGeoIndex(resolution Meters, newEntry func() interface{}) *geoIndex { return &geoIndex{resolution, make(map[cell]interface{}), newEntry} }
go
{ "resource": "" }
q171932
AddEntryAt
validation
func (geoIndex *geoIndex) AddEntryAt(point Point) interface{} { square := cellOf(point, geoIndex.resolution) if _, ok := geoIndex.index[square]; !ok { geoIndex.index[square] = geoIndex.newEntry() } return geoIndex.index[square] }
go
{ "resource": "" }
q171933
GetEntryAt
validation
func (geoIndex *geoIndex) GetEntryAt(point Point) interface{} { square := cellOf(point, geoIndex.resolution) entries, ok := geoIndex.index[square] if !ok { return geoIndex.newEntry() } return entries }
go
{ "resource": "" }
q171934
Range
validation
func (geoIndex *geoIndex) Range(topLeft Point, bottomRight Point) []interface{} { topLeftIndex := cellOf(topLeft, geoIndex.resolution) bottomRightIndex := cellOf(bottomRight, geoIndex.resolution) return geoIndex.get(bottomRightIndex.x, topLeftIndex.x, topLeftIndex.y, bottomRightIndex.y) }
go
{ "resource": "" }
q171935
NewClusteringIndex
validation
func NewClusteringIndex() *ClusteringIndex { index := &ClusteringIndex{} index.streetLevel = NewPointsIndex(Km(0.5)) index.cityLevel = NewCountIndex(Km(10)) index.worldLevel = NewCountIndex(Km(500)) return index }
go
{ "resource": "" }
q171936
NewExpiringClusteringIndex
validation
func NewExpiringClusteringIndex(expiration Minutes) *ClusteringIndex { index := &ClusteringIndex{} index.streetLevel = NewExpiringPointsIndex(Km(0.5), expiration) index.cityLevel = NewExpiringCountIndex(Km(10), expiration) index.worldLevel = NewExpiringCountIndex(Km(500), expiration) return index }
go
{ "resource": "" }
q171937
Range
validation
func (index *ClusteringIndex) Range(topLeft Point, bottomRight Point) []Point { dist := distance(topLeft, bottomRight) if dist < streetLevel { return index.streetLevel.Range(topLeft, bottomRight) } else if dist < cityLevel { return index.cityLevel.Range(topLeft, bottomRight) } else { return index.worldLevel....
go
{ "resource": "" }
q171938
KNearest
validation
func (index *ClusteringIndex) KNearest(point Point, k int, maxDistance Meters, accept func(p Point) bool) []Point { return index.streetLevel.KNearest(point, k, maxDistance, accept) }
go
{ "resource": "" }
q171939
Push
validation
func (queue *queue) Push(element interface{}) { if queue.size == queue.cap { queue.resize(queue.cap * 2) } queue.elements[queue.end%int64(queue.cap)] = element queue.end++ queue.size++ }
go
{ "resource": "" }
q171940
Pop
validation
func (queue *queue) Pop() interface{} { if queue.size == 0 { return nil } if queue.size < queue.cap/4 && queue.size > 4 { queue.resize(queue.cap / 2) } result := queue.elements[queue.start%int64(queue.cap)] queue.start++ queue.size-- return result }
go
{ "resource": "" }
q171941
Peek
validation
func (queue *queue) Peek() interface{} { if queue.size == 0 { return nil } return queue.elements[queue.start%int64(queue.cap)] }
go
{ "resource": "" }
q171942
PeekBack
validation
func (queue *queue) PeekBack() interface{} { if queue.size == 0 { return nil } return queue.elements[(queue.end-1)%int64(queue.cap)] }
go
{ "resource": "" }
q171943
ForEach
validation
func (queue *queue) ForEach(process func(interface{})) { for i := queue.start; i < queue.end; i++ { process(queue.elements[i%int64(queue.cap)]) } }
go
{ "resource": "" }
q171944
Clone
validation
func (set basicSet) Clone() set { clone := basicSet(make(map[string]interface{})) for k, v := range set { clone[k] = v } return clone }
go
{ "resource": "" }
q171945
NewCountIndex
validation
func NewCountIndex(resolution Meters) *CountIndex { newCounter := func() interface{} { return &singleValueAccumulatingCounter{} } return &CountIndex{newGeoIndex(resolution, newCounter), make(map[string]Point)} }
go
{ "resource": "" }
q171946
NewExpiringCountIndex
validation
func NewExpiringCountIndex(resolution Meters, expiration Minutes) *CountIndex { newExpiringCounter := func() interface{} { return newExpiringCounter(expiration) } return &CountIndex{newGeoIndex(resolution, newExpiringCounter), make(map[string]Point)} }
go
{ "resource": "" }
q171947
Range
validation
func (countIndex *CountIndex) Range(topLeft Point, bottomRight Point) []Point { counters := countIndex.index.Range(topLeft, bottomRight) points := make([]Point, 0) for _, c := range counters { if c.(counter).Point() != nil { points = append(points, c.(counter).Point()) } } return points }
go
{ "resource": "" }
q171948
KNearest
validation
func (index *CountIndex) KNearest(point Point, k int, maxDistance Meters, accept func(p Point) bool) []Point { panic("Unsupported operation") }
go
{ "resource": "" }
q171949
DirectionTo
validation
func DirectionTo(p1, p2 Point) Direction { bearing := BearingTo(p1, p2) index := bearing - 22.5 if index < 0 { index += 360 } indexInt := int(index / 45.0) return Direction(indexInt) }
go
{ "resource": "" }
q171950
BearingTo
validation
func BearingTo(p1, p2 Point) float64 { dLon := toRadians(p2.Lon() - p1.Lon()) lat1 := toRadians(p1.Lat()) lat2 := toRadians(p2.Lat()) y := math.Sin(dLon) * math.Cos(lat2) x := math.Cos(lat1)*math.Sin(lat2) - math.Sin(lat1)*math.Cos(lat2)*math.Cos(dLon) brng := toDegrees(math.Atan2(y, x)) return brng }
go
{ "resource": "" }
q171951
approximateSquareDistance
validation
func approximateSquareDistance(p1, p2 Point) Meters { avgLat := (p1.Lat() + p2.Lat()) / 2.0 latLen := math.Abs(p1.Lat()-p2.Lat()) * float64(latDegreeLength) lonLen := math.Abs(p1.Lon()-p2.Lon()) * float64(lonLength.get(avgLat)) return Meters(latLen*latLen + lonLen*lonLen) }
go
{ "resource": "" }
q171952
newResult
validation
func newResult(base []element, inner []element, includes map[string][]element) *result { return &result{ base: base, inner: inner, includes: includes, } }
go
{ "resource": "" }
q171953
NewSource
validation
func NewSource(base, inner *File, includes []*File) *source { return &source{ base: base, inner: inner, includes: includes, } }
go
{ "resource": "" }
q171954
newHelperMethodYield
validation
func newHelperMethodYield(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodYield, error) { if len(ln.tokens) < 3 { return nil, fmt.Errorf("no template name is specified [file: %s][line: %d]", ln.fileName(), ln.no) } e := &helperMethodYield{ elementBase: newElementBase(ln, rslt,...
go
{ "resource": "" }
q171955
newHelperMethodDoctype
validation
func newHelperMethodDoctype(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodDoctype, error) { if len(ln.tokens) < 3 { return nil, fmt.Errorf("doctype is not specified [file: %s][line: %d]", ln.fileName(), ln.no) } doctype := ln.tokens[2] if _, ok := doctypes[doctype]; !ok { r...
go
{ "resource": "" }
q171956
NewFile
validation
func NewFile(path string, data []byte) *File { return &File{ path: path, data: data, } }
go
{ "resource": "" }
q171957
Load
validation
func Load(basePath, innerPath string, opts *Options) (*template.Template, error) { // Initialize the options. opts = InitializeOptions(opts) name := basePath + colon + innerPath if !opts.DynamicReload { if tpl, ok := getCache(name); ok { return &tpl, nil } } // Read files. src, err := readFiles(basePat...
go
{ "resource": "" }
q171958
getCache
validation
func getCache(name string) (template.Template, bool) { cacheMutex.RLock() tpl, ok := cache[name] cacheMutex.RUnlock() return tpl, ok }
go
{ "resource": "" }
q171959
setCache
validation
func setCache(name string, tpl template.Template) { cacheMutex.Lock() cache[name] = tpl cacheMutex.Unlock() }
go
{ "resource": "" }
q171960
FlushCache
validation
func FlushCache() { cacheMutex.Lock() cache = make(map[string]template.Template) cacheMutex.Unlock() }
go
{ "resource": "" }
q171961
newPlainTextInner
validation
func newPlainTextInner(ln *line, rslt *result, src *source, parent element, insertBr bool, opts *Options) *plainTextInner { return &plainTextInner{ elementBase: newElementBase(ln, rslt, src, parent, opts), insertBr: insertBr, } }
go
{ "resource": "" }
q171962
newEmptyElement
validation
func newEmptyElement(ln *line, rslt *result, src *source, parent element, opts *Options) *emptyElement { return &emptyElement{ elementBase: newElementBase(ln, rslt, src, parent, opts), } }
go
{ "resource": "" }
q171963
newComment
validation
func newComment(ln *line, rslt *result, src *source, parent element, opts *Options) *comment { return &comment{ elementBase: newElementBase(ln, rslt, src, parent, opts), } }
go
{ "resource": "" }
q171964
newHelperMethodJavascript
validation
func newHelperMethodJavascript(ln *line, rslt *result, src *source, parent element, opts *Options) *helperMethodJavascript { return &helperMethodJavascript{ elementBase: newElementBase(ln, rslt, src, parent, opts), } }
go
{ "resource": "" }
q171965
ParseSource
validation
func ParseSource(src *source, opts *Options) (*result, error) { // Initialize the options. opts = InitializeOptions(opts) rslt := newResult(nil, nil, nil) base, err := parseBytes(src.base.data, rslt, src, opts, src.base) if err != nil { return nil, err } inner, err := parseBytes(src.inner.data, rslt, src, o...
go
{ "resource": "" }
q171966
parseBytes
validation
func parseBytes(data []byte, rslt *result, src *source, opts *Options, f *File) ([]element, error) { var elements []element lines := strings.Split(formatLF(string(data)), lf) i := 0 l := len(lines) // Ignore the last empty line. if l > 0 && lines[l-1] == "" { l-- } for i < l { // Fetch a line. ln := n...
go
{ "resource": "" }
q171967
appendChildren
validation
func appendChildren(parent element, rslt *result, lines []string, i *int, l int, src *source, opts *Options, f *File) error { for *i < l { // Fetch a line. ln := newLine(*i+1, lines[*i], opts, f) // Check if the line is a child of the parent. ok, err := ln.childOf(parent) if err != nil { return err } ...
go
{ "resource": "" }
q171968
newHTMLComment
validation
func newHTMLComment(ln *line, rslt *result, src *source, parent element, opts *Options) *htmlComment { return &htmlComment{ elementBase: newElementBase(ln, rslt, src, parent, opts), } }
go
{ "resource": "" }
q171969
newHelperMethodInclude
validation
func newHelperMethodInclude(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodInclude, error) { if len(ln.tokens) < 3 { return nil, fmt.Errorf("no template name is specified [file: %s][line: %d]", ln.fileName(), ln.no) } var pipeline string if len(ln.tokens) > 3 { pipeline = st...
go
{ "resource": "" }
q171970
newHelperMethodConditionalComment
validation
func newHelperMethodConditionalComment(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodConditionalComment, error) { switch len(ln.tokens) { case 2: return nil, fmt.Errorf("no comment type is specified [file: %s][line: %d]", ln.fileName(), ln.no) case 3: return nil, fmt.Errorf("n...
go
{ "resource": "" }
q171971
CompileResult
validation
func CompileResult(name string, rslt *result, opts *Options) (*template.Template, error) { // Initialize the options. opts = InitializeOptions(opts) // Create a template. t := template.New(name) return CompileResultWithTemplate(t, rslt, opts) }
go
{ "resource": "" }
q171972
CompileResultWithTemplate
validation
func CompileResultWithTemplate(t *template.Template, rslt *result, opts *Options) (*template.Template, error) { // Initialize the options. opts = InitializeOptions(opts) var err error // Create a buffer. baseBf := bytes.NewBuffer(nil) innerBf := bytes.NewBuffer(nil) includeBfs := make(map[string]*bytes.Buffer)...
go
{ "resource": "" }
q171973
AppendChild
validation
func (e *elementBase) AppendChild(child element) { e.children = append(e.children, child) }
go
{ "resource": "" }
q171974
writeChildren
validation
func (e *elementBase) writeChildren(bf *bytes.Buffer) (int64, error) { l := len(e.children) for index, child := range e.children { if index == l-1 { child.SetLastChild(true) } if e.opts.formatter != nil { if i, err := e.opts.formatter.OpeningElement(bf, child); err != nil { return int64(i), err } ...
go
{ "resource": "" }
q171975
newElementBase
validation
func newElementBase(ln *line, rslt *result, src *source, parent element, opts *Options) elementBase { return elementBase{ ln: ln, rslt: rslt, src: src, parent: parent, opts: opts, } }
go
{ "resource": "" }
q171976
readFiles
validation
func readFiles(basePath, innerPath string, opts *Options) (*source, error) { // Read the base file. base, err := readFile(basePath, opts) if err != nil { return nil, err } // Read the inner file. inner, err := readFile(innerPath, opts) if err != nil { return nil, err } var includes []*File // Find incl...
go
{ "resource": "" }
q171977
readFile
validation
func readFile(path string, opts *Options) (*File, error) { var data []byte var err error if path != "" { name := filepath.Join(opts.BaseDir, path+dot+opts.Extension) if opts.Asset != nil { data, err = opts.Asset(name) } else { data, err = ioutil.ReadFile(name) } if err != nil { return nil, err ...
go
{ "resource": "" }
q171978
findIncludes
validation
func findIncludes(data []byte, opts *Options, includes *[]*File, targetFile *File) error { includePaths, err := findIncludePaths(data, opts, targetFile) if err != nil { return err } for _, includePath := range includePaths { if !hasFile(*includes, includePath) { f, err := readFile(includePath, opts) if e...
go
{ "resource": "" }
q171979
findIncludePaths
validation
func findIncludePaths(data []byte, opts *Options, f *File) ([]string, error) { var includePaths []string for i, str := range strings.Split(formatLF(string(data)), lf) { ln := newLine(i+1, str, opts, f) if ln.isHelperMethodOf(helperMethodNameInclude) { if len(ln.tokens) < 3 { return nil, fmt.Errorf("no te...
go
{ "resource": "" }
q171980
hasFile
validation
func hasFile(files []*File, path string) bool { for _, f := range files { if f.path == path { return true } } return false }
go
{ "resource": "" }
q171981
newHelperMethodCSS
validation
func newHelperMethodCSS(ln *line, rslt *result, src *source, parent element, opts *Options) *helperMethodCSS { return &helperMethodCSS{ elementBase: newElementBase(ln, rslt, src, parent, opts), } }
go
{ "resource": "" }
q171982
newElement
validation
func newElement(ln *line, rslt *result, src *source, parent element, opts *Options) (element, error) { var e element var err error switch { case parent != nil && parent.ContainPlainText(): e = newPlainTextInner(ln, rslt, src, parent, parent.InsertBr(), opts) case ln.isEmpty(): e = newEmptyElement(ln, rslt, sr...
go
{ "resource": "" }
q171983
newHelperMethodContent
validation
func newHelperMethodContent(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodContent, error) { if len(ln.tokens) < 3 || ln.tokens[2] == "" { return nil, fmt.Errorf("no name is specified [file: %s][line: %d]", ln.fileName(), ln.no) } e := &helperMethodContent{ elementBase: newEle...
go
{ "resource": "" }
q171984
setAttributes
validation
func (e *htmlTag) setAttributes() error { parsedTokens := e.parseTokens() var i int var token string var setTextValue bool // Set attributes to the element. for i, token = range parsedTokens { kv := strings.Split(token, equal) if len(kv) < 2 { setTextValue = true break } k := kv[0] v := string...
go
{ "resource": "" }
q171985
noCloseTag
validation
func (e *htmlTag) noCloseTag() bool { for _, name := range e.opts.NoCloseTagNames { if e.tagName == name { return true } } return false }
go
{ "resource": "" }
q171986
IsBlockElement
validation
func (e *htmlTag) IsBlockElement() bool { if inline, found := inlineElements[e.tagName]; found { return !inline } else { return true } }
go
{ "resource": "" }
q171987
newHTMLTag
validation
func newHTMLTag(ln *line, rslt *result, src *source, parent element, opts *Options) (*htmlTag, error) { if len(ln.tokens) < 1 { return nil, fmt.Errorf("an HTML tag is not specified [file: %s][line: %d]", ln.fileName(), ln.no) } s := ln.tokens[0] tagName := extractTagName(s) id, err := extractID(s, ln) if err...
go
{ "resource": "" }
q171988
extractTagName
validation
func extractTagName(s string) string { tagName := strings.Split(strings.Split(s, sharp)[0], dot)[0] if tagName == "" { tagName = tagNameDiv } return tagName }
go
{ "resource": "" }
q171989
extractID
validation
func extractID(s string, ln *line) (string, error) { tokens := strings.Split(s, sharp) l := len(tokens) if l < 2 { return "", nil } if l > 2 { return "", fmt.Errorf("multiple IDs are specified [file: %s][line: %d]", ln.fileName(), ln.no) } return strings.Split(tokens[1], dot)[0], nil }
go
{ "resource": "" }
q171990
extractClasses
validation
func extractClasses(s string) []string { var classes []string for i, token := range strings.Split(s, dot) { if i == 0 { continue } class := strings.Split(token, sharp)[0] if class == "" { continue } classes = append(classes, class) } return classes }
go
{ "resource": "" }
q171991
parseTokens
validation
func (e *htmlTag) parseTokens() []string { var inQuote bool var inDelim bool var tokens []string var token string str := strings.Join(e.ln.tokens[1:], space) for _, chr := range str { switch c := string(chr); c { case space: if inQuote || inDelim { token += c } else { tokens = append(tokens, to...
go
{ "resource": "" }
q171992
newPlainText
validation
func newPlainText(ln *line, rslt *result, src *source, parent element, opts *Options) *plainText { return &plainText{ elementBase: newElementBase(ln, rslt, src, parent, opts), insertBr: ln.tokens[0] == doublePipe, } }
go
{ "resource": "" }
q171993
isHelperMethod
validation
func (l *line) isHelperMethod() bool { return len(l.tokens) > 1 && l.tokens[0] == equal }
go
{ "resource": "" }
q171994
isHelperMethodOf
validation
func (l *line) isHelperMethodOf(name string) bool { return l.isHelperMethod() && l.tokens[1] == name }
go
{ "resource": "" }
q171995
isPlainText
validation
func (l *line) isPlainText() bool { return len(l.tokens) > 0 && (l.tokens[0] == pipe || l.tokens[0] == doublePipe) }
go
{ "resource": "" }
q171996
isComment
validation
func (l *line) isComment() bool { return len(l.tokens) > 0 && l.tokens[0] == slash }
go
{ "resource": "" }
q171997
isHTMLComment
validation
func (l *line) isHTMLComment() bool { return len(l.tokens) > 0 && l.tokens[0] == slash+slash }
go
{ "resource": "" }
q171998
isAction
validation
func (l *line) isAction() bool { str := strings.TrimSpace(l.str) return strings.HasPrefix(str, l.opts.DelimLeft) && strings.HasSuffix(str, l.opts.DelimRight) }
go
{ "resource": "" }
q171999
fileName
validation
func (l *line) fileName() string { return l.file.path + dot + l.opts.Extension }
go
{ "resource": "" }