Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source libSC Regex Reiter.c
Document Actions

Reiter.c

by Michael L Powell last modified 2007-01-26 03:24

Click here to get the file

Size 1.7 kB - File type text/plain

File contents

/*ident	"@(#)Regex:Reiter.c	3.1" */
/******************************************************************************
*
* C++ Standard Components, Release 3.0.
*
* Copyright (c) 1991, 1992 AT&T and Unix System Laboratories, Inc.
* Copyright (c) 1988, 1989, 1990 AT&T.  All Rights Reserved.
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T and Unix System
* Laboratories, Inc.  The copyright notice above does not evidence
* any actual or intended publication of such source code.
*
******************************************************************************/

#include "Regexlib.h"

static Subex foo;
static const Substrinfo nomatch = {-1, 0};

Regexiter::Regexiter(const Regex &_r, const char *_start, style _s)
: r(_r), start(_start), p(_start), s(_s) {
}	

Regexiter::~Regexiter() {
}
	
#define max(A,B) ((A)>(B)?(A):(B))


Substrinfo 
Regexiter::next() {
	return next(foo);
}

Substrinfo 
Regexiter::next(String &the_substr) {
	return next(foo, the_substr);
}

Substrinfo 
Regexiter::next(Subex &subex, String &the_substr) {
	Substrinfo m = next(subex);
	if (m)
		the_substr.assign(start + m.i, m.len);
	return m;
}

Substrinfo 
Regexiter::next(Subex & subex) {
	if (p == 0)
		return nomatch;
	Substrinfo m = r.match(p, subex, p==start);

	// so indices returned by subex() will be wrt start
	subex.base = start;

	if (!m) {
		p = 0;
		return nomatch;
	}

	p += m.i;
	// make index wrt start
	m.i = p - start;
	if (*p == '\0') {  // if match occurred at end of string
		assert(m.len == 0);
		p = 0;
	}
	else {
		if (s == overlapping)
			++p;
		else
			p += max(m.len, 1);
	}
	return m;
}

const Regex &
Regexiter::the_regex() {
	return r;
}

const char *
Regexiter::the_target() {
	return start;
}

Regexiter::style
Regexiter::the_style() {
	return s;
}
« March 2024 »
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: