o
    8ήcMK                    @   s
  d dl Z d dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZmZmZmZmZmZ d dlmZmZ d dlmZmZmZ d dl m!Z!m"Z"m#Z#m$Z$ d dl%m&Z& d d	l'm(Z( d d
l)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZN d dlOmPZP ejQdkZRdZSe	ejTG dd dejZUe
ejTdd e
ejTdd e
ejTdd e
ejTdd e
ejTdd eejVG dd deZWdd ZXd d! ZYeejZej[d"d# Z\eej[d$d% Z]eejTd&d' Z^eejTd(d) Z_d*d+ Z`ed,d- Zaed.d/ Zbed0d1 Zced2d3 Zded5d4d5Zeed6d7d8d9 Zfd:d; Zged<d= Zhed>d? Zied@dA Zjed6d7dBdC ZkedDdE ZledFdG ZmedHdI Zned6d7dJdK ZoedLdM ZpedNdO ZqeerdPdQ ZseetdRdS ZueejvdTdU ZweejxdVdW ZyeejzdXdY Z{eej|dZd[ Z}eej~d\d] Zeejd^d_ Zeejd`da Zdbdc Zddde Zdfdg Zedhdi Zedjdk ZeeeZeeeZeejTdld6dmdnZeejTdod6dpdqZeejTdrd6dsdtZeejTdud6dvdwZeejTdxdydz ZeejTd{d6d|d}ZeejTd~dd ZeejTddd Zedd ZeejTdd6ddZeejTdd7ddZeejTdd8ddZdd Zeee7Zeee8ZeejTdd8ddZeejTdd9ddZdd ZeejTded6 eejTded dd Zeee@Zeee?ZeejTdd:ddZedd ZeejTddd ZeejTddd Zedd Zedd Zdd Zdd ZeejTdd;ddZeejTdd;ddZeejTdd;ddZed<ddZedd Zedd ZeddĄ Zed6d7ddƄ ZeddȄ Zeejddʄ Zeejeejdd̄ Zedd΄ ZeejddЄ Zeejdd҄ ZeejTdӃd=ddՄZddׄ ZeejTd؃eeLeJ eddڄ ZeejTdۃee1e dd݄ Zeddڄ ZeeeDeEeZeee>e=eCZeejTd߃dd ZejQdkreejTddd ZeejTddd ZeejTddd ZeejTddd ZƐd<ddZeejTdee7 eejTdeeK eejTdeeM eejTdeeN eejTdee6d6 dd Zedd Zedd Zdd Zeed6ZeedZdd Zeee.Zeee/ZeejTd dd ZeejTddd Zedd Zedd	 ZeejTd
dd Zedd Zedd ZeejTddd Zedd Zedd ZeejTddd Zedd Zedd ZeejTdd d! Zee߃d"d# Zed$d% Zd&eS Zed'd( Zeed)d* Zeerd+d, Zeerd-d. Zed/ejTd0d1 Zed2ejVeejd3d4 ZdS (>      N)IntTypeConstant)
modelsregister_modelmake_attribute_wrapperunboxboxNativeValueoverloadoverload_method	intrinsicregister_jitable)lower_constant
lower_castlower_builtiniternext_implimpl_ret_new_refRefType)register_defaultStructModel)utilstypescgutils)PY_UNICODE_1BYTE_KINDPY_UNICODE_2BYTE_KINDPY_UNICODE_4BYTE_KINDPY_UNICODE_WCHAR_KIND)	c_helpers)
_Py_hash_t)memcpy_region)TypingError)!_Py_TOUPPER_Py_TOLOWER_Py_UCS4_Py_ISALNUM_PyUnicode_ToUpperFull_PyUnicode_ToLowerFull_PyUnicode_ToFoldedFull_PyUnicode_ToTitleFull_PyUnicode_IsPrintable_PyUnicode_IsSpace_Py_ISSPACE_PyUnicode_IsXidStart_PyUnicode_IsXidContinue_PyUnicode_IsCased_PyUnicode_IsCaseIgnorable_PyUnicode_IsUppercase_PyUnicode_IsLowercase_PyUnicode_IsLineBreak_Py_ISLINEBREAK_Py_ISLINEFEED_Py_ISCARRIAGERETURN_PyUnicode_IsTitlecase_Py_ISLOWER_Py_ISUPPER_Py_TAB_Py_LINEFEED_Py_CARRIAGE_RETURN	_Py_SPACE_PyUnicode_IsAlpha_PyUnicode_IsNumeric_Py_ISALPHA_PyUnicode_IsDigit_PyUnicode_IsDecimalDigit)slicing)       c                   @   s   e Zd Zdd ZdS )UnicodeModelc              	   C   sV   dt jfdt jfdt jfdt jfdtfdt t jfdt jfg}tj	
| ||| d S )Ndatalengthkindis_asciihashmeminfoparent)r   voidptrintpint32uint32r   MemInfoPointerpyobjectr   r   __init__selfdmmfe_typemembers rZ   </tmp/pip-target-vg8gfxp4/lib/python/numba/cpython/unicode.pyrT   M   s   
zUnicodeModel.__init__N)__name__
__module____qualname__rT   rZ   rZ   rZ   r[   rF   K   s    rF   rG   _datarH   _lengthrI   _kindrJ   	_is_asciirK   _hashc                       s   e Zd Z fddZ  ZS )UnicodeIteratorModelc                    s2   dt t jfd|jfg}tt| ||| d S )NindexrG   )r   EphemeralPointeruintprG   superrd   rT   rU   	__class__rZ   r[   rT   d   s   zUnicodeIteratorModel.__init__)r\   r]   r^   rT   __classcell__rZ   rZ   ri   r[   rd   b   s    rd   c                 C   s   ddl m}m}m}m}m}m}m}m}m	}	 t
d }
|||||||||||}||
}| }| }| }| }|| |	||	||	||	|}|du rStd|j}|j}|j}|d t| }|| |}t|||||jfS )ztGet string data from a python string for use at compile-time to embed
    the string data into the LLVM module.
    r   )		CFUNCTYPEc_void_pc_intc_uint	c_ssize_tc_ubyte	py_objectPOINTERbyrefextract_unicodeNz1cannot extract unicode data from the given string   )ctypesrl   rm   rn   ro   rp   rq   rr   rs   rt   r   
ValueErrorvalue_kind_to_byte_widthfrom_addressbytes)objrl   rm   rn   ro   rp   rq   rr   rs   rt   extract_unicode_fnprotofnrH   rI   rJ   hashvrG   nbytesoutrZ   rZ   r[   compile_time_get_string_datal   s&   , r   c                 C   sz   t |\}}}}}|j}	| |	|}
t|| |}|
|_|j||_|j||_|j	||_	|j
d|_
| S )zf
    Get string data by `compile_time_get_string_data()` and return a
    unicode_type LLVM value
    )r   moduleinsert_const_bytesr   create_struct_proxyrG   rH   typerI   rJ   rK   	_getvalue)contextbuildertypliteral_string	databytesrH   rI   rJ   r   modgvuni_strrZ   rZ   r[   make_string_from_constant   s   r   c                 C   s   t | |||jS N)r   literal_value)r   r   fromtytotyvalrZ   rZ   r[   cast_from_literal   s   
r   c                 C   s   t | |||S r   )r   )r   r   r   pyvalrZ   rZ   r[   constant_unicode      r   c                 C   s   |j |\}}}}}}t| |j|j}	||	_||	_||	_||	_	||	_
|j |||	_||	_t|j|j  }
t|	 |
dS )zE
    Convert a unicode str object to a native unicode structure.
    )is_error)pyapistring_as_string_size_and_kindr   r   r   r   rG   rH   rI   rJ   rK   nrt_meminfo_new_from_pyobjectrL   rM   is_not_nullerr_occurredr	   r   )r   r}   cokrG   rH   rI   rJ   r   r   r   rZ   rZ   r[   unbox_unicode_str   s   
r   c                 C   sR   t | |j|j|d}|j|j|j|j}|j	| |jj
|j| | |S )z@
    Convert a native unicode structure to a unicode string
    ry   )r   r   r   r   r   string_from_kind_and_datarI   rG   rH   object_hashnrtdecref)r   r   r   r   resrZ   rZ   r[   box_unicode_str   s   r   c                        fdd}|S )Nc                    s@   |\}}| |t  }||||g}||tdS N    )bitcastr   
as_pointerloadgepzext)r   r   	signatureargsrG   idxptrchbitsizerZ   r[   codegen   s   z#make_deref_codegen.<locals>.codegenrZ   r   r   rZ   r   r[   make_deref_codegen   s   r   c                 C      t t jt j}|tdfS NrD   r   rQ   rN   rO   r   	typingctxrG   offsetsigrZ   rZ   r[   deref_uint8      r   c                 C   r   N   r   r   rZ   rZ   r[   deref_uint16   r   r   c                 C   r   r   r   r   rZ   rZ   r[   deref_uint32   r   r   c                 C   s(   dd }t t jt jt jt j}||fS )zmake empty string with data buffer of size alloc_bytes.

    Must set length and kind values for string after it is returned
    c              	   S   s   |\}}}}t tj}|| |}	||||t|jd}
| j	||
|	_
||	_||	_||	_| td|	_| j||	j
|	_t |	jj|	_|	 S )Nrv   r   )r   r   r   unicode_typemuladdr   r   r   meminfo_allocrL   rI   rJ   rH   get_constantr   rK   meminfo_datarG   get_null_valuerM   r   )r   r   r   r   kind_valchar_bytes_val
length_valis_ascii_valuni_str_ctorr   
nbytes_valrZ   rZ   r[   details   s    

z_malloc_string.<locals>.details)r   r   rP   rO   rQ   )r   rI   
char_bytesrH   rJ   r   r   rZ   rZ   r[   _malloc_string   s   r   c                 C   s,   t | }t| |||}t||td |S Nr   )rz   r   _set_code_pointnprQ   )rI   rH   rJ   
char_widthsrZ   rZ   r[   _empty_string  s   r   F)_nrtc                 C   sF   | j tkrt| j|S | j tkrt| j|S | j tkr!t| j|S dS r   )ra   r   r   r_   r   r   r   r   )airZ   rZ   r[   _get_code_point  s   


r   c                    r   )Nc                    sT   |\}}} dk r| |t }||t  }|||||g |  S r   )truncr   r   r   storer   get_dummy_value)r   r   r   r   rG   r   r   r   r   rZ   r[   r   ,  s   
z!make_set_codegen.<locals>.codegenrZ   r   rZ   r   r[   make_set_codegen+  s   r   c                 C       t t jt jt j}|tdfS r   r   voidrN   int64rQ   r   r   rG   r   r   r   rZ   rZ   r[   	set_uint87     r   c                 C   r   r   r   r   rZ   rZ   r[   
set_uint16=  r   r   c                 C   r   r   r   r   rZ   rZ   r[   
set_uint32C  r   r   c                 C   s\   | j tkrt| j|| d S | j tkrt| j|| d S | j tkr*t| j|| d S td)Nz4Unexpected unicode representation in _set_code_point)	ra   r   r   r_   r   r   r   r   AssertionError)r   r   r   rZ   rZ   r[   r   I  s   


r   c                 C   sP   | t ks|t krtd| tkr|S | tkr|tkr|S | S | tkr$| S td)N!PY_UNICODE_WCHAR_KIND unsupportedz/Unexpected unicode representation in _pick_kind)r   r   r   r   r   )kind1kind2rZ   rZ   r[   
_pick_kind\  s   r   c                 C   s$   | dkr|dkrt dS t dS Nrv   r   )r   rQ   )	is_ascii1	is_ascii2rZ   rZ   r[   _pick_asciin  s   

r   c                 C   s<   | t krdS | tkrdS | tkrdS | tkrtdtd)Nrv         r   z'Unexpected unicode encoding encountered)r   r   r   r   r   )rI   rZ   rZ   r[   rz   u  s   rz   c                 C   sz   |dkrdS || | j krdS || |j krdS t|D ]}t| || }t||| }||k r3 dS ||kr: dS qdS )Nr   r   rv   )r`   ranger   )r   a_offsetbb_offsetnr   a_chrb_chrrZ   rZ   r[   _cmp_region  s   r  c                 C   s4   | dk rt S | dk rtS d}| |krd}t|tS )zK
    Compute the minimum unicode kind needed to hold a given codepoint
       i   rE   z;Invalid codepoint. Found value greater than Unicode maximum)r   r   rx   r   )cpMAX_UNICODEmsgrZ   rZ   r[   _codepoint_to_kind  s   r
  c                 C   s   | dk S )z;
    Returns true if a codepoint is in the ASCII range
       rZ   )r   rZ   rZ   r[   _codepoint_is_ascii  s   r  c                 C      t | tjr
dd S d S )Nc                 S   s   | S r   rZ   r   rZ   rZ   r[   <lambda>      zunicode_str.<locals>.<lambda>
isinstancer   UnicodeTyper  rZ   rZ   r[   unicode_str     r  c                 C      t | tjrdd }|S d S )Nc                 S      | j S r   )r`   r  rZ   rZ   r[   len_impl     zunicode_len.<locals>.len_implr  )r   r  rZ   rZ   r[   unicode_len     r  c                 C   s   | j r|j sd S t| tjr| j}n| }t|tjr|j}n|}tjtjtjf}t||}t||}|r<|r<dd }|S ||A rFdd }|S d S )Nc                 S   sd   | d u }|d u }|s|r|r|rdS dS t | } t |}t| t|kr&dS t| d|dt| dkS )NTFr   )strlenr  )r   r   a_noneb_nonerZ   rZ   r[   eq_impl  s   zunicode_eq.<locals>.eq_implc                 S      dS NFrZ   r   r   rZ   rZ   r[   r        )is_internalr  r   Optionalr   r  StringLiteralUnicodeCharSeq)r   r   check_acheck_baccept	a_unicode	b_unicoder   rZ   rZ   r[   
unicode_eq  s$   

r.  c                 C   s`   | j r|j sd S tjtjtjf}t| |}t||}|r$|r$dd }|S ||A r.dd }|S d S )Nc                 S   s
   | |k S r   rZ   r#  rZ   rZ   r[   ne_impl     
