1"use strict";(self.webpackChunkmodular_fe=self.webpackChunkmodular_fe||[]).push([["13795"],{77723(e,n,i){i.r(n),i.d(n,{metadata:()=>t,default:()=>h,frontMatter:()=>l,contentTitle:()=>o,toc:()=>d,assets:()=>c});var t=JSON.parse('{"id":"docs/std/collections/string/iterators/CodepointSliceIter","title":"CodepointSliceIter","description":"Iterator for `StringSlice` over substring slices containing a single Unicode codepoint.","source":"@site/versioned_docs/version-1.1.0/docs/std/collections/string/iterators/CodepointSliceIter.md","sourceDirName":"docs/std/collections/string/iterators","slug":"/docs/std/collections/string/iterators/CodepointSliceIter","permalink":"/docs/std/collections/string/iterators/CodepointSliceIter","draft":false,"unlisted":false,"editUrl":"https://github.com/modular/modular/edit/main/Mojo/docs/site/std/collections/string/iterators/CodepointSliceIter.md","tags":[],"version":"1.1.0","frontMatter":{"title":"CodepointSliceIter","version":"1.1.0.dev0","slug":"CodepointSliceIter","type":"struct","namespace":"std.collections.string.iterators","lang":"mojo","show_stability_marker":null,"description":"Iterator for `StringSlice` over substring slices containing a single Unicode codepoint."},"sidebar":"stdSidebar","previous":{"title":"BytesIter","permalink":"/docs/std/collections/string/iterators/BytesIter"},"next":{"title":"CodepointsIter","permalink":"/docs/std/collections/string/iterators/CodepointsIter"}}'),s=i(74848),r=i(28453);let l={title:"CodepointSliceIter",version:"1.1.0.dev0",slug:"CodepointSliceIter",type:"struct",namespace:"std.collections.string.iterators",lang:"mojo",show_stability_marker:null,description:"Iterator for `StringSlice` over substring slices containing a single Unicode codepoint."},o,c={},d=[{value:"Parameters",id:"parameters",level:2},{value:"Implemented traits",id:"implemented-traits",level:2},{value:"<code>comptime</code> members",id:"comptime-members",level:2},{value:"<code>Element</code>",id:"element",level:3},{value:"<code>IteratorType</code>",id:"iteratortype",level:3},{value:"Parameters",id:"parameters-1",level:4},{value:"Methods",id:"methods",level:2},{value:"<code>__iter__</code>",id:"__iter__",level:3},{value:"<code>__next__</code>",id:"__next__",level:3},{value:"<code>__len__</code>",id:"__len__",level:3},{value:"<code>peek_next</code>",id:"peek_next",level:3},{value:"<code>peek_back</code>",id:"peek_back",level:3},{value:"<code>next</code>",id:"next",level:3},{value:"<code>next_back</code>",id:"next_back",level:3}];function a(e){let n={a:"a",b:"b",code:"code",div:"div",h2:"h2",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",section:"section",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,s.jsxs)(n.section,{className:"mojo-docs",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"struct CodepointSliceIter[mut: Bool, //, origin: Origin[mut=mut], forward: Bool = True]"})}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["Iterator for ",(0,s.jsx)(n.code,{children:"StringSlice"})," over substring slices containing a single Unicode codepoint."]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"forward"})," parameter only controls the behavior of the ",(0,s.jsx)(n.code,{children:"__next__()"}),"\nmethod used for normal iteration. Calls to ",(0,s.jsx)(n.code,{children:"next()"})," will always take an\nelement from the front of the iterator, and calls to ",(0,s.jsx)(n.code,{children:"next_back()"})," will\nalways take an element from the end."]}),"\n",(0,s.jsx)(n.h2,{id:"parameters",children:"Parameters"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\u200B",(0,s.jsx)(n.b,{children:"mut"})," (",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/builtin/bool/Bool",children:(0,s.jsx)(n.code,{children:"Bool"})}),"): Whether the slice is mutable."]}),"\n",(0,s.jsxs)(n.li,{children:["\u200B",(0,s.jsx)(n.b,{children:"origin"})," (",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/origin/Origin",children:(0,s.jsx)(n.code,{children:"Origin[mut=mut]"})}),"): The origin of the underlying string data."]}),"\n",(0,s.jsxs)(n.li,{children:["\u200B",(0,s.jsx)(n.b,{children:"forward"})," (",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/builtin/bool/Bool",children:(0,s.jsx)(n.code,{children:"Bool"})}),"): The iteration direction. ",(0,s.jsx)(n.code,{children:"False"})," is backwards."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"implemented-traits",children:"Implemented traits"}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"../../../../../../docs/std/traits/anytype/AnyType",children:(0,s.jsx)(n.code,{children:"AnyType"})}),",\n",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/traits/copyable/Copyable",children:(0,s.jsx)(n.code,{children:"Copyable"})}),",\n",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/traits/deinitable/Deinitable",children:(0,s.jsx)(n.code,{children:"Deinitable"})}),",\n",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/traits/copyable/ImplicitlyCopyable",children:(0,s.jsx)(n.code,{children:"ImplicitlyCopyable"})}),",\n",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/iter/Iterable",children:(0,s.jsx)(n.code,{children:"Iterable"})}),",\n",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/iter/Iterator",children:(0,s.jsx)(n.code,{children:"Iterator"})}),",\n",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/traits/movable/Movable",children:(0,s.jsx)(n.code,{children:"Movable"})}),",\n",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/builtin/len/Sized",children:(0,s.jsx)(n.code,{children:"Sized"})})]}),"\n",(0,s.jsxs)(n.h2,{id:"comptime-members",children:[(0,s.jsx)(n.code,{children:"comptime"})," members"]}
1),"\n",(0,s.jsxs)(n.div,{className:"mojo-alias-header",children:["\n",(0,s.jsx)(n.h3,{id:"element",children:(0,s.jsx)(n.code,{children:"Element"})}),"\n"]}),"\n",(0,s.jsxs)(n.div,{className:"mojo-alias-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-alias-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"comptime Element = StringSpan[origin]"})}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"The element type yielded by iteration."}),"\n"]}),"\n",(0,s.jsxs)(n.div,{className:"mojo-alias-header",children:["\n",(0,s.jsx)(n.h3,{id:"iteratortype",children:(0,s.jsx)(n.code,{children:"IteratorType"})}),"\n"]}),"\n",(0,s.jsxs)(n.div,{className:"mojo-alias-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-alias-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"comptime IteratorType[iterable_mut: Bool, //, iterable_origin: Origin[mut=iterable_mut]] = CodepointSliceIter[origin, forward]"})}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"The iterator type for this codepoint iterator."}),"\n",(0,s.jsx)(n.h4,{id:"parameters-1",children:"Parameters"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\u200B",(0,s.jsx)(n.b,{children:"iterable_mut"})," (",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/builtin/bool/Bool",children:(0,s.jsx)(n.code,{children:"Bool"})}),"): Whether the iterable is mutable."]}),"\n",(0,s.jsxs)(n.li,{children:["\u200B",(0,s.jsx)(n.b,{children:"iterable_origin"})," (",(0,s.jsx)(n.a,{href:"../../../../../../docs/std/origin/Origin",children:(0,s.jsx)(n.code,{children:"Origin[mut=iterable_mut]"})}),"): The origin of the iterable."]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"methods",children:"Methods"}),"\n",(0,s.jsx)(n.h3,{id:"__iter__",children:(0,s.jsx)(n.code,{children:"__iter__"})}),"\n",(0,s.jsxs)(n.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"def __iter__(ref self) -> Self"})}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["Iterate over the ",(0,s.jsx)(n.code,{children:"StringSlice"})," yielding individual characters."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Self"}),": An iterator over the characters in the string slice."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"__next__",children:(0,s.jsx)(n.code,{children:"__next__"})}),"\n",(0,s.jsxs)(n.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"def __next__(mut self) -> StringSpan[origin]"})}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"Get the next codepoint in the underlying string slice."}),"\n",(0,s.jsx)(n.p,{children:"This returns the next single-codepoint substring slice encoded in the\nunderlying string, and advances the iterator state."}),"\n",(0,s.jsxs)(n.p,{children:["If ",(0,s.jsx)(n.code,{children:"forward"})," is set to ",(0,s.jsx)(n.code,{children:"False"}),", this will return the next codepoint\nfrom the end of the string."]}),"\n",(0,s.jsx)(n.p,{children:"This function will abort if this iterator has been exhausted."}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"StringSpan[origin]"}),": The next character in the string."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Raises:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"StopIteration"})," if the iterator has been exhausted."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"__len__",children:(0,s.jsx)(n.code,{children:"__len__"})}),"\n",(0,s.jsxs)(n.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"def __len__(self) -> Int"})}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["Returns the remaining length of this iterator in ",(0,s.jsx)(n.code,{children:"Codepoint"}),"s."]}),"\n",(0,s.jsxs)(n.p,{children:["The value returned from this method indicates the number of subsequent\ncalls to ",(0,s.jsx)(n.code,{children:"next()"})," that will return a value."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"../../../../../../docs/std/simd/#int",children:(0,s.jsx)(n.code,{children:"Int"})}),": Number of codepoints remaining in this iterator."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"peek_next",children:(0,s.jsx)(n.code,{children:"peek_next"})}),"\n",(0,s.jsxs)(n.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"def peek_next(self) -> Optional[StringSpan[origin]]"})}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"Check what the next single-codepoint slice in this iterator is, without advancing the iterator state."}),"\n",(0,s.jsx)(n.p,{children:"Repeated calls to this method will return the same value."}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Examples:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"peek_next()"})," does not advance the iterator, so repeated calls will\nreturn the same value:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-mojo",children:'from std.collections.string import Codepoint\nfrom std.testing import assert_equal\n\nvar input = StringSlice("123")\nvar iter = input.codepoint_slices()\n\nassert_equal(iter.peek_next().value(
1), "1")\nassert_equal(iter.peek_next().value(), "1")\nassert_equal(iter.peek_next().value(), "1")\n\n# A call to `next()` return the same value as `peek_next()` had,\n# but also advance the iterator.\nassert_equal(iter.next().value(), "1")\n\n# Later `peek_next()` calls will return the _new_ next character:\nassert_equal(iter.peek_next().value(), "2")\n'})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"../../../../../../docs/std/collections/optional/Optional",children:(0,s.jsx)(n.code,{children:"Optional[StringSpan[origin]]"})}),": The next codepoint slice in the underlying string, or None if the\nstring is empty."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"peek_back",children:(0,s.jsx)(n.code,{children:"peek_back"})}),"\n",(0,s.jsxs)(n.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"def peek_back(mut self) -> Optional[StringSpan[origin]]"})}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"Check what the last single-codepoint slice in this iterator is, without advancing the iterator state."}),"\n",(0,s.jsx)(n.p,{children:"Repeated calls to this method will return the same value."}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Examples:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"peek_back()"})," does not advance the iterator, so repeated calls will\nreturn the same value:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-mojo",children:'from std.collections.string import Codepoint\nfrom std.testing import assert_equal\n\nvar input = StringSlice("123")\nvar iter = input.codepoint_slices()\n\n# Repeated calls to `peek_back()` return the same value.\nassert_equal(iter.peek_back().value(), "3")\nassert_equal(iter.peek_back().value(), "3")\nassert_equal(iter.peek_back().value(), "3")\n\n# A call to `next_back()` return the same value as `peek_back()` had,\n# but also advance the iterator.\nassert_equal(iter.next_back().value(), "3")\n\n# Later `peek_back()` calls will return the _new_ next character:\nassert_equal(iter.peek_back().value(), "2")\n'})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"../../../../../../docs/std/collections/optional/Optional",children:(0,s.jsx)(n.code,{children:"Optional[StringSpan[origin]]"})}),": The last codepoint slice in the underlying string, or None if the\nstring is empty."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"next",children:(0,s.jsx)(n.code,{children:"next"})}),"\n",(0,s.jsxs)(n.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"def next(mut self) -> Optional[StringSpan[origin]]"})}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"Get the next codepoint slice in the underlying string slice, or None if the iterator is empty."}),"\n",(0,s.jsx)(n.p,{children:"This returns the next single-codepoint substring encoded in the\nunderlying string, and advances the iterator state."}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"../../../../../../docs/std/collections/optional/Optional",children:(0,s.jsx)(n.code,{children:"Optional[StringSpan[origin]]"})}),": A character if the string is not empty, otherwise None."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"next_back",children:(0,s.jsx)(n.code,{children:"next_back"})}),"\n",(0,s.jsxs)(n.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(n.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.code,{children:"def next_back(mut self) -> Optional[StringSpan[origin]]"})}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"Get the last single-codepoint slice in this iterator is, or None if the iterator is empty."}),"\n",(0,s.jsx)(n.p,{children:"This returns the last codepoint slice in this iterator, and advances\nthe iterator state."}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"../../../../../../docs/std/collections/optional/Optional",children:(0,s.jsx)(n.code,{children:"Optional[StringSpan[origin]]"})}),": The last codepoint slice in the underlying string, or None if the\nstring is empty."]}),"\n"]}),"\n"]})}function h(e={}){let{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(a,{...e})}):a(e)}},28453(e,n,i){i.d(n,{R:()=>l,x:()=>o});var t=i(96540);let s={},r=t.createContext(s);function l(e){let n=t.useContext(r);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),t.createElement(r.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.