rust_macios/core_foundation/cf_string/
iter.rs

1use crate::{
2    core_foundation::{CFIndex, CFTypeObject},
3    kernel::UniChar,
4};
5
6use super::CFString;
7
8pub struct Iter<'a> {
9    pub(super) string: &'a CFString,
10    pub(super) index: CFIndex,
11}
12
13impl<'a> Iterator for Iter<'a> {
14    type Item = UniChar;
15
16    fn next(&mut self) -> Option<Self::Item> {
17        unsafe {
18            if self.index >= CFString::get_length(self.string.get_internal_object()) {
19                None
20            } else {
21                let item =
22                    CFString::get_character_at_index(self.string.get_internal_object(), self.index);
23                self.index += 1;
24                Some(item)
25            }
26        }
27    }
28}