pub struct MinimalEncoder { /* private fields */ }Expand description
Encoder that encodes minimally
Algorithm:
The eleventh commandment was “Thou Shalt Compute” or “Thou Shalt Not Compute” - I forget which (Alan Perilis).
This implementation computes. As an alternative, the QR-Code specification suggests heuristics like this one:
If initial input data is in the exclusive subset of the Alphanumeric character set AND if there are less than [6,7,8] characters followed by data from the remainder of the 8-bit byte character set, THEN select the 8- bit byte mode ELSE select Alphanumeric mode;
This is probably right for 99.99% of cases but there is at least this one counter example: The string “AAAAAAa” encodes 2 bits smaller as ALPHANUMERIC(AAAAAA), BYTE(a) than by encoding it as BYTE(AAAAAAa). Perhaps that is the only counter example but without having proof, it remains unclear.
ECI switching:
In multi language content the algorithm selects the most compact representation using ECI modes. For example the most compact representation of the string “\u0150\u015C” (O-double-acute, S-circumflex) is ECI(UTF-8), BYTE(\u0150\u015C) while prepending one or more times the same leading character as in “\u0150\u0150\u015C”, the most compact representation uses two ECIs so that the string is encoded as ECI(ISO-8859-2), BYTE(\u0150\u0150), ECI(ISO-8859-3), BYTE(\u015C).
@author Alex Geller
Implementations§
Source§impl MinimalEncoder
impl MinimalEncoder
Sourcepub fn new(
stringToEncode: &str,
priorityCharset: Option<CharacterSet>,
isGS1: bool,
ecLevel: ErrorCorrectionLevel,
) -> Self
pub fn new( stringToEncode: &str, priorityCharset: Option<CharacterSet>, isGS1: bool, ecLevel: ErrorCorrectionLevel, ) -> Self
Creates a MinimalEncoder
@param stringToEncode The string to encode @param priorityCharset The preferred {@link Charset}. When the value of the argument is null, the algorithm chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority charset to encode any character in the input that can be encoded by it if the charset is among the supported charsets. @param isGS1 {@code true} if a FNC1 is to be prepended; {@code false} otherwise @param ecLevel The error correction level. @see RXingResultList#getVersion
Sourcepub fn encode_with_details(
stringToEncode: &str,
version: Option<VersionRef>,
priorityCharset: Option<CharacterSet>,
isGS1: bool,
ecLevel: ErrorCorrectionLevel,
) -> Result<RXingResultList>
pub fn encode_with_details( stringToEncode: &str, version: Option<VersionRef>, priorityCharset: Option<CharacterSet>, isGS1: bool, ecLevel: ErrorCorrectionLevel, ) -> Result<RXingResultList>
Encodes the string minimally
@param stringToEncode The string to encode @param version The preferred {@link Version}. A minimal version is computed (see {@link RXingResultList#getVersion method} when the value of the argument is null @param priorityCharset The preferred {@link Charset}. When the value of the argument is null, the algorithm chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority charset to encode any character in the input that can be encoded by it if the charset is among the supported charsets. @param isGS1 {@code true} if a FNC1 is to be prepended; {@code false} otherwise @param ecLevel The error correction level. @return An instance of {@code RXingResultList} representing the minimal solution. @see RXingResultList#getBits @see RXingResultList#getVersion @see RXingResultList#getSize
pub fn encode(&self, version: Option<VersionRef>) -> Result<RXingResultList>
pub fn getVersionSize(version: VersionRef) -> VersionSize
pub fn getVersion(versionSize: VersionSize) -> Result<VersionRef>
pub fn isNumeric(c: &str) -> bool
pub fn isDoubleByteKanji(c: &str) -> bool
pub fn isAlphanumeric(c: &str) -> bool
pub fn canEncode(&self, mode: &Mode, c: &str) -> bool
pub fn getCompactedOrdinal(mode: Option<Mode>) -> Result<u32>
pub fn addEdge( &self, edges: &mut [Vec<Vec<Option<Arc<Edge>>>>], position: usize, edge: Option<Arc<Edge>>, ) -> Result<()>
pub fn addEdges( &self, version: VersionRef, edges: &mut [Vec<Vec<Option<Arc<Edge>>>>], from: usize, previous: Option<Arc<Edge>>, ) -> Result<()>
pub fn encodeSpecificVersion( &self, version: VersionRef, ) -> Result<RXingResultList>
Auto Trait Implementations§
impl Freeze for MinimalEncoder
impl RefUnwindSafe for MinimalEncoder
impl Send for MinimalEncoder
impl Sync for MinimalEncoder
impl Unpin for MinimalEncoder
impl UnwindSafe for MinimalEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.