Split long lines in various {Java, JavaScript, Python, C++, C, Rust} code, without changing behavior.

pull/16/head
Project Nayuki 7 years ago
parent dfe960aa60
commit 272ca8bb54

@ -70,7 +70,8 @@ testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl);
testable int getNumRawDataModules(int version); testable int getNumRawDataModules(int version);
testable void calcReedSolomonGenerator(int degree, uint8_t result[]); testable void calcReedSolomonGenerator(int degree, uint8_t result[]);
testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen, const uint8_t generator[], int degree, uint8_t result[]); testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen,
const uint8_t generator[], int degree, uint8_t result[]);
testable uint8_t finiteFieldMultiply(uint8_t x, uint8_t y); testable uint8_t finiteFieldMultiply(uint8_t x, uint8_t y);
testable void initializeFunctionModules(int version, uint8_t qrcode[]); testable void initializeFunctionModules(int version, uint8_t qrcode[]);
@ -451,7 +452,9 @@ testable void calcReedSolomonGenerator(int degree, uint8_t result[]) {
// Calculates the remainder of the polynomial data[0 : dataLen] when divided by the generator[0 : degree], where all // Calculates the remainder of the polynomial data[0 : dataLen] when divided by the generator[0 : degree], where all
// polynomials are in big endian and the generator has an implicit leading 1 term, storing the result in result[0 : degree]. // polynomials are in big endian and the generator has an implicit leading 1 term, storing the result in result[0 : degree].
testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen, const uint8_t generator[], int degree, uint8_t result[]) { testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen,
const uint8_t generator[], int degree, uint8_t result[]) {
// Perform polynomial division // Perform polynomial division
assert(1 <= degree && degree <= 30); assert(1 <= degree && degree <= 30);
memset(result, 0, degree * sizeof(result[0])); memset(result, 0, degree * sizeof(result[0]));

@ -539,7 +539,9 @@ int QrCode::getNumRawDataModules(int ver) {
int QrCode::getNumDataCodewords(int ver, const Ecc &ecl) { int QrCode::getNumDataCodewords(int ver, const Ecc &ecl) {
if (ver < 1 || ver > 40) if (ver < 1 || ver > 40)
throw "Version number out of range"; throw "Version number out of range";
return getNumRawDataModules(ver) / 8 - ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver]; return getNumRawDataModules(ver) / 8
- ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver]
* NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
} }

@ -310,7 +310,9 @@ public final class QrCode {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); sb.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
sb.append(String.format("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 %1$d %1$d\" stroke=\"none\">\n", size + border * 2)); sb.append(String.format(
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 %1$d %1$d\" stroke=\"none\">\n",
size + border * 2));
sb.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n"); sb.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n");
sb.append("\t<path d=\""); sb.append("\t<path d=\"");
boolean head = true; boolean head = true;
@ -716,7 +718,9 @@ public final class QrCode {
static int getNumDataCodewords(int ver, Ecc ecl) { static int getNumDataCodewords(int ver, Ecc ecl) {
if (ver < 1 || ver > 40) if (ver < 1 || ver > 40)
throw new IllegalArgumentException("Version number out of range"); throw new IllegalArgumentException("Version number out of range");
return getNumRawDataModules(ver) / 8 - ECC_CODEWORDS_PER_BLOCK[ecl.ordinal()][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal()][ver]; return getNumRawDataModules(ver) / 8
- ECC_CODEWORDS_PER_BLOCK[ecl.ordinal()][ver]
* NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal()][ver];
} }

@ -211,7 +211,8 @@ var qrcodegen = new function() {
throw "Border must be non-negative"; throw "Border must be non-negative";
var result = '<?xml version="1.0" encoding="UTF-8"?>\n'; var result = '<?xml version="1.0" encoding="UTF-8"?>\n';
result += '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'; result += '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n';
result += '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 ' + (size + border * 2) + ' ' + (size + border * 2) + '" stroke="none">\n'; result += '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 ' +
(size + border * 2) + ' ' + (size + border * 2) + '" stroke="none">\n';
result += '\t<rect width="100%" height="100%" fill="#FFFFFF"/>\n'; result += '\t<rect width="100%" height="100%" fill="#FFFFFF"/>\n';
result += '\t<path d="'; result += '\t<path d="';
var head = true; var head = true;
@ -669,7 +670,9 @@ var qrcodegen = new function() {
QrCode.getNumDataCodewords = function(ver, ecl) { QrCode.getNumDataCodewords = function(ver, ecl) {
if (ver < 1 || ver > 40) if (ver < 1 || ver > 40)
throw "Version number out of range"; throw "Version number out of range";
return Math.floor(QrCode.getNumRawDataModules(ver) / 8) - QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver]; return Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] *
QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
}; };

