Cleanup of many components of the code.

Many unwraps, expects, and panics removed or handled.

More rustification of the codebase.

Squashed commit of the following:

commit 80c6483cf8c819496a7b781f9e3a149d1f18d5fe
Author: Henry <henry@azule.info>
Date:   Fri Feb 10 20:36:57 2023 -0600

    add other parsed result option

commit 412d92ae585e7bf194697f5282dbc045e448bace
Author: Henry <henry@azule.info>
Date:   Fri Feb 10 19:06:34 2023 -0600

    fix some panics

commit 9108d3e931aadec00fc0bf346ebc52d24e5d8146
Author: Henry <henry@azule.info>
Date:   Fri Feb 10 18:56:30 2023 -0600

    clippy --fix

commit 8cd89d314323f54f342f15fc73297b62d418ac79
Author: Henry <henry@azule.info>
Date:   Fri Feb 10 18:55:45 2023 -0600

    some more cleanup in aztec

commit fb7f9242e273b85a4bb212f22a185a0dcbfafc36
Author: Henry <henry@azule.info>
Date:   Fri Feb 10 18:19:54 2023 -0600

    cleanup root

commit 4fb7c0639830869149332b29be789e891eade3e7
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 16:50:15 2023 -0600

    format

commit 3ac271af657b25fbe5ee39cbdf8859e5aa38ea41
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 16:43:14 2023 -0600

    clippy --fix

commit 0c5b4c1477159db93a9da9645039f51cd1a7c574
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 16:04:31 2023 -0600

    qrcode cleanup complete

commit 70c1d107cc672e45d46567c650c46fece7e7da9c
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 13:28:25 2023 -0600

    clippy --fix

commit e13263d0f1f2a13dbb59b6e60d8b871a32babc92
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 13:27:44 2023 -0600

    qrcode detector cleanup

commit f7f2855099e469fe1091868c6099196705d0ae83
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 11:48:13 2023 -0600

    qrcode decoder

commit bdbaaba597b3479639c2ed3726465a69e3004471
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 11:13:18 2023 -0600

    clippy --fix

commit fd6dbcaeb1f45dc91ae98f0e7c58aad48d67df78
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 11:12:28 2023 -0600

    pdf417 cleanup complete

commit 7bbd47604c2639a5eb61bdb5533e71be3bce95a1
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 10:39:28 2023 -0600

    clippy --fix

commit 8f4962b7bb5f133524fe4d3d4948e5672a88c545
Author: Henry Schimke <henry@azule.info>
Date:   Fri Feb 10 10:39:00 2023 -0600

    cleanup on pdf417 hie

commit 254c8243953776d3c8704dd81529aadd05d5a94e
Author: Henry <henry@azule.info>
Date:   Fri Feb 10 02:51:21 2023 +0000

    partway through pdf417 hle

commit d4a5b00fde8c0282b0c6e4175a21c1e111b11533
Author: Henry <henry@azule.info>
Date:   Wed Feb 8 21:35:25 2023 +0000

    clippy --fix

commit 2bd4a8e218aa963a88997b50bc5a198f9a88205e
Author: Henry <henry@azule.info>
Date:   Wed Feb 8 21:31:55 2023 +0000

    pdf417 decode and detect cleanup

commit 05130ac54a72c2303045d64507bf6185aa74e531
Author: Henry Schimke <henry@azule.info>
Date:   Tue Feb 7 08:06:25 2023 -0600

    at decodeTextCompaction in decoded_bit_straem_parser

commit 924c023a7d2339dfffa6ef0c4a805fb192576796
Author: Henry Schimke <henry@azule.info>
Date:   Mon Feb 6 18:22:02 2023 -0600

    clippy --fix

commit 5cfb81a885c22b4b5ec937a79be31d0815def211
Author: Henry Schimke <henry@azule.info>
Date:   Mon Feb 6 18:20:22 2023 -0600

    oned cleanup

commit 0649b64854baf56a8e3314728d4f6cf4063db8b2
Author: Henry Schimke <henry@azule.info>
Date:   Mon Feb 6 11:47:28 2023 -0600

    rss cleanup

commit 2d3127898fc11f7e65d590e983cda799b798b646
Author: Henry Schimke <henry@azule.info>
Date:   Mon Feb 6 10:19:56 2023 -0600

    multi cleanup

commit 7e8b43a159083a2096123e6204d4d1d359c59981
Author: Henry <henry@azule.info>
Date:   Sun Feb 5 21:41:59 2023 -0600

    cargo fmt

commit df8285e8da07b4bffd48ca6e596de3f010eb8d9e
Author: Henry <henry@azule.info>
Date:   Sun Feb 5 21:41:29 2023 -0600

    maxicode cleanup

commit a51f923a14016eb416ca202b2194258808dde3e7
Author: Henry <henry@azule.info>
Date:   Sun Feb 5 21:27:57 2023 -0600

    cargo fmt

commit 332d7eef4a25318611025a3fcb0b70c604d917be
Author: Henry <henry@azule.info>
Date:   Sun Feb 5 21:27:48 2023 -0600

    cleanup datamatrix

commit eb2311c476a9c9993f271ab6cf9fd359aedca26f
Author: Henry <henry@azule.info>
Date:   Sun Feb 5 21:27:26 2023 -0600

    cargo clippy --fix

commit 2abaa4c51d287f619d4c7a438f85ba2a30f159cf
Author: Henry <henry@azule.info>
Date:   Sun Feb 5 19:13:02 2023 -0600

    finish cleanup in parsers

