1"use strict";(self.webpackChunkmodular_fe=self.webpackChunkmodular_fe||[]).push([["12345"],{68683(e,t,i){i.r(t),i.d(t,{metadata:()=>r,default:()=>h,frontMatter:()=>l,contentTitle:()=>d,toc:()=>c,assets:()=>o});var r=JSON.parse('{"id":"docs/std/collections/string/iterators/GraphemeIndicesIter","title":"GraphemeIndicesIter","description":"Iterator over grapheme clusters paired with their starting byte offset.","source":"@site/versioned_docs/version-1.1.0/docs/std/collections/string/iterators/GraphemeIndicesIter.md","sourceDirName":"docs/std/collections/string/iterators","slug":"/docs/std/collections/string/iterators/GraphemeIndicesIter","permalink":"/docs/std/collections/string/iterators/GraphemeIndicesIter","draft":false,"unlisted":false,"editUrl":"https://github.com/modular/modular/edit/main/Mojo/docs/site/std/collections/string/iterators/GraphemeIndicesIter.md","tags":[],"version":"1.1.0","frontMatter":{"title":"GraphemeIndicesIter","version":"1.1.0.dev0","slug":"GraphemeIndicesIter","type":"struct","namespace":"std.collections.string.iterators","lang":"mojo","show_stability_marker":null,"description":"Iterator over grapheme clusters paired with their starting byte offset."},"sidebar":"stdSidebar","previous":{"title":"CodepointsIter","permalink":"/docs/std/collections/string/iterators/CodepointsIter"},"next":{"title":"GraphemeSliceIter","permalink":"/docs/std/collections/string/iterators/GraphemeSliceIter"}}'),s=i(74848),n=i(28453);let l={title:"GraphemeIndicesIter",version:"1.1.0.dev0",slug:"GraphemeIndicesIter",type:"struct",namespace:"std.collections.string.iterators",lang:"mojo",show_stability_marker:null,description:"Iterator over grapheme clusters paired with their starting byte offset."},d,o={},c=[{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}];function a(e){let t={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,n.R)(),...e.components};return(0,s.jsxs)(t.section,{className:"mojo-docs",children:["\n",(0,s.jsxs)(t.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.code,{children:"struct GraphemeIndicesIter[mut: Bool, //, origin: Origin[mut=mut]]"})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"Iterator over grapheme clusters paired with their starting byte offset."}),"\n",(0,s.jsxs)(t.p,{children:["Each call to ",(0,s.jsx)(t.code,{children:"__next__()"})," yields a ",(0,s.jsx)(t.code,{children:"Tuple[Int, StringSlice[origin]]"})," where\nthe first element is the byte offset (relative to the original string)\nat which the grapheme begins, and the second is the grapheme slice\nitself."]}),"\n",(0,s.jsxs)(t.p,{children:["Mirrors ",(0,s.jsx)(t.code,{children:"str::grapheme_indices"})," from Rust's ",(0,s.jsx)(t.code,{children:"unicode-segmentation"})," crate.\nUseful for text editors and UIs that need to map cursor byte positions\nback to grapheme boundaries."]}),"\n",(0,s.jsx)(t.p,{children:"Example:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-mojo",children:'from std.testing import assert_equal\nvar s = StringSlice("abc")\nvar pairs = List[Tuple[Int, String]]()\nfor off, g in s.grapheme_indices():\n pairs.append((off, String(g)))\nassert_equal(len(pairs), 3)\nassert_equal(pairs[0][0], 0)\nassert_equal(pairs[1][0], 1)\nassert_equal(pairs[2][0], 2)\n'})}),"\n",(0,s.jsx)(t.h2,{id:"parameters",children:"Parameters"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["\u200B",(0,s.jsx)(t.b,{children:"mut"})," (",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/builtin/bool/Bool",children:(0,s.jsx)(t.code,{children:"Bool"})}),"): Whether the slice is mutable."]}),"\n",(0,s.jsxs)(t.li,{children:["\u200B",(0,s.jsx)(t.b,{children:"origin"})," (",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/origin/Origin",children:(0,s.jsx)(t.code,{children:"Origin[mut=mut]"})}),"): The origin of the underlying string data."]}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"implemented-traits",children:"Implemented traits"}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.a,{href:"../../../../../../docs/std/traits/anytype/AnyType",children:(0,s.jsx)(t.code,{children:"AnyType"})}),",\n",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/traits/copyable/Copyable",children:(0,s.jsx)(t.code,{children:"Copyable"})}),",\n",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/traits/deinitable/Deinitable",children:(0,s.jsx)(t.code,{children:"Deinitable"})}),",\n",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/traits/copyable/ImplicitlyCopyable",children:(0,s.jsx)(t.code,{children:"ImplicitlyCopyable"})}),",\n",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/iter/Iterable",children:(0,s.jsx)(t.code,{children:"Iterable"})}),",\n",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/iter/Iterator",children:(0,s.jsx)(t.code,{children:"Iterator"})}),",\n",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/traits/movable/Movable",children:(0,s.jsx)(t.code,{children:"Movable"})})]}),"\n",(0,s.jsxs)(t.h2,{id:"comptime-members",children:[(0,s.jsx)(t.code,{children:"comptime"})," members"]}
1),"\n",(0,s.jsxs)(t.div,{className:"mojo-alias-header",children:["\n",(0,s.jsx)(t.h3,{id:"element",children:(0,s.jsx)(t.code,{children:"Element"})}),"\n"]}),"\n",(0,s.jsxs)(t.div,{className:"mojo-alias-detail",children:["\n",(0,s.jsxs)(t.div,{className:"mojo-alias-sig",children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.code,{children:"comptime Element = Tuple[Int, StringSpan[origin]]"})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"The element type yielded by iteration."}),"\n"]}),"\n",(0,s.jsxs)(t.div,{className:"mojo-alias-header",children:["\n",(0,s.jsx)(t.h3,{id:"iteratortype",children:(0,s.jsx)(t.code,{children:"IteratorType"})}),"\n"]}),"\n",(0,s.jsxs)(t.div,{className:"mojo-alias-detail",children:["\n",(0,s.jsxs)(t.div,{className:"mojo-alias-sig",children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.code,{children:"comptime IteratorType[iterable_mut: Bool, //, iterable_origin: Origin[mut=iterable_mut]] = GraphemeIndicesIter[origin]"})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"The iterator type for this grapheme indices iterator."}),"\n",(0,s.jsx)(t.h4,{id:"parameters-1",children:"Parameters"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["\u200B",(0,s.jsx)(t.b,{children:"iterable_mut"})," (",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/builtin/bool/Bool",children:(0,s.jsx)(t.code,{children:"Bool"})}),"): Whether the iterable is mutable."]}),"\n",(0,s.jsxs)(t.li,{children:["\u200B",(0,s.jsx)(t.b,{children:"iterable_origin"})," (",(0,s.jsx)(t.a,{href:"../../../../../../docs/std/origin/Origin",children:(0,s.jsx)(t.code,{children:"Origin[mut=iterable_mut]"})}),"): The origin of the iterable."]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"methods",children:"Methods"}),"\n",(0,s.jsx)(t.h3,{id:"__iter__",children:(0,s.jsx)(t.code,{children:"__iter__"})}),"\n",(0,s.jsxs)(t.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(t.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.code,{children:"def __iter__(ref self) -> Self"})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"Iterate over the grapheme indices in the underlying string slice."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"Self"}),": An iterator yielding ",(0,s.jsx)(t.code,{children:"(byte_offset, grapheme)"})," pairs."]}),"\n"]}),"\n",(0,s.jsx)(t.h3,{id:"__next__",children:(0,s.jsx)(t.code,{children:"__next__"})}),"\n",(0,s.jsxs)(t.div,{className:"mojo-function-detail",children:["\n",(0,s.jsxs)(t.div,{className:"mojo-function-sig",children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.code,{children:"def __next__(mut self) -> Tuple[Int, StringSpan[origin]]"})}),"\n"]}),"\n",(0,s.jsxs)(t.p,{children:["Get the next ",(0,s.jsx)(t.code,{children:"(byte_offset, grapheme)"})," pair."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Returns:"})}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.a,{href:"../../../../../../docs/std/builtin/tuple/Tuple",children:(0,s.jsx)(t.code,{children:"Tuple[Int, StringSpan[origin]]"})}),": The byte offset at which the next grapheme starts and the\ngrapheme slice itself."]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Raises:"})}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"StopIteration"})," if the iterator has been exhausted."]}),"\n"]}),"\n"]})}function h(e={}){let{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(a,{...e})}):a(e)}},28453(e,t,i){i.d(t,{R:()=>l,x:()=>d});var r=i(96540);let s={},n=r.createContext(s);function l(e){let t=r.useContext(n);return r.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(n.Provider,{value:t},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.