@@ -190,6 +190,41 @@ impl Id3v2Tag {
190190 None
191191 }
192192
193+ /// Gets all of the values for a text frame
194+ ///
195+ /// NOTE: Multiple values are only supported in ID3v2.4, this will not be
196+ /// very useful for ID3v2.2/3 tags.
197+ ///
198+ /// # Examples
199+ ///
200+ /// ```rust
201+ /// use lofty::id3::v2::{FrameId, Id3v2Tag};
202+ /// use lofty::Accessor;
203+ /// use std::borrow::Cow;
204+ ///
205+ /// const TITLE_ID: FrameId<'_> = FrameId::Valid(Cow::Borrowed("TIT2"));
206+ ///
207+ /// let mut tag = Id3v2Tag::new();
208+ ///
209+ /// tag.set_title(String::from("Foo\0Bar"));
210+ ///
211+ /// let mut titles = tag.get_texts(&TITLE_ID);
212+ ///
213+ /// assert_eq!(titles.next(), Some("Foo"));
214+ /// assert_eq!(titles.next(), Some("Bar"));
215+ /// ```
216+ pub fn get_texts ( & self , id : & FrameId < ' _ > ) -> Option < impl Iterator < Item = & str > > {
217+ if let Some ( Frame {
218+ value : FrameValue :: Text ( TextInformationFrame { value, .. } ) ,
219+ ..
220+ } ) = self . get ( id)
221+ {
222+ return Some ( value. split ( '\0' ) ) ;
223+ }
224+
225+ None
226+ }
227+
193228 /// Gets the text for a user-defined frame
194229 ///
195230 /// NOTE: If the tag is [`Id3v2Version::V4`], there could be multiple values separated by null characters (`'\0'`).
@@ -2376,11 +2411,12 @@ mod tests {
23762411 fn read_multiple_composers_should_not_fail_with_bad_frame_length ( ) {
23772412 // Issue #255
23782413 let tag = read_tag ( "tests/tags/assets/id3v2/multiple_composers.id3v24" ) ;
2379- assert_eq ! (
2380- tag. get_text( & FrameId :: Valid ( Cow :: Borrowed ( "TCOM" ) ) )
2381- . as_deref( )
2382- . unwrap( ) ,
2383- "A/B"
2384- ) ;
2414+ let mut composers = tag
2415+ . get_texts ( & FrameId :: Valid ( Cow :: Borrowed ( "TCOM" ) ) )
2416+ . unwrap ( ) ;
2417+
2418+ assert_eq ! ( composers. next( ) , Some ( "A" ) ) ;
2419+ assert_eq ! ( composers. next( ) , Some ( "B" ) ) ;
2420+ assert_eq ! ( composers. next( ) , None )
23852421 }
23862422}
0 commit comments