@ -543,7 +543,9 @@ class QrCode(object):
This stateless pure function could be implemented as a (40*4)-cell lookup table.""" This stateless pure function could be implemented as a (40*4)-cell lookup table."""
if not (1 <= ver <= 40): if not (1 <= ver <= 40):
raise ValueError("Version number out of range") raise ValueError("Version number out of range")
return QrCode._get_num_raw_data_modules(ver) // 8 - QrCode._ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * QrCode._NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver] return QrCode._get_num_raw_data_modules(ver) // 8 \
- QrCode._ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] \
* QrCode._NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver]
# ---- Private tables of constants ---- # ---- Private tables of constants ----

@ -72,13 +72,15 @@ impl QrCode {
pub fn encode_segments_advanced(segs: &[QrSegment], mut ecl: QrCodeEcc, pub fn encode_segments_advanced(segs: &[QrSegment], mut ecl: QrCodeEcc,
minversion: u8, maxversion: u8, mask: i8, boostecl: bool) -> Option<QrCode> { minversion: u8, maxversion: u8, mask: i8, boostecl: bool) -> Option<QrCode> {
assert!(1 <= minversion && minversion <= maxversion && maxversion <= 40 && -1 <= mask && mask <= 7, "Invalid value"); assert!(1 <= minversion && minversion <= maxversion && maxversion <= 40
&& -1 <= mask && mask <= 7, "Invalid value");
// Find the minimal version number to use // Find the minimal version number to use
let mut version: u8 = minversion; let mut version: u8 = minversion;
let datausedbits: usize; let datausedbits: usize;
loop { loop {
let datacapacitybits: usize = QrCode::get_num_data_codewords(version, ecl) * 8; // Number of data bits available // Number of data bits available
let datacapacitybits: usize = QrCode::get_num_data_codewords(version, ecl) * 8;
if let Some(n) = QrSegment::get_total_bits(segs, version) { if let Some(n) = QrSegment::get_total_bits(segs, version) {
if n <= datacapacitybits { if n <= datacapacitybits {
datausedbits = n; datausedbits = n;
@ -223,7 +225,9 @@ impl QrCode {
let mut result: String = String::new(); let mut result: String = String::new();
result.push_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); result.push_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
result.push_str("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); result.push_str("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
result.push_str(&format!("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {0} {0}\" stroke=\"none\">\n", self.size + border * 2)); result.push_str(&format!(
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {0} {0}\" stroke=\"none\">\n",
self.size + border * 2));
result.push_str("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n"); result.push_str("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n");
result.push_str("\t<path d=\""); result.push_str("\t<path d=\"");
let mut head: bool = true; let mut head: bool = true;
@ -284,7 +288,8 @@ impl QrCode {
fn draw_format_bits(&mut self, mask: u8) { fn draw_format_bits(&mut self, mask: u8) {
// Calculate error correction code and pack bits // Calculate error correction code and pack bits
let size: i32 = self.size; let size: i32 = self.size;
let mut data: u32 = self.errorcorrectionlevel.format_bits() << 3 | (mask as u32); // errcorrlvl is uint2, mask is uint3 // errcorrlvl is uint2, mask is uint3
let mut data: u32 = self.errorcorrectionlevel.format_bits() << 3 | (mask as u32);
let mut rem: u32 = data; let mut rem: u32 = data;
for _ in 0 .. 10 { for _ in 0 .. 10 {
rem = (rem << 1) ^ ((rem >> 9) * 0x537); rem = (rem << 1) ^ ((rem >> 9) * 0x537);

Loading…
Cancel
Save