コード例 #1
0
ファイル: encode.go プロジェクト: johnvilsack/barcode
func getCodeIndexList(content []rune) *utils.BitList {
	result := new(utils.BitList)
	curEncoding := byte(0)
	for i := 0; i < len(content); i++ {

		if shouldUseCTable(content[i:], curEncoding) {
			if curEncoding != startCSymbol {
				result.AddByte(startCSymbol)
				curEncoding = startCSymbol
			}
			idx := (content[i] - '0') * 10
			i++
			idx = idx + (content[i] - '0')

			result.AddByte(byte(idx))
		} else {
			if curEncoding != startBSymbol {
				result.AddByte(startBSymbol)
				curEncoding = startBSymbol
			}
			idx := strings.IndexRune(bTable, content[i])
			if idx < 0 {
				return nil
			}
			result.AddByte(byte(idx))
		}
	}
	fmt.Println(result.GetBytes())
	return result
}