aboutsummaryrefslogtreecommitdiff
path: root/patterns.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-31 17:30:32 +0000
committerFuwn <[email protected]>2026-01-31 17:30:32 +0000
commita1798d9b974854f1053ca4d3793f0b4ba100b2c2 (patch)
treed6bfef5151614b5744b002ac979bc06303c995b3 /patterns.go
parentdocs(README): Update "How It Works" source (diff)
downloadiku-a1798d9b974854f1053ca4d3793f0b4ba100b2c2.tar.xz
iku-a1798d9b974854f1053ca4d3793f0b4ba100b2c2.zip
refactor: Extract line pattern detection to patterns.go
Diffstat (limited to 'patterns.go')
-rw-r--r--patterns.go83
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
+}