rxing/common/
eci_input.rs

1/*
2 * Copyright 2021 ZXing authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//package com.google.zxing.common;
18
19use std::fmt::Display;
20
21use crate::common::Result;
22
23use super::Eci;
24
25/**
26 * Interface to navigate a sequence of ECIs and bytes.
27 *
28 * @author Alex Geller
29 */
30pub trait ECIInput: Display {
31    /**
32     * Returns the length of this input.  The length is the number
33     * of {@code byte}s in or ECIs in the sequence.
34     *
35     * @return  the number of {@code char}s in this sequence
36     */
37    fn length(&self) -> usize;
38
39    /**
40     * Returns the {@code byte} value at the specified index.  An index ranges from zero
41     * to {@code length() - 1}.  The first {@code byte} value of the sequence is at
42     * index zero, the next at index one, and so on, as for array
43     * indexing.
44     *
45     * @param   index the index of the {@code byte} value to be returned
46     *
47     * @return  the specified {@code byte} value as character or the FNC1 character
48     *
49     * @throws  IndexOutOfBoundsException
50     *          if the {@code index} argument is negative or not less than
51     *          {@code length()}
52     * @throws  IllegalArgumentException
53     *          if the value at the {@code index} argument is an ECI (@see #isECI)
54     */
55    fn charAt(&self, index: usize) -> Result<char>;
56
57    /**
58     * Returns a {@code CharSequence} that is a subsequence of this sequence.
59     * The subsequence starts with the {@code char} value at the specified index and
60     * ends with the {@code char} value at index {@code end - 1}.  The length
61     * (in {@code char}s) of the
62     * returned sequence is {@code end - start}, so if {@code start == end}
63     * then an empty sequence is returned.
64     *
65     * @param   start   the start index, inclusive
66     * @param   end     the end index, exclusive
67     *
68     * @return  the specified subsequence
69     *
70     * @throws  IndexOutOfBoundsException
71     *          if {@code start} or {@code end} are negative,
72     *          if {@code end} is greater than {@code length()},
73     *          or if {@code start} is greater than {@code end}
74     * @throws  IllegalArgumentException
75     *          if a value in the range {@code start}-{@code end} is an ECI (@see #isECI)
76     */
77    fn subSequence(&self, start: usize, end: usize) -> Result<Vec<char>>;
78
79    /**
80     * Determines if a value is an ECI
81     *
82     * @param   index the index of the value
83     *
84     * @return  true if the value at position {@code index} is an ECI
85     *
86     * @throws  IndexOutOfBoundsException
87     *          if the {@code index} argument is negative or not less than
88     *          {@code length()}
89     */
90    fn isECI(&self, index: u32) -> Result<bool>;
91
92    /**
93     * Returns the {@code int} ECI value at the specified index.  An index ranges from zero
94     * to {@code length() - 1}.  The first {@code byte} value of the sequence is at
95     * index zero, the next at index one, and so on, as for array
96     * indexing.
97     *
98     * @param   index the index of the {@code int} value to be returned
99     *
100     * @return  the specified {@code int} ECI value.
101     *          The ECI specified the encoding of all bytes with a higher index until the
102     *          next ECI or until the end of the input if no other ECI follows.
103     *
104     * @throws  IndexOutOfBoundsException
105     *          if the {@code index} argument is negative or not less than
106     *          {@code length()}
107     * @throws  IllegalArgumentException
108     *          if the value at the {@code index} argument is not an ECI (@see #isECI)
109     */
110    fn getECIValue(&self, index: usize) -> Result<Eci>;
111    fn haveNCharacters(&self, index: usize, n: usize) -> Result<bool>;
112}