Example #1
0
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
Example #2
0
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
Example #3
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
Example #4
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
Example #5
0
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
Example #6
0
File: glob.py Project: AlekSi/topaz
    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
Example #7
0
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
Example #8
0
 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
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 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
Example #12
0
 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
Example #13
0
 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)
Example #14
0
 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)
Example #15
0
File: glob.py Project: AlekSi/topaz
    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
Example #16
0
File: glob.py Project: AlekSi/topaz
 def ismatch(self, cache, string):
     string = os.path.normcase(string)
     ctx = regexp_match(cache, self.regexp, string)
     return rsre_core.search_context(ctx)
Example #17
0
 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)
Example #18
0
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))
Example #19
0
 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)
Example #20
0
 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)
Example #21
0
 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)
Example #22
0
 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 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)
Example #24
0
 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)
Example #25
0
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))
Example #26
0
 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)
Example #27
0
 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)
Example #28
0
 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)
Example #29
0
 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)
Example #30
0
 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)
Example #31
0
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))