
    Ij                     R   d Z ddlmZ ddlmZ ddlmZ ddlmZ	 	 	 dd	e
d
ededz  de
de
f
dZ	 	 dd	e
dedz  de
de
fdZ	 	 dd	e
dedz  de
de
fdZ	 	 dd	e
dedz  de
de
fdZd	e
dede
fdZd	e
de
fdZd	e
defdZd	e
defdZd	e
de
fdZd	e
de
fdZd	e
de
fdZd	e
de
fdZdS )a  Provides string utility functions.

This module offers a collection of string utility functions built on the Rich library.
These utilities are designed to correctly handle strings with ANSI style sequences and
full-width characters (like those used in CJK languages).
    )AlignMethod)	StyleType)Text   )
rich_utilsN valalignwidth	characterreturnc                     |t          j                    }t          j        |           }|                    |||           t          j        |          S )ah  Align string to a given width.

    There are convenience wrappers around this function: align_left(), align_center(), and align_right()

    :param val: string to align
    :param align: one of "left", "center", or "right".
    :param width: Desired width. Defaults to width of the terminal.
    :param character: Character to pad with. Defaults to " ".

    Nr   r   )ruconsole_widthr   	from_ansir
   rich_text_to_string)r	   r
   r   r   texts        i/home/jenkins/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/cmd2/string_utils.pyr
   r
      sO      } "">#DJJuEYJ777!$'''    c                 (    t          | d||          S )zLeft-align string to a given width.

    :param val: string to align
    :param width: Desired width. Defaults to width of the terminal.
    :param character: Character to pad with. Defaults to " ".

    leftr   r
   r	   r   r   s      r   
align_leftr   '   s     fEY????r   c                 (    t          | d||          S )zCenter-align string to a given width.

    :param val: string to align
    :param width: Desired width. Defaults to width of the terminal.
    :param character: Character to pad with. Defaults to " ".

    centerr   r   r   s      r   align_centerr   6   s     heyAAAAr   c                 (    t          | d||          S )zRight-align string to a given width.

    :param val: string to align
    :param width: Desired width. Defaults to width of the terminal.
    :param character: Character to pad with. Defaults to " ".

    rightr   r   r   s      r   align_rightr!   E   s     gUi@@@@r   stylec                 |    t          j        |           }|                    |           t          j        |          S )zApply an ANSI style to a string, preserving any existing styles.

    :param val: string to be styled
    :param style: style instance or style definition to apply.
    :return: the stylized string
    )r   r   stylizer   r   )r	   r"   r   s      r   r$   r$   T   s6     >#DLL!$'''r   c                 B    t           j                            d|           S )zStrip all ANSI style sequences (colors, bold, etc.) from a string.

    This targets SGR sequences specifically and leaves other terminal
    control codes intact.

    :param val: string to be stripped
    :return: the stripped string
     )r   ANSI_STYLE_SEQUENCE_REsubr	   s    r   strip_styler*   a   s     $((S111r   c                 8    t          j        |           }|j        S )zReturn the display width of a string.

    This is intended for single-line strings.
    Replace tabs with spaces before calling this.

    :param val: the string being measured
    :return: width of the string when printed to the terminal
    )r   r   cell_len)r	   r   s     r   	str_widthr-   m   s     >#D=r   c                 v    ddl m} t          |           dk    o | d         | d         k    o| d         |j        v S )z~Check if a string is quoted.

    :param val: the string being checked for quotes
    :return: True if a string is quoted
    r   )	constantsr   )r&   r/   lenQUOTES)r	   r/   s     r   	is_quotedr3   z   sI     s88a<LCFc"g-L#a&I<L2LLr   c                 "    d| v rdnd}|| z   |z   S )zQuote a string."' )r	   quotes     r   r8   r8      s"    #::CC3E3;r   c                 J    t          |           sd| vr| S t          |           S )z>Quote a string if it contains spaces and isn't already quoted.r   )r3   r8   r)   s    r   quote_if_neededr:      s)    ~~ C
::r   c                 8    t          |           r
| dd         } | S )zStrip outer quotes from a string.

     Applies to both single and double quotes.

    :param val:  string to strip outer quotes from
    :return: same string with potentially outer quotes stripped
    r   r0   )r3   r)   s    r   strip_quotesr<      s$     ~~ !B$iJr   c                 Z    ddl }|                    d|                                           S )zNormalize and casefold Unicode strings for saner comparisons.

    :param val: input unicode string
    :return: a normalized and case-folded version of the input string
    r   NNFC)unicodedata	normalizecasefold)r	   r?   s     r   	norm_foldrB      s2       ,,55777r   )Nr   )__doc__
rich.alignr   
rich.styler   	rich.textr   r&   r   r   strintr
   r   r   r!   r$   r*   r-   boolr3   r8   r:   r<   rB   r7   r   r   <module>rJ      s    # " " " " "                         	( (	(( :( 	(
 	( ( ( (4 @ @	@:@ @ 		@ @ @ @" B B	B:B B 		B B B B" A A	A:A A 		A A A A
( 
(Y 
(3 
( 
( 
( 
(	2S 	2S 	2 	2 	2 	2
3 
3 
 
 
 
M3 M4 M M M Ms s         
c 
c 
 
 
 
83 83 8 8 8 8 8 8r   