o
    z²ˆW(  ã                   @   sÌ   d dl mZ d dlZddlmZmZmZ e d¡Ze edƒ¡Z	da
g d¢add„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd"dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zed!krdeƒ  dS dS )#é    )Úprint_functionNé   )ÚBÚbytesÚord2z^[ -~]*$)&)é~   r   )éŸ   r   )i¯  r   )iÆ  r   )iÇ  r   )i×  r   )iÝ  r   )io  r   )i‚  r   )i‰  r   )iû  r   )i_  é   )i+  r   )ia  r   )i±   r   )iê   r   )i(#  r   )i*#  r	   )i+  r   )i>0  r	   )i?0  r   )i–0  r	   )iš0  r   )iµM  r	   )iÿM  r   )i£×  r	   )iÿø  r   )ijú  r	   )iþ  r   )i#þ  r   )ikþ  r	   )iÿþ  r   )i`ÿ  r	   )iÜÿ  r   )iæÿ  r	   )iÿ× r   )iýÿ r	   )iýÿ r   c                 C   s6   | dks| dkr
dS t D ]\}}| |kr|  S qdS )z5Return the screen column width for unicode ordinal o.é   é   r   r   )Úwidths)ÚoÚnumÚwid© r   úJ/var/www/html/kck/venv/lib/python3.10/site-packages/screen/old_str_util.pyÚ	get_widthR   s   ÿr   c           	      C   s  t | tƒs	J | ƒ‚t| | ƒ}|d@ s||d fS tdƒ|d f}t| ƒ| }|dk r-|S |d@ dkrYt| |d  ƒ}|d@ dkrC|S |d@ d> |d	@ B }|dk rS|S ||d fS |d
k r_|S |d@ dkr¡t| |d  ƒ}|d@ dkru|S t| |d  ƒ}|d@ dkr…|S |d@ d> |d	@ d> B |d	@ B }|dk r›|S ||d
 fS |dk r§|S |d@ dkrÿt| |d  ƒ}|d@ dkr½|S t| |d  ƒ}|d@ dkrÍ|S t| |d  ƒ}|d@ dkrÝ|S |d@ d> |d	@ d> B |d	@ d> B |d	@ B }|dk rù|S ||d fS |S )zH
    Return (ordinal at pos, next position) for UTF-8 encoded text.
    é€   r   ú?r	   éà   éÀ   é   é   é?   é   éð   r   é   i   é   éø   é   é   i   )Ú
isinstancer   r   ÚordÚlen)	ÚtextÚposÚb1ÚerrorÚltÚb2r   Úb3Úb4r   r   r   Ú
decode_one]   s\    ,r,   c                 C   s   t | | ƒ|d fS )z7
    decode_one implementation for unicode strings
    r   )r"   )r$   Úir   r   r   Údecode_one_uni‘   s   r.   c                 C   s„   t | tƒs	J | ƒ‚tdƒ|d f}|}|dkr@t| | ƒd@ dkr.t| |ƒ\}}||d fS |d8 }||d kr:|S |dksdS dS )z‹
    Return (ordinal at pos, next position) for UTF-8 encoded text.
    pos is assumed to be on the trailing byte of a utf-8 sequence.
    r   r   r   r   r   r   N)r!   r   r"   r   r,   )r$   r%   r'   Úpr   Únextr   r   r   Údecode_one_right˜   s   úr1   c                 C   s   | dv sJ ‚| a d S )N)Úutf8ÚnarrowÚwide©Ú_byte_encoding)Úencr   r   r   Úset_byte_encoding©   s   r8   c                   C   s   t S )Nr5   r   r   r   r   Úget_byte_encoding¯   s   r9   c                 C   s  ||ksJ t ||fƒƒ‚t| tƒotdk}t| tƒ }|s|rRttg| }|}d}d}	||k rN|| |ƒ\}
}	t|
ƒ}|| |krD||fS |	}||7 }||k s/||fS t| ƒtks^J t | ƒƒ‚|| }||krl||| fS tdkr|t| ||ƒdkr||d8 }||| fS )a9  
    Calculate the closest position to the screen column pref_col in text
    where start_offs is the offset into text assumed to be screen column 0
    and end_offs is the end of the range to search.

    text may be unicode or a byte string in the target _byte_encoding

    Returns (position, actual_col).
    r2   r   r   r4   r	   )	Úreprr!   r   r6   r,   r.   r   ÚtypeÚwithin_double_byte)r$   Ú
