pub struct PdfString { /* private fields */ }Expand description
A PDF string object: raw bytes plus the syntax they were written in.
use pdfrum_object::PdfString;
let s = PdfString::literal(b"A simple test");
assert_eq!(s.as_text(), "A simple test");
assert_eq!(s.syntax(), pdfrum_object::StringSyntax::Literal);
// A UTF-16BE byte-order mark selects the Unicode reading.
let unicode = PdfString::hex(b"\xFE\xFF\x03\x30\x03\x31");
assert_eq!(unicode.as_text(), "\u{0330}\u{0331}");
assert_eq!(unicode.syntax(), pdfrum_object::StringSyntax::Hex);Implementations§
Source§impl PdfString
impl PdfString
Sourcepub fn new(bytes: impl AsRef<[u8]>, syntax: StringSyntax) -> Self
pub fn new(bytes: impl AsRef<[u8]>, syntax: StringSyntax) -> Self
A string with an explicit syntax.
Sourcepub fn syntax(&self) -> StringSyntax
pub fn syntax(&self) -> StringSyntax
Whether the source syntax was <hex> rather than (literal).
Sourcepub fn is_hex(&self) -> bool
pub fn is_hex(&self) -> bool
true when PdfString::syntax is StringSyntax::Hex.
Sourcepub fn as_text(&self) -> Cow<'_, str>
pub fn as_text(&self) -> Cow<'_, str>
Interpret the bytes as text — see decode_text.
Trait Implementations§
impl Eq for PdfString
impl StructuralPartialEq for PdfString
Auto Trait Implementations§
impl Freeze for PdfString
impl RefUnwindSafe for PdfString
impl Send for PdfString
impl Sync for PdfString
impl Unpin for PdfString
impl UnsafeUnpin for PdfString
impl UnwindSafe for PdfString
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
Mutably borrows from an owned value. Read more