Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Henry Spencer's Regexp Engine Revisited

, 2 Jul 2003
A small, Unicode-aware regular expression engine based on Henry Spencer's early work
/* Internal regexp header */
#include "regexp.h"

#ifdef REGEXP_UNICODE
#define LIT(a) L##a
typedef unsigned short UCHAR_TYPE;
#else
#define LIT(a) a
typedef unsigned char UCHAR_TYPE;
#endif

/* NOTE: this structure is completely opaque. */
struct tag_regexp {
    int regnsubexp;			/* Internal use only. */
	CHAR_TYPE regstart;			/* Internal use only. */
	CHAR_TYPE reganch;			/* Internal use only. */
	CHAR_TYPE *regmust;			/* Internal use only. */
	int regmlen;			/* Internal use only. */
	CHAR_TYPE program[1];		/* Unwarranted chumminess with compiler. */
};


#ifdef REGEXP_UNICODE
#include <wchar.h>
#include <wctype.h>
#define cstrlen wcslen
#define cstrcspn wcscspn
#define cstrstr wcsstr
#define cstrchr wcschr
#define cstrncpy wcsncpy
#define cstrncmp wcsncmp
#define cstrspn wcsspn
#define cisalnum iswalnum
#define cisalpha iswalpha
#define cisblank iswblank
#define ciscntrl iswcntrl
#define cisdigit iswdigit
#define cisgraph iswgraph
#define cislower iswlower
#define cisprint iswprint
#define cispunct iswpunct
#define cisspace iswspace
#define cisupper iswupper
#define cisxdigit iswxdigit
#define ctolower towlower
#else
#include <ctype.h>
#define cstrlen strlen
#define cstrcspn strcspn
#define cstrstr strstr
#define cstrchr strchr
#define cstrncpy strncpy
#define cstrncmp strncmp
#define cstrspn strspn
#define cisalnum isalnum
#define cisalpha isalpha
#define cisblank isblank
#define ciscntrl iscntrl
#define cisdigit isdigit
#define cisgraph isgraph
#define cislower islower
#define cisprint isprint
#define cispunct ispunct
#define cisspace isspace
#define cisupper isupper
#define cisxdigit isxdigit
#define ctolower tolower
#endif

#define REGEXP_MAXEXP 0x7fff   /* max number of subexpressions */

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sunspot
Web Developer
Canada Canada
I'm a senior software developer, working at Silanis Technology (http://www.silanis.com). I've acquired quite a bit of experience (usually the hard way!) in Win32 and raw COM programming on the job. In my spare time, I like to monkey around with POSIX code.
 
I'm mostly interested in portable C++ libraries. I'm happiest when I develop portable C++ code--C++ being such a powerful language as long as one keeps clear of the rather nasty subtleties of the language.
 
I hope the articles I contribute will be of some help to someone. If even one person gains a few hours through use of that code, I'll be very happy.
 
When not coding, I like to listen to Anime and try to learn Japanese. It's not working too well so far, unfortunately. :{)

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 3 Jul 2003
Article Copyright 2003 by Sunspot
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid