pub struct PdfiumSearchFlags(/* private fields */);Expand description
A bitflag type representing various search options for PDF text searching.
This struct wraps PDFium library constants to provide a type-safe way to combine multiple search flags using bitwise operations.
§Examples
use pdfium::*;
// Search with no flags
let flags = PdfiumSearchFlags::empty();
// Search with case sensitivity
let flags = PdfiumSearchFlags::MATCH_CASE;
// Search for whole words only, case-sensitive
let flags = PdfiumSearchFlags::MATCH_CASE | PdfiumSearchFlags::MATCH_WHOLE_WORD;
// Use all search options
let flags = PdfiumSearchFlags::all();Implementations§
Source§impl PdfiumSearchFlags
impl PdfiumSearchFlags
Sourcepub const MATCH_CASE: Self
pub const MATCH_CASE: Self
Enables case-sensitive text matching during PDF search operations. When this flag is set, “Hello” will not match “hello”.
Sourcepub const MATCH_WHOLE_WORD: Self
pub const MATCH_WHOLE_WORD: Self
Enables whole word matching during PDF search operations. When this flag is set, searching for “cat” will not match “category”. The search term must be bounded by word boundaries (spaces, punctuation, etc.).
Sourcepub const CONSECUTIVE: Self
pub const CONSECUTIVE: Self
The CONSECUTIVE flag modifies the behavior of the text search to start the next
or previous search from the position immediately following or preceding the current
match, rather than skipping to the end or start of the current match. This is
particularly useful for finding overlapping or consecutive matches of the search term
in the text.
-
Behavior with
CONSECUTIVE:- When this flag is set, the search continues from the character immediately after the
start of the current match (for
FPDFText_FindNext) or immediately before the end of the current match (forFPDFText_FindPrev). - This allows the search to potentially find overlapping instances of the search term.
For example, searching for “ana” in “banana” could find matches at positions 1 (“ana”)
and 3 (“ana”) if
CONSECUTIVEis enabled. - Without this flag, the search would typically skip to the position after the end of
the current match (for
FPDFText_FindNext) or before the start of the current match (forFPDFText_FindPrev), potentially missing overlapping matches.
- When this flag is set, the search continues from the character immediately after the
start of the current match (for
-
Default Behavior (without
CONSECUTIVE):- If the flag is not set, after finding a match,
FPDFText_FindNextstarts the next search from the character after the end of the current match (m_resEnd + 1), andFPDFText_FindPrevstarts from the character before the start of the current match (m_resStart - 1). This prevents overlapping matches.
- If the flag is not set, after finding a match,
Source§impl PdfiumSearchFlags
impl PdfiumSearchFlags
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Get a flags value with all bits unset.
Examples found in repository?
80pub fn example_search() -> PdfiumResult<()> {
81 // Load the PDF document to search within
82 let document = PdfiumDocument::new_from_path("resources/groningen.pdf", None)?;
83
84 // Get the first page (index 0) for searching
85 let page = document.page(0)?;
86
87 // Extract text objects from the page for searching
88 let text = page.text()?;
89
90 // Search for "amsterdam" with case-insensitive matching
91 // PdfiumSearchFlags::empty() means no special search flags (case-insensitive by default)
92 // The last parameter (0) is the starting position for the search
93 let search = text.find("amsterdam", PdfiumSearchFlags::empty(), 0);
94 println!("Found amsterdam {} times", search.count());
95
96 // Search for "groningen" with case-insensitive matching
97 let search = text.find("groningen", PdfiumSearchFlags::empty(), 0);
98 println!(
99 "Found groningen {} times (case insensitive)",
100 search.count()
101 );
102
103 // Search for "Groningen" with case-sensitive matching
104 // MATCH_CASE flag enforces exact case matching
105 let search = text.find("Groningen", PdfiumSearchFlags::MATCH_CASE, 0);
106 println!("Found Groningen {} times (case sensitive)", search.count());
107
108 // Perform another case-insensitive search to iterate through results
109 let search = text.find("groningen", PdfiumSearchFlags::empty(), 0);
110
111 // Iterate through each search result to extract detailed information
112 for result in search {
113 // Extract the text fragment at the found position
114 // result.index() gives the character position where the match starts
115 // result.count() gives the length of the matched text
116 let fragment = text.extract(result.index(), result.count());
117 println!(
118 "Found groningen (case insensitive) at {}, fragment = '{fragment}'",
119 result.index()
120 );
121 }
122
123 // Expected output:
124 //
125 // Found amsterdam 0 times
126 // Found groningen 5 times (case insensitive)
127 // Found Groningen 5 times (case sensitive)
128 // Found groningen (case insensitive) at 14, fragment = 'Groningen'
129 // Found groningen (case insensitive) at 232, fragment = 'Groningen'
130 // Found groningen (case insensitive) at 475, fragment = 'Groningen'
131 // Found groningen (case insensitive) at 920, fragment = 'Groningen'
132 // Found groningen (case insensitive) at 1050, fragment = 'Groningen'
133
134 Ok(())
135}Sourcepub const fn bits(&self) -> i32
pub const fn bits(&self) -> i32
Get the underlying bits value.
The returned value is exactly the bits set in this flags value.
Sourcepub const fn from_bits(bits: i32) -> Option<Self>
pub const fn from_bits(bits: i32) -> Option<Self>
Convert from a bits value.
This method will return None if any unknown bits are set.
Sourcepub const fn from_bits_truncate(bits: i32) -> Self
pub const fn from_bits_truncate(bits: i32) -> Self
Convert from a bits value, unsetting any unknown bits.
Sourcepub const fn from_bits_retain(bits: i32) -> Self
pub const fn from_bits_retain(bits: i32) -> Self
Convert from a bits value exactly.
Sourcepub fn from_name(name: &str) -> Option<Self>
pub fn from_name(name: &str) -> Option<Self>
Get a flags value with the bits of a flag with the given name set.
This method will return None if name is empty or doesn’t
correspond to any named flag.
Sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Whether any set bits in a source flags value are also set in a target flags value.
Sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Whether all set bits in a source flags value are also set in a target flags value.
Sourcepub fn remove(&mut self, other: Self)
pub fn remove(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags
value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
remove won’t truncate other, but the ! operator will.
Sourcepub fn toggle(&mut self, other: Self)
pub fn toggle(&mut self, other: Self)
The bitwise exclusive-or (^) of the bits in two flags values.
Sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Call insert when value is true or remove when value is false.
Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
The bitwise and (&) of the bits in two flags values.
Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
The bitwise or (|) of the bits in two flags values.
Sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags
value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
The bitwise exclusive-or (^) of the bits in two flags values.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
The bitwise negation (!) of the bits in a flags value, truncating the result.
Source§impl PdfiumSearchFlags
impl PdfiumSearchFlags
Sourcepub const fn iter(&self) -> Iter<PdfiumSearchFlags>
pub const fn iter(&self) -> Iter<PdfiumSearchFlags>
Yield a set of contained flags values.
Each yielded flags value will correspond to a defined named flag. Any unknown bits will be yielded together as a final flags value.
Sourcepub const fn iter_names(&self) -> IterNames<PdfiumSearchFlags>
pub const fn iter_names(&self) -> IterNames<PdfiumSearchFlags>
Yield a set of contained named flags values.
This method is like iter, except only yields bits in contained named flags.
Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
Trait Implementations§
Source§impl Binary for PdfiumSearchFlags
impl Binary for PdfiumSearchFlags
Source§impl BitAnd for PdfiumSearchFlags
impl BitAnd for PdfiumSearchFlags
Source§impl BitAndAssign for PdfiumSearchFlags
impl BitAndAssign for PdfiumSearchFlags
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
The bitwise and (&) of the bits in two flags values.
Source§impl BitOr for PdfiumSearchFlags
impl BitOr for PdfiumSearchFlags
Source§fn bitor(self, other: PdfiumSearchFlags) -> Self
fn bitor(self, other: PdfiumSearchFlags) -> Self
The bitwise or (|) of the bits in two flags values.
Source§type Output = PdfiumSearchFlags
type Output = PdfiumSearchFlags
| operator.Source§impl BitOrAssign for PdfiumSearchFlags
impl BitOrAssign for PdfiumSearchFlags
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
The bitwise or (|) of the bits in two flags values.
Source§impl BitXor for PdfiumSearchFlags
impl BitXor for PdfiumSearchFlags
Source§impl BitXorAssign for PdfiumSearchFlags
impl BitXorAssign for PdfiumSearchFlags
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
The bitwise exclusive-or (^) of the bits in two flags values.
Source§impl Clone for PdfiumSearchFlags
impl Clone for PdfiumSearchFlags
Source§fn clone(&self) -> PdfiumSearchFlags
fn clone(&self) -> PdfiumSearchFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PdfiumSearchFlags
impl Debug for PdfiumSearchFlags
Source§impl Extend<PdfiumSearchFlags> for PdfiumSearchFlags
impl Extend<PdfiumSearchFlags> for PdfiumSearchFlags
Source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
The bitwise or (|) of the bits in each flags value.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Flags for PdfiumSearchFlags
impl Flags for PdfiumSearchFlags
Source§const FLAGS: &'static [Flag<PdfiumSearchFlags>]
const FLAGS: &'static [Flag<PdfiumSearchFlags>]
Source§fn from_bits_retain(bits: i32) -> PdfiumSearchFlags
fn from_bits_retain(bits: i32) -> PdfiumSearchFlags
Source§fn contains_unknown_bits(&self) -> bool
fn contains_unknown_bits(&self) -> bool
true if any unknown bits are set.Source§fn from_bits_truncate(bits: Self::Bits) -> Self
fn from_bits_truncate(bits: Self::Bits) -> Self
Source§fn from_name(name: &str) -> Option<Self>
fn from_name(name: &str) -> Option<Self>
Source§fn iter_names(&self) -> IterNames<Self>
fn iter_names(&self) -> IterNames<Self>
Source§fn iter_defined_names() -> IterDefinedNames<Self>
fn iter_defined_names() -> IterDefinedNames<Self>
Self::FLAGS.Source§fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn contains(&self, other: Self) -> boolwhere
Self: Sized,
fn contains(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn insert(&mut self, other: Self)where
Self: Sized,
fn insert(&mut self, other: Self)where
Self: Sized,
|) of the bits in two flags values.Source§fn remove(&mut self, other: Self)where
Self: Sized,
fn remove(&mut self, other: Self)where
Self: Sized,
&!). Read moreSource§fn toggle(&mut self, other: Self)where
Self: Sized,
fn toggle(&mut self, other: Self)where
Self: Sized,
^) of the bits in two flags values.Source§fn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
&) of the bits in two flags values.Source§fn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
&!). Read moreSource§fn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
^) of the bits in two flags values.Source§fn complement(self) -> Self
fn complement(self) -> Self
!) of the bits in a flags value, truncating the result.Source§impl FromIterator<PdfiumSearchFlags> for PdfiumSearchFlags
impl FromIterator<PdfiumSearchFlags> for PdfiumSearchFlags
Source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
The bitwise or (|) of the bits in each flags value.
Source§impl Hash for PdfiumSearchFlags
impl Hash for PdfiumSearchFlags
Source§impl IntoIterator for PdfiumSearchFlags
impl IntoIterator for PdfiumSearchFlags
Source§impl LowerHex for PdfiumSearchFlags
impl LowerHex for PdfiumSearchFlags
Source§impl Not for PdfiumSearchFlags
impl Not for PdfiumSearchFlags
Source§impl Octal for PdfiumSearchFlags
impl Octal for PdfiumSearchFlags
Source§impl Ord for PdfiumSearchFlags
impl Ord for PdfiumSearchFlags
Source§fn cmp(&self, other: &PdfiumSearchFlags) -> Ordering
fn cmp(&self, other: &PdfiumSearchFlags) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for PdfiumSearchFlags
impl PartialEq for PdfiumSearchFlags
Source§impl PartialOrd for PdfiumSearchFlags
impl PartialOrd for PdfiumSearchFlags
Source§impl PublicFlags for PdfiumSearchFlags
impl PublicFlags for PdfiumSearchFlags
Source§impl Sub for PdfiumSearchFlags
impl Sub for PdfiumSearchFlags
Source§fn sub(self, other: Self) -> Self
fn sub(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Source§type Output = PdfiumSearchFlags
type Output = PdfiumSearchFlags
- operator.Source§impl SubAssign for PdfiumSearchFlags
impl SubAssign for PdfiumSearchFlags
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.