+
    =iF4                       R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	 ^RI
H
t ^RIHtHtHtHtHtHtHtHtHtHtHtHtHtHt ]'       d   ^ RIHt ^ t ! R R	]4      t]! R
R7      R R l4       t]! R
R7      R R l4       t ]! R
R7      R R l4       t!]! R
R7      R R l4       t"]! R
R7      R R l4       t# ! R R]	4      t$]! R
R7      R R l4       t%R R lt&R%R R llt'R R  lt(R! R" lt)R%R# R$ llt*R# )&z
Grapheme cluster segmentation following Unicode Standard Annex #29.

This module provides pure-Python implementation of the grapheme cluster boundary algorithm as
defined in UAX #29: Unicode Text Segmentation.

https://www.unicode.org/reports/tr29/
)annotations)IntEnum)	lru_cache)TYPE_CHECKING
NamedTuple)bisearch)
GRAPHEME_L
GRAPHEME_T
GRAPHEME_VGRAPHEME_LVINCB_EXTENDINCB_LINKERGRAPHEME_LVTINCB_CONSONANTGRAPHEME_EXTENDGRAPHEME_CONTROLGRAPHEME_PREPENDGRAPHEME_SPACINGMARKEXTENDED_PICTOGRAPHICGRAPHEME_REGIONAL_INDICATOR)Iteratorc                  R    ] tR t^,tRt^ t^t^t^t^t	^t
^t^t^t^	t^
t^t^t^tRtR# )GCBz'Grapheme Cluster Break property values. N)__name__
__module____qualname____firstlineno____doc__OTHERCRLFCONTROLEXTENDZWJREGIONAL_INDICATORPREPENDSPACING_MARKLVTLVLVT__static_attributes__r       s/Users/tonyclaw/.openclaw/workspace/scripts/youtube-playlists/venv/lib/python3.14/site-packages/wcwidth/grapheme.pyr   r   ,   sL    1E	
B	
BGF
CGL	A
A
A	B
Cr.   r   i   )maxsizec                    V ^8  d   QhRRRR/# )   ucsintreturnr   r   )formats   "r/   __annotate__r7   C   s        r.   c                   V ^8X  d   \         P                  # V ^
8X  d   \         P                  # V R8X  d   \         P                  # \	        V \
        4      '       d   \         P                  # \	        V \        4      '       d   \         P                  # \	        V \        4      '       d   \         P                  # \	        V \        4      '       d   \         P                  # \	        V \        4      '       d   \         P                  # \	        V \        4      '       d   \         P                   # \	        V \"        4      '       d   \         P$                  # \	        V \&        4      '       d   \         P(                  # \	        V \*        4      '       d   \         P,                  # \	        V \.        4      '       d   \         P0                  # \         P2                  # )z;Return the Grapheme_Cluster_Break property for a codepoint.i   )r   r    r!   r$   	_bisearchr   r"   r   r#   r   r%   r   r&   r   r'   r   r(   r
   r)   r	   r*   r   r+   r   r,   r   r3   s   &r/   _grapheme_cluster_breakr;   B   s'   
 f}vv
