mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
rename helper methods
This commit is contained in:
@@ -121,9 +121,7 @@ pub fn decode(codewords: &[u32], ecLevel: &str) -> Result<DecoderRXingResult, Ex
|
||||
codeIndex = byteCompaction(code, codewords, codeIndex, &mut result)?
|
||||
}
|
||||
MODE_SHIFT_TO_BYTE_COMPACTION_MODE => {
|
||||
result.append_char(
|
||||
char::from_u32(codewords[codeIndex]).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
result.append_char(char::from_u32(codewords[codeIndex]).ok_or(Exceptions::parse)?);
|
||||
codeIndex += 1;
|
||||
}
|
||||
NUMERIC_COMPACTION_MODE_LATCH => {
|
||||
@@ -149,7 +147,7 @@ pub fn decode(codewords: &[u32], ecLevel: &str) -> Result<DecoderRXingResult, Ex
|
||||
BEGIN_MACRO_PDF417_OPTIONAL_FIELD | MACRO_PDF417_TERMINATOR =>
|
||||
// Should not see these outside a macro block
|
||||
{
|
||||
return Err(Exceptions::formatEmpty())
|
||||
return Err(Exceptions::format)
|
||||
}
|
||||
_ => {
|
||||
// Default to text compaction. During testing numerous barcodes
|
||||
@@ -164,7 +162,7 @@ pub fn decode(codewords: &[u32], ecLevel: &str) -> Result<DecoderRXingResult, Ex
|
||||
result = result.build_result();
|
||||
|
||||
if result.is_empty() && resultMetadata.getFileId().is_empty() {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
let mut decoderRXingResult = DecoderRXingResult::new(
|
||||
@@ -186,7 +184,7 @@ pub fn decodeMacroBlock(
|
||||
let mut codeIndex = codeIndex;
|
||||
if codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0] as usize {
|
||||
// we must have at least two bytes left for the segment index
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
let mut segmentIndexArray = [0; NUMBER_OF_SEQUENCE_CODEWORDS];
|
||||
for seq in segmentIndexArray
|
||||
@@ -204,7 +202,7 @@ pub fn decodeMacroBlock(
|
||||
resultMetadata.setSegmentIndex(parsed_int);
|
||||
} else {
|
||||
// too large; bad input?
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
// Decoding the fileId codewords as 0-899 numbers, each 0-filled to width 3. This follows the spec
|
||||
@@ -221,7 +219,7 @@ pub fn decodeMacroBlock(
|
||||
}
|
||||
if fileId.chars().count() == 0 {
|
||||
// at least one fileId codeword is required (Annex H.2)
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
resultMetadata.setFileId(fileId);
|
||||
|
||||
@@ -258,7 +256,7 @@ pub fn decodeMacroBlock(
|
||||
codeIndex = numericCompaction(codewords, codeIndex + 1, &mut segmentCount)?;
|
||||
segmentCount = segmentCount.build_result();
|
||||
let Ok(parsed_segment_count) = segmentCount.to_string().parse() else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
};
|
||||
resultMetadata.setSegmentCount(parsed_segment_count);
|
||||
}
|
||||
@@ -267,7 +265,7 @@ pub fn decodeMacroBlock(
|
||||
codeIndex = numericCompaction(codewords, codeIndex + 1, &mut timestamp)?;
|
||||
timestamp = timestamp.build_result();
|
||||
let Ok(parsed_timestamp) = timestamp.to_string().parse() else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
};
|
||||
resultMetadata.setTimestamp(parsed_timestamp);
|
||||
}
|
||||
@@ -276,7 +274,7 @@ pub fn decodeMacroBlock(
|
||||
codeIndex = numericCompaction(codewords, codeIndex + 1, &mut checksum)?;
|
||||
checksum = checksum.build_result();
|
||||
let Ok(parsed_checksum ) = checksum.to_string().parse() else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
};
|
||||
resultMetadata.setChecksum(parsed_checksum);
|
||||
}
|
||||
@@ -285,18 +283,18 @@ pub fn decodeMacroBlock(
|
||||
codeIndex = numericCompaction(codewords, codeIndex + 1, &mut fileSize)?;
|
||||
fileSize = fileSize.build_result();
|
||||
let Ok(parsed_file_size)= fileSize.to_string().parse() else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
};
|
||||
resultMetadata.setFileSize(parsed_file_size);
|
||||
}
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
_ => return Err(Exceptions::format),
|
||||
}
|
||||
}
|
||||
MACRO_PDF417_TERMINATOR => {
|
||||
codeIndex += 1;
|
||||
resultMetadata.setLastSegment(true);
|
||||
}
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
_ => return Err(Exceptions::format),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +386,7 @@ fn textCompaction(
|
||||
result,
|
||||
subMode,
|
||||
)
|
||||
.ok_or(Exceptions::illegalStateEmpty())?;
|
||||
.ok_or(Exceptions::illegalState)?;
|
||||
result.appendECI(codewords[codeIndex])?;
|
||||
codeIndex += 1;
|
||||
textCompactionData = vec![0; (codewords[0] as usize - codeIndex) * 2];
|
||||
@@ -770,16 +768,14 @@ fn numericCompaction(
|
||||
Remove leading 1 => RXingResult is 000213298174000
|
||||
*/
|
||||
fn decodeBase900toBase10(codewords: &[u32], count: usize) -> Result<String, Exceptions> {
|
||||
let mut result = 0.to_biguint().ok_or(Exceptions::arithmeticEmpty())?;
|
||||
let mut result = 0.to_biguint().ok_or(Exceptions::arithmetic)?;
|
||||
for i in 0..count {
|
||||
result += &EXP900[count - i - 1]
|
||||
* (codewords[i]
|
||||
.to_biguint()
|
||||
.ok_or(Exceptions::arithmeticEmpty())?);
|
||||
result +=
|
||||
&EXP900[count - i - 1] * (codewords[i].to_biguint().ok_or(Exceptions::arithmetic)?);
|
||||
}
|
||||
let resultString = result.to_string();
|
||||
if !resultString.starts_with('1') {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
Ok(resultString[1..].to_owned())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user