diff options
| author | Fuwn <[email protected]> | 2026-01-31 17:30:32 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-31 17:30:32 +0000 |
| commit | a1798d9b974854f1053ca4d3793f0b4ba100b2c2 (patch) | |
| tree | d6bfef5151614b5744b002ac979bc06303c995b3 /patterns.go | |
| parent | docs(README): Update "How It Works" source (diff) | |
| download | iku-a1798d9b974854f1053ca4d3793f0b4ba100b2c2.tar.xz iku-a1798d9b974854f1053ca4d3793f0b4ba100b2c2.zip | |
refactor: Extract line pattern detection to patterns.go
Diffstat (limited to 'patterns.go')
| -rw-r--r-- | patterns.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/patterns.go b/patterns.go new file mode 100644 index 0000000..5cd35ca --- /dev/null +++ b/patterns.go @@ -0,0 +1,83 @@ +package main + +import "regexp" + +var ( + closingBracePattern = regexp.MustCompile(`^\s*[\}\)]`) + openingBracePattern = regexp.MustCompile(`[\{\(]\s*$`) + caseLabelPattern = regexp.MustCompile(`^\s*(case\s|default\s*:)|(^\s+.*:\s*$)`) +) + +func isCommentOnly(sourceLine string) bool { + for characterIndex := range len(sourceLine) { + character := sourceLine[characterIndex] + + if character == ' ' || character == '\t' { + continue + } + + return len(sourceLine) > characterIndex+1 && sourceLine[characterIndex] == '/' && sourceLine[characterIndex+1] == '/' + } + + return false +} + +func isPackageLine(trimmedLine string) bool { + return len(trimmedLine) > 8 && trimmedLine[:8] == "package " +} + +func countRawStringDelimiters(sourceLine string) int { + delimiterCount := 0 + insideDoubleQuotedString := false + insideCharacterLiteral := false + + for characterIndex := 0; characterIndex < len(sourceLine); characterIndex++ { + character := sourceLine[characterIndex] + + if insideCharacterLiteral { + if character == '\\' && characterIndex+1 < len(sourceLine) { + characterIndex++ + + continue + } + + if character == '\'' { + insideCharacterLiteral = false + } + + continue + } + + if insideDoubleQuotedString { + if character == '\\' && characterIndex+1 < len(sourceLine) { + characterIndex++ + + continue + } + + if character == '"' { + insideDoubleQuotedString = false + } + + continue + } + + if character == '\'' { + insideCharacterLiteral = true + + continue + } + + if character == '"' { + insideDoubleQuotedString = true + + continue + } + + if character == '`' { + delimiterCount++ + } + } + + return delimiterCount +} |