Skip to content

Commit 80ec229

Browse files
authored
refactor: use the built-in max/min to simplify the code (#10657)
Signed-off-by: alaningtrump <alaningtrump@outlook.com>
1 parent 7a3583b commit 80ec229

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

pkg/functions/peg/parser.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,7 @@ func (p *RuleParser) parse(arena *Arena, ctx *ParseContext, start int) ParseResu
461461
if result.Type != Fail {
462462
text := ""
463463
if result.Start < len(ctx.Input) {
464-
end := result.End
465-
if end > len(ctx.Input) {
466-
end = len(ctx.Input)
467-
}
464+
end := min(result.End, len(ctx.Input))
468465
text = ctx.Input[result.Start:end]
469466
}
470467

@@ -514,10 +511,7 @@ func (p *TagParser) parse(arena *Arena, ctx *ParseContext, start int) ParseResul
514511
if result.Type != Fail {
515512
text := ""
516513
if result.Start < len(ctx.Input) {
517-
end := result.End
518-
if end > len(ctx.Input) {
519-
end = len(ctx.Input)
520-
}
514+
end := min(result.End, len(ctx.Input))
521515
text = ctx.Input[result.Start:end]
522516
}
523517

0 commit comments

Comments
 (0)