zunicode_ne.<locals>.ne_implc                 S   r!  )NTrZ   r#  rZ   rZ   r[   r     r$  zunicode_ne.<locals>.eq_impl)r%  r   r  r'  r(  r  )r   r   r+  r,  r-  r/  r   rZ   rZ   r[   
unicode_ne  s   

r1  c                 C   @   t | tjtjf}t |tjtjf}|r|rdd }|S d S d S )Nc                 S   sJ   t t| t|}t| d|d|}|dkrdS |dkr#t| t|k S dS )Nr   r   TFminr  r  r   r   minleneqcoderZ   rZ   r[   lt_impl      zunicode_lt.<locals>.lt_implr  r   r  r'  )r   r   r,  r-  r8  rZ   rZ   r[   
unicode_lt     r;  c                 C   r2  )Nc                 S   sJ   t t| t|}t| d|d|}|dkrdS |dkr#t| t|kS dS )Nr   rv   TFr3  r5  rZ   rZ   r[   gt_impl  r9  zunicode_gt.<locals>.gt_implr:  )r   r   r,  r-  r=  rZ   rZ   r[   
unicode_gt  r<  r>  c                 C   r2  )Nc                 S   s
   | |k S r   rZ   r#  rZ   rZ   r[   le_impl   r0  zunicode_le.<locals>.le_implr:  )r   r   r,  r-  r?  rZ   rZ   r[   
unicode_le     r@  c                 C   r2  )Nc                 S   s
   | |k  S r   rZ   r#  rZ   rZ   r[   ge_impl*  r0  zunicode_ge.<locals>.ge_implr:  )r   r   r,  r-  rB  rZ   rZ   r[   
unicode_ge%  rA  rC  c                 C   s,   t | tjrt |tjrdd }|S d S d S )Nc                 S   s   t | |dkS Nr   )_findr#  rZ   rZ   r[   contains_impl2  r   z'unicode_contains.<locals>.contains_implr  )r   r   rF  rZ   rZ   r[   unicode_contains/  s   rG  c                 C   sb   | }t | tjr| j}n	t | tjr| j}tjtjf}|dur-t ||s/td	||| dS dS )zCheck object belongs to one of specific types
    ty: type
        Type of the object
    name: str
        Name of the object
    N"{}" must be {}, not {})
r  r   Omittedry   r&  r   IntegerNoneTyper    format)tynamethetyacceptedrZ   rZ   r[   unicode_idx_check_type8  s   rQ  c                 C   s(   t | tjsd|tj| }t|dS )z$Check object belongs to unicode typerH  N)r  r   r  rL  r    )rM  rN  r	  rZ   rZ   r[   unicode_sub_check_typeL  s   rR  c                       d fdd	}|S )z%Generate finder either left or right.Nc                    sV   t | }t |}|d u rd}|d u r|}t|||\}}|| |k r$dS  | |||S )Nr   r   )r  _adjust_indices)rG   substrstartendrH   
sub_length	find_funcrZ   r[   implU  s   zgenerate_finder.<locals>.implNNrZ   )rZ  r[  rZ   rY  r[   generate_finderS  s   r]  c                 C   sZ   t |dkr|S t|tt | |t | d D ]}t| ||dt |dkr*|  S qdS )zLeft finder.r   rv   r   r  r   r4  r  rG   rU  rV  rW  r   rZ   rZ   r[   _finderf  s   $r`  c                 C   s\   t |dkr|S ttt | |t | |d dD ]}t| ||dt |dkr+|  S qdS )zRight finder.r   rv   r   r^  r_  rZ   rZ   r[   _rfinderq  s   &ra  findc                 C   <   t |tjrddd}|S t|d t|d t|d tS )zImplements str.find()Nc                 S      |  t|S r   )rb  r  rG   rU  rV  rW  rZ   rZ   r[   	find_impl     zunicode_find.<locals>.find_implrV  rW  rU  r\  )r  r   r(  rQ  rR  rE  )rG   rU  rV  rW  rf  rZ   rZ   r[   unicode_find     



rh  rfindc                 C   rc  )zImplements str.rfind()Nc                 S   rd  r   )rj  r  re  rZ   rZ   r[   
rfind_impl  rg  z!unicode_rfind.<locals>.rfind_implrV  rW  rU  r\  )r  r   r(  rQ  rR  _rfind)rG   rU  rV  rW  rk  rZ   rZ   r[   unicode_rfind  ri  rm  rindexc                 C   ,   t |d t |d t|d ddd}|S )zImplements str.rindex()rV  rW  subNc                 S   "   |  |||}|dk rtd|S Nr   zsubstring not found)rj  rx   r   rp  rV  rW  resultrZ   rZ   r[   rindex_impl     z#unicode_rindex.<locals>.rindex_implr\  rQ  rR  )r   rp  rV  rW  ru  rZ   rZ   r[   unicode_rindex  
   



rx  re   c                 C   ro  )zImplements str.index()rV  rW  rp  Nc                 S   rq  rr  )rb  rx   rs  rZ   rZ   r[   
index_impl  rv  z!unicode_index.<locals>.index_implr\  rw  )r   rp  rV  rW  rz  rZ   rZ   r[   unicode_index  ry  r{  	partitionc                 C   j   |}t |tjr|j}n	t |tjr|j}tjtjf}|dur/t ||s/dd||}t	|dd }|S )zImplements str.partition()NrH  sepc                 S   s   t |}t| jd| j}t|}| j|jk st| |k r!| ||fS |dkr)td| |}|dk r7| ||fS | d| || || t|  fS Nr   empty separator)r  r   ra   rb   r  rx   rb  rG   r~  	empty_str
sep_lengthposrZ   rZ   r[   r[       


"zunicode_partition.<locals>.impl
r  r   rI  ry   r&  r   r  r(  rL  r    rG   r~  rO  rP  r	  r[  rZ   rZ   r[   unicode_partition     r  countc                 C   s@   t | t | t|tjrddd}|S d}t|t|)Nc                 S   s   d}t | }t |}t||d}t|||}|| dk s ||kr"dS | || } t | }d|}}|dkr9|d S || |kr\| |||  |krR|d7 }||7 }n|d7 }|| |ks?|S Nr   rv   )r  _normalize_slice_idx_count)srcrp  rV  rW  r  src_lensub_lenrZ   rZ   r[   
count_impl  s&   

z!unicode_count.<locals>.count_implz+The substring must be a UnicodeType, not {}r\  )_count_args_types_checkr  r   r  r    rL  r   )r  rp  rV  rW  r  	error_msgrZ   rZ   r[   unicode_count  s   
r  
rpartitionc                 C   r}  )zImplements str.rpartition()NrH  r~  c                 S   s   t |}t| jd| j}t|}| j|jk st| |k r!||| fS |dkr)td| |}|dk r7||| fS | d| || || t|  fS r  )r  r   ra   rb   r  rx   rj  r  rZ   rZ   r[   r[    r  z unicode_rpartition.<locals>.implr  r  rZ   rZ   r[   unicode_rpartition  r  r  
startswithc                 C   s4   t |tjrdd }|S t |tjrdd }|S d S )Nc                 S   s   t | d|dt|dkS r   )r  r  r#  rZ   rZ   r[   startswith_impl3  s   z+unicode_startswith.<locals>.startswith_implc                 S   rd  r   )r  r  r#  rZ   rZ   r[   r  7  rg  r  r   r  r(  )r   r   r  rZ   rZ   r[   unicode_startswith0  s   r  c                 C   sL   || kr| }|dk r|| 7 }|dk rd}|dk r"|| 7 }|dk r"d}||fS r   rZ   )rH   rV  rW  rZ   rZ   r[   rT  =  s   rT  endswithc                 C   s   |d u st |tjtjtjfstd|d u s&t |tjtjtjfs&tdt |tjtjfr6ddd}|S t |tjrCddd}|S t |tj	rPddd}|S d S )Nz!The arg must be a Integer or Nonec                 S   s&   |D ]}|  |||du r dS qdS )NTF)r  )r   rU  rV  rW  itemrZ   rZ   r[   endswith_implZ  s
   z'unicode_endswith.<locals>.endswith_implc                 S   s   t | }t |}|d u rd}|d u r|}t|||\}}|| |k r$dS |dkr*dS | || } t | | }t| ||d|dkS )Nr   FT)r  rT  r  )r   rU  rV  rW  rH   rX  r   rZ   rZ   r[   r  c  s   c                 S   s   |  t|||S r   )r  r  )r   rU  rV  rW  rZ   rZ   r[   r  y     r\  )
r  r   rI  rJ  rK  r    TupleUniTupler  r(  )r   rU  rV  rW  r  rZ   rZ   r[   unicode_endswithM  s(   


r  
expandtabsrD   c                 C   sd   |}t |tjr|j}n	t |tjr|j}tjtf}|dur+t ||s+td	||ddd}|S )zImplements str.expandtabs()Nz"tabsize" must be {}, not {}rD   c                 S   s`  t | }d }}d}t|D ]F}t| |}|tkr9d}|dkr8|||  }|tj| kr0td||7 }||7 }q|tjd krDtd|d7 }|d7 }|ttfv rTd}q|sY| S t	| j
|| j}	d }}t|D ]D}t| |}|tkr|dkr|||  }||7 }t||| D ]}
t|	|
t q||7 }qi|d7 }t|	|| |d7 }|ttfv rd}qi|	S )Nr   FTznew string is too longrv   )r  r   r   r9   sysmaxsizeOverflowErrorr:   r;   r   ra   rb   r   r<   )rG   tabsizerH   jline_posfoundr   
code_pointincrr   r   rZ   rZ   r[   expandtabs_impl  sT   

z+unicode_expandtabs.<locals>.expandtabs_implrD   )
r  r   rI  ry   r&  r   rJ  intr    rL  )rG   r  rO  rP  r  rZ   rZ   r[   unicode_expandtabs  s   


.r  splitr   c                 C   s   |dkst |tjtjtjfsd S t |tjrd	dd}|S t |tjr+d	dd}|S |d u s=t |tjs=t|ddd u rDd	dd}|S d S )
Nr   c                 S   s   | j t||dS )N)maxsplit)r  r  )r   r~  r  rZ   rZ   r[   
split_impl  r  z!unicode_split.<locals>.split_implc           
      S   s  t | }t |}|dkrtdg }d}d}|dkr?|dkr?t|d}t|D ]}t| ||kr=|| ||  |d }q'n<d}	||k r{|dksM|	|k r{t| ||d|dkrk|| ||  ||7 }|}|	d7 }	n|d7 }||k r{|dksM|	|k sM||kr|| |d   |S )Nr   r  rv   r   )r  rx   r   r   appendr  )
r   r~  r  a_lensep_lenpartslastr   sep_code_pointsplit_countrZ   rZ   r[   r    s>   


ry   Fc                 S   s   t | }g }d}d}d}d}t|D ]1}t| |}	t|	}
|r'|
r"q|}d}q|
s*q|| ||  d}|d7 }|dkrC||krC nq||krS|sS|| |d   |S )Nr   TFrv   r   )r  r   r   r*   r  )r   r~  r  r  r  r  r   r  in_whitespace_blockr  is_whitespacerZ   rZ   r[   split_whitespace_impl  s2   
z,unicode_split.<locals>.split_whitespace_implrD  )	r  r   rI  rJ  IntegerLiteralr(  r  rK  getattr)r   r~  r  r  r  rZ   rZ   r[   unicode_split  s$   

"
 r  c                    s   d fdd	}|S )z@Generate whitespace rsplit func based on either ascii or unicodeNr   c                    s  |dk rt j}g }t| d }|dkr_|dkr)t| |} |s!n|d8 }|dks|dk r.n1|}|d8 }|dkrJt| |} |rBn|d8 }|dks8|| |d |d   |d8 }|dks|dkr|dkryt| |} |sqn|d8 }|dksg|dkr|| d|d   |d d d S Nr   rv   r   )r  r  r  r   r  )rG   r~  r  rt  r   r  r  isspace_funcrZ   r[   rsplit_whitespace_impl  sD   


z?generate_rsplit_whitespace_impl.<locals>.rsplit_whitespace_implrD  rZ   )r  r  rZ   r  r[   generate_rsplit_whitespace_impl  s   &r  rsplitc                 C   sh   dd }||dt jt jt jf ||dt jtf |du s&t|t jt jfr-ddd}|S dd	d
}|S )zImplements str.unicode_rsplit()c                 S   sV   | }t | tjr| j}n	t | tjr| j}|dur't ||s)td||| dS dS )z.Check object belongs to one of specified typesNrH  )r  r   rI  ry   r&  r   r    rL  )rM  rN  rP  rO  rZ   rZ   r[   _unicode_rsplit_check_typeL  s   z2unicode_rsplit.<locals>._unicode_rsplit_check_typer~  r  Nr   c                 S   s   | j r	t| ||S t| ||S r   )rb   ascii_rsplit_whitespace_implunicode_rsplit_whitespace_impl)rG   r~  r  rZ   rZ   r[   r  a  s   z.unicode_rsplit.<locals>.rsplit_whitespace_implc                 S   s   t |}| j|jk st| t|k r| gS dd }|dk r tj}t|}|dkr,td|dkr6|| ||S g }t| }|dkrb| j|d|d}|dk rMn|| || |  |}|d8 }|dks@|| d|  |d d d S )Nc                 S   s   g }t |d}t| d  }}|dkrC|dkrCt | |}||kr7|| |d |d   |d  }}|d8 }|d8 }|dkrC|dks|dkrR|| d|d   |d d d S r  )r   r  r  )rG   r   r  rt  ch_code_pointr   r  data_code_pointrZ   rZ   r[   _rsplit_charn  s   

