MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / makeNumeric

Method makeNumeric

Libraries/QRCode/tests/QrSegment.cpp:58–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57
58qrcodegen::QrSegment qrcodegen::QrSegment::makeNumeric(const char *digits) {
59 BitBuffer bb;
60 int accumData = 0;
61 int accumCount = 0;
62 int charCount = 0;
63 for (; *digits != '\0'; digits++, charCount++) {
64 char c = *digits;
65 if (c < '0' || c > '9')
66 throw "String contains non-numeric characters";
67 accumData = accumData * 10 + (c - '0');
68 accumCount++;
69 if (accumCount == 3) {
70 bb.appendBits(accumData, 10);
71 accumData = 0;
72 accumCount = 0;
73 }
74 }
75 if (accumCount > 0) // 1 or 2 digits remaining
76 bb.appendBits(accumData, accumCount * 3 + 1);
77 return QrSegment(Mode::NUMERIC, charCount, bb.getBytes(), bb.getBitLength());
78}
79
80
81qrcodegen::QrSegment qrcodegen::QrSegment::makeAlphanumeric(const char *text) {

Callers

nothing calls this directly

Calls 4

QrSegmentClass · 0.85
appendBitsMethod · 0.80
getBytesMethod · 0.80
getBitLengthMethod · 0.80

Tested by

no test coverage detected