Refine ZPL repeat code generation for CompressedASCII (#10)

This commit is contained in:
Copilot
2026-02-22 00:36:45 +02:00
committed by GitHub
parent 98464cac0a
commit b89d47a378

View File

@@ -71,23 +71,40 @@ func getRepeatCode(repeatCount int, char string) string {
highString := " ghijklmnopqrstuvwxyz" highString := " ghijklmnopqrstuvwxyz"
lowString := " GHIJKLMNOPQRSTUVWXY" lowString := " GHIJKLMNOPQRSTUVWXY"
repeatStr := "" encode := func(count int) string {
for repeatCount > maxRepeat { var singleRepeatStr strings.Builder
repeatStr += getRepeatCode(maxRepeat, char) high := count / 20
repeatCount -= maxRepeat low := count % 20
if high > 0 {
singleRepeatStr.WriteByte(highString[high])
}
if low > 0 {
singleRepeatStr.WriteByte(lowString[low])
}
singleRepeatStr.WriteString(char)
return singleRepeatStr.String()
} }
high := repeatCount / 20 if repeatCount > maxRepeat {
low := repeatCount % 20 var repeatStr strings.Builder
remainder := repeatCount % maxRepeat
quotient := repeatCount / maxRepeat
if high > 0 { if remainder > 0 {
repeatStr += string(highString[high]) repeatStr.WriteString(encode(remainder))
} }
if low > 0 {
repeatStr += string(lowString[low]) maxEncoding := encode(maxRepeat)
for i := 0; i < quotient; i++ {
repeatStr.WriteString(maxEncoding)
}
return repeatStr.String()
} }
return repeatStr + char return encode(repeatCount)
} }
// CompressASCII compresses the ASCII data of a ZPL Graphic Field using RLE. // CompressASCII compresses the ASCII data of a ZPL Graphic Field using RLE.