about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/str/iter.rs23
2 files changed, 24 insertions, 0 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 64e2a951309..2fcb2ca9248 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -137,6 +137,7 @@
 #![feature(stmt_expr_attributes)]
 #![feature(str_split_as_str)]
 #![feature(str_split_inclusive_as_str)]
+#![feature(char_indices_offset)]
 #![feature(trait_alias)]
 #![feature(transparent_unions)]
 #![feature(try_blocks)]
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs
index 83f484dc570..cd67c773780 100644
--- a/library/core/src/str/iter.rs
+++ b/library/core/src/str/iter.rs
@@ -189,6 +189,29 @@ impl<'a> CharIndices<'a> {
     pub fn as_str(&self) -> &'a str {
         self.iter.as_str()
     }
+
+    /// Returns the byte position of the next character, or the length 
+    /// of the underlying string if there are no more characters.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// let mut chars = "a楽".char_indices();
+    ///
+    /// assert_eq!(chars.offset(), 0);
+    /// assert_eq!(chars.next(), Some((0, 'a')));
+    ///
+    /// assert_eq!(chars.offset(), 1);
+    /// assert_eq!(chars.next(), Some((1, '楽')));
+    ///
+    /// assert_eq!(chars.offset(), 4);
+    /// assert_eq!(chars.next(), None);
+    /// ```
+    #[inline]
+    #[unstable(feature = "char_indices_offset", issue = "none")]
+    pub fn offset(&self) -> usize {
+        self.front_offset
+    }
 }
 
 /// An iterator over the bytes of a string slice.