commit 716aa2fbf728716cff36657a5fd80e7bca5276b7
Author: Henry Schimke <henry@azule.info>
Date:   Sun Feb 5 17:44:56 2023 -0600

    cleanup continues

commit 7d843788a49fa9cc82c4616d226c0f882e73612b
Author: Henry Schimke <henry@azule.info>
Date:   Sun Feb 5 15:15:09 2023 -0600

    common cleanup

commit fd251866c68f22d450dd428c93d7a3620bf1be27
Author: Henry Schimke <henry@azule.info>
Date:   Sun Feb 5 10:24:54 2023 -0600

    cleanup reedsolomon

commit 132e27ed1468f5c1ce998516ff5a00687217c3e6
Author: Henry Schimke <henry@azule.info>
Date:   Sun Feb 5 09:52:04 2023 -0600

    make MathUtils more generic

commit d8352b7fff4cb4f9ecc8e8a969710d26ef410e8b
Author: Henry Schimke <henry@azule.info>
Date:   Sun Feb 5 09:29:33 2023 -0600

    cleanup some string handling in ResultParser

    There may still be some edge cases where multi-byte characters break the parser
This commit is contained in:
Henry
2023-02-10 20:41:25 -06:00
parent 5222bb25b7
commit 28723be2eb
180 changed files with 3248 additions and 4117 deletions

View File

@@ -35,61 +35,61 @@ const FACTOR_SETS: [u32; 16] = [5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48
*/
static FACTORS: Lazy<[Vec<u32>; 16]> = Lazy::new(|| {
[
Vec::from([228, 48, 15, 111, 62]),
Vec::from([23, 68, 144, 134, 240, 92, 254]),
Vec::from([28, 24, 185, 166, 223, 248, 116, 255, 110, 61]),
Vec::from([175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120]),
Vec::from([41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242]),
Vec::from([
vec![228, 48, 15, 111, 62],
vec![23, 68, 144, 134, 240, 92, 254],
vec![28, 24, 185, 166, 223, 248, 116, 255, 110, 61],
vec![175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120],
vec![41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242],
vec![
156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185,
]),
Vec::from([
],
vec![
83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90, 188,
]),
Vec::from([
],
vec![
15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186,
172,
]),
Vec::from([
],
vec![
52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172, 254, 124, 12,
181, 184, 96, 50, 193,
]),
Vec::from([
],
vec![
211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17, 138, 110,
213, 141, 136, 120, 151, 233, 168, 93, 255,
]),
Vec::from([
],
vec![
245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80, 182, 229, 18,
2, 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25, 225, 98, 81, 112,
]),
Vec::from([
],
vec![
77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175, 95, 100, 9,
167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202, 69, 50, 150, 177, 226,
5, 9, 5,
]),
Vec::from([
],
vec![
245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87, 191, 106,
16, 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138, 186, 240, 82, 44, 176,
87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19,
]),
Vec::from([
],
vec![
175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235, 150, 159,
36, 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232, 144, 238, 22, 150,
201, 117, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53,
143, 46,
]),
Vec::from([
],
vec![
242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37, 185, 112,
134, 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71, 161, 44, 147, 6, 27,
218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224,
124, 86, 47, 11, 204,
]),
Vec::from([
],
vec![
220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127, 213, 136,
248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236, 66, 139, 153, 185,
202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239, 181, 241, 59, 52, 172, 25,
49, 232, 211, 189, 64, 54, 108, 153, 132, 63, 96, 103, 82, 186,
]),
],
]
});
@@ -181,7 +181,12 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
let mut d = block;
while d < symbolInfo.getDataCapacity() as usize {
// for (int d = block; d < symbolInfo.getDataCapacity(); d += blockCount) {
temp.push(codewords.chars().nth(d).unwrap());
temp.push(
codewords
.chars()
.nth(d)
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
);
d += blockCount;
}
@@ -193,10 +198,13 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
let (char_index, replace_char) = sb
.char_indices()
.nth(symbolInfo.getDataCapacity() as usize + e)
.unwrap();
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
sb.replace_range(
char_index..(replace_char.len_utf8()),
&ecc.chars().nth(pos).unwrap().to_string(),
&ecc.chars()
.nth(pos)
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
.to_string(),
);
// sb.setCharAt(symbolInfo.getDataCapacity() + e, ecc.charAt(pos));
pos += 1;
@@ -232,20 +240,25 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
// }
for i in 0..codewords.chars().count() {
// for (int i = 0; i < codewords.length(); i++) {
let m = ecc[numECWords - 1] as usize ^ codewords.chars().nth(i).unwrap() as usize;
let m = ecc[numECWords - 1] as usize
^ codewords
.chars()
.nth(i)
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as usize;
for k in (1..numECWords).rev() {
// for (int k = numECWords - 1; k > 0; k--) {
if m != 0 && poly[k] != 0 {
ecc[k] = char::from_u32(
ecc[k - 1] as u32 ^ ALOG[(LOG[m] + LOG[poly[k] as usize]) as usize % 255],
)
.unwrap();
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
} else {
ecc[k] = ecc[k - 1];
}
}
if m != 0 && poly[0] != 0 {
ecc[0] = char::from_u32(ALOG[(LOG[m] + LOG[poly[0] as usize]) as usize % 255]).unwrap();
ecc[0] = char::from_u32(ALOG[(LOG[m] + LOG[poly[0] as usize]) as usize % 255])
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
} else {
ecc[0] = 0 as char;
}