From c61d2c3981c7ae940835965960e9615a8a2fcba2 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Thu, 7 Nov 2019 23:54:32 +0900 Subject: [PATCH] Refactor condition --- scanner/scanner.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scanner/scanner.go b/scanner/scanner.go index 2bd6b27f..e11418e3 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -87,6 +87,19 @@ func (s *Scanner) progressLine(ctx *Context) { ctx.progress(1) } +func (s *Scanner) isNeededKeepPreviousIndentNum(ctx *Context, c rune) bool { + if !s.isChangedToIndentStateUp() { + return false + } + if ctx.isDocument() { + return true + } + if c == '-' && ctx.bufferedSrc() != "" { + return true + } + return false +} + func (s *Scanner) updateIndent(ctx *Context, c rune) { if s.isFirstCharAtLine && c == ' ' { s.indentNum++ @@ -120,9 +133,7 @@ func (s *Scanner) updateIndent(ctx *Context, c rune) { } } s.isFirstCharAtLine = false - if ctx.isDocument() && s.isChangedToIndentStateUp() { - return - } else if c == '-' && ctx.bufferedSrc() != "" && s.isChangedToIndentStateUp() { + if s.isNeededKeepPreviousIndentNum(ctx, c) { return } s.prevIndentNum = s.indentNum