z9unicode_rsplit.<locals>.rsplit_impl.<locals>._rsplit_charr   r  rv   )rV  rW  r   )r  ra   r  r  r  rx   rj  r  )rG   r~  r  r  r  rt  r  r  rZ   rZ   r[   rsplit_implh  s.   z#unicode_rsplit.<locals>.rsplit_implrD  )r   r  r(  rK  rJ  r  r  rI  )rG   r~  r  r  r  r  rZ   rZ   r[   unicode_rsplitH  s   


/r  center c                 C   s^   t |tjs
tdt |tjrddd}|S |dks(t |tjtjfs(tdddd}|S )NThe width must be an Integerr  c                 S      |  |t|S r   )r  r  stringwidthfillcharrZ   rZ   r[   center_impl     z#unicode_center.<locals>.center_impl"The fillchar must be a UnicodeTypec           	      S   s|   t | }t |}|dkrtd||kr| S || }|d ||@ d@  }|| }|| }||kr6||  | S ||  ||  S )Nrv   5The fill character must be exactly one character longr   r  rx   )	r  r  r  str_lenfillchar_len	allmarginlmarginrmarginl_stringrZ   rZ   r[   r    s   r  r  r   rJ  r    r(  rI  r  )r  r  r  r  rZ   rZ   r[   unicode_center  s   

r  c                    rS  )Nr  c                    st   t |tjs
tdt |tjr  rd
dd}|S d
dd}|S |dks1t |tjtjfs1tdd
 fdd		}|S )Nr  r  c                 S   r  r   )ljustr  r  rZ   rZ   r[   
ljust_impl  r  z<gen_unicode_Xjust.<locals>.unicode_Xjust.<locals>.ljust_implc                 S   r  r   )rjustr  r  rZ   rZ   r[   
rjust_impl  r  z<gen_unicode_Xjust.<locals>.unicode_Xjust.<locals>.rjust_implr  c                    sL   t | }t |}|dkrtd||kr| S |||  } r"| | S ||  S )Nrv   r  r  )r  r  r  r  r  newstrSTRING_FIRSTrZ   r[   r[    s   z6gen_unicode_Xjust.<locals>.unicode_Xjust.<locals>.implr  r  )r  r  r  r  r  r[  r  rZ   r[   unicode_Xjust  s   

z(gen_unicode_Xjust.<locals>.unicode_Xjustr  rZ   )r  r  rZ   r  r[   gen_unicode_Xjust  s   %r  r  r  Tc                    r   )zDGenerate splitlines performer based on ascii or unicode line breaks.c           
         s   t | }g }d }}||k r_||k r$t| |} |rn|d7 }||k s|}||k rP|d |k rHt| |}t| |d }	t|rHt|	rH|d7 }|d7 }|rP|}|| ||  |}||k s|S r  )r  r   r5   r4   r  )
rG   keependsrH   rt  r   r  r  eolcur_cpnext_cpis_line_break_funcrZ   r[   r[    s0   

z&generate_splitlines_func.<locals>.implrZ   )r  r[  rZ   r  r[   generate_splitlines_func  s   r  
splitlinesc                 C   sl   |}t |tjr|j}n	t |tjr|j}tjttjt	f}|dur/t ||s/t
dd||ddd}|S )zImplements str.splitlines()NrH  r  Fc                 S   s   | j rt| |S t| |S r   )rb   _ascii_splitlines_unicode_splitlines)rG   r  rZ   rZ   r[   splitlines_impl&  s   

z+unicode_splitlines.<locals>.splitlines_implF)r  r   rI  ry   r&  r   rJ  r  Booleanboolr    rL  )rG   r  rO  rP  r  rZ   rZ   r[   unicode_splitlines  s   
r  c                 C   s   t |}|dkr
dS t | }|d | }| j}| j}|D ]}|t |7 }t||j}t||j}qt|||}|d }	t|d|	dt |	 t |	}
td|D ]"}t||
| d| |
|7 }
|| }	t||
|	dt |	 |
t |	7 }
qN|S )Nr    rv   )r  ra   rb   r   r   r   _strncpyr   )r~  r  	parts_lenr  rH   rI   rJ   prt  part
dst_offsetr   rZ   rZ   r[   	join_list/  s,   r  joinc                 C   sz   t |tjr#t |jtjrdd }|S t |jtjr dd }|S 	 d S t |tjr/dd }|S t |tjr;dd }|S d S )Nc                 S   
   t | |S r   r  )r~  r  rZ   rZ   r[   join_list_implT  r0  z$unicode_join.<locals>.join_list_implc                 S   s   dd |D }t | |S )Nc                 S   s   g | ]}t |qS rZ   r  .0r  rZ   rZ   r[   
<listcomp>Y      z8unicode_join.<locals>.join_list_impl.<locals>.<listcomp>r  )r~  r  _partsrZ   rZ   r[   r  X     
c                 S   s   dd |D }|  |S )Nc                 S   s   g | ]}|qS rZ   rZ   r  rZ   rZ   r[   r	  `  s    z8unicode_join.<locals>.join_iter_impl.<locals>.<listcomp>)r  r~  r  
parts_listrZ   rZ   r[   join_iter_impl_  r  z$unicode_join.<locals>.join_iter_implc                    s$    fddt t D }t| |S )Nc                    s   g | ]} | qS rZ   rZ   )r  r   r  rZ   r[   r	  f  r
  z7unicode_join.<locals>.join_str_impl.<locals>.<listcomp>)r   r  r  r  rZ   r  r[   join_str_imple  s   
z#unicode_join.<locals>.join_str_impl)r  r   Listdtyper  r(  IterableType)r~  r  r  r  r  rZ   rZ   r[   unicode_joinO  s   r  zfillc                 C   s    t |tjs
tddd }|S )Nz<width> must be an Integerc                 S   s\   t | }||kr
| S |r| d nd}d||  }|dv r(|| | dd   }|S ||  }|S )Nr   r  0)+-rv   r  )r  r  r  
first_charpaddingr  rZ   rZ   r[   
zfill_implp  s   z!unicode_zfill.<locals>.zfill_impl)r  r   rJ  r    )r  r  r  rZ   rZ   r[   unicode_zfillk  s   r  c                 C   s`   t | }d}|d urt|D ]}| | |vr|  S q|S t|D ]}t| | s-|  S q!|S r   r  r   r*   r  charsr  r   rZ   rZ   r[   unicode_strip_left_bound  s   r"  c                 C   s|   t | }d}|d ur$t|d ddD ]}| | |vr!|d7 } |S q|S t|d ddD ]}t| | s;|d7 } |S q,|S r  r  r   rZ   rZ   r[   unicode_strip_right_bound  s"   	r#  c                 C   @   t | tjr	| j} | d u st | tjtjtjfstdd S d S )Nz%The arg must be a UnicodeType or None)r  r   r&  r   rI  r  rK  r    )r!  rZ   rZ   r[   unicode_strip_types_check     r%  c                 C   r$  )Nz,The slice indices must be an Integer or None)r  r   r&  r   rI  rJ  rK  r    )argrZ   rZ   r[   r    r&  r  lstripc                 C   0   t |tjrddd}|S t| ddd}|S )Nc                 S   rd  r   )r(  r  r  r!  rZ   rZ   r[   lstrip_impl  rg  z#unicode_lstrip.<locals>.lstrip_implc                 S   s   | t | |d  S r   )r"  r*  rZ   rZ   r[   r+    r  r   r  r   r(  r%  )r  r!  r+  rZ   rZ   r[   unicode_lstrip     

r-  rstripc                 C   r)  )Nc                 S   rd  r   )r/  r  r*  rZ   rZ   r[   rstrip_impl  rg  z#unicode_rstrip.<locals>.rstrip_implc                 S   s   | d t | | S r   )r#  r*  rZ   rZ   r[   r0    r  r   r,  )r  r!  r0  rZ   rZ   r[   unicode_rstrip  r.  r1  stripc                 C   r)  )Nc                 S   rd  r   )r2  r  r*  rZ   rZ   r[   
strip_impl  rg  z!unicode_strip.<locals>.strip_implc                 S   s    t | |}t| |}| || S r   )r"  r#  )r  r!  lbrbrZ   rZ   r[   r3    s   

