Skip to content

Commit

Permalink
Allow XmpMeta::array_item to accept XmpMeta::LAST_ITEM (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten-adobe authored Oct 31, 2022
1 parent 745ec4c commit 9af24fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ extern "C" {
out_error: *mut CXmpError,
schema_ns: *const c_char,
prop_name: *const c_char,
index: u32,
index: i32,
out_options: *mut u32,
) -> *const c_char;

Expand Down
13 changes: 13 additions & 0 deletions src/tests/xmp_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,19 @@ mod array_item {
);
}

#[test]
fn last_item() {
let m = XmpMeta::from_str(ARRAY_EXAMPLE).unwrap();

assert_eq!(
m.array_item(xmp_ns::DC, "subject", XmpMeta::LAST_ITEM),
Some(XmpValue {
value: "test".to_owned(),
options: 0
})
);
}

#[test]
fn item_options() {
let mut m = XmpMeta::from_str(ARRAY_EXAMPLE).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/xmp_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,14 @@ impl XmpMeta {
///
/// * `namespace` and `array_name`: See [Accessing
/// properties](#accessing-properties).
/// * `item_index`: Index into the array.
/// **IMPORTANT:** Indices in XMP are 1-based, unlike Rust where
/// indices are typically 0-based.
/// * `item_index`: Index into the array. **IMPORTANT:** Indices in XMP are
/// 1-based, unlike Rust where indices are typically 0-based. Use
/// [`XmpMeta::LAST_ITEM`] to specify the last existing array item.
pub fn array_item(
&self,
namespace: &str,
array_name: &str,
item_index: u32,
item_index: i32,
) -> Option<XmpValue<String>> {
if let Some(m) = self.m {
let c_ns = CString::new(namespace).unwrap_or_default();
Expand Down Expand Up @@ -1506,7 +1506,7 @@ pub struct ArrayProperty<'a> {
meta: &'a XmpMeta,
ns: CString,
name: CString,
index: u32,
index: i32,
}

impl<'a> Iterator for ArrayProperty<'a> {
Expand Down

0 comments on commit 9af24fd

Please sign in to comment.