Refactored Java QrSegmentAdvanced to move a piece of logic to a new function.

pull/39/merge
Project Nayuki 6 years ago
parent 012d469ca5
commit 18ff8dc0e5

@ -112,16 +112,7 @@ public final class QrSegmentAdvanced {
int c = codePoints[i]; int c = codePoints[i];
int[] curCosts = new int[numModes]; int[] curCosts = new int[numModes];
{ // Always extend a bytes segment { // Always extend a bytes segment
int b; curCosts[0] = prevCosts[0] + countUtf8Bytes(c) * 8 * 6;
if (c < 0x80)
b = 1;
else if (c < 0x800)
b = 2;
else if (c < 0x10000)
b = 3;
else
b = 4;
curCosts[0] = prevCosts[0] + b * 8 * 6;
charModes[i][0] = modeTypes[0]; charModes[i][0] = modeTypes[0];
} }
// Extend a segment if possible // Extend a segment if possible
@ -216,6 +207,16 @@ public final class QrSegmentAdvanced {
} }
private static int countUtf8Bytes(int cp) {
if (cp < 0) throw new IllegalArgumentException("Invalid code point");
else if (cp < 0x80) return 1;
else if (cp < 0x800) return 2;
else if (cp < 0x10000) return 3;
else if (cp < 0x110000) return 4;
else throw new IllegalArgumentException("Invalid code point");
}
/*---- Kanji mode segment encoder ----*/ /*---- Kanji mode segment encoder ----*/

Loading…
Cancel
Save