r   r,  )r  r!  r3  rZ   rZ   r[   unicode_strip  s   

r6  c                 C   s@   | du r
|rdS |S | dk r| |7 } | dk s| |krt d| S )a%  
    Parameters
    ----------
    idx : int or None
        the index
    length : int
        the string length
    is_start : bool; optional with defaults to True
        Is it the *start* or the *stop* of the slice?

    Returns
    -------
    norm_idx : int
        normalized index
    Nr   zstring index out of range)
IndexError)r   rH   is_startrZ   rZ   r[   normalize_str_idx  s   r9  c                 C   s:   | du r|S | |   kr|k r| | S  | dk rdS | S )a%  
    Used for unicode_count

    If arg < -slice_len, returns 0 (prevents circle)

    If arg is within slice, e.g -slice_len <= arg < slice_len
    returns its real index via arg % slice_len

    If arg > slice_len, returns arg (in this case count must
    return 0 if it is start index)
    Nr   rZ   )r'  	slice_lendefaultrZ   rZ   r[   r    s   r  c                 C   s   |||}dd }||fS )zFix slice object.
    c           	      S   sF   |j \}}|\}}| |||}t| ||| t||| | S r   )r   make_helperrB   guard_invalid_slice	fix_slicer   )	r   r   r   r   	slicetype
lengthtypesliceobjrH   slicerZ   rZ   r[   r   )  s   
z!_normalize_slice.<locals>.codegenrZ   )r   rA  rH   r   r   rZ   rZ   r[   _normalize_slice#  s   
rC  c                 C   s   t |}dd }||fS )z2Compute the span from the given slice object.
    c                 S   s,   |j \}|\}| |||}t||}|S r   )r   r<  rB   get_slice_length)r   r   r   r   r?  rA  rB  result_sizerZ   rZ   r[   r   :  s
   z_slice_span.<locals>.codegen)r   rO   )r   rA  r   r   rZ   rZ   r[   _slice_span4  s   
rF  c           
      C   sv   |j | j kr%t|j }|| }|| }|| }t| j||j||dd d S t|D ]}	t| ||	 t|||	  q)d S )Nrv   )align)ra   rz   r   r_   r   r   r   )
dstr   r  
src_offsetr  
byte_widthsrc_byte_offsetdst_byte_offsetr   r   rZ   rZ   r[   r  D  s   


r  c                 C   s2   |t jksJ dd }t t jt jt j}||fS )z_Create a slice of a unicode string using a view of its data to avoid
    extra allocation.
    c                 S   s   |\}}}t tj| ||d}t tj| |}|j|_|j|_|j|_||_| t	d|_
| jt}	|	| jtjfi }
| |	|
}|||jf}|||}||j|g|_t |jj|_| jrq| j||jd | | S )Nr   r   r   )r   r   r   r   rL   rI   rJ   rH   r   r   rK   typing_contextresolve_value_typerz   get_call_typerP   get_functionr   r   rG   r   rM   r   
enable_nrtr   increfr   r   )r   r   r   r   r  rV  rH   in_strview_strbw_typbw_sigbw_implrJ  r   rZ   rZ   r[   r   Z  s8   
z$_get_str_slice_view.<locals>.codegen)r   r   rO   )r   src_tstart_tlength_tr   r   rZ   rZ   r[   _get_str_slice_viewS  s   r[  c                 C   sD   t | tjrt |tjrdd }|S t |tjr dd }|S d S d S )Nc                 S   sD   t |t| }t| |}t|}t|}t|d|}t|d| |S r   )r9  r  r   r
  r  r   r   )r   r   r  rI   rJ   retrZ   rZ   r[   getitem_char}  s   
z%unicode_getitem.<locals>.getitem_charc                 S   s   t |t| }t|}t| |j}t|}t|}t|j|j |j	|jD ]}t| |}|t|M }t|}||kr?t
||}q%|jdkrQ|| jkrQt| |j|S t|||}	|j}
t|D ]}t|	|t| |
 |
|j7 }
q^|	S )Nrv   )rC  r  rF  r   rV  r
  r  r   stepstopr   ra   r[  r   r   )r   r   	slice_idxspanr  rI   rJ   r   new_kindr\  currZ   rZ   r[   getitem_slice  s,   

z&unicode_getitem.<locals>.getitem_slice)r  r   r  rJ  	SliceType)r   r   r]  rd  rZ   rZ   r[   unicode_getitemy  s   $rf  c                 C   sP   t | tjrt |tjrdd }|S t | tjr$t |tjr&dd }|S d S d S )Nc                 S   s   | j |j  }t| j|j}t| j|j}t|||}tt| D ]}t||t	| | q tt|D ]}t|t| | t	|| q2|S r   )
r`   r   ra   r   rb   r   r   r  r   r   )r   r   
new_lengthrb  	new_asciirt  r   r  rZ   rZ   r[   concat_impl  s   z#unicode_concat.<locals>.concat_implc                 S   s   | t | S r   r  r#  rZ   rZ   r[   ri       r  )r   r   ri  rZ   rZ   r[   unicode_concat  s   
rk  c                 C   s   | dks|dk r
dS |dkr| S | j | }| j}t||| j}t| }t|d| d| |}d| |krEt|||d| |d9 }d| |ks3d| |ks[|| }t||||| | |S d S )Nr  rv   r   r   )r`   ra   r   rb   r  r  )str_argmult_argrg  rb  rt  len_a	copy_sizerestrZ   rZ   r[   _repeat_impl  s&   
rq  c                 C   sP   t | tjrt |tjrdd }|S t | tjr$t |tjr&dd }|S d S d S )Nc                 S   r  r   rq  r#  rZ   rZ   r[   wrap  r0  zunicode_repeat.<locals>.wrapc                 S   s
   t || S r   rr  r#  rZ   rZ   r[   rs    r0  )r  r   r  rJ  )r   r   rs  rZ   rZ   r[   unicode_repeat  s   rt  c                 C   r  )Nc                 S   s   t | dkS r   r  r   rZ   rZ   r[   r[    rj  zunicode_not.<locals>.implr  r   r[  rZ   rZ   r[   unicode_not  r  rw  replacec                 C   s   |}t |tjr|j}n	t |tjr|j}t |ttjfs$td	|t |tj
tjfs4td	|t |tj
sAtd	|ddd}|S )NzGUnsupported parameters. The parameters must be Integer. Given count: {}z+The object must be a UnicodeType. Given: {}r   c           	      S   s   |dkr| S |dkr]t | }|dkr||| | S |g}tt||}t|D ]#}|||  |d |kr>|| q)|d||d d   q)|t|krX|| d|S | ||}||}|S )Nr   r  r   rv   )listr  r4  r  r   r  r  )	r   old_strnew_strr  scharssplit_result	min_countr   rt  rZ   rZ   r[   r[    s&   


zunicode_replace.<locals>.implr   )r  r   rI  ry   r&  r   r  rJ  r    rL  r  rK  )r   rz  r{  r  rO  r[  rZ   rZ   r[   unicode_replace  s&   
r  c                        fdd}|S )Nc                        fdd}|S )Nc                    s   t | }|dkr
dS |dkrt| d}| jr |S |S | jr4t|D ]}t| |} |s3 dS q%t|D ]}t| |}|sF dS q8dS )Nr   Frv   T)r  r   rb   r   )rG   rH   r  r   
ascii_funcunicode_funcrZ   r[   r[  -  s(   


z.gen_isAlX.<locals>.unicode_isAlX.<locals>.implrZ   rG   r[  r  rZ   r[   unicode_isAlX+  s   z gen_isAlX.<locals>.unicode_isAlXrZ   )r  r  r  rZ   r  r[   	gen_isAlX*  s   r  isalphac                 C   s   t | pt| S r   )r>   r=   xrZ   rZ   r[   r  N  s   r  isalnumc                    s    fdd}|S )Nc                    sp   t | }|dkrt| dS |dkrdS d}t|D ]}t| |} |s*|r- dS |s5|r5d}q|S Nrv   r   FTr  r   r   )r   lcasedr   r  is_loweris_titleis_upperrZ   r[   r[  \  s   
z_is_upper.<locals>.implrZ   )r  r  r  r[  rZ   r  r[   	_is_upperW  s   r  c                 C   r!  r"  rZ   r  rZ   rZ   r[   r  m  r  isupperc                 C      dd }|S )z
    Implements .isupper()
    c                 S   s   | j rt| S t| S r   )rb   _ascii_is_upper_unicode_is_upperru  rZ   rZ   r[   r[  z  s   zunicode_isupper.<locals>.implrZ   rv  rZ   rZ   r[   unicode_isupperu  s   r  )rC      isasciic                 C   r  )z Implements UnicodeType.isascii()c                 S   r  r   )rb   rG   rZ   rZ   r[   r[    r  zunicode_isascii.<locals>.implrZ   r  rZ   rZ   r[   unicode_isascii  s   r  istitlec                 C   r  )z
    Implements UnicodeType.istitle()
    The algorithm is an approximate translation from CPython:
    https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/unicodeobject.c#L11829-L11885 # noqa: E501
    c                 S   s   t | }|dkrt| d}t|pt|S |dkrdS d}d}t|D ])}t| |}t|s2t|r<|r7 dS d}d}q#t|rJ|sE dS d}d}q#d}q#|S r  )r  r   r0   r6   r   r1   )rG   rH   charr  previous_is_casedr   rZ   rZ   r[   r[    s,   

zunicode_istitle.<locals>.implrZ   r  rZ   rZ   r[   unicode_istitle  s   r  islowerc                 C   r  )aP  
    impl is an approximate translation of:
    https://github.com/python/cpython/blob/201c8f79450628241574fba940e08107178dc3a5/Objects/unicodeobject.c#L11900-L11933    # noqa: E501
    mixed with:
    https://github.com/python/cpython/blob/201c8f79450628241574fba940e08107178dc3a5/Objects/bytes_methods.c#L131-L156    # noqa: E501
    c                 S   sp   t | }|dkrtt| dS |dkrdS d}t|D ]}t| |}t|s*t|r- dS |s5t|r5d}q|S r  )r  r1   r   r   r0   r6   )rG   rH   r  r   r  rZ   rZ   r[   r[    s   
zunicode_islower.<locals>.implrZ   r  rZ   rZ   r[   unicode_islower  s   	r  isidentifierc                 C   r  )z%Implements UnicodeType.isidentifier()c                 S   s^   t | }|dkr
dS t| d}t|s|dkrdS td|D ]}t| |}t|s, dS qdS )Nr   F_   rv   T)r  r   r,   r   r-   )rG   rH   first_cpr   r  rZ   rZ   r[   r[    s   

z"unicode_isidentifier.<locals>.implrZ   r  rZ   rZ   r[   unicode_isidentifier  s   r  c                    r  )Nc                    r  )Nc                    sX   t | }|dkr t| dS r|dkrdS t|D ]}t| |} |s) dS qdS r  r  )rG   rH   r   r  _PyUnicode_IS_funcempty_is_falserZ   r[   r[    s   
z*gen_isX.<locals>.unicode_isX.<locals>.implrZ   r  r  rZ   r[   unicode_isX  s   zgen_isX.<locals>.unicode_isXrZ   )r  r  r  rZ   r  r[   gen_isX  s   r  isspace	isnumericisdigit	isdecimalisprintablec                    r  )z)Generate common case operation performer.c           	         s   t | }|dkrt| j|| jS | jr!t| j|d} | | |S ttd| | j}dg}| |||}|d }t|}t||t|}t|D ]}t||t	|| qH|S )Nr   rv   rC   )
r  r   ra   rb   r   r
  r  r   r   r   )	rG   rH   r   tmpmaxchars	newlengthmaxcharnewkindr   r  rZ   r[   r[    s    
zcase_operation.<locals>.implrZ   )r  r  r[  rZ   r  r[   case_operation  s   r  c                 C   s   d}|d }|dkrt | |}t|sn|d8 }|dks
|dko#t|}|rI|d }||k r@t | |}t|s8n|d7 }||k s.||kpHt| }|rMdS dS )zEThis is a translation of the function that handles the capital sigma.r   rv   i  i  )r   r/   r.   )rG   rH   r   r   r  final_sigmarZ   rZ   r[   _handle_capital_sigma/  s&   

r  c                 C   s&   | dkrt ||||d< dS t| |S )z>This is a translation of the function that lowers a character.i  r   rv   )r  r&   )r  rG   rH   r   mappedrZ   rZ   r[   _lower_ucs4G  s   
r  c                    r   )Nc           
         s   d}t |D ]:}tjdtd}t| |} rt|| |||}nt||}|d | D ]}	t|d |	|d< t|||	 |d7 }q*q|S Nr   rC   r  rv   )	r   r   zerosr#   r   r  r%   maxr   )
rG   rH   r   r  kr   r  r  n_resmlowerrZ   r[   _do_upper_or_lowerR  s   


z7_gen_unicode_upper_or_lower.<locals>._do_upper_or_lowerrZ   )r  r  rZ   r  r[   _gen_unicode_upper_or_lowerQ  s   r  c                    r   )Nc                    s0   t t| D ]}t| |}t|| | qd S r   )r   r  r   r   rG   r   r   r  funcrZ   r[   _ascii_upper_or_loweri  s   
z8_gen_ascii_upper_or_lower.<locals>._ascii_upper_or_lowerrZ   )r  r  rZ   r  r[   _gen_ascii_upper_or_lowerh  s   r  r  c                 C   
   t ttS )zImplements .lower())r  _ascii_lower_unicode_lowerr  rZ   rZ   r[   unicode_lowert     
r  upperc                 C   r  )zImplements .upper())r  _ascii_upper_unicode_upperr  rZ   rZ   r[   unicode_upperz  r  r  c                 C   s~   d}t jdtd}t|D ]/}|d t| |}t||}|d | D ]}	|d }
t|
|	|d< t|||	 |d7 }q$q|S r  )	r   r  r#   r   fillr   r'   r  r   )rG   rH   r   r  r  r  r   r  r  r  r  rZ   rZ   r[   _unicode_casefold  s   



r  c                 C   s0   t t| D ]}t| |}t||t| qd S r   )r   r  r   r   r"   r  rZ   rZ   r[   _ascii_casefold  s   
r  casefoldc                 C   r  )zImplements str.casefold())r  r  r  r  rZ   rZ   r[   unicode_casefold  r  r  c                 C   s   d}d}t jdtd}t| d}trt||}nt||}|d | D ]}	t||	}t|||	 |d7 }q#t	d|D ],}
|
d t| |
}t|| ||
|}|d | D ]}	t||	}t|||	 |d7 }qTq:||d< |S r  )r   r  r#   r   _py38_or_laterr(   r%   r  r   r   r  r  )rG   rH   r   r  r  r  r  r  r  r  r   rZ   rZ   r[   _unicode_capitalize  s,   







r  c                 C   sL   t | d}t|dt| tdt| D ]}t | |}t||t| qd S r  )r   r   r!   r   r  r"   )rG   r   r  r   rZ   rZ   r[   _ascii_capitalize  s   

r  
capitalizec                 C   r  r   )r  r  r  r  rZ   rZ   r[   unicode_capitalize     
r  c                 C   s   d}d}t jdtd}t|D ]A}|d t| |}|r&t|| |||}	ntt||}	|d|	 D ]}
|\}t||
|d< t	|||
 |d7 }q3t
t|}q|S )zCThis is a translation of the function that titles a unicode string.r   FrC   r  Nrv   )r   emptyr#   r   r  r   r  r(   r  r   r.   )rG   rH   r   r  r  previous_casedr  r   r  r  r  r  rZ   rZ   r[   _unicode_title  s    


r  c                 C   sh   d}t t| D ])}t| |}t|r|st|}d}nt|r)|r&t|}d}nd}t||| qdS )z" Does .title() on an ASCII string FTN)r   r  r   r7   r!   r8   r"   r   )rG   r   r  r   r  rZ   rZ   r[   _ascii_title  s   
r  titlec                 C   r  )zImplements str.title())r  r  r  r  rZ   rZ   r[   unicode_title  s   
r  c                 C   sN   t t| D ]}t| |}t|rt|}nt|rt|}t||| qd S r   )r   r  r   r8   r"   r7   r!   r   r  rZ   rZ   r[   _ascii_swapcase	  s   

r  c                 C   s   d}d}t jdtd}t|D ]A}|d t| |}t|r(t|| |||}	nt|r2t	||}	nd}	||d< |d |	 D ]}
t
||
}t|||
 |d7 }q>q||d< |S r  )r   r  r#   r   r  r   r0   r  r1   r%   r  r   )rG   rH   r   r  r  r  r  r   r  r  r  rZ   rZ   r[   _unicode_swapcase	  s&   



r  swapcasec                 C   r  r   )r  r  r  r  rZ   rZ   r[   unicode_swapcase$	  r  r  c                 C   r  )Nc                 S   s"   t | }|dkrtdt| dS )Nrv   zord() expected a characterr   )r  	TypeErrorr   )r   lcrZ   rZ   r[   r[  -	  s   
zol_ord.<locals>.implr  )r   r[  rZ   rZ   r[   ol_ord*	  s   r  c                 C   s4   | t ksJ t| }t|d|tk}t|d|  |S r   )_MAX_UNICODEr
  r   r   r   )r   rI   r\  rZ   rZ   r[   _unicode_char<	  s
   r  zchr() arg not in range(0x%hx)c                 C   s$   | dk s| t krtttt| S r   )r  rx   _out_of_range_msgr  r#   )ordinalrZ   rZ   r[   _PyUnicode_FromOrdinalI	  s   r  c                 C   r  )Nc                 S   s   t | S r   )r  )r   rZ   rZ   r[   r[  U	  s   zol_chr.<locals>.implr  r   rJ  )r   r[  rZ   rZ   r[   ol_chrR	  r  r  c                    s(   t | tjr| d  fdd}|S d S )N
   c           	         s   d}| dk r|  } d}| dkrdS |d t tt|  }t}t|}t|||d}|r6t|dtd |d }| dkrYt	|  \} }td| }t||| |d8 }| dks>|S )NFr   Tr  rv   r  )
r  r   floorlog10r   rz   r   r   orddivmod)	r  flagrH   rI   r   r   r   digitr   tenrZ   r[   r[  `	  s(   zinteger_str.<locals>.implr  )r  r[  rZ   r  r[   integer_strZ	  s
   r  c                 C   r  )Nc                 S   s   | rdS dS )NTrueFalserZ   r   rZ   rZ   r[   r  z	  s    zboolean_str.<locals>.<lambda>)r  r   r  r  rZ   rZ   r[   boolean_strw	  r  r  getiterc           
      C   sp   |j \}|\}| ||j}| tjd}t||}||_||_	| j
r,| j||| | }	t| ||j|	S r   )r   r<  return_typer   r   rg   r   alloca_once_valuere   rG   rQ  r   rR  r   r   )
r   r   r   r   rM  rG   iterobjzeroindexptrr   rZ   rZ   r[   getiter_unicode	  s   r	  iternextc                 C   s  |j \}|\}| j}|tj}||tjtjfi }	| 	||	}
|t
}||tjfi }| 	||}| j|||d}|||jf}||j}|d||}|| ||# |
||j|f}|| t||}|||j W d    d S 1 sw   Y  d S )Nr   <)r   rM  rN  operatorgetitemrO  r   r   rg   rP  r  r<  rG   r   re   icmp_unsigned	set_validif_thenyield_r   increment_indexr   )r   r   r   r   rt  itertyitertyctxfntygetitem_siggetitem_impllen_sigr  r  strlenre   is_validgotitemnindexrZ   rZ   r[   iternext_unicode	  s,   


"r  )r   r\  r  rD  r  r  r   )Tr  )r  r  numpyr   llvmlite.irr   r   numba.core.extendingr   r   r   r   r   r	   r
   r   r   r   numba.core.imputilsr   r   r   r   r   r   numba.core.datamodelr   r   
numba.corer   r   r   numba.core.pythonapir   r   r   r   numba._helperlibr   numba.cpython.hashingr   numba.core.unsafe.bytesr   numba.core.errorsr    numba.cpython.unicode_supportr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   numba.cpythonrB   	PYVERSIONr  r  r  rF   UnicodeIteratorTyperd   r   r   r'  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rz   r  r
  r  r  r  r  r  eqr.  ner1  ltr;  gtr>  ler@  gerC  containsrG  rQ  rR  r]  r`  ra  rE  rl  rh  rm  rx  r{  r  r  r  r  rT  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r#  r%  r  r-  r1  r6  r9  r  rC  rF  r  r[  r  rf  r   iaddrk  rq  r   rt  not_rw  r  r  _unicode_is_alnumr  _always_falser  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  chrr  r  r  r	  NEWr  rZ   rZ   rZ   r[   <module>   s0   0 
	























&



	
	











#
$

#



1
@T,

Q%)#







	
	






%
9



1!






%




	

		