start_offsÚend_offsÚpref_colÚutfsÚunisÚdecoder-   ÚscÚnr   Úwr   r   r   Úcalc_text_pos³   s2   
úrF   c                 C   sÌ   t | ƒ}|dks|dks||kr|}||ksJ t||fƒƒ‚t| tƒo&tdk}t| tƒ }|r4t | ¡r;|rbt | ¡sbtt	g| }|}d}d}	||k r`|| |ƒ\}
}	t
|
ƒ}|	}||7 }||k sK|S || S )am  
    Return the screen column width of text between start_offs and end_offs.

    text may be unicode or a byte string in the target _byte_encoding

    Some characters are wide (take two columns) and others affect the
    previous character (take zero columns).  Use the widths table above
    to calculate the screen column width of text[start_offs:end_offs]
    r   éÿÿÿÿr2   r   )r#   r:   r!   r   r6   ÚSAFE_ASCII_REÚmatchÚSAFE_ASCII_BYTES_REr,   r.   r   )r$   r=   r>   r(   r@   rA   rB   r-   rC   rD   r   rE   r   r   r   Ú
calc_widthØ   s&   ürK   c                 C   sn   t | tƒrt| | ƒ}t|ƒdkS t | tƒsJ ‚tdkr)t| |ƒ\}}t|ƒdkS tdkr5t| ||ƒdkS dS )zƒ
    Test if the character at offs within text is wide.

    text may be unicode or a byte string in the target _byte_encoding
    r	   r2   r4   r   F)r!   Úunicoder"   r   r   r6   r,   r<   )r$   Úoffsr   rD   r   r   r   Úis_wide_charû   s   
rN   c                 C   sœ   ||k sJ ‚t | tƒr|d S t | tƒsJ ‚tdkr8|d }t| | ƒd@ dkr6|d8 }t| | ƒd@ dks(|S tdkrJt| ||d ƒdkrJ|d S |d S )z?
    Return the position of the character before end_offs.
    r   r2   r   r   r4   r	   ©r!   rL   r   r6   r   r<   ©r$   r=   r>   r   r   r   r   Úmove_prev_char  s   
ÿrQ   c                 C   s¨   ||k sJ ‚t | tƒr|d S t | tƒsJ ‚tdkr@|d }||k r>t| | ƒd@ dkr>|d7 }||k r>t| | ƒd@ dks,|S tdkrPt| ||ƒdkrP|d S |d S )z@
    Return the position of the character after start_offs.
    r   r2   r   r   r4   r	   rO   rP   r   r   r   Úmove_next_char  s   
ÿrR   c                 C   sÀ   t | tƒsJ ‚t| | ƒ}d|  krdk r7n n||krdS t| |d  ƒdkr5t| ||d ƒdkr5dS dS |dk r=dS |d }||krVt| | ƒdk rNn|d8 }||ksE|| d@ r^dS dS )aj  Return whether pos is within a double-byte encoded character.

    text -- byte string in question
    line_start -- offset of beginning of line (< pos)
    pos -- offset in question

    Return values:
    0 -- not within dbe char, or double_byte_encoding == False
    1 -- pos is on the 1st half of a dbe char
    2 -- pos is on the 2nd half of a dbe char
    é@   é   r   r   é   r	   r   )r!   r   r   r<   )r$   Ú
line_startr%   Úvr-   r   r   r   r<   1  s(   ýr<   c                  C   s   dd l } g }d }| j ¡ D ]h}|d d… dkrq| ¡ }| dd¡\}}| dd¡\}}| dd¡d }d|v r?| d¡d }t|d	ƒ}|d
v rKd}	n	|dv rRd}	nd}	|d u ra| d|	f¡ |	}||	krl||	f|d< q| ||	f¡ |	}qtdƒ |dd … D ]	}
td|
f ƒ q€tdƒ d S )Nr   r   ú#ú;z # ú Ú.z..é   )Ú	COMBININGÚMODIFIERz	<control>)ÚWÚFr	   rG   z
widths = [z	%r,ú])ÚsysÚstdinÚ	readlinesÚstripÚsplitÚintÚappendÚprint)rb   ÚoutÚlastÚlineÚhexÚrestr   Úword1r   Úlr   r   r   r   Úprocess_east_asian_widthZ  s:   
rq   Ú__main__)r   r   )Ú
__future__r   ÚreÚcompatr   r   r   ÚcompilerH   rJ   r6   r   r   r,   r.   r1   r8   r9   rF   rK   rN   rQ   rR   r<   rq   Ú__name__r   r   r   r   Ú<module>   s.   
,4
%#)'
ÿ