Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions pkg/parser/ansi_strip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,3 @@ import (
func StripANSI(s string) string {
return stringutil.StripANSI(s)
}

// isFinalCSIChar checks if a character is a valid CSI final character
// Final characters are in range 0x40-0x7E (@-~)
func isFinalCSIChar(b byte) bool {
return b >= 0x40 && b <= 0x7E
}

// isCSIParameterChar checks if a character is a valid CSI parameter or intermediate character
// Parameter characters are in range 0x30-0x3F (0-?)
// Intermediate characters are in range 0x20-0x2F (space-/)
func isCSIParameterChar(b byte) bool {
return (b >= 0x20 && b <= 0x2F) || (b >= 0x30 && b <= 0x3F)
}
79 changes: 0 additions & 79 deletions pkg/parser/frontmatter_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,85 +563,6 @@ func TestStripANSI(t *testing.T) {
}
}

// Test isCSIParameterChar function
func TestIsCSIParameterChar(t *testing.T) {
tests := []struct {
name string
char byte
expected bool
}{
// Valid parameter characters (0x30-0x3F, 0-?)
{name: "0 (0x30)", char: '0', expected: true},
{name: "9 (0x39)", char: '9', expected: true},
{name: "; (0x3B)", char: ';', expected: true},
{name: "? (0x3F)", char: '?', expected: true},

// Valid intermediate characters (0x20-0x2F, space-/)
{name: "space (0x20)", char: ' ', expected: true},
{name: "! (0x21)", char: '!', expected: true},
{name: "/ (0x2F)", char: '/', expected: true},

// Invalid characters (below 0x20)
{name: "tab (0x09)", char: '\t', expected: false},
{name: "newline (0x0A)", char: '\n', expected: false},
{name: "null (0x00)", char: 0x00, expected: false},

// Invalid characters (above 0x3F)
{name: "@ (0x40)", char: '@', expected: false},
{name: "A (0x41)", char: 'A', expected: false},
{name: "m (0x6D)", char: 'm', expected: false},
{name: "~ (0x7E)", char: '~', expected: false},
{name: "DEL (0x7F)", char: 0x7F, expected: false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := isCSIParameterChar(tt.char)
if result != tt.expected {
t.Errorf("isCSIParameterChar(%q/0x%02X) = %v, want %v", tt.char, tt.char, result, tt.expected)
}
})
}
}

// Test isFinalCSIChar function
func TestIsFinalCSIChar(t *testing.T) {
tests := []struct {
name string
char byte
expected bool
}{
// Valid final characters (0x40-0x7E, @-~)
{name: "@ (0x40)", char: '@', expected: true},
{name: "A (0x41)", char: 'A', expected: true},
{name: "Z (0x5A)", char: 'Z', expected: true},
{name: "a (0x61)", char: 'a', expected: true},
{name: "m (0x6D)", char: 'm', expected: true}, // Common color final char
{name: "~ (0x7E)", char: '~', expected: true},

// Invalid characters (below 0x40)
{name: "space (0x20)", char: ' ', expected: false},
{name: "0 (0x30)", char: '0', expected: false},
{name: "9 (0x39)", char: '9', expected: false},
{name: "; (0x3B)", char: ';', expected: false},
{name: "? (0x3F)", char: '?', expected: false},

// Invalid characters (above 0x7E)
{name: "DEL (0x7F)", char: 0x7F, expected: false},
{name: "high byte (0x80)", char: 0x80, expected: false},
{name: "high byte (0xFF)", char: 0xFF, expected: false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := isFinalCSIChar(tt.char)
if result != tt.expected {
t.Errorf("isFinalCSIChar(%q/0x%02X) = %v, want %v", tt.char, tt.char, result, tt.expected)
}
})
}
}

// Benchmark StripANSI function for performance
func BenchmarkStripANSI(b *testing.B) {
testCases := []struct {
Expand Down
Loading