
    }i	                        d dl mZ d dlZd dl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 erd dlmZ  G d	 d
ee         e
e         ee                   ZdS )    )annotationsN)TYPE_CHECKINGAnyGeneric)LazyExprNamespace)StringNamespace)SQLExprT)is_pyspark_pre_4)
NativeExprc                      e Zd Zd+dZd,d	Z	 d-d.dZd/dZd0dZd1dZd2dZ	d3dZ
d4dZd5d Zd6d#Zd1d$Zd1d%Zd7d'Zd8d)Zd8d*Zd
S )9SQLExprStringNamespacevaluer   returnr   c                6    | j                             |          S N)	compliant_lit)selfr   s     J/home/jrussi/.local/lib/python3.11/site-packages/narwhals/_sql/expr_str.pyr   zSQLExprStringNamespace._lit   s    ~""5)))    namestrargsc                (     | j         j        |g|R  S r   )r   	_function)r   r   r   s      r   r   z SQLExprStringNamespace._function   s    't~'4t4444r   N	condition	otherwise
Any | Nonec                :    | j                             |||          S r   )r   _when)r   r   r   r   s       r   r    zSQLExprStringNamespace._when   s     ~##Iui@@@r   patternr	   literalboolc                    d fd}t          |t                    r. j                                                            |d           n|} j                            ||          S )	Nexprr   r!   r   c                >    rdnd}                     || |          S )Ncontainsregexp_matchesr   )r%   r!   	func_namer"   r   s      r   funcz-SQLExprStringNamespace.contains.<locals>.func   s(    &-C

3CI>>)T7;;;r   )dtype)r!   )r%   r   r!   r   r   r   )
isinstancer   r   __narwhals_namespace__lit_with_elementwise)r   r!   r"   r+   compliant_patterns   ` `  r   r'   zSQLExprStringNamespace.contains   s    	< 	< 	< 	< 	< 	< 	< '3''DN113377t7LLL 	
 ~//>O/PPPr   suffixc                B      j                              fd          S )Nc                X                         d|                                         S )N	ends_withr   r   )r%   r   r2   s    r   <lambda>z2SQLExprStringNamespace.ends_with.<locals>.<lambda>,   s#    T499V;L;LMM r   r   r0   )r   r2   s   ``r   r5   z SQLExprStringNamespace.ends_with*   s-    ~//MMMMM
 
 	
