MCPcopy Create free account
hub / github.com/boombuler/barcode / EncodeWithColor

Function EncodeWithColor

codabar/encoder.go:36–49  ·  view source on GitHub ↗

Encode creates a codabar barcode for the given content and color scheme

(content string, color barcode.ColorScheme)

Source from the content-addressed store, hash-verified

34
35// Encode creates a codabar barcode for the given content and color scheme
36func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode, error) {
37 checkValid, _ := regexp.Compile(`[ABCD][0123456789\-\$\:/\.\+]*[ABCD]$`)
38 if content == "!" || checkValid.ReplaceAllString(content, "!") != "!" {
39 return nil, fmt.Errorf("can not encode \"%s\"", content)
40 }
41 resBits := new(utils.BitList)
42 for i, r := range content {
43 if i > 0 {
44 resBits.AddBit(false)
45 }
46 resBits.AddBit(encodingTable[r]...)
47 }
48 return utils.New1DCodeWithColor(barcode.TypeCodabar, content, resBits, color), nil
49}
50
51// Encode creates a codabar barcode for the given content
52func Encode(content string) (barcode.Barcode, error) {

Callers 1

EncodeFunction · 0.70

Calls 2

New1DCodeWithColorFunction · 0.92
AddBitMethod · 0.80

Tested by

no test coverage detected