Skip to content

Commit

Permalink
Merge pull request #5 from go-andiamo/escaping
Browse files Browse the repository at this point in the history
Escaping
  • Loading branch information
marrow16 committed Oct 27, 2022
2 parents 62c3170 + e4f1c6a commit b988d55
Show file tree
Hide file tree
Showing 4 changed files with 481 additions and 113 deletions.
10 changes: 9 additions & 1 deletion enclosures.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ func (e *Enclosure) clone() Enclosure {
}
}

func (e *Enclosure) isDoubleEscaping() bool {
return e.IsQuote && e.Escapable && e.End == e.Escape
}

func (e *Enclosure) isEscapable() bool {
return e.IsQuote && e.Escapable
}

var (
DoubleQuotes = _DoubleQuotes
DoubleQuotesBackSlashEscaped = _DoubleQuotesBackSlashEscaped
Expand All @@ -48,7 +56,7 @@ var (
LeftRightDoublePrimeQuotes = _LeftRightDoublePrimeQuotes
SingleLowHigh9Quotes = _SingleLowHigh9Quotes
DoubleLowHigh9Quotes = _DoubleLowHigh9Quotes
Brackets = _Parenthesis
Parenthesis = _Parenthesis
CurlyBrackets = _CurlyBrackets
SquareBrackets = _SquareBrackets
LtGtAngleBrackets = _LtGtAngleBrackets
Expand Down
38 changes: 38 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package splitter

import "fmt"

type SplittingErrorType int

const (
Unopened SplittingErrorType = iota
Unclosed
)

type SplittingError struct {
Type SplittingErrorType
Position int
Rune rune
Enclosure *Enclosure
}

func newSplittingError(t SplittingErrorType, pos int, r rune, enc *Enclosure) error {
return &SplittingError{
Type: t,
Position: pos,
Rune: r,
Enclosure: enc,
}
}

const (
unopenedFmt = "unopened '%s' at position %d"
unclosedFmt = "unclosed '%s' at position %d"
)

func (e *SplittingError) Error() string {
if e.Type == Unopened {
return fmt.Sprintf(unopenedFmt, string(e.Rune), e.Position)
}
return fmt.Sprintf(unclosedFmt, string(e.Rune), e.Position)
}
Loading

0 comments on commit b988d55

Please sign in to comment.