Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <ianmlewis@gmail.com>
  • Loading branch information
ianlewis committed Nov 18, 2024
1 parent be163ca commit b1db0c6
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions idx/idx.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ type whitespaceFolder struct {
wsSpan bool
}

func (w *whitespaceFolder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
// for nDst < len(dst) && nSrc < len(src) {
// Transform implements [transform.Transformer.Transform].
func (w *whitespaceFolder) Transform(dst, src []byte, atEOF bool) (int, int, error) {
var nSrc, nDst int
for nSrc < len(src) {
c, size := utf8.DecodeRune(src[nSrc:])
if c == utf8.RuneError && !atEOF {
err = transform.ErrShortSrc
return
return nDst, nSrc, transform.ErrShortSrc
}

isSpace := unicode.IsSpace(c)
Expand All @@ -76,38 +76,38 @@ func (w *whitespaceFolder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc in
// Ignore leading whitespace.
continue
}
// We are in an internal whitespace span.
w.wsSpan = true
continue
} else {
if w.wsSpan {
// Emit a single space if we are coming out of a whitespace span.
// NOTE: trailing whitespace is never emitted by design.
// NOTE: ' ' has length one.
spc := ' '
if nDst+utf8.RuneLen(spc) > len(dst) {
err = transform.ErrShortDst
return
}
nDst += utf8.EncodeRune(dst[nDst:], spc)
w.wsSpan = false
}

if w.wsSpan {
// Emit a single space if we are coming out of a whitespace span.
// NOTE: trailing whitespace is never emitted by design.
spc := ' '
if nDst+utf8.RuneLen(spc) > len(dst) {
return nDst, nSrc, transform.ErrShortDst
}
w.notStart = true
nSrc += size
nDst += utf8.EncodeRune(dst[nDst:], spc)
// We are no longer in an internal whitespace span.
w.wsSpan = false
}
w.notStart = true
nSrc += size

// Emit the character.
// NOTE: we cannot use size here because c could be utf8.RuneError in
// which case size would be 1 but the length of utf8.RuneError is 3.
if nDst+utf8.RuneLen(c) > len(dst) {
err = transform.ErrShortDst
return
return nDst, nSrc, transform.ErrShortDst
}
nDst += utf8.EncodeRune(dst[nDst:], c)
}

return
return nDst, nSrc, nil
}

// Reset implements [transform.Transformer.Reset].
func (w *whitespaceFolder) Reset() {
*w = whitespaceFolder{}
}
Expand Down

0 comments on commit b1db0c6

Please # to comment.