Skip to content

Commit

Permalink
chore: some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hschimke committed Dec 23, 2024
1 parent 4ea071e commit dfecd5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
9 changes: 8 additions & 1 deletion src/common/bit_source_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ impl BitSourceBuilder {
}
}

pub fn toByteArray(&mut self) -> &Vec<u8> {
pub fn asByteArray(&mut self) -> &Vec<u8> {
if self.bitsLeftInNextByte < 8 {
self.write(0, self.bitsLeftInNextByte);
}
&self.output
}

pub fn toByteArray(mut self) -> Vec<u8> {
if self.bitsLeftInNextByte < 8 {
self.write(0, self.bitsLeftInNextByte);
}
self.output
}
}

impl Default for BitSourceBuilder {
Expand Down
22 changes: 11 additions & 11 deletions src/common/eci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ impl Eci {
(self as i32) >= 899
}

pub fn try_from_i32(value: i32) -> Result<Self> {
let v = Self::from(value);
if v == Eci::Unknown {
Err(Exceptions::ILLEGAL_ARGUMENT)
} else {
Ok(v)
}
}
// pub fn try_from_i32(value: i32) -> Result<Self> {
// let v = Self::from(value);
// if v == Eci::Unknown {
// Err(Exceptions::ILLEGAL_ARGUMENT)
// } else {
// Ok(v)
// }
// }

pub fn try_from_u32(value: u32) -> Result<Self> {
Self::try_from_i32(value as i32)
}
// pub fn try_from_u32(value: u32) -> Result<Self> {
// Self::try_from_i32(value as i32)
// }
}

impl From<u32> for Eci {
Expand Down
1 change: 1 addition & 0 deletions src/common/minimal_eci_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ impl MinimalECIInput {
.iter()
.map(|x| *x as u16)
.collect();

let mut i = bytes.len() as isize - 1;
while i >= 0 {
// for (int i = bytes.length - 1; i >= 0; i--) {
Expand Down
10 changes: 5 additions & 5 deletions src/qrcode/decoder/DecodedBitStreamParserTestCase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn testSimpleByteMode() {
builder.write(0xF2, 8);
builder.write(0xF3, 8);
let result = decoded_bit_stream_parser::decode(
builder.toByteArray(),
builder.asByteArray(),
Version::getVersionForNumber(1).expect("unwrap"),
ErrorCorrectionLevel::H,
&HashMap::new(),
Expand All @@ -57,7 +57,7 @@ fn testSimpleSJIS() {
builder.write(0xA3, 8);
builder.write(0xD0, 8);
let result = decoded_bit_stream_parser::decode(
builder.toByteArray(),
builder.asByteArray(),
Version::getVersionForNumber(1).expect("unwrap"),
ErrorCorrectionLevel::H,
&HashMap::new(),
Expand All @@ -80,7 +80,7 @@ fn testECI() {
builder.write(0xA2, 8);
builder.write(0xA3, 8);
let result = decoded_bit_stream_parser::decode(
builder.toByteArray(),
builder.asByteArray(),
Version::getVersionForNumber(1).expect("unwrap"),
ErrorCorrectionLevel::H,
&HashMap::new(),
Expand All @@ -100,7 +100,7 @@ fn testHanzi() {
builder.write(0x01, 8); // 1 characters
builder.write(0x03C1, 13);
let result = decoded_bit_stream_parser::decode(
builder.toByteArray(),
builder.asByteArray(),
Version::getVersionForNumber(1).expect("unwrap"),
ErrorCorrectionLevel::H,
&HashMap::new(),
Expand All @@ -121,7 +121,7 @@ fn testHanziLevel1() {
// A5A2 (U+30A2) => A5A2 - A1A1 = 401, 4*60 + 01 = 0181
builder.write(0x0181, 13);
let result = decoded_bit_stream_parser::decode(
builder.toByteArray(),
builder.asByteArray(),
Version::getVersionForNumber(1).expect("unwrap"),
ErrorCorrectionLevel::H,
&HashMap::new(),
Expand Down

0 comments on commit dfecd5d

Please sign in to comment.