f}vv
f}ww&''{{o&&zz122%%%&''{{*++j!!uuj!!uuj!!uuk""vvl##ww99r.   c                    V ^8  d   QhRRRR/# r2   r3   r4   r5   boolr   )r6   s   "r/   r7   r7   f   s     7 73 74 7r.   c                4    \        \        V \        4      4      # )z6Check if codepoint has Extended_Pictographic property.)r>   r9   r   r:   s   &r/   _is_extended_pictographicr@   e   s     	#4566r.   c                    V ^8  d   QhRRRR/# r=   r   )r6   s   "r/   r7   r7   l        - - - -r.   c                4    \        \        V \        4      4      # )z,Check if codepoint has InCB=Linker property.)r>   r9   r   r:   s   &r/   _is_incb_linkerrD   k        	#{+,,r.   c                    V ^8  d   QhRRRR/# r=   r   )r6   s   "r/   r7   r7   r   s     0 0C 0D 0r.   c                4    \        \        V \        4      4      # )z/Check if codepoint has InCB=Consonant property.)r>   r9   r   r:   s   &r/   _is_incb_consonantrH   q   s     	#~.//r.   c                    V ^8  d   QhRRRR/# r=   r   )r6   s   "r/   r7   r7   x   rB   r.   c                4    \        \        V \        4      4      # )z,Check if codepoint has InCB=Extend property.)r>   r9   r   r:   s   &r/   _is_incb_extendrK   w   rE   r.   c                  0    ] tR t^}t$ RtR]R&   R]R&   RtR# )BreakResultz*Result of grapheme cluster break decision.r>   should_breakr4   ri_countr   N)r   r   r   r   r   __annotations__r-   r   r.   r/   rM   rM   }   s    4Mr.   rM   c               $    V ^8  d   QhRRRRRR/# )r2   prev_gcbr   curr_gcbr5   zBreakResult | Noner   )r6   s   "r/   r7   r7      s"     - -# - -9K -r.   c                J   V \         P                  8X  d#   V\         P                  8X  d   \        R^ R7      # V \         P                  \         P                  \         P                  39   d   \        R^ R7      # V\         P                  \         P                  \         P                  39   d   \        R^ R7      # V \         P
                  8X  dQ   V\         P
                  \         P                  \         P                  \         P                  39   d   \        R^ R7      # V \         P                  \         P                  39   d3   V\         P                  \         P                  39   d   \        R^ R7      # V \         P                  \         P                  39   d#   V\         P                  8X  d   \        R^ R7      # V\         P                  8X  d   \        R^ R7      # V\         P                  8X  d   \        R^ R7      # V \         P                  8X  d   \        R^ R7      # R# )z
Check simple GCB-pair-based break rules (cacheable).

Returns BreakResult for rules that can be determined from GCB properties alone, or None if
complex lookback rules (GB9c, GB11) need to be checked.
FrN   rO   TN)r   r    r!   rM   r"   r(   r)   r+   r,   r*   r#   r'   r&   )rR   rS   s   &&r/   _simple_break_checkrV      st    366h#&&0:: CKK00q99 CKK00q99 355X#%%)HH:: CFFCEE?"xCEE355>'A:: CGGSUU##CEE(9:: 3:::: 3###:: 3;;:: r.   c               0    V ^8  d   QhRRRRRRRRRRR	R
/# )r2   rR   r   rS   textstrcurr_idxr4   rO   r5   rM   r   )r6   s   "r/   r7   r7      sL     @= @=@=@= @= 	@=
 @= @=r.   c                   \        W4      pVe   V# V\        P                  8X  d   \        R^ R7      # \	        W#,          4      p\        V4      '       d   RpV^,
          pV^ 8  dt   \	        W(,          4      p	\        V	4      '       d   RpV^,          pK6  \        V	4      '       d   V^,          pKR  \        V	4      '       d   V'       d   \        R^ R7      # M V \        P                  8X  d}   \        V4      '       dl   V^,
          pV^ 8  d\   \	        W(,          4      p	\        V	4      p
V
\        P                  8X  d   V^,          pKC  \        V	4      '       d   \        R^ R7      #  V \        P                  8X  dE   V\        P                  8X  d0   V^,          ^8X  d   \        RV^,           R7      # \        R^R7      # V\        P                  8X  d   ^M^ p\        RVR7      # )z
Determine if there should be a grapheme cluster break between prev and curr.

Implements UAX #29 grapheme cluster boundary rules.
FrU   T)rV   r   r$   rM   ordrH   rD   rK   r@   r;   r#   r%   )rR   rS   rX   rZ   rO   resultcurr_ucs
has_linkeriprev_ucs	prev_props   &&&&&      r/   _should_breakrc      s    !4F 377::
 4>"H(##
qL1f47|Hx((!
Q **Q#H--&EAFF 3778BBqL1f47|H/9ICJJ&Q*844"BB 3)))h#:P:P.Pa<1EHqLIIq99  6 66qAHD8<<r.   Nc               (    V ^8  d   QhRRRRRRRR/# 	r2   unistrrY   startr4   endz
int | Noner5   zIterator[str]r   )r6   s   "r/   r7   r7      s6     A$ A$A$A$ 
A$ 	A$r.   c              #    "   V '       g   R# \        V 4      pVf   TpW8  g   W8  d   R# \        W#4      pTp^ p\        \        W,          4      4      pV\        P
                  8X  d   ^p\        V^,           V4       FR  p\        \        W,          4      4      p\        WhWV4      p	V	P                  pV	P                  '       d	   WV x  TpTpKT  	  WV x  R# 5i)a  
Iterate over grapheme clusters in a Unicode string.

Grapheme clusters are "user-perceived characters" - what a user would
consider a single character, which may consist of multiple Unicode
codepoints (e.g., a base character with combining marks, emoji sequences).

:param unistr: The Unicode string to segment.
:param start: Starting index (default 0).
:param end: Ending index (default len(unistr)).
:yields: Grapheme cluster substrings.

Example::

    >>> list(iter_graphemes('cafe\u0301'))
    ['c', 'a', 'f', 'e\u0301']
    >>> list(iter_graphemes('\U0001F468\u200D\U0001F469\u200D\U0001F467'))
    ['o', 'k', '\U0001F468\u200D\U0001F469\u200D\U0001F467']
    >>> list(iter_graphemes('\U0001F1FA\U0001F1F8'))
    ['o', 'k', '\U0001F1FA\U0001F1F8']

.. versionadded:: 0.3.0
N)
lenminr;   r\   r   r%   rangerc   rO   rN   )
rf   rg   rh   lengthcluster_startrO   rR   idxrS   r]   s
   &&&       r/   iter_graphemesrp      s     8 [F
{|u
c
C MH 's6='9:H 3)))UQY$*3v{+;<x6I??s++M % s
##s   CCc               $    V ^8  d   QhRRRRRR/# )r2   rX   rY   posr4   r5   r   )r6   s   "r/   r7   r7   <  s!     1 1c 1 1 1r.   c                t   \        W^,
          ,          4      pV^
8X  d%   V^8  d   W^,
          ,          R8X  d
   V^,
          # V^8  dg   V^8  dW   V^ 8  dP   \        W^,
          ,          4      pV^8  d1   \        V4      \        P                  8X  d   \	        W^,
          4      # V^,
          # V^,
          pV^ 8  d`   W,
          \
        8  dO   \        W,          4      p^ Tu;8:  d   ^8  d   M MM*\        V4      \        P                  8X  d   MV^,          pKf  Tp\        \        W,          4      4      pV\        P                  8X  d   ^M^ p\        V^,           V4       FL  p	\        \        W	,          4      4      p
\        WzW	V4      pVP                  pVP                  '       d   T	pT
pKN  	  V# )ac  
Find the start of the grapheme cluster containing the character before pos.

Scans backwards from pos to find a safe starting point, then iterates forward using standard
break rules to find the actual cluster boundary.

:param text: The Unicode string.
:param pos: Position to search before (exclusive).
:returns: Start position of the grapheme cluster.
)r\   r;   r   r&   _find_cluster_startMAX_GRAPHEME_SCANr"   r%   rl   rc   rO   rN   )rX   rr   	target_cpprev_cp
safe_startcprn   left_gcbrO   r`   	right_gcbr]   s   &&          r/   ru   ru   <  sp    DqM"I DSAX$Qw-4*?Qw 4!8	T)$Qw-(G$#:7#Cs{{#R*4q99Qw qJ
q.c.2CC!"2"2&#++5a
 M&s4+;'<=H 6 66qAH:>3'+CL9	xDXF??M ( r.   c               $    V ^8  d   QhRRRRRR/# )r2   rf   rY   rr   r4   r5   r   )r6   s   "r/   r7   r7   p  s!     > >S >s >s >r.   c           	     R    V^ 8:  d   ^ # \        V \        V\        V 4      4      4      # )a  
Find the grapheme cluster boundary immediately before a position.

:param unistr: The Unicode string to search.
:param pos: Position in the string (0 < pos <= len(unistr)).
:returns: Start index of the grapheme cluster containing the character at pos-1.

Example::

    >>> grapheme_boundary_before('Hello \U0001F44B\U0001F3FB', 8)
    6
    >>> grapheme_boundary_before('a\r\nb', 3)
    1

.. versionadded:: 0.3.6
)ru   rk   rj   )rf   rr   s   &&r/   grapheme_boundary_beforer   p  s&    " axvs3F'<==r.   c               (    V ^8  d   QhRRRRRRRR/# re   r   )r6   s   "r/   r7   r7     s0     & &&& 
& 	&r.   c              #     "   V '       g   R# \        V 4      pVf   TM
\        W#4      p\        V^ 4      pW8  g   W8  d   R# TpWA8  d   \        W4      pWQ8  d   R# WV x  TpK#  R# 5i)ay  
Iterate over grapheme clusters in reverse order (last to first).

:param unistr: The Unicode string to segment.
:param start: Starting index (default 0).
:param end: Ending index (default len(unistr)).
:yields: Grapheme cluster substrings in reverse order.

Example::

    >>> list(iter_graphemes_reverse('cafe\u0301'))
    ['e\u0301', 'f', 'a', 'c']

.. versionadded:: 0.3.6
N)rj   rk   maxru   )rf   rg   rh   rm   rr   rn   s   &&&   r/   iter_graphemes_reverser     so     ( [FK&S%5CqME|u
C
++F8 3'' s   A(A*)    N)+r   
__future__r   enumr   	functoolsr   typingr   r   r   r9   table_graphemer   r	   r
   r   r   r   r   r   r   r   r   r   r   r   collections.abcr   rv   r   r;   r@   rD   rH   rK   rM   rV   rc   rp   ru   r   r   r   r.   r/   <module>r      s   #   , ,: : : : (  ' , 4 D 47 7
 4- -
 40 0
 4- -
*  4- -`@=FA$H1h>,& &r.   