Created
February 21, 2012 05:37
-
-
Save vls/1873993 to your computer and use it in GitHub Desktop.
pyre2 modification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cdef inline _re2.StringPiece* _alloc_sp(self, char* cstring, Py_ssize_t& size): | |
cdef _re2.StringPiece * sp | |
sp = new _re2.StringPiece(cstring, size) | |
return sp | |
cdef inline void _dealloc_sp(self, _re2.StringPiece* sp): | |
del sp | |
cdef inline _my_match(self, _re2.StringPiece sp_zero, int pos, int size, _re2.re2_Anchor anchoring, _re2.StringPiece* submatch, int nsubmatch): | |
return self.re_pattern.Match(sp_zero, <int>pos, <int>size, anchoring, submatch, nsubmatch) | |
cpdef search(self, string, int pos=0, int endpos=-1): | |
cdef Py_ssize_t size | |
cdef int result | |
cdef char * cstring | |
cdef int encoded = 0 | |
cdef _re2.StringPiece * sp | |
cdef _re2.re2_Anchor anchoring | |
anchoring = _re2.UNANCHORED | |
#if hasattr(string, 'tostring'): | |
# string = string.tostring() | |
string = unicode_to_bytestring(string, &encoded) | |
if pystring_to_bytestring(string, &cstring, &size) == -1: | |
raise TypeError("expected string or buffer") | |
if endpos >= 0 and endpos <= pos: | |
return None | |
if endpos >= 0 and endpos < size: | |
size = endpos | |
if pos > size: | |
return None | |
sp = self._alloc_sp(cstring, size) | |
result = self._my_match(sp[0], pos, size, anchoring, NULL, 0) | |
#self._dealloc_sp(sp) | |
if result == 0: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment