
    =wg                         d dl Z d dlZd dlmZmZmZ  e j                  d      Z e j                  d      Z	d Z
d Zd Zd Z ej                  dej                        Zd	 Zd
 ZddZy)    N)string_typeubyteutf-8c                     d}|dk  rY|t        |       k  rK|t        |      k  r=| |   ||   k(  r2|dz  }|dk  r(|t        |       k  r|t        |      k  r| |   ||   k(  r2|S )z
    Returns the position of the first differing character in the sequences a
    and b. For example, first_diff('render', 'rending') == 4. This function
    limits the return value to 255 so the difference can be encoded in a single
    byte.
    r         )lenabis      G/var/www/horilla/myenv/lib/python3.12/site-packages/whoosh/util/text.py
first_diffr   *   sk     	
A
s(q3q6za#a&jQqTQqT\	Q s(q3q6za#a&jQqTQqT\H    c                 <    t        | |      }t        |      ||d z   S )zw
    Compresses bytestring b as a byte representing the prefix it shares with a,
    followed by the suffix bytes.
    N)r   r   r   s      r   prefix_encoder   8   s$     	1aA7QqrU?r   c              #      K   t        d      }| D ]2  }t        ||      }t        |      ||d j                  d      z    |}4 yw)zCompresses the given list of (unicode) strings by storing each string
    (except the first one) as an integer (encoded in a byte) representing
    the prefix it shares with its predecessor, followed by the suffix encoded
    as UTF-8.
     Nr   )r   r   chrencode)lslastwr   s       r   prefix_encode_allr   B   sO      R5D tQ!fqu||G,,,s   AAc              #      K   t        d      }| D ]0  }t        |d         }|d| |dd j                  d      z   }| |}2 yw)zBDecompresses a list of strings compressed by prefix_encode().
    r   r   Nr	   r   )r   orddecode)r   r   r   r   decodeds        r   prefix_decode_allr    P   sV      R5D !Ir(QqrU\\'22	s   AAz\D+|\d+c                 X    	 t        |       S # t        $ r | j                         cY S w xY wN)int
ValueErrorlower)r   s    r   _nkconvr&   a   s+    1v wwys   
 ))c                 L    t        d t        j                  |       D              S )a5  Converts string ``s`` into a tuple that will sort "naturally" (i.e.,
    ``name5`` will come before ``name10`` and ``1`` will come before ``A``).
    This function is designed to be used as the ``key`` argument to sorting
    functions.

    :param s: the str/unicode string to convert.
    :rtype: tuple
    c              3   2   K   | ]  }t        |        y wr"   )r&   ).0ms     r   	<genexpr>znatural_key.<locals>.<genexpr>u   s     66s   )tuple_nkrefindall)ss    r   natural_keyr0   h   s     6U]]1%5666r   c                     t        | t              s| S |r|t        j                  z  }t        j                  | t        j
                  |z        S )zA wrapper for re.compile that checks whether "pattern" is a regex object
    or a string to be compiled, and automatically adds the re.UNICODE flag.
    )
isinstancer   reVERBOSEcompileUNICODE)patternflagsverboses      r   rcompiler:   z   s>    
 g{+::grzzE122r   )r   F)codecsr3   whoosh.compatr   r   r   
getencoder
utf8encode
getdecoder
utf8decoder   r   r   r    r5   r6   r-   r&   r0   r:    r   r   <module>rB      sq   8  . . Vw'
Vw'

	 	

:rzz*7$
3r   