r   c                >      j                              fd          S )Nc                0                         d|           S )Nlengthr)   r%   r   s    r   r7   z2SQLExprStringNamespace.len_chars.<locals>.<lambda>1   s    $77 r   r8   r   s   `r   	len_charsz SQLExprStringNamespace.len_chars/   s)    ~//7777
 
 	
r   c                    |rdndg |s4 j         j                                        r                     d          g j                              fd|          S )Nreplaceregexp_replacegc                L     j         |                               |gR  S r   r6   )r%   r   fnameoptionsr!   r   s     r   r7   z4SQLExprStringNamespace.replace_all.<locals>.<lambda>;   s7    tTYYw//!9@! ! ! r   )r   )r   _implementation	is_duckdbr   r0   )r   r   r!   r"   rD   rE   s   ` ` @@r   replace_allz"SQLExprStringNamespace.replace_all4   s    ")?YY/? 	'4>9CCEE 	'yy~~&G~//       	 0 
 
 	
r   offsetintr;   
int | Nonec                L     d fd} j                             |          S )Nr%   r   r   c                $                        d|           }dk     r+t          j        |                    dz                       n                    dz             }                              n|}                     d| ||          S )Nr;   r      substr)r   operatoraddr   )r%   
col_length_offset_lengthr;   rI   r   s       r   r+   z*SQLExprStringNamespace.slice.<locals>.funcB   s    $77J A:: Z6A:)>)>???YYvz** 
 ,2+=dii''':G>>(D'7CCCr   r%   r   r   r   r8   )r   rI   r;   r+   s   ``` r   slicezSQLExprStringNamespace.sliceA   sM    		D 		D 		D 		D 		D 		D 		D 		D ~//555r   byc                     t           j        j                  }|r|n                     |           j                             fd          S )Nc                2                         d|           S )N	str_splitr)   )r%   r   split_bys    r   r7   z.SQLExprStringNamespace.split.<locals>.<lambda>U   s    T8DD r   )r
   r   rF   r   r0   )r   rW   _is_pyspark_pre_4r[   s   `  @r   splitzSQLExprStringNamespace.splitO   sZ     -T^-KLL*=22		"~//DDDDD
 
 	
r   prefixc                B      j                              fd          S )Nc                X                         d|                                         S )Nstarts_withr6   )r%   r^   r   s    r   r7   z4SQLExprStringNamespace.starts_with.<locals>.<lambda>Z   s#    tTYYv=N=NOO r   r8   )r   r^   s   ``r   ra   z"SQLExprStringNamespace.starts_withX   s-    ~//OOOOO
 
 	
r   
characters
str | Nonec                N     dd l  j                             fd          S )Nr   c                j                         d|                     j        n                    S )Ntrim)r   r   
whitespace)r%   rb   r   strings    r   r7   z4SQLExprStringNamespace.strip_chars.<locals>.<lambda>a   s7    		z/A&++zRR  r   )rh   r   r0   )r   rb   rh   s   ``@r   strip_charsz"SQLExprStringNamespace.strip_chars]   sF    ~//     
 
 	
r   c                >      j                              fd          S )Nc                0                         d|           S )Nlowerr)   r<   s    r   r7   z5SQLExprStringNamespace.to_lowercase.<locals>.<lambda>j       66 r   r8   r=   s   `r   to_lowercasez#SQLExprStringNamespace.to_lowercaseh   )    ~//6666
 
 	
r   c                >      j                              fd          S )Nc                0                         d|           S )Nupperr)   r<   s    r   r7   z5SQLExprStringNamespace.to_uppercase.<locals>.<lambda>o   rm   r   r8   r=   s   `r   to_uppercasez#SQLExprStringNamespace.to_uppercasem   ro   r   widthc                ~     t           j        j                  d fd} j                            |          S )Nr%   r   r   c                                        d|                                         k     }rdn                    d          }rdz
  n                    dz
            }rn                              }                    d                              d          }}                     d| |          }                     d| |          }                     d|                     d                    }	                     d	|	||          }
                    t          j        ||                               d
||
                              t          j        ||                               d
||
                              |                     d	| ||          |                               S )Nr;   0rN   -+ra   rO      lpadconcat)r   r   r    rP   and_)r%   less_than_widthzerowidth_after_sign
full_widthhyphenplusstarts_with_minusstarts_with_plus	substringpadded_substringr\   r   rt   s              r   r+   z*SQLExprStringNamespace.zfill.<locals>.funcz   s   "nnXt<<tyy?O?OOO+?333D,=Wuqyy499UUVYCWCW"3I59I9IJ99S>>499S>>DF $}dF K K#~~mT4HHxtyy||DDI#~~fiAQSWXX::/AAx1ABB

M"2ODDNN8T3CDDJJ'vtZFF    r   rU   )r
   r   rF   _with_callable)r   rt   r+   r\   s   `` @r   zfillzSQLExprStringNamespace.zfillr   sZ     -T^-KLL	 	 	 	 	 	 	 	6 ~,,T222r   	fill_charc                     t           j        j                  }|rn                               |r|n                     |          d fd} j                            |          S )Nr%   r   r   c           	                                                  d|                                         k                         d|           |           S )Nr;   r{   r    r   r   )r%   r;   	lpad_filllpad_lengthr   s    r   
_pad_startz4SQLExprStringNamespace.pad_start.<locals>._pad_start   S    ::x..61B1BBvt[)DD  r   rU   r
   r   rF   r   r   )r   r;   r   r\   r   r   r   s   ``   @@r   	pad_startz SQLExprStringNamespace.pad_start   s     -T^-KLL 1Hfftyy7H7H!2LII		)8L8L		 	 	 	 	 	 	 	 	 ~,,Z888r   c                     t           j        j                  }|rn                               |r|n                     |          d fd} j                            |          S )Nr%   r   r   c           	                                                  d|                                         k                         d|           |           S )Nr;   rpadr   )r%   r;   	rpad_fillrpad_lengthr   s    r   _pad_endz0SQLExprStringNamespace.pad_end.<locals>._pad_end   r   r   rU   r   )r   r;   r   r\   r   r   r   s   ``   @@r   pad_endzSQLExprStringNamespace.pad_end   s     -T^-KLL 1Hfftyy7H7H!2LII		)8L8L		 	 	 	 	 	 	 	 	 ~,,X666r   )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	   )r2   r   r   r	   )r   r	   )r   r	   r!   r   r"   r#   r   r	   )rI   rJ   r;   rK   r   r	   )rW   r   r   r	   )r^   r   r   r	   )rb   rc   r   r	   )rt   rJ   r   r	   )r;   rJ   r   r   r   r	   )__name__
__module____qualname__r   r   r    r'   r5   r>   rH   rV   r]   ra   ri   rn   rs   r   r   r    r   r   r   r      sj       * * * *5 5 5 5 CGA A A A A
Q Q Q Q
 
 
 


 
 
 


 
 
 
6 6 6 6
 
 
 

 
 
 

	
 	
 	
 	

 
 
 


 
 
 

#3 #3 #3 #3J9 9 9 9 7 7 7 7 7 7r   r   )
__future__r   rP   typingr   r   r   narwhals._compliantr   !narwhals._compliant.any_namespacer   narwhals._sql.typingr	   narwhals._utilsr
   narwhals._compliant.exprr   r   r   r   r   <module>r      s    " " " " " "  . . . . . . . . . . 1 1 1 1 1 1 = = = = = = ) ) ) ) ) ) , , , , , , 4333333f7 f7 f7 f7 f7h!:GH<Mf7 f7 f7 f7 f7r   