def main(n): assert n >= 0 pattern = [n] * n string = chr(n) * n rsre_core.search(pattern, string) # unicodestr = unichr(n) * n ctx = rsre_core.UnicodeMatchContext(pattern, unicodestr, 0, len(unicodestr), 0) rsre_core.search_context(ctx) # return 0
def method_match_operator(self, space, s): ctx = self.make_ctx(s) matched = rsre_core.search_context(ctx) self.get_match_result(space, ctx, matched) if matched: return space.newint(ctx.match_start) else: return space.w_nil
def search(pattern, string, start=0, end=sys.maxint): start, end = _adjust(start, end, len(string)) start = Position(start) end = Position(end) ctx = MatchContextForTests(string, start, end) if search_context(ctx, pattern): return ctx else: return None
def single_compile(self, glob, flags=0): parts = self.path_split(glob) if glob[-1] == "/": last = DirectoriesOnly(None, flags) else: file = parts.pop() ctx = regexp_match(self.cache, r"^[a-zA-Z0-9._]+$", file) if rsre_core.search_context(ctx): last = ConstantEntry(None, flags, file) else: last = EntryMatch(None, flags, file) while parts: last.separator = parts.pop() dir = parts.pop() if dir == "**": if parts: last = RecursiveDirectories(last, flags) else: last = StartRecursiveDirectories(last, flags) else: pattern = r"^[^\*\?\]]+" ctx = regexp_match(self.cache, pattern, dir) if rsre_core.search_context(ctx): partidx = len(parts) - 2 assert partidx >= 0 ctx = regexp_match(self.cache, pattern, parts[partidx]) while rsre_core.search_context(ctx): next_sep = parts.pop() next_sect = parts.pop() dir = next_sect + next_sep + dir partidx = len(parts) - 2 assert partidx >= 0 ctx = regexp_match(self.cache, pattern, parts[partidx]) last = ConstantDirectory(last, flags, dir) elif len(dir) > 0: last = DirectoryMatch(last, flags, dir) if glob[0] == "/": last = RootDirectory(last, flags) return last
def utf8search(pattern, utf8string, bytestart=0, byteend=sys.maxint): # bytestart and byteend must be valid byte positions inside the # utf8string. from rpython.rlib.rsre.rsre_core import search_context ctx = make_utf8_ctx(utf8string, bytestart, byteend) if search_context(ctx, pattern): return ctx else: return None
def method_match_operator(self, space, w_s): if w_s is space.w_nil: return space.w_nil s = Coerce.str(space, w_s) ctx, pattern = self.make_ctx(s) matched = rsre_core.search_context(ctx, pattern) self.get_match_result(space, ctx, s, matched) if matched: return space.newint(ctx.match_start) else: return space.w_nil
def method_match(self, space, w_s, w_offset=None): if w_s is space.w_nil: return space.w_nil s = Coerce.str(space, w_s) if w_offset is not None: offset = Coerce.int(space, w_offset) else: offset = 0 ctx = self.make_ctx(s, offset) matched = rsre_core.search_context(ctx) return self.get_match_result(space, ctx, s, matched)
def _match_all_strings(self, extract, s, start, end): ctx = self.make_ctx(s, start, end) matchlist = [] while ctx.match_start <= ctx.end: if not rsre_core.search_context(ctx): break match = extract(ctx, self.groupcount) matchlist.append(match) # Advance starting point for next match no_progress = (ctx.match_start == ctx.match_end) ctx.reset(ctx.match_end + no_progress) return matchlist
def match_port(self, w_port): self.ensure_compiled() if isinstance(w_port, values.W_StringInputPort): # fast path ctx = rsre_core.search(self.code, w_port.str, start=w_port.ptr) if not ctx: return None start, end = ctx.span(0) # the whole match w_port.ptr = end return _extract_result(ctx, self.groupcount) buf = PortBuffer(w_port) ctx = rsre_core.BufMatchContext(self.code, buf, 0, buf.getlength(), 0) matched = rsre_core.search_context(ctx) if not matched: return None return _extract_result(ctx, self.groupcount)
def path_split(self, string): ret = [] ctx = regexp_match(self.cache, "/+", string) last_end = 0 while rsre_core.search_context(ctx): cur_start, cur_end = ctx.match_start, ctx.match_end assert cur_start >= 0 assert cur_end >= cur_start ret.append(string[last_end:cur_start]) ret.append(string[cur_start:cur_end]) last_end = cur_end ctx.reset(last_end) if last_end > 0: ret.append(string[last_end:]) else: ret.append(string) if ret: while len(ret[-1]) == 0: ret.pop() return ret
def ismatch(self, cache, string): string = os.path.normcase(string) ctx = regexp_match(cache, self.regexp, string) return rsre_core.search_context(ctx)
def ismatch(self, cache, string): string = os.path.normcase(string) if string.startswith(".") and not self.match_dotfiles: return False ctx, pattern = regexp_match(cache, self.regexp, string) return rsre_core.search_context(ctx, pattern)
def searchcontext(space, ctx, pattern): try: return rsre_core.search_context(ctx, pattern) except rsre_core.Error as e: raise OperationError(space.w_RuntimeError, space.newtext(e.msg))
def search_context(self, space, ctx): try: return rsre_core.search_context(ctx) except rsre_core.Error, e: raise space.error(space.w_RuntimeError, e.msg)
def match_string_positions(self, s, start=0, end=sys.maxint): ctx = self.make_ctx(s, start, end) if not rsre_core.search_context(ctx, self.code): return None return _extract_spans(ctx, self.groupcount)
def match_string_positions(self, s, start=0, end=sys.maxint): ctx = self.make_ctx(s, start, end) if not rsre_core.search_context(ctx): return None return _extract_spans(ctx, self.groupcount)
def ismatch(self, cache, string): string = os.path.normcase(string) if string.startswith(".") and not self.match_dotfiles: return False ctx = regexp_match(cache, self.regexp, string) return rsre_core.search_context(ctx)
def match_string(self, s, start=0, end=sys.maxint): ctx = self.make_ctx(s, start, end) if not rsre_core.search_context(ctx): return None return _extract_result(ctx, self.groupcount)
def searchcontext(space, ctx): try: return rsre_core.search_context(ctx) except rsre_core.Error as e: raise OperationError(space.w_RuntimeError, space.wrap(e.msg))
def match_string(self, s, start=0, end=sys.maxint): ctx = self.make_ctx(s, start, end) if not rsre_core.search_context(ctx, self.code): return None return _extract_result(ctx, self.groupcount)
def method_eqeqeq(self, space, s): ctx = self.make_ctx(s) matched = rsre_core.search_context(ctx) self.get_match_result(space, ctx, s, matched) return space.newbool(matched)
def method_eqeqeq(self, space, s): ctx = self.make_ctx(s) matched = rsre_core.search_context(ctx) self.get_match_result(space, ctx, matched) return space.newbool(matched)
def method_match(self, space, s): ctx = self.make_ctx(s) matched = rsre_core.search_context(ctx) return self.get_match_result(space, ctx, matched)
def searchcontext(space, ctx): try: return rsre_core.search_context(ctx) except rsre_core.Error, e: raise OperationError(space.w_RuntimeError, space.wrap(e.msg))