mirror of
				https://github.com/wting/autojump
				synced 2025-06-13 12:54:07 +00:00 
			
		
		
		
	add unicode and ignore case regex flags
This commit is contained in:
		
							parent
							
								
									bd091b8766
								
							
						
					
					
						commit
						bb04405cd6
					
				@ -30,7 +30,7 @@ from operator import attrgetter
 | 
				
			|||||||
from operator import itemgetter
 | 
					from operator import itemgetter
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import platform
 | 
					import platform
 | 
				
			||||||
from re import search
 | 
					import re
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from argparse import ArgumentParser
 | 
					from argparse import ArgumentParser
 | 
				
			||||||
@ -208,7 +208,7 @@ def find_matches(config, needles, count=1):
 | 
				
			|||||||
    return first(exact_matches).path
 | 
					    return first(exact_matches).path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def match_exact_regex(needles, haystack):
 | 
					def match_exact_regex(needles, haystack, ignore_case=False):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Performs an exact match by combining all arguments into a single regex
 | 
					    Performs an exact match by combining all arguments into a single regex
 | 
				
			||||||
    expression and finding matches.
 | 
					    expression and finding matches.
 | 
				
			||||||
@ -222,9 +222,9 @@ def match_exact_regex(needles, haystack):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        result = [(path="The quick brown fox jumped over the lazy dog", 12.3)]
 | 
					        result = [(path="The quick brown fox jumped over the lazy dog", 12.3)]
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					 | 
				
			||||||
    regex_needle = '.*' + '.*'.join(needles) + '.*'
 | 
					    regex_needle = '.*' + '.*'.join(needles) + '.*'
 | 
				
			||||||
    find = lambda haystack: search(regex_needle, haystack.path)
 | 
					    regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE
 | 
				
			||||||
 | 
					    find = lambda haystack: re.search(regex_needle, haystack.path, flags=regex_flags)
 | 
				
			||||||
    return ifilter(find, haystack)
 | 
					    return ifilter(find, haystack)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user