o =?h@sdZddlZddlmZmZmZddlmZddZGdddZd d Z d d Z d dZ e dkr?ddl mZeddddSdS)z'Define SearchEngine for search dialogs.N) StringVar BooleanVarTclError) messageboxcCst|ds t||_|jS)zReturn the singleton SearchEngine instance for the process. The single SearchEngine saves settings between dialog instances. If there is not a SearchEngine already, make one. _searchengine)hasattr SearchEnginer)rootr ;/opt/alt/python310/lib64/python3.10/idlelib/searchengine.pygets  r c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZd"ddZd#ddZd$ddZd$d d!ZdS)%rzr3r:r9wrapped startlinecharsmr r r r7s,   zSearchEngine.search_forwardc Csd}|}|d|d|d} t|| dd|} | r)|s%| |kr)|| fS|d}|r6||kr6 dSd}|dkrT|sA dSd}d}|d} tt| d\}}|d|d|d} t| d}q)NrrArBTrCzend-1c.)r search_reverser=indexmapintsplitlen) rr8r/r>r3r:r9rFrGrHrIr-r r r r6s0    zSearchEngine.search_backwardr)Nr)r)__name__ __module__ __qualname____doc__rrrrr r!r"r#r&r'r1r(r@r7r6r r r r rs"  (rcCs|||}|s dSd}|\}}||kr<||kr<|}||kr#|d}|||}|s. |S|\}}||kr<||ks|S)a&Search backwards and return an re match object or None. This is done by searching forwards until there is no match. Prog: compiled re object with a search method returning a match. Chars: line of text, without \n. Col: stop index for the search; the limit for match.end(). NrB)rDspan)r/rHr3rIfoundijr r r rKs    rKcCsRz |d}|d}Wn tyd}}Ynw|s!|d}|s%|}||fS)zFReturn tuple of 'line.col' indexes from selection or insert mark. z sel.firstzsel.lastNinsert)rLr)r8r;r<r r r r4s    r4cCstt|d\}}||fS)z8Return (line, col) tuple of ints from 'line.col' string.rJ)rMrNrO)rLr>r3r r r r5sr5__main__)mainz#idlelib.idle_test.test_searchengine) verbosity)rTr$Ztkinterrrrrr rrKr4r5rQZunittestr[r r r r s  +