
    OTh                     L    d dl mZmZ dZd ZddZd ZddZd Zd	 Z	d
 Z
d Zy)    )GraphemeIteratorget_last_certain_break_indexz16.0.0c                 *    t        t        |             S )un  
    Returns an iterator of all graphemes of given string.

    >>> rainbow_flag = "🏳️‍🌈"
    >>> [codepoint for codepoint in rainbow_flag]
    ['🏳', '️', '‍', '🌈']
    >>> list(grapheme.graphemes("multi codepoint: " + rainbow_flag))
    ['m', 'u', 'l', 't', 'i', ' ', 'c', 'o', 'd', 'e', 'p', 'o', 'i', 'n', 't', ':', ' ', '🏳️‍🌈']
    )iterr   strings    Q/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/grapheme/api.py	graphemesr
      s      ())    Nc                     |t        d t        |       D              S t        |       }d}	 	 ||k\  r	 |S t        |       |dz  }# t        $ r Y |S w xY w)us  
    Returns the number of graphemes in the string.

    Note that this functions needs to traverse the full string to calculate the length,
    unlike `len(string)` and it's time consumption is linear to the length of the string
    (up to the `until` value).

    Only counts up to the `until` argument, if given. This is useful when testing
    the length of a string against some limit and the excess length is not interesting.

    >>> rainbow_flag = "🏳️‍🌈"
    >>> len(rainbow_flag)
    4
    >>> graphemes.length(rainbow_flag)
    1
    >>> graphemes.length("".join(str(i) for i in range(100)), 30)
    30
    c              3       K   | ]  }d   yw)   N ).0_s     r	   	<genexpr>zlength.<locals>.<genexpr>'   s     717s   r   r   )sumr   r
   nextStopIteration)r   untiliteratorcounts       r	   lengthr      s|    & }7.v6777 HE
	~ L N QJE 
  	 L	s   A A 	AAc                 8    t        d t        |       D              S )zV
    Returns an iterator of number of code points in each grapheme of the string.
    c              3   2   K   | ]  }t        |        y wN)len)r   gs     r	   r   z#grapheme_lengths.<locals>.<genexpr>=   s     21A2s   )r   r
   r   s    r	   grapheme_lengthsr   9   s     2	& 1222r   c                     |d}|||k\  ry|dk  rt        d      d}d}t        t        |             D ]  \  }}||k(  r|}n||k(  r| || c S ||z  }  || |d S y)u`  
    Returns a substring of the given string, counting graphemes instead of codepoints.

    Negative indices is currently not supported.
    >>> string = "tamil நி (ni)"

    >>> string[:7]
    'tamil ந'
    >>> grapheme.slice(string, end=7)
    'tamil நி'
    >>> string[7:]
    'ி (ni)'
    >>> grapheme.slice(string, 7)
    ' (ni)'
    Nr    z-Negative indexing is currently not supported.)NotImplementedError	enumerater   )r   startendsum_start_indexgrapheme_indexgrapheme_lengths          r	   slicer*   @   s    " }
5C<qy!"QRRDK+45Ef5M+N  'U"Ks"+d++  kl##r   c                    || vryt        t        |            }t        |      dk(  ryt        |      dk(  r|d   t        |       v S t        |       }g }t        t        |            D ]  }	 |j	                  t        |              |D ]+  }||k(  r y|j	                  |       |j                  d       - ||k(  S # t        $ r Y  yw xY w)u  
    Returns true if the sequence of graphemes in substring is also present in string.

    This differs from the normal python `in` operator, since the python operator will return
    true if the sequence of codepoints are withing the other string without considering
    grapheme boundaries.

    Performance notes: Very fast if `substring not in string`, since that also means that
    the same graphemes can not be in the two strings. Otherwise this function has linear time
    complexity in relation to the string length. It will traverse the sequence of graphemes until
    a match is found, so it will generally perform better for grapheme sequences that match early.

    >>> "🇸🇪" in "🇪🇸🇪🇪"
    True
    >>> grapheme.contains("🇪🇸🇪🇪", "🇸🇪")
    False
    Fr   Tr   )listr
   r   rangeappendr   r   pop)r   	substringsubstr_graphemesstr_iterstr_sub_partr   r   s          r	   containsr4   h   s    $ Ii01
!		!	#"i&777V$s+,- 	A##DN3	  	 A//"Q	  /// ! s   ,B==	C
	C
c                 j    | j                  |      xr! t        | t        |            t        |      k(  S )uz  
    Like str.startswith, but also checks that the string starts with the given prefixes sequence of
    graphemes.

    str.startswith may return true for a prefix that is not visually represented as a prefix if a
    grapheme cluster is continued after the prefix ends.

    >>> grapheme.startswith("✊🏾", "✊")
    False
    >>> "✊🏾".startswith("✊")
    True
    )
startswithsafe_split_indexr   )r   prefixs     r	   r6   r6      s2     V$])9&#f+)NRUV\R])]]r   c                 t    t        |       t        |      z
  }| j                  |      xr t        | |      |k(  S )u  
    Like str.endswith, but also checks that the string endswith the given prefixes sequence of
    graphemes.

    str.endswith may return true for a suffix that is not visually represented as a suffix if a
    grapheme cluster is initiated before the suffix starts.

    >>> grapheme.endswith("🏳️‍🌈", "🌈")
    False
    >>> "🏳️‍🌈".endswith("🌈")
    True
    )r   endswithr7   )r   suffixexpected_indexs      r	   r:   r:      s8     [3v;.N??6"a'7'OSa'aar   c                 d    t        | |      }t        | |d       D ]  }||z   |kD  r |S ||z  } |S )u  
    Returns the highest index up to `max_len` at which the given string can be sliced,
    without breaking a grapheme.

    This is useful for when you want to split or take a substring from a string,
    and don't really care about
    the exact grapheme length, but don't want to risk breaking existing graphemes.

    This function does normally not traverse the full grapheme sequence up to the given length,
    so it can be used for arbitrarily long strings and high `max_len`.
    However, some grapheme boundaries depend on the previous state,
    so the worst case performance is O(n). In practice, it's only very long non-broken sequences
    of country flags (represented as Regional Indicators) that will perform badly.

    The return value will always be between `0` and `len(string)`.

    >>> string = "tamil நி (ni)"
    >>> i = grapheme.safe_split_index(string, 7)
    >>> i
    6
    >>> string[:i]
    'tamil '
    >>> string[i:]
    'நி (ni)'
    N)r   r   )r   max_len
last_indexis       r	   r7   r7      sS    4 .fg>JfZ[12 >G# 	a
 r   r   )NN)grapheme.finderr   r   UNICODE_VERSIONr
   r   r   r*   r4   r6   r:   r7   r   r   r	   <module>rC      s:    J
*"L3%P*0Z^ b"r   