1 parent
0703d74e4b
commit
976d5a3fec
42 files changed
+1608
-2087
No files matched your search
@@ -0,0 +1,64 @@
|
||||
namespace QrCode
|
||||
|
||||
class QRData_Numeric
|
||||
|
||||
function new()
|
||||
m.mode = QrCode.QRMode.Numeric
|
||||
|
||||
m.CHAR_TABLE = {
|
||||
"0": 0,
|
||||
"1": 1,
|
||||
"2": 2,
|
||||
"3": 3,
|
||||
"4": 4,
|
||||
"5": 5,
|
||||
"6": 6,
|
||||
"7": 7,
|
||||
"8": 8,
|
||||
"9": 9
|
||||
}
|
||||
end function
|
||||
|
||||
public function setData(data as string)
|
||||
m.data = data
|
||||
m.length = data.len()
|
||||
end function
|
||||
|
||||
public function writeToBuffer(buffer as QRBitBuffer) as void
|
||||
i = 0
|
||||
data = m.data
|
||||
length = data.len()
|
||||
|
||||
while i + 2 < length
|
||||
buffer.put(m.strToNum(data.mid(i, i + 3)), 10)
|
||||
i += 3
|
||||
end while
|
||||
|
||||
leftovers = length - i
|
||||
if leftovers <= 0
|
||||
return
|
||||
end if
|
||||
|
||||
if leftovers = 1
|
||||
buffer.put(m.strToNum(data.mid(i, i + 1)), 4)
|
||||
else if leftovers = 2
|
||||
buffer.put(m.strToNum(data.mid(i, i + 2)), 7)
|
||||
end if
|
||||
end function
|
||||
|
||||
private function strToNum(text as string) as integer
|
||||
num = 0
|
||||
for i = 0 to text.len() - 1 step 1
|
||||
digit = m.CHAR_TABLE[text.mid(i, 1)]
|
||||
if digit = invalid
|
||||
' print "illegal char: ", text.mid(i, 1)
|
||||
return 0
|
||||
end if
|
||||
num = num * 10 + digit
|
||||
end for
|
||||
return num
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user