This commit is contained in:
FluorescentCIAAfricanAmerican
2020-04-22 12:56:21 -04:00
commit 3bf9df6b27
15370 changed files with 5489726 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
#ifndef CREGEX_H
#include <jm/cregex.h>
#endif
+11
View File
@@ -0,0 +1,11 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#ifndef CREGEX_H
#include <jm/cregex.h>
#endif
+13
View File
@@ -0,0 +1,13 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#ifndef __FILEITER_H
#include <jm/fileiter.h>
#endif
+309
View File
@@ -0,0 +1,309 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE cregex.h
* VERSION 2.12
*/
#ifndef CREGEX_H
#define CREGEX_H
#include <jm/jm_cfg.h>
/* include these defs only for POSIX compatablity */
typedef int regoff_t;
typedef struct
{
unsigned int re_magic;
unsigned int re_nsub; /* number of parenthesized subexpressions */
const char* re_endp; /* end pointer for REG_PEND */
void* guts; /* none of your business :-) */
unsigned int eflags; /* none of your business :-) */
} regex_tA;
#ifndef JM_NO_WCSTRING
typedef struct
{
unsigned int re_magic;
unsigned int re_nsub; /* number of parenthesized subexpressions */
const wchar_t* re_endp; /* end pointer for REG_PEND */
void* guts; /* none of your business :-) */
unsigned int eflags; /* none of your business :-) */
} regex_tW;
#endif
typedef struct
{
regoff_t rm_so; /* start of match */
regoff_t rm_eo; /* end of match */
} regmatch_t;
/* regcomp() flags */
#define REG_BASIC 0000
#define REG_EXTENDED 0001
#define REG_ICASE 0002
#define REG_NOSUB 0004
#define REG_NEWLINE 0010
#define REG_NOSPEC 0020
#define REG_PEND 0040
#define REG_DUMP 0200
#define REG_NOCOLLATE 0400
#define REG_ASSERT 15
#define REG_INVARG 16
#define REG_ATOI 255 /* convert name to number (!) */
#define REG_ITOA 0400 /* convert number to name (!) */
/* regexec() flags */
#define REG_NOTBOL 00001
#define REG_NOTEOL 00002
#define REG_STARTEND 00004
#ifdef __cplusplus
extern "C" {
#endif
JM_IX_DECL int RE_CCALL regcompA(regex_tA*, const char*, int);
JM_IX_DECL unsigned int RE_CCALL regerrorA(int, const regex_tA*, char*, unsigned int);
JM_IX_DECL int RE_CCALL regexecA(const regex_tA*, const char*, unsigned int, regmatch_t*, int);
JM_IX_DECL void RE_CCALL regfreeA(regex_tA*);
#ifndef JM_NO_WCSTRING
JM_IX_DECL int RE_CCALL regcompW(regex_tW*, const wchar_t*, int);
JM_IX_DECL unsigned int RE_CCALL regerrorW(int, const regex_tW*, wchar_t*, unsigned int);
JM_IX_DECL int RE_CCALL regexecW(const regex_tW*, const wchar_t*, unsigned int, regmatch_t*, int);
JM_IX_DECL void RE_CCALL regfreeW(regex_tW*);
#endif
#ifdef UNICODE
#define regcomp regcompW
#define regerror regerrorW
#define regexec regexecW
#define regfree regfreeW
#define regex_t regex_tW
#else
#define regcomp regcompA
#define regerror regerrorA
#define regexec regexecA
#define regfree regfreeA
#define regex_t regex_tA
#endif
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
JM_NAMESPACE(__JM)
#endif
/* regerror() flags */
typedef enum
{
REG_NOERROR = 0, /* Success. */
REG_NOMATCH = 1, /* Didn't find a match (for regexec). */
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
REG_BADPAT = 2, /* Invalid pattern. */
REG_ECOLLATE = 3, /* Undefined collating element. */
REG_ECTYPE = 4, /* Invalid character class name. */
REG_EESCAPE = 5, /* Trailing backslash. */
REG_ESUBREG = 6, /* Invalid back reference. */
REG_EBRACK = 7, /* Unmatched left bracket. */
REG_EPAREN = 8, /* Parenthesis imbalance. */
REG_EBRACE = 9, /* Unmatched \{. */
REG_BADBR = 10, /* Invalid contents of \{\}. */
REG_ERANGE = 11, /* Invalid range end. */
REG_ESPACE = 12, /* Ran out of memory. */
REG_BADRPT = 13, /* No preceding re for repetition op. */
REG_EEND = 14, /* unexpected end of expression */
REG_ESIZE = 15, /* expression too big */
REG_ERPAREN = 16, /* unmatched right parenthesis */
REG_EMPTY = 17, /* empty expression */
REG_E_MEMORY = 18, /* out of memory */
REG_E_UNKNOWN = 19 /* unknown error */
} reg_errcode_t;
enum match_flags
{
match_default = 0,
match_not_bol = 1, // first is not start of line
match_not_eol = match_not_bol << 1, // last is not end of line
match_not_bob = match_not_eol << 1, // first is not start of buffer
match_not_eob = match_not_bob << 1, // last is not end of buffer
match_not_bow = match_not_eob << 1, // first is not start of word
match_not_eow = match_not_bow << 1, // last is not end of word
match_not_dot_newline = match_not_eow << 1, // \n is not matched by '.'
match_not_dot_null = match_not_dot_newline << 1, // '\0' is not matched by '.'
match_prev_avail = match_not_dot_null << 1, // *--first is a valid expression
match_init = match_prev_avail << 1, // internal use
match_any = match_init << 1, // don't care what we match
match_not_null = match_any << 1, // string can't be null
match_continuous = match_not_null << 1, // each grep match must continue from
// uninterupted from the previous one
match_stop = match_continuous << 1 // stop after first match (grep)
};
#ifdef __cplusplus
JM_END_NAMESPACE
#endif
//
// C++ high level wrapper goes here:
//
#if defined(__cplusplus) && !defined(JM_NO_STRING_H)
#include <string>
#include <vector>
JM_NAMESPACE(__JM)
class RegExData;
class RegEx;
struct pred1;
struct pred2;
struct pred3;
struct pred4;
typedef bool (*GrepCallback)(const RegEx& expression);
typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression);
typedef bool (*FindFilesCallback)(const char* file);
class JM_IX_DECL RegEx
{
private:
RegExData* pdata;
public:
RegEx();
RegEx(const RegEx& o);
~RegEx();
RegEx(const char* c, bool icase = false);
RegEx(const __JM_STD::string& s, bool icase = false);
RegEx& operator=(const RegEx& o);
RegEx& operator=(const char* p);
RegEx& operator=(const __JM_STD::string& s){ return this->operator=(s.c_str()); }
unsigned int SetExpression(const char* p, bool icase = false);
unsigned int SetExpression(const __JM_STD::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); }
__JM_STD::string Expression()const;
//
// now matching operators:
//
bool Match(const char* p, unsigned int flags = match_default);
bool Match(const __JM_STD::string& s, unsigned int flags = match_default) { return Match(s.c_str(), flags); }
bool Search(const char* p, unsigned int flags = match_default);
bool Search(const __JM_STD::string& s, unsigned int flags = match_default) { return Search(s.c_str(), flags); }
unsigned int Grep(GrepCallback cb, const char* p, unsigned int flags = match_default);
unsigned int Grep(GrepCallback cb, const __JM_STD::string& s, unsigned int flags = match_default) { return Grep(cb, s.c_str(), flags); }
unsigned int Grep(__JM_STD::vector<__JM_STD::string>& v, const char* p, unsigned int flags = match_default);
unsigned int Grep(__JM_STD::vector<__JM_STD::string>& v, const __JM_STD::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); }
unsigned int Grep(__JM_STD::vector<unsigned int>& v, const char* p, unsigned int flags = match_default);
unsigned int Grep(__JM_STD::vector<unsigned int>& v, const __JM_STD::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); }
unsigned int GrepFiles(GrepFileCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default);
unsigned int GrepFiles(GrepFileCallback cb, const __JM_STD::string& files, bool recurse = false, unsigned int flags = match_default) { return GrepFiles(cb, files.c_str(), recurse, flags); }
unsigned int FindFiles(FindFilesCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default);
unsigned int FindFiles(FindFilesCallback cb, const __JM_STD::string& files, bool recurse = false, unsigned int flags = match_default) { return FindFiles(cb, files.c_str(), recurse, flags); }
//
// now operators for returning what matched in more detail:
//
unsigned int Position(int i = 0)const;
unsigned int Length(int i = 0)const;
unsigned int Line()const;
unsigned int Marks()const;
__JM_STD::string What(int i = 0)const;
__JM_STD::string operator[](int i)const { return What(i); }
friend struct pred1;
friend struct pred2;
friend struct pred3;
friend struct pred4;
};
JM_END_NAMESPACE
#if !defined(JM_NO_NAMESPACES) && !defined(JM_NO_USING) && defined(__cplusplus)
using __JM::RegEx;
using __JM::GrepCallback;
using __JM::GrepFileCallback;
using __JM::FindFilesCallback;
#endif
#endif // __cplusplus
#if !defined(JM_NO_NAMESPACES) && !defined(JM_NO_USING) && defined(__cplusplus)
using __JM::match_flags;
using __JM::reg_errcode_t;
using __JM::REG_NOERROR;
using __JM::REG_NOMATCH;
using __JM::REG_BADPAT;
using __JM::REG_ECOLLATE;
using __JM::REG_ECTYPE;
using __JM::REG_EESCAPE;
using __JM::REG_ESUBREG;
using __JM::REG_EBRACK;
using __JM::REG_EPAREN;
using __JM::REG_EBRACE;
using __JM::REG_BADBR;
using __JM::REG_ERANGE;
using __JM::REG_ESPACE;
using __JM::REG_BADRPT;
using __JM::REG_EEND;
using __JM::REG_ESIZE;
using __JM::REG_ERPAREN;
using __JM::REG_EMPTY;
using __JM::REG_E_MEMORY;
using __JM::REG_E_UNKNOWN;
using __JM::match_default;
using __JM::match_not_bol;
using __JM::match_not_eol;
using __JM::match_not_bob;
using __JM::match_not_eob;
using __JM::match_not_bow;
using __JM::match_not_eow;
using __JM::match_not_dot_newline;
using __JM::match_not_dot_null;
using __JM::match_prev_avail;
using __JM::match_init;
using __JM::match_any;
using __JM::match_not_null;
using __JM::match_continuous;
using __JM::match_stop;
#endif
#endif
+368
View File
@@ -0,0 +1,368 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
*
* FILE fileiter.h
* VERSION 2.12
*
* this file declares various platform independent file and directory
* iterators, plus binary file input in the form of class map_file.
*
*/
#ifndef __FILEITER_H
#define __FILEITER_H
#include <jm/jm_cfg.h>
#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32)) && !defined(JM_NO_WIN32)
#define FI_W32
#include <windows.h>
JM_NAMESPACE(__JM)
typedef WIN32_FIND_DATA _fi_find_data;
typedef HANDLE _fi_find_handle;
JM_END_NAMESPACE
#define _fi_invalid_handle INVALID_HANDLE_VALUE
#define _fi_dir FILE_ATTRIBUTE_DIRECTORY
#else
#include <stdio.h>
#include <ctype.h>
#ifndef JM_NO_STL
#include <iterator>
#include <list>
#if defined(__SUNPRO_CC) && !defined(JM_NO_NAMESPACES)
using __JM_STD::list;
#endif
#endif
#include <assert.h>
#include <dirent.h>
#ifndef MAX_PATH
#define MAX_PATH 256
#endif
JM_NAMESPACE(__JM)
struct _fi_find_data
{
unsigned dwFileAttributes;
char cFileName[MAX_PATH];
};
struct _fi_priv_data;
typedef _fi_priv_data* _fi_find_handle;
#define _fi_invalid_handle NULL
#define _fi_dir 1
_fi_find_handle _fi_FindFirstFile(const char* lpFileName, _fi_find_data* lpFindFileData);
bool _fi_FindNextFile(_fi_find_handle hFindFile, _fi_find_data* lpFindFileData);
bool _fi_FindClose(_fi_find_handle hFindFile);
JM_END_NAMESPACE
#ifdef FindFirstFile
#undef FindFirstFile
#endif
#ifdef FindNextFile
#undef FindNextFile
#endif
#ifdef FindClose
#undef FindClose
#endif
#define FindFirstFile _fi_FindFirstFile
#define FindNextFile _fi_FindNextFile
#define FindClose _fi_FindClose
#endif
JM_NAMESPACE(__JM)
#ifdef FI_W32 // win32 mapfile
class JM_IX_DECL mapfile
{
HANDLE hfile;
HANDLE hmap;
const char* _first;
const char* _last;
public:
typedef const char* iterator;
mapfile(){ hfile = hmap = 0; _first = _last = 0; }
mapfile(const char* file){ hfile = hmap = 0; _first = _last = 0; open(file); }
~mapfile(){ close(); }
void open(const char* file);
void close();
const char* begin(){ return _first; }
const char* end(){ return _last; }
size_t size(){ return _last - _first; }
bool valid(){ return (hfile != 0) && (hfile != INVALID_HANDLE_VALUE); }
};
#elif !defined(JM_NO_STL) // use POSIX API to emulate the memory map:
class JM_IX_DECL mapfile_iterator;
class JM_IX_DECL mapfile
{
typedef char* pointer;
FILE* hfile;
long int _size;
pointer* _first;
pointer* _last;
mutable __JM_STD::list<pointer*> condemed;
enum sizes
{
buf_size = 4096
};
void lock(pointer* node)const;
void unlock(pointer* node)const;
public:
typedef mapfile_iterator iterator;
mapfile(){ hfile = 0; _size = 0; _first = _last = 0; }
mapfile(const char* file){ hfile = 0; _size = 0; _first = _last = 0; open(file); }
~mapfile(){ close(); }
void open(const char* file);
void close();
iterator begin()const;
iterator end()const;
unsigned long size()const{ return _size; }
bool valid()const{ return hfile != 0; }
friend class mapfile_iterator;
};
class JM_IX_DECL mapfile_iterator : public JM_RA_ITERATOR(char, long)
{
typedef mapfile::pointer pointer;
pointer* node;
const mapfile* file;
unsigned long offset;
long position()const
{
return file ? ((node - file->_first) * mapfile::buf_size + offset) : 0;
}
void position(long pos)
{
if(file)
{
node = file->_first + (pos / mapfile::buf_size);
offset = pos % mapfile::buf_size;
}
}
public:
mapfile_iterator() { node = 0; file = 0; offset = 0; }
mapfile_iterator(const mapfile* f, long position)
{
file = f;
node = f->_first + position / mapfile::buf_size;
offset = position % mapfile::buf_size;
if(file)
file->lock(node);
}
mapfile_iterator(const mapfile_iterator& i)
{
file = i.file;
node = i.node;
offset = i.offset;
if(file)
file->lock(node);
}
~mapfile_iterator()
{
if(file && node)
file->unlock(node);
}
mapfile_iterator& operator = (const mapfile_iterator& i);
char operator* ()const
{
assert(node >= file->_first);
assert(node < file->_last);
return file ? *(*node + sizeof(int) + offset) : char(0);
}
mapfile_iterator& operator++ ();
mapfile_iterator operator++ (int);
mapfile_iterator& operator-- ();
mapfile_iterator operator-- (int);
mapfile_iterator& operator += (long off)
{
position(position() + off);
return *this;
}
mapfile_iterator& operator -= (long off)
{
position(position() - off);
return *this;
}
friend inline bool operator==(const mapfile_iterator& i, const mapfile_iterator& j)
{
return (i.file == j.file) && (i.node == j.node) && (i.offset == j.offset);
}
#ifndef JM_NO_NOT_EQUAL
friend inline bool operator!=(const mapfile_iterator& i, const mapfile_iterator& j)
{
return !(i == j);
}
#endif
friend inline bool operator<(const mapfile_iterator& i, const mapfile_iterator& j)
{
return i.position() < j.position();
}
friend mapfile_iterator operator + (const mapfile_iterator& i, long off);
friend mapfile_iterator operator - (const mapfile_iterator& i, long off);
friend inline long operator - (const mapfile_iterator& i, const mapfile_iterator& j)
{
return i.position() - j.position();
}
};
#endif
// _fi_sep determines the directory separator, either '\\' or '/'
JM_IX_DECL extern const char* _fi_sep;
struct file_iterator_ref
{
_fi_find_handle hf;
_fi_find_data _data;
long count;
};
class JM_IX_DECL file_iterator : public JM_INPUT_ITERATOR(const char*, __JM_STDC::ptrdiff_t)
{
char* _root;
char* _path;
char* ptr;
file_iterator_ref* ref;
public:
file_iterator();
file_iterator(const char* wild);
~file_iterator();
file_iterator(const file_iterator&);
file_iterator& operator=(const file_iterator&);
const char* root() { return _root; }
const char* path() { return _path; }
_fi_find_data* data() { return &(ref->_data); }
void next();
file_iterator& operator++() { next(); return *this; }
file_iterator operator++(int);
const char* operator*() { return path(); }
friend inline bool operator == (const file_iterator& f1, const file_iterator& f2)
{
return ((f1.ref->hf == _fi_invalid_handle) && (f1.ref->hf == _fi_invalid_handle));
}
#ifndef JM_NO_NOT_EQUAL
friend inline bool operator != (const file_iterator& f1, const file_iterator& f2)
{
return !(f1 == f2);
}
#endif
};
inline bool operator < (const file_iterator& f1, const file_iterator& f2)
{
return false;
}
class JM_IX_DECL directory_iterator : public JM_INPUT_ITERATOR(const char*, __JM_STDC::ptrdiff_t)
{
char* _root;
char* _path;
char* ptr;
file_iterator_ref* ref;
public:
directory_iterator();
directory_iterator(const char* wild);
~directory_iterator();
directory_iterator(const directory_iterator& other);
directory_iterator& operator=(const directory_iterator& other);
const char* root() { return _root; }
const char* path() { return _path; }
_fi_find_data* data() { return &(ref->_data); }
void next();
directory_iterator& operator++() { next(); return *this; }
directory_iterator operator++(int);
const char* operator*() { return path(); }
static const char* separator() { return _fi_sep; }
friend inline bool operator == (const directory_iterator& f1, const directory_iterator& f2)
{
return ((f1.ref->hf == _fi_invalid_handle) && (f1.ref->hf == _fi_invalid_handle));
}
#ifndef JM_NO_NOT_EQUAL
friend inline bool operator != (const directory_iterator& f1, const directory_iterator& f2)
{
return !(f1 == f2);
}
#endif
};
inline bool operator < (const directory_iterator& f1, const directory_iterator& f2)
{
return false;
}
JM_END_NAMESPACE
#if !defined(JM_NO_NAMESPACES) && !defined(JM_NO_USING)
using __JM::directory_iterator;
using __JM::file_iterator;
using __JM::mapfile;
#endif
#endif // __WINITER_H
File diff suppressed because it is too large Load Diff
+414
View File
@@ -0,0 +1,414 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#ifndef JM_OPT_H
#define JM_OPT_H
/* #define JM_AUTO_CONFIGURE */
#ifdef JM_AUTO_CONFIGURE
/* Namespace Options: */
/* JM_NO_NAMESPACES Define if your compiler does not support namespaces */
/* #define JM_NO_NAMESPACES */
/* __JM Defines the namespace used for this library,
defaults to "jm", but can be changed by defining
__JM on the command line. */
/* #define __JM */
/* __JM_STD Defines the namespace used by the underlying STL
(if any), defaults to "std", can be changed by
defining __JM_STD on the command line. */
/* #define __JM_STD */
/* __JM_STDC Defines the namespace used by the C Library defs.
Defaults to "std" as recomended by the latest
draft standard, can be redefined by defining
__JM_STDC on the command line. */
/* #define __JM_STDC */
/* Compiler options: */
/* JM_NO_EXCEPTIONS Disables exception handling support. */
/* #define JM_NO_EXCEPTIONS */
/* JM_NO_MUTABLE Disables use of mutable keyword. */
/* #define JM_NO_MUTABLE */
/* JM_INT32 The type for 32-bit integers - what C calls intfast32_t */
/* #define JM_INT32 */
/* JM_NO_DEFAULT_PARAM If templates can not have default parameters. */
/* #define JM_NO_DEFAULT_PARAM */
/* JM_NO_TRICKY_DEFAULT_PARAM If templates can not have derived default parameters. */
/* #define JM_NO_TRICKY_DEFAULT_PARAM */
/* JM_NO_TEMPLATE_TYPENAME If class scope typedefs of the form:
typedef typename X<T> Y;
where T is a template parameter to this,
do not compile unless the typename is omitted. */
/* #define JM_NO_TEMPLATE_TYPENAME */
/* JM_NO_TEMPLATE_FRIEND If template friend declarations are not supported */
/* #define JM_NO_TEMPLATE_FRIEND */
/* JM_PLATFORM_WINDOWS Platform is MS Windows. */
/* #define JM_PLATFORM_WINDOWS */
/* JM_PLATFORM_DOS Platform if MSDOS. */
/* #define JM_PLATFORM_DOS */
/* JM_PLATFORM_W32 Platform is MS Win32 */
/* #define JM_PLATFORM_W32 */
/* JM_NO_WIN32 Disable Win32 support even when present */
/* #define JM_NO_WIN32 */
/* JM_NO_BOOL If bool is not a distict type. */
/* #define JM_NO_BOOL */
/* JM_NO_WCHAR_H If there is no <wchar.h> */
/* #define JM_NO_WCHAR_H */
/* JM_NO_WCTYPE_H If there is no <wctype.h> */
/* #define JM_NO_WCTYPE_H */
/* JM_NO_WCSTRING If there are no wcslen and wcsncmp functions available. */
/* #define JM_NO_WCSTRING */
/* JM_NO_SWPRINTF If there is no swprintf available. */
/* #define JM_NO_SWPRINTF */
/* JM_NO_WSPRINTF If there is no wsprintf available. */
/* #define JM_NO_WSPRINTF */
/* JM_NO_MEMBER_TEMPLATES If member function templates or nested template classes are not allowed. */
/* #define JM_NO_MEMBER_TEMPLATES */
/* JM_NO_TEMPLATE_RETURNS If template functions based on return type are not supported. */
/* #define JM_NO_TEMPLATE_RETURNS */
/* JM_NO_PARTIAL_FUNC_SPEC If partial template function specialisation is not supported */
/* #define JM_NO_PARTIAL_FUNC_SPEC */
/* JM_NO_INT64 If 64bit integers are not supported. */
/* JM_INT64t The type of a 64-bit signed integer if available. */
/* JM_IMM64(val) Declares a 64-bit immediate value by appending any
necessary suffix to val. */
/* JM_INT64_T 0 = NA
1 = short
2 = int
3 = long
4 = int64_t
5 = long long
6 = __int64 */
/* #define JM_INT64_T */
/* JM_NO_CAT Define if the compiler does not support POSIX style
message categories (catopen catgets catclose). */
/* #define JM_NO_CAT */
/* JM_THREADS Define if the compiler supports multiple threads in
the current translation mode. */
/* #define JM_THREADS */
/* JM_TEMPLATE_SPECIALISE Defaults to template<> , ie the template specialisation
prefix, can be redefined to nothing for older compilers. */
/* #define JM_TEMPLATE_SPECIALISE */
/* JM_NESTED_TEMPLATE_DECL Defaults to template, the standard prefix when accessing
nested template classes, can be redefined to nothing if
the compiler does not support this. */
/* #define JM_NESTED_TEMPLATE_DECL */
/* JM_NO_TEMPLATE_INST If explicit template instantiation with the "template class X<T>"
syntax is not supported */
/* #define JM_NO_TEMPLATE_INST */
/* JM_NO_TEMPLATE_MERGE If template in separate translation units don't merge at link time */
/* #define JM_NO_TEMPLATE_MERGE */
/* JM_NO_TEMPLATE_MERGE_A If template merging from library archives is not supported */
/* #define JM_NO_TEMPLATE_MERGE_A */
/* JM_NO_TEMPLATE_SWITCH_MERGE If merging of templates containing switch statements is not supported */
/* #define JM_NO_TEMPLATE_SWITCH_MERGE */
/* RE_CALL Optionally define a calling convention for C++ functions */
/* #define RE_CALL */
/* RE_CCALL Optionally define a calling convention for C functions */
/* #define RE_CCALL */
/* JM_SIZEOF_SHORT sizeof(short) */
/* #define JM_SIZEOF_SHORT */
/* JM_SIZEOF_INT sizeof(int) */
/* #define JM_SIZEOF_INT */
/* JM_SIZEOF_LONG sizeof(long) */
/* #define JM_SIZEOF_LONG */
/* JM_SIZEOF_WCHAR_T sizeof(wchar_t) */
/* #define JM_SIZEOF_WCHAR_T */
/* STL options: */
/* JM_NO_EXCEPTION_H Define if you do not a compliant <exception>
header file. */
/* #define JM_NO_EXCEPTION_H */
/* JM_NO_ITERATOR_H Define if you do not have a version of <iterator>. */
/* #define JM_NO_ITERATOR_H */
/* JM_NO_MEMORY_H Define if <memory> does not fully comply with the
latest standard, and is not auto-recognised,
that means nested template classes
which hardly any compilers support at present. */
/* #define JM_NO_MEMORY_H */
/* JM_NO_LOCALE_H Define if there is no verion of the standard
<locale> header available. */
/* #define JM_NO_LOCALE_H */
/* JM_NO_STL Disables the use of any supporting STL code. */
/* #define JM_NO_STL */
/* JM_NO_NOT_EQUAL Disables the generation of operator!= if this
clashes with the STL version. */
/* JM_NO_STRING_H Define if <string> not available */
/* #define JM_NO_STRING_H */
/* JM_NO_STRING_DEF_ARGS Define if std::basic_string<charT> not allowed - in
other words if the template is missing its required
default arguments. */
/* #define JM_NO_STRING_DEF_ARGS */
/* JM_NO_TYPEINFO Define if <typeinfo> is absent or non-standard */
/* #define JM_NO_TYPEINFO */
/* JM_USE_ALGO If <algo.h> not <algorithm> is present */
/* #define JM_USE_ALGO */
/* JM_OLD_IOSTREAM If the new iostreamm classes are not available */
/* #define JM_OLD_IOSTREAM */
/* JM_DISTANCE_T For std::distance:
0 = NA
1 = std::distance(i, j, n)
2 = n = std::distance(i, j) */
/* #define JM_DISTANCE_T */
/* JM_ITERATOR_T Defines generic standard iterator type if available, use this as
a shortcut to define all the other iterator types.
1 = __JM_STD::iterator<__JM_STD::tag_type, T, D, T*, T&>
2 = __JM_STD::iterator<__JM_STD::tag_type, T, D> */
/* #define JM_ITERATOR_T */
/* JM_OI_T For output iterators:
0 = NA
1 = __JM_STD::iterator<__JM_STD::output_iterator_tag, T, D, T*, T&>
2 = __JM_STD::iterator<__JM_STD::output_iterator_tag, T, D>
3 = __JM_STD::output_iterator */
/* #define JM_OI_T */
/* JM_II_T For input iterators:
0 = NA
1 = __JM_STD::iterator<__JM_STD::input_iterator_tag, T, D, T*, T&>
2 = __JM_STD::iterator<__JM_STD::input_iterator_tag, T, D>
3 = __JM_STD::input_iterator<T, D>
4 = __JM_STD::input_iterator<T> */
/* #define JM_II_T */
/* JM_FI_T For forward iterators:
0 = NA
1 = __JM_STD::iterator<__JM_STD::forward_iterator_tag, T, D, T*, T&>
2 = __JM_STD::iterator<__JM_STD::forward_iterator_tag, T, D>
3 = __JM_STD::forward_iterator<T, D> */
/* #define JM_FI_T */
/* JM_BI_T For bidirectional iterators:
0 = NA
1 = __JM_STD::iterator<__JM_STD::bidirectional_iterator_tag, T, D, T*, T&>
2 = __JM_STD::iterator<__JM_STD::bidirectional_iterator_tag, T, D>
3 = __JM_STD::bidirectional_iterator<T, D> */
/* #define JM_BI_T */
/* JM_RI_T For random access iterators:
0 = NA
1 = __JM_STD::iterator<__JM_STD::random_access_iterator_tag, T, D, T*, T&>
2 = __JM_STD::iterator<__JM_STD::random_access_iterator_tag, T, D>
3 = __JM_STD::random_access_iterator<T, D> */
/* #define JM_RI_T */
/* JM_NO_OI_ASSIGN If output iterators ostream_iterator<>, back_insert_iterator<> and
front_insert_iterator<> do not have assignment operators */
/* #define JM_NO_OI_ASSIGN */
#if JM_INT64_T == 0
#define JM_NO_INT64
#elif JM_INT64_T == 1
#define JM_INT64t short
#define JM_IMM64(val) val
#elif JM_INT64_T == 2
#define JM_INT64t int
#define JM_IMM64(val) val
#elif JM_INT64_T == 3
#define JM_INT64t long
#define JM_IMM64(val) val##L
#elif JM_INT64_T == 4
#define JM_INT64t int64_t
#define JM_IMM64(val) INT64_C(val)
#elif JM_INT64_T == 5
#define JM_INT64t long long
#define JM_IMM64(val) val##LL
#elif JM_INT64_T == 6
#define JM_INT64t __int64
#define JM_IMM64(val) val##i64
#else
syntax error: unknown value for JM_INT64_T
#endif
#if JM_DISTANCE_T == 0
# define JM_DISTANCE(i, j, n) n = j - i
#elif JM_DISTANCE_T == 1
# define JM_DISTANCE(i, j, n) n = __JM_STD::distance(i, j)
#elif JM_DISTANCE_T == 2
# define JM_DISTANCE(i, j, n) (n = 0, __JM_STD::distance(i, j, n))
#else
syntax erorr
#endif
#ifdef JM_ITERATOR_T
#ifndef JM_OI_T
#define JM_OI_T JM_ITERATOR_T
#endif
#ifndef JM_II_T
#define JM_II_T JM_ITERATOR_T
#endif
#ifndef JM_FI_T
#define JM_FI_T JM_ITERATOR_T
#endif
#ifndef JM_BI_T
#define JM_BI_T JM_ITERATOR_T
#endif
#ifndef JM_RI_T
#define JM_RI_T JM_ITERATOR_T
#endif
#endif
#if JM_OI_T == 0
# define JM_OUTPUT_ITERATOR(T, D) dummy_iterator_base<T>
#elif JM_OI_T == 1
# define JM_OUTPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::output_iterator_tag, T, D, T*, T&>
#elif JM_OI_T == 2
# define JM_OUTPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::output_iterator_tag, T, D>
#elif JM_OI_T == 3
# define JM_OUTPUT_ITERATOR(T, D) __JM_STD::output_iterator
#else
syntax error
#endif
#if JM_II_T == 0
# define JM_INPUT_ITERATOR(T, D) dummy_iterator_base<T>
#elif JM_II_T == 1
#define JM_INPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::input_iterator_tag, T, D, T*, T&>
#elif JM_II_T == 2
#define JM_INPUT_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::input_iterator_tag, T, D>
#elif JM_II_T == 3
# define JM_INPUT_ITERATOR(T, D) __JM_STD::input_iterator<T, D>
#elif JM_II_T == 4
# define JM_INPUT_ITERATOR(T, D) __JM_STD::input_iterator<T>
#else
syntax error
#endif
#if JM_FI_T == 0
# define JM_FWD_ITERATOR(T, D) dummy_iterator_base<T>
#elif JM_FI_T == 1
# define JM_FWD_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::forward_iterator_tag, T, D, T*, T&>
#elif JM_FI_T == 2
# define JM_FWD_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::forward_iterator_tag, T, D>
#elif JM_FI_T == 3
# define JM_FWD_ITERATOR(T, D) __JM_STD::forward_iterator<T, D>
#else
syntax error
#endif
#if JM_BI_T == 0
# define JM_BIDI_ITERATOR(T, D) dummy_iterator_base<T>
#elif JM_BI_T == 1
# define JM_BIDI_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::bidirectional_iterator_tag, T, D, T*, T&>
#elif JM_BI_T == 2
# define JM_BIDI_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::bidirectional_iterator_tag, T, D>
#elif JM_BI_T == 3
# define JM_BIDI_ITERATOR(T, D) __JM_STD::bidirectional_iterator<T, D>
#else
syntax error
#endif
#if JM_RI_T == 0
# define JM_RA_ITERATOR(T, D) dummy_iterator_base<T>
#elif JM_RI_T == 1
# define JM_RA_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::random_access_iterator_tag, T, D, T*, T&>
#elif JM_RI_T == 2
# define JM_RA_ITERATOR(T, D) __JM_STD::iterator<__JM_STD::random_access_iterator_tag, T, D>
#elif JM_RI_T == 3
# define JM_RA_ITERATOR(T, D) __JM_STD::random_access_iterator<T, D>
#else
syntax error
#endif
#ifndef JM_NO_EXCEPTION_H
#include <exception>
#endif
#ifndef JM_NO_ITERATOR_H
#include <iterator>
#ifdef JM_USE_ALGO
#include <algo.h>
#else
#include <algorithm>
#endif
#endif
#ifdef JM_NO_MEMORY_H
#define JM_OLD_ALLOCATORS
#define REBIND_INSTANCE(x, y, inst) re_alloc_binder<x, y>(inst)
#define REBIND_TYPE(x, y) re_alloc_binder<x, y>
#define JM_DEF_ALLOC_PARAM(x) JM_DEFAULT_PARAM( jm_def_alloc )
#define JM_DEF_ALLOC(x) jm_def_alloc
#define JM_NEED_BINDER
#define JM_NEED_ALLOC
#else
#include <memory>
#define REBIND_INSTANCE(x, y, inst) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other(inst)
#define REBIND_TYPE(x, y) y::JM_NESTED_TEMPLATE_DECL rebind<x>::other
#define JM_DEF_ALLOC_PARAM(x) JM_TRICKY_DEFAULT_PARAM( __JM_STD::allocator<x> )
#define JM_DEF_ALLOC(x) __JM_STD::allocator<x>
#endif
#endif // JM_AUTO_CONFIGURE
#endif /* JM_OPT_H */
+209
View File
@@ -0,0 +1,209 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE jstack.h
* VERSION 2.12
*/
#ifndef __JSTACH_H
#define __JSTACK_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
JM_NAMESPACE(__JM)
//
// class jstack
// simplified stack optimised for push/peek/pop
// operations, we could use std::stack<std::vector<T>> instead...
//
template <class T, class Allocator JM_DEF_ALLOC_PARAM(T) >
class jstack
{
private:
typedef JM_MAYBE_TYPENAME REBIND_TYPE(unsigned char, Allocator) alloc_type;
typedef typename REBIND_TYPE(T, Allocator)::size_type size_type;
struct node
{
node* next;
T* start; // first item
T* end; // last item
T* last; // end of storage
};
//
// empty base member optimisation:
struct data : public alloc_type
{
unsigned char buf[sizeof(T)*16];
data(const Allocator& a) : alloc_type(a){}
};
data alloc_inst;
mutable node* stack;
mutable node* unused;
node base;
size_type block_size;
void RE_CALL pop_aux()const;
void RE_CALL push_aux();
public:
jstack(size_type n = 64, const Allocator& a = Allocator());
~jstack();
node* RE_CALL get_node()
{
node* new_stack = (node*)alloc_inst.allocate(sizeof(node) + sizeof(T) * block_size);
new_stack->last = (T*)(new_stack+1);
new_stack->start = new_stack->end = new_stack->last + block_size;
new_stack->next = 0;
return new_stack;
}
bool RE_CALL empty()
{
return (stack->start == stack->end) && (stack->next == 0);
}
bool RE_CALL good()
{
return (stack->start != stack->end) || (stack->next != 0);
}
T& RE_CALL peek()
{
if(stack->start == stack->end)
pop_aux();
return *stack->end;
}
const T& RE_CALL peek()const
{
if(stack->start == stack->end)
pop_aux();
return *stack->end;
}
void RE_CALL pop()
{
if(stack->start == stack->end)
pop_aux();
jm_destroy(stack->end);
++(stack->end);
}
void RE_CALL pop(T& t)
{
if(stack->start == stack->end)
pop_aux();
t = *stack->end;
jm_destroy(stack->end);
++(stack->end);
}
void RE_CALL push(const T& t)
{
if(stack->end == stack->last)
push_aux();
--(stack->end);
jm_construct(stack->end, t);
}
};
template <class T, class Allocator>
jstack<T, Allocator>::jstack(size_type n, const Allocator& a)
: alloc_inst(a)
{
unused = 0;
block_size = n;
stack = &base;
base.last = (T*)alloc_inst.buf;
base.end = base.start = base.last + 16;
base.next = 0;
}
template <class T, class Allocator>
void RE_CALL jstack<T, Allocator>::push_aux()
{
// make sure we have spare space on TOS:
register node* new_node;
if(unused)
{
new_node = unused;
unused = new_node->next;
new_node->next = stack;
stack = new_node;
}
else
{
new_node = get_node();
new_node->next = stack;
stack = new_node;
}
}
template <class T, class Allocator>
void RE_CALL jstack<T, Allocator>::pop_aux()const
{
// make sure that we have a valid item
// on TOS:
jm_assert(stack->next);
register node* p = stack;
stack = p->next;
p->next = unused;
unused = p;
}
template <class T, class Allocator>
jstack<T, Allocator>::~jstack()
{
node* condemned;
while(good())
pop();
while(unused)
{
condemned = unused;
unused = unused->next;
alloc_inst.deallocate((unsigned char*)condemned, sizeof(node) + sizeof(T) * block_size);
}
while(stack != &base)
{
condemned = stack;
stack = stack->next;
alloc_inst.deallocate((unsigned char*)condemned, sizeof(node) + sizeof(T) * block_size);
}
}
JM_END_NAMESPACE
#endif
+79
View File
@@ -0,0 +1,79 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_cls.h
* VERSION 2.12
* This is an internal header file, do not include directly.
* character class lookup, for regular
* expression library.
*/
#ifndef RE_CLS_H
#define RE_CLS_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#ifndef RE_STR_H
#include <jm/re_str.h>
#endif
JM_NAMESPACE(__JM)
#define re_classes_max 14
void RE_CALL re_init_classes();
void RE_CALL re_free_classes();
void RE_CALL re_update_classes();
JM_IX_DECL jm_uintfast32_t RE_CALL __re_lookup_class(const char* p);
inline jm_uintfast32_t RE_CALL re_lookup_class(const char* first, const char* last)
{
re_str<char> s(first, last);
return __re_lookup_class(s.c_str());
}
#ifndef JM_NO_WCSTRING
inline jm_uintfast32_t RE_CALL re_lookup_class(const wchar_t* first, const wchar_t* last)
{
re_str<wchar_t> s(first, last);
unsigned int len = re_strnarrow((char*)NULL, 0, s.c_str());
auto_array<char> buf(new char[len]);
re_strnarrow((char*)buf, len, s.c_str());
len = __re_lookup_class((char*)buf);
return len;
}
#endif
#ifdef RE_LOCALE_CPP
extern jm_uintfast32_t re_char_class_id[];
extern const char* re_char_class_names[];
#endif
JM_END_NAMESPACE
#endif
+61
View File
@@ -0,0 +1,61 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_coll.h
* VERSION 2.12
* This is an internal header file, do not include directly
*/
#ifndef RE_COLL_H
#define RE_COLL_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#ifndef RE_STR_H
#include <re_str.h>
#endif
JM_NAMESPACE(__JM)
JM_IX_DECL bool RE_CALL re_lookup_def_collate_name(re_str<char>& buf, const char* name);
void RE_CALL re_init_collate();
void RE_CALL re_free_collate();
void RE_CALL re_update_collate();
JM_IX_DECL bool RE_CALL __re_lookup_collate(re_str<char>& buf, const char* p);
inline bool RE_CALL re_lookup_collate(re_str<char>& buf, const char* first, const char* last)
{
re_str<char> s(first, last);
return __re_lookup_collate(buf, s.c_str());
}
#ifndef JM_NO_WCSTRING
JM_IX_DECL bool RE_CALL re_lookup_collate(re_str<wchar_t>& out, const wchar_t* first, const wchar_t* last);
#endif
JM_END_NAMESPACE
#endif
+112
View File
@@ -0,0 +1,112 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_kmp.h
* VERSION 2.12
* Knuth-Morris-Pratt search.
*/
#ifndef __RE_KMP_H
#define __RE_KMP_H
#ifdef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
JM_NAMESPACE(__JM)
template <class charT>
struct kmp_info
{
unsigned int size;
unsigned int len;
const charT* pstr;
int kmp_next[1];
};
template <class charT, class Allocator>
void kmp_free(kmp_info<charT>* pinfo, Allocator a)
{
typedef JM_MAYBE_TYPENAME REBIND_TYPE(char, Allocator) atype;
atype(a).deallocate((char*)pinfo, pinfo->size);
}
template <class iterator, class charT, class Trans, class Allocator>
kmp_info<charT>* kmp_compile(iterator first, iterator last, charT, Trans translate, Allocator a
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
typedef JM_MAYBE_TYPENAME REBIND_TYPE(char, Allocator) atype;
int i, j, m;
i = 0;
m = 0;
JM_DISTANCE(first, last, m);
++m;
unsigned int size = sizeof(kmp_info<charT>) + sizeof(int)*m + sizeof(charT)*m;
--m;
//
// allocate struct and fill it in:
//
kmp_info<charT>* pinfo = (kmp_info<charT>*)atype(a).allocate(size);
pinfo->size = size;
pinfo->len = m;
charT* p = (charT*)((char*)pinfo + sizeof(kmp_info<charT>) + sizeof(int)*(m+1));
pinfo->pstr = p;
while(first != last)
{
*p = translate(*first MAYBE_PASS_LOCALE(l));
++first;
++p;
}
*p = 0;
//
// finally do regular kmp compile:
//
j = pinfo->kmp_next[0] = -1;
while (i < m)
{
while ((j > -1) && (pinfo->pstr[i] != pinfo->pstr[j]))
j = pinfo->kmp_next[j];
++i;
++j;
if (pinfo->pstr[i] == pinfo->pstr[j])
pinfo->kmp_next[i] = pinfo->kmp_next[j];
else
pinfo->kmp_next[i] = j;
}
return pinfo;
}
JM_END_NAMESPACE // namespace regex
#endif // __RE_KMP_H
+155
View File
@@ -0,0 +1,155 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_lib.h
* VERSION 2.12
* Automatic library file inclusion.
*/
#ifndef RE_LIB_H
#define RE_LIB_H
#if defined(_MSC_VER) && !defined(RE_BUILD_DLL)
#ifdef _DLL
#ifdef _DEBUG
#pragma comment(lib, "mre200dl.lib")
#else // DEBUG
#pragma comment(lib, "mre200l.lib")
#endif // _DEBUG
#else // _DLL
#ifdef _MT
#ifdef _DEBUG
#pragma comment(lib, "mre200dm.lib")
#else //_DEBUG
#pragma comment(lib, "mre200m.lib")
#endif //_DEBUG
#else //_MT
#ifdef _DEBUG
#pragma comment(lib, "mre200d.lib")
#else //_DEBUG
#pragma comment(lib, "mre200.lib")
#endif //_DEBUG
#endif //_MT
#endif //_DLL
#endif //_MSC_VER
#if defined(__BORLANDC__) && !defined(RE_BUILD_DLL)
#if (__BORLANDC__ > 0x520) && !defined(_NO_VCL)
#define JM_USE_VCL
#endif
#if __BORLANDC__ <= 0x520
#ifdef JM_USE_VCL
#ifdef _RTLDLL
#pragma comment(lib, "b2re200lv.lib")
#else
#pragma comment(lib, "b2re200v.lib")
#endif
#else // VCL
#ifdef _RTLDLL
#ifdef __MT__
#pragma comment(lib, "b2re200lm.lib")
#else // __MT__
#pragma comment(lib, "b2re200l.lib")
#endif // __MT__
#else //_RTLDLL
#ifdef __MT__
#pragma comment(lib, "b2re200m.lib")
#else // __MT__
#pragma comment(lib, "b2re200.lib")
#endif // __MT__
#endif // _RTLDLL
#endif // VCL
#elif __BORLANDC__ <= 0x530
#ifdef JM_USE_VCL
#ifdef _RTLDLL
#pragma comment(lib, "b3re200lv.lib")
#else
#pragma comment(lib, "b3re200v.lib")
#endif
#else // VCL
#ifdef _RTLDLL
#ifdef __MT__
#pragma comment(lib, "b3re200lm.lib")
#else // __MT__
#pragma comment(lib, "b3re200l.lib")
#endif // __MT__
#else //_RTLDLL
#ifdef __MT__
#pragma comment(lib, "b3re200m.lib")
#else // __MT__
#pragma comment(lib, "b3re200.lib")
#endif // __MT__
#endif // _RTLDLL
#endif // VCL
#else // Version: 0x540
#ifdef JM_USE_VCL
#ifdef _RTLDLL
#pragma comment(lib, "b4re200lv.lib")
#else
#pragma comment(lib, "b4re200v.lib")
#endif
#else // VCL
#ifdef _RTLDLL
#ifdef __MT__
#pragma comment(lib, "b4re200lm.lib")
#else // __MT__
#pragma comment(lib, "b4re200l.lib")
#endif // __MT__
#else //_RTLDLL
#ifdef __MT__
#pragma comment(lib, "b4re200m.lib")
#else // __MT__
#pragma comment(lib, "b4re200.lib")
#endif // __MT__
#endif // _RTLDLL
#endif // VCL
#endif
#endif //__BORLANDC__
#endif // RE_LIB_H
+184
View File
@@ -0,0 +1,184 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_lst.h
* VERSION 2.12
* This is an internal header file, do not include directly.
* re_list support class, for regular
* expression library.
*/
#ifndef RE_LST_H
#define RE_LST_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#include <new.h>
JM_NAMESPACE(__JM)
template <class T, class Allocator>
class re_list
{
public:
struct node
{
node* next;
T t;
node(const T& o) : t(o) {}
};
public:
class iterator
{
node* pos;
public:
iterator() { pos = 0; }
~iterator() {}
iterator(const iterator& i) { pos = i.pos; }
iterator(node* n) { pos = n; }
iterator& operator=(const iterator& i)
{
pos = i.pos;
return *this;
}
bool operator==(iterator& i)
{
return pos == i.pos;
}
bool operator!=(iterator& i)
{
return pos != i.pos;
}
T& operator*() { return pos->t; }
iterator& operator++()
{
pos = pos->next;
return *this;
}
iterator operator++(int)
{
iterator t(*this);
pos = pos->next;
return t;
}
const node* tell()const
{
return pos;
}
};
class const_iterator
{
const node* pos;
public:
const_iterator() { pos = 0; }
~const_iterator() {}
const_iterator(const const_iterator& i) { pos = i.pos; }
const_iterator(const iterator& i) { pos = i.tell(); }
const_iterator(const node* n) { pos = n; }
const_iterator& operator=(const iterator& i)
{
pos = i.tell();
return *this;
}
const_iterator& operator=(const const_iterator& i)
{
pos = i.pos;
return *this;
}
bool operator==(const_iterator& i)
{
return pos == i.pos;
}
bool operator!=(const_iterator& i)
{
return pos != i.pos;
}
const T& operator*() { return pos->t; }
const_iterator& operator++()
{
pos = pos->next;
return *this;
}
const_iterator operator++(int)
{
const_iterator t(*this);
pos = pos->next;
return t;
}
};
private:
typedef JM_MAYBE_TYPENAME REBIND_TYPE(node, Allocator) node_alloc;
struct data : public node_alloc
{
node* first;
data(const Allocator& a) : node_alloc(a), first(0) {}
};
data alloc_inst;
public:
re_list(const Allocator& a = Allocator()) : alloc_inst(a) {}
~re_list() { clear(); }
iterator RE_CALL begin() { return iterator(alloc_inst.first); }
iterator RE_CALL end() { return iterator(0); }
const_iterator RE_CALL begin()const { return const_iterator(alloc_inst.first); }
const_iterator RE_CALL end()const { return const_iterator(0); }
void RE_CALL add(const T& t)
{
node* temp;
temp = alloc_inst.allocate(1);
#ifndef JM_NO_EXCEPTIONS
try{
#endif
alloc_inst.construct(temp, t);
#ifndef JM_NO_EXCEPTIONS
}catch(...){ alloc_inst.deallocate(temp, 1); throw; }
#endif
temp->next = alloc_inst.first;
alloc_inst.first = temp;
}
void RE_CALL clear();
};
template <class T, class Allocator>
void RE_CALL re_list<T, Allocator>::clear()
{
node* temp;
while(alloc_inst.first)
{
temp = alloc_inst.first;
alloc_inst.first = alloc_inst.first->next;
alloc_inst.destroy(temp);
alloc_inst.deallocate(temp, 1);
}
}
JM_END_NAMESPACE
#endif
+90
View File
@@ -0,0 +1,90 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_mss.h
* VERSION 2.12
* This is an internal header file, do not include directly.
* Message helper functions, for regular
* expression library.
*/
#ifndef RE_MSS_H
#define RE_MSS_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
JM_NAMESPACE(__JM)
//
// re_get_message
// returns required buffer size if len is zero
// otherwise fills in buf.
//
JM_IX_DECL unsigned int RE_CALL re_get_default_message(char* buf, unsigned int len, unsigned int id);
JM_IX_DECL unsigned int RE_CALL __re_get_message(char* buf, unsigned int len, unsigned int id);
template <class charT>
unsigned int RE_CALL re_get_message(charT* buf, unsigned int len, unsigned int id)
{
unsigned int size = __re_get_message((char*)0, 0, id);
if(len < size)
return size;
auto_array<char> cb(new char[size]);
__re_get_message((char*)cb, size, id);
size = re_strwiden(buf, len, (char*)cb);
return size;
}
inline unsigned int RE_CALL re_get_message(char* buf, unsigned int len, unsigned int id)
{
return __re_get_message(buf, len, id);
}
//
// declare message initialisers:
//
void RE_CALL re_message_init();
void RE_CALL re_message_update();
void RE_CALL re_message_free();
#ifdef RE_LOCALE_CPP
__JM_STD::messages<char>::string_type RE_CALL re_get_def_message(unsigned int i);
__JM_STD::messages<wchar_t>::string_type RE_CALL re_get_def_message_w(unsigned int i);
extern const char *re_default_error_messages[];
#endif
JM_END_NAMESPACE
#endif
+371
View File
@@ -0,0 +1,371 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_nls.h
* VERSION 2.12
* This is an internal header file, do not include directly
*/
#ifndef RE_NLS_H
#define RE_NLS_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#ifdef RE_LOCALE_CPP
#include <jm/regfac.h>
#endif
#include <limits.h>
JM_NAMESPACE(__JM)
enum char_class_type
{
#ifdef RE_LOCALE_CPP
char_class_none = 0,
char_class_alnum = __JM_STD::ctype_base::alnum,
char_class_alpha = __JM_STD::ctype_base::alpha,
char_class_cntrl = __JM_STD::ctype_base::cntrl,
char_class_digit = __JM_STD::ctype_base::digit,
char_class_graph = __JM_STD::ctype_base::graph,
char_class_lower = __JM_STD::ctype_base::lower,
char_class_print = __JM_STD::ctype_base::print,
char_class_punct = __JM_STD::ctype_base::punct,
char_class_space = __JM_STD::ctype_base::space,
char_class_upper = __JM_STD::ctype_base::upper,
char_class_xdigit = __JM_STD::ctype_base::xdigit,
char_class_blank = 1<<12,
char_class_underscore = 1<<13,
char_class_word = __JM_STD::ctype_base::alnum | char_class_underscore,
char_class_unicode = 1<<14,
char_class_all_base = char_class_alnum | char_class_alpha | char_class_cntrl
| char_class_digit | char_class_graph | char_class_lower
| char_class_print | char_class_punct | char_class_space
| char_class_upper | char_class_xdigit
#elif defined(RE_LOCALE_W32)
char_class_none = 0,
char_class_alnum = C1_ALPHA | C1_DIGIT,
char_class_alpha = C1_ALPHA,
char_class_cntrl = C1_CNTRL,
char_class_digit = C1_DIGIT,
char_class_graph = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA,
char_class_lower = C1_LOWER,
char_class_print = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_BLANK | C1_ALPHA,
char_class_punct = C1_PUNCT,
char_class_space = C1_SPACE,
char_class_upper = C1_UPPER,
char_class_xdigit = C1_XDIGIT,
char_class_blank = C1_BLANK,
char_class_underscore = 0x0200,
char_class_word = C1_ALPHA | C1_DIGIT | char_class_underscore,
char_class_unicode = 0x0400
#else
char_class_none = 0,
char_class_alpha = 1,
char_class_cntrl = char_class_alpha << 1,
char_class_digit = char_class_cntrl << 1,
char_class_lower = char_class_digit << 1,
char_class_punct = char_class_lower << 1,
char_class_space = char_class_punct << 1,
char_class_upper = char_class_space << 1,
char_class_xdigit = char_class_upper << 1,
char_class_blank = char_class_xdigit << 1,
char_class_unicode = char_class_blank << 1,
char_class_underscore = char_class_unicode << 1,
char_class_alnum = char_class_alpha | char_class_digit,
char_class_graph = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore,
char_class_print = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore | char_class_blank,
char_class_word = char_class_alpha | char_class_digit | char_class_underscore
#endif
};
//
// declare our initialise class and functions:
//
template <class charT>
class re_initialiser
{
public:
void update();
};
JM_IX_DECL void RE_CALL re_init();
JM_IX_DECL void RE_CALL re_update();
JM_IX_DECL void RE_CALL re_free();
JM_IX_DECL void RE_CALL re_init_w();
JM_IX_DECL void RE_CALL re_update_w();
JM_IX_DECL void RE_CALL re_free_w();
JM_TEMPLATE_SPECIALISE
class re_initialiser<char>
{
public:
re_initialiser() { re_init(); }
~re_initialiser() { re_free(); }
void RE_CALL update() { re_update(); }
};
#ifndef JM_NO_WCSTRING
JM_TEMPLATE_SPECIALISE
class re_initialiser<wchar_t>
{
public:
re_initialiser() { re_init_w(); }
~re_initialiser() { re_free_w(); }
void RE_CALL update() { re_update_w(); }
};
#endif
//
// start by declaring externals for RE_LOCALE_C
// and RE_LOCALE_W32:
//
JM_IX_DECL extern unsigned char re_syntax_map[];
JM_IX_DECL extern unsigned short re_class_map[];
JM_IX_DECL extern char re_lower_case_map[];
JM_IX_DECL extern char re_zero;
JM_IX_DECL extern char re_ten;
#ifndef JM_NO_WCSTRING
JM_IX_DECL extern unsigned short re_unicode_classes[];
JM_IX_DECL extern const wchar_t* re_lower_case_map_w;
JM_IX_DECL extern wchar_t re_zero_w;
JM_IX_DECL extern wchar_t re_ten_w;
JM_IX_DECL wchar_t RE_CALL re_wtolower(wchar_t c);
JM_IX_DECL bool RE_CALL re_iswclass(wchar_t c, jm_uintfast32_t f);
#endif
JM_IX_DECL const char* RE_CALL re_get_error_str(unsigned int id);
JM_IX_DECL unsigned int RE_CALL re_get_syntax_type(wchar_t c);
#ifdef RE_LOCALE_CPP
__JM_STD::string RE_CALL re_get_error_str(unsigned int id, const __JM_STD::locale&);
#endif
//
// add some API's for character manipulation:
//
inline char RE_CALL re_tolower(char c
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
return JM_USE_FACET(l, __JM_STD::ctype<char>).tolower(c);
#else
return re_lower_case_map[(unsigned char)c];
#endif
}
#ifndef JM_NO_WCSTRING
inline wchar_t RE_CALL re_tolower(wchar_t c
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
return JM_USE_FACET(l, __JM_STD::ctype<wchar_t>).tolower(c);
#else
return c < 256 ? re_lower_case_map_w[c] : re_wtolower(c);
#endif
}
#endif
inline bool RE_CALL re_istype(char c, jm_uintfast32_t f
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
if(JM_USE_FACET(l, __JM_STD::ctype<char>).is((__JM_STD::ctype<char>::mask)(f & char_class_all_base), c))
return true;
if((f & char_class_underscore) && (c == '_'))
return true;
if((f & char_class_blank) && ((c == ' ') || (c == '\t')))
return true;
return false;
#else
return re_class_map[(unsigned char)c] & f;
#endif
}
#ifndef JM_NO_WCSTRING
inline bool RE_CALL re_istype(wchar_t c, jm_uintfast32_t f
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
if(JM_USE_FACET(l, __JM_STD::ctype<wchar_t>).is((__JM_STD::ctype<wchar_t>::mask)(f & char_class_all_base), c))
return true;
if((f & char_class_underscore) && (c == '_'))
return true;
if((f & char_class_blank) && ((c == ' ') || (c == '\t')))
return true;
return false;
#else
return c < 256 ? re_unicode_classes[c] & f : re_iswclass(c, f);
#endif
}
#endif
inline char RE_CALL re_get_zero(char
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
return JM_USE_FACET(l, regfacet<char>).zero();
#else
return re_zero;
#endif
}
#ifndef JM_NO_WCSTRING
inline wchar_t RE_CALL re_get_zero(wchar_t
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
return JM_USE_FACET(l, regfacet<wchar_t>).zero();
#else
return re_zero_w;
#endif
}
#endif
inline char RE_CALL re_get_ten(char
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
return JM_USE_FACET(l, regfacet<char>).ten();
#else
return re_ten;
#endif
}
#ifndef JM_NO_WCSTRING
inline wchar_t RE_CALL re_get_ten(wchar_t
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef RE_LOCALE_CPP
return JM_USE_FACET(l, regfacet<wchar_t>).ten();
#else
return re_ten_w;
#endif
}
#endif
//
// re_toi:
// convert a single character to the int it represents:
//
template <class charT>
unsigned int RE_CALL re_toi(charT c
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
if(re_istype(c, char_class_digit MAYBE_PASS_LOCALE(l)))
return c - re_get_zero(c MAYBE_PASS_LOCALE(l));
if(re_istype(c, char_class_xdigit MAYBE_PASS_LOCALE(l)))
return 10 + re_tolower(c MAYBE_PASS_LOCALE(l)) - re_tolower(re_get_ten(c MAYBE_PASS_LOCALE(l)) MAYBE_PASS_LOCALE(l));
return -1; // error!!
}
//
// re_toi:
// parse an int from the input string
// update first to point to end of int
// on exit.
//
template <class charT>
unsigned int RE_CALL re_toi(const charT*& first, const charT*const last, int radix
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
unsigned int maxval;
if(radix < 0)
{
// if radix is less than zero, then restrict
// return value to charT. NB assumes sizeof(charT) <= sizeof(int)
radix *= -1;
maxval = 1 << (sizeof(charT) * CHAR_BIT - 1);
maxval /= radix;
maxval *= 2;
maxval -= 1;
}
else
{
maxval = (unsigned int)-1;
maxval /= radix;
}
unsigned int result = 0;
unsigned int type = (radix > 10) ? char_class_xdigit : char_class_digit;
while((first != last) && re_istype(*first, type MAYBE_PASS_LOCALE(l)) && (result <= maxval))
{
result *= radix;
result += re_toi(*first MAYBE_PASS_LOCALE(l));
++first;
}
return result;
}
#ifndef JM_NO_WCSTRING
JM_IX_DECL bool RE_CALL re_is_combining(wchar_t c);
#endif
extern const char* regex_message_catalogue;
JM_IX_DECL const char* RE_CALL get_global_locale_name(int);
JM_END_NAMESPACE
#endif
+185
View File
@@ -0,0 +1,185 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_raw.h
* VERSION 2.12
*/
#ifndef RE_RAW_H
#define RE_RAW_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
JM_NAMESPACE(__JM)
union padding
{
void* p;
unsigned int i;
};
//
// class raw_storage
// basically this is a simplified vector<unsigned char>
// this is used by reg_expression for expression storage
//
template <class Allocator>
class raw_storage
{
public:
typedef Allocator alloc_type;
typedef typename REBIND_TYPE(unsigned char, alloc_type)::size_type size_type;
typedef JM_MAYBE_TYPENAME REBIND_TYPE(unsigned char, alloc_type) alloc_inst_type;
typedef typename REBIND_TYPE(unsigned char, alloc_type)::pointer pointer;
private:
//
// empty member optimisation:
struct alloc_data : public alloc_inst_type
{
pointer last;
alloc_data(const Allocator& a) : alloc_inst_type(a){}
} alloc_inst;
pointer start, end;
public:
raw_storage(const Allocator& a = Allocator());
raw_storage(size_type n, const Allocator& a = Allocator());
~raw_storage()
{
alloc_inst.deallocate(start, (alloc_inst.last - start));
}
void RE_CALL resize(size_type n);
void* RE_CALL extend(size_type n)
{
if(size_type(alloc_inst.last - end) < n)
resize(n + (end - start));
register void* result = end;
end += n;
return result;
}
void* RE_CALL insert(size_type pos, size_type n);
size_type RE_CALL size()
{
return end - start;
}
size_type RE_CALL capacity()
{
return alloc_inst.last - start;
}
void* RE_CALL data()const
{
return start;
}
size_type RE_CALL index(void* ptr)
{
return (unsigned char*)ptr - start;
}
void RE_CALL clear()
{
end = start;
}
void RE_CALL align()
{
// move end up to a boundary:
end = (unsigned char*)((long)(end + sizeof(padding) - 1) & ~((long)sizeof(padding) - 1));
}
Allocator RE_CALL allocator()const;
};
template <class Allocator>
CONSTRUCTOR_INLINE raw_storage<Allocator>::raw_storage(const Allocator& a)
: alloc_inst(a)
{
start = end = alloc_inst.allocate(1024);
alloc_inst.last = start + 1024;
}
template <class Allocator>
CONSTRUCTOR_INLINE raw_storage<Allocator>::raw_storage(size_type n, const Allocator& a)
: alloc_inst(a)
{
start = end = alloc_inst.allocate(n);
alloc_inst.last = start + n;
}
template <class Allocator>
Allocator RE_CALL raw_storage<Allocator>::allocator()const
{
return alloc_inst;
}
template <class Allocator>
void RE_CALL raw_storage<Allocator>::resize(size_type n)
{
register size_type newsize = (alloc_inst.last - start) * 2;
register size_type datasize = end - start;
if(newsize < n)
newsize = n;
// extend newsize to WORD/DWORD boundary:
newsize = (newsize + (sizeof(padding) - 1)) & ~(sizeof(padding) - 1);
// allocate and copy data:
register unsigned char* ptr = alloc_inst.allocate(newsize);
memcpy(ptr, start, datasize);
// get rid of old buffer:
alloc_inst.deallocate(start, (alloc_inst.last - start));
// and set up pointers:
start = ptr;
end = ptr + datasize;
alloc_inst.last = ptr + newsize;
}
template <class Allocator>
void* RE_CALL raw_storage<Allocator>::insert(size_type pos, size_type n)
{
jm_assert(pos <= size_type(end - start));
if(size_type(alloc_inst.last - end) < n)
resize(n + (end - start));
register void* result = start + pos;
memmove(start + pos + n, start + pos, (end - start) - pos);
end += n;
return result;
}
JM_END_NAMESPACE
#endif
+301
View File
@@ -0,0 +1,301 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_str.h
* VERSION 2.12
* This is an internal header file, do not include directly.
* String support and helper functions, for regular
* expression library.
*/
#ifndef RE_STR_H
#define RE_STR_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#include <string.h>
JM_NAMESPACE(__JM)
//
// start by defining some template function aliases for C API functions:
//
template <class charT>
size_t RE_CALL re_strlen(const charT *s)
{
size_t len = 0;
while(*s)
{
++s;
++len;
}
return len;
}
template <class charT>
int RE_CALL re_strcmp(const charT *s1, const charT *s2)
{
while(*s1 && *s2)
{
if(*s1 != *s2)
return *s1 - *s2;
++s1;
++s2;
}
return *s1 - *s2;
}
template <class charT>
charT* RE_CALL re_strcpy(charT *s1, const charT *s2)
{
charT* base = s1;
while(*s2)
{
*s1 = *s2;
++s1;
++s2;
}
*s1 = *s2;
return base;
}
template <class charT>
unsigned int RE_CALL re_strwiden(charT *s1, unsigned int len, const char *s2)
{
unsigned int result = 1 + re_strlen(s2);
if(result > len)
return result;
while(*s2)
{
*s1 = (unsigned char)*s2;
++s2;
++s1;
}
*s1 = (unsigned char)*s2;
return result;
}
template <class charT>
unsigned int RE_CALL re_strnarrow(char *s1, unsigned int len, const charT *s2)
{
unsigned int result = 1 + re_strlen(s2);
if(result > len)
return result;
while(*s2)
{
*s1 = (char)(unsigned char)*s2;
++s2;
++s1;
}
*s1 = (char)(unsigned char)*s2;
return result;
}
inline size_t RE_CALL re_strlen(const char *s)
{
return strlen(s);
}
inline int RE_CALL re_strcmp(const char *s1, const char *s2)
{
return strcmp(s1, s2);
}
inline char* RE_CALL re_strcpy(char *s1, const char *s2)
{
return strcpy(s1, s2);
}
#ifndef JM_NO_WCSTRING
inline size_t RE_CALL re_strlen(const wchar_t *s)
{
return wcslen(s);
}
inline int RE_CALL re_strcmp(const wchar_t *s1, const wchar_t *s2)
{
return wcscmp(s1, s2);
}
inline wchar_t* RE_CALL re_strcpy(wchar_t *s1, const wchar_t *s2)
{
return wcscpy(s1, s2);
}
#endif
#if !defined(JM_NO_WCSTRING) || defined(JM_PLATFORM_W32)
JM_IX_DECL unsigned int RE_CALL _re_strnarrow(char *s1, unsigned int len, const wchar_t *s2);
JM_IX_DECL unsigned int RE_CALL _re_strwiden(wchar_t *s1, unsigned int len, const char *s2);
inline unsigned int RE_CALL re_strnarrow(char *s1, unsigned int len, const wchar_t *s2)
{
return _re_strnarrow(s1, len, s2);
}
inline unsigned int RE_CALL re_strwiden(wchar_t *s1, unsigned int len, const char *s2)
{
return _re_strwiden(s1, len, s2);
}
#endif
template <class charT>
charT* RE_CALL re_strdup(const charT* p)
{
charT* buf = new charT[re_strlen(p) + 1];
re_strcpy(buf, p);
return buf;
}
template <class charT>
charT* RE_CALL re_strdup(const charT* p1, const charT* p2)
{
unsigned int len = p2 - p1 + 1;
charT* buf = new charT[len];
memcpy(buf, p1, (len - 1) * sizeof(charT));
*(buf + len - 1) = 0;
return buf;
}
template <class charT>
inline void RE_CALL re_strfree(charT* p)
{
delete[] p;
}
template <class charT>
class re_str
{
charT* buf;
public:
re_str()
{
charT c = 0;
buf = re_strdup(&c);
}
~re_str();
re_str(const re_str& other);
re_str(const charT* p1);
re_str(const charT* p1, const charT* p2);
re_str(charT c);
re_str& RE_CALL operator=(const re_str& other)
{
re_strfree(buf);
buf = re_strdup(other.buf);
return *this;
}
re_str& RE_CALL operator=(const charT* p)
{
re_strfree(buf);
buf = re_strdup(p);
return *this;
}
re_str& RE_CALL operator=(charT c)
{
re_strfree(buf);
buf = re_strdup(&c, &c+1);
return *this;
}
const charT* RE_CALL c_str()const { return buf; }
RE_CALL operator const charT*()const { return buf; }
unsigned int RE_CALL size()const { return re_strlen(buf); }
charT& RE_CALL operator[](unsigned int i) { return buf[i]; }
charT RE_CALL operator[](unsigned int i)const { return buf[i]; }
bool RE_CALL operator==(const re_str& other)const { return re_strcmp(buf, other.buf) == 0; }
bool RE_CALL operator==(const charT* p)const { return re_strcmp(buf, p) == 0; }
bool RE_CALL operator==(const charT c)const
{
if((*buf) && (*buf == c) && (*(buf+1) == 0))
return true;
return false;
}
bool RE_CALL operator!=(const re_str& other)const { return re_strcmp(buf, other.buf) != 0; }
bool RE_CALL operator!=(const charT* p)const { return re_strcmp(buf, p) != 0; }
bool RE_CALL operator!=(const charT c)const { return !(*this == c); }
bool RE_CALL operator<(const re_str& other)const { return re_strcmp(buf, other.buf) < 0; }
bool RE_CALL operator<=(const re_str& other)const { return re_strcmp(buf, other.buf) <= 0; }
bool RE_CALL operator>(const re_str& other)const { return re_strcmp(buf, other.buf) > 0; }
bool RE_CALL operator>=(const re_str& other)const { return re_strcmp(buf, other.buf) >= 0; }
bool RE_CALL operator<(const charT* p)const { return re_strcmp(buf, p) < 0; }
bool RE_CALL operator<=(const charT* p)const { return re_strcmp(buf, p) <= 0; }
bool RE_CALL operator>(const charT* p)const { return re_strcmp(buf, p) > 0; }
bool RE_CALL operator>=(const charT* p)const { return re_strcmp(buf, p) >= 0; }
};
template <class charT>
CONSTRUCTOR_INLINE re_str<charT>::~re_str() { re_strfree(buf); }
template <class charT>
CONSTRUCTOR_INLINE re_str<charT>::re_str(const re_str<charT>& other) { buf = re_strdup(other.buf); }
template <class charT>
CONSTRUCTOR_INLINE re_str<charT>::re_str(const charT* p1) { buf = re_strdup(p1); }
template <class charT>
CONSTRUCTOR_INLINE re_str<charT>::re_str(const charT* p1, const charT* p2) { buf = re_strdup(p1, p2); }
template <class charT>
CONSTRUCTOR_INLINE re_str<charT>::re_str(charT c) { buf = re_strdup(&c, &c+1); }
#ifndef JM_NO_WCSTRING
JM_IX_DECL void RE_CALL re_transform(re_str<wchar_t>& out, const re_str<wchar_t>& in);
#endif
JM_IX_DECL void RE_CALL re_transform(re_str<char>& out, const re_str<char>& in);
template <class charT>
void RE_CALL re_trunc_primary(re_str<charT>& s)
{
for(unsigned int i = 0; i < s.size(); ++i)
{
if(s[i] <= 1)
{
s[i] = 0;
break;
}
}
}
#ifdef RE_LOCALE_C
#define TRANSFORM_ERROR (size_t)-1
#else
#define TRANSFORM_ERROR 0
#endif
JM_END_NAMESPACE
#endif
+169
View File
@@ -0,0 +1,169 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_thrd.h
* VERSION 2.12
* Thread synch helper functions, for regular
* expression library.
*/
#ifndef RE_THRD_H
#define RE_THRD_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#if defined(JM_PLATFORM_W32) && defined(JM_THREADS)
//#include <windows.h>
#endif
#if !defined(JM_PLATFORM_W32) && defined(JM_THREADS)
#include <pthread.h>
#endif
JM_NAMESPACE(__JM)
void RE_CALL re_init_threads();
void RE_CALL re_free_threads();
#ifdef JM_THREADS
#ifndef JM_PLATFORM_W32
typedef pthread_mutex_t CRITICAL_SECTION;
inline void RE_CALL InitializeCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_init(ps, NULL);
}
inline void RE_CALL DeleteCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_destroy(ps);
}
inline void RE_CALL EnterCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_lock(ps);
}
inline void RE_CALL LeaveCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_unlock(ps);
}
#endif
template <class Lock>
class lock_guard
{
typedef Lock lock_type;
public:
lock_guard(lock_type& m, bool aq = true)
: mut(m), owned(false){ acquire(aq); }
~lock_guard()
{ acquire(false); }
void RE_CALL acquire(bool aq = true, DWORD timeout = INFINITE)
{
if(aq && !owned)
{
mut.acquire(true, timeout);
owned = true;
}
else if(!aq && owned)
{
mut.acquire(false);
owned = false;
}
}
private:
lock_type& mut;
bool owned;
};
class critical_section
{
public:
critical_section()
{ InitializeCriticalSection(&hmutex);}
critical_section(const critical_section&)
{ InitializeCriticalSection(&hmutex);}
const critical_section& RE_CALL operator=(const critical_section&)
{return *this;}
~critical_section()
{DeleteCriticalSection(&hmutex);}
private:
void RE_CALL acquire(bool aq, DWORD unused = INFINITE)
{ if(aq) EnterCriticalSection(&hmutex);
else LeaveCriticalSection(&hmutex);
}
CRITICAL_SECTION hmutex;
public:
typedef lock_guard<critical_section> ro_guard;
typedef lock_guard<critical_section> rw_guard;
friend lock_guard<critical_section>;
};
inline bool RE_CALL operator==(const critical_section&, const critical_section&)
{
return false;
}
inline bool RE_CALL operator<(const critical_section&, const critical_section&)
{
return true;
}
typedef lock_guard<critical_section> cs_guard;
JM_IX_DECL extern critical_section* p_re_lock;
JM_IX_DECL extern unsigned int re_lock_count;
#define JM_GUARD(inst) __JM::critical_section::rw_guard g(inst);
#else // JM_THREADS
#define JM_GUARD(inst)
#endif // JM_THREADS
JM_END_NAMESPACE
#endif // sentry
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+168
View File
@@ -0,0 +1,168 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE regfac.h
* VERSION 2.12
*/
#ifndef REGFAC_H
#define REGFAC_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#ifdef RE_LOCALE_CPP
#include <string>
#include <jm/re_str.h>
#include <jm/re_cls.h>
#include <list>
#include <map>
//
// class regfacet
//
// provides syntax data etc, customised versions
// can be installed in an instance of std::locale and imbue'd
// into a reg_expression for per-instance localisation.
//
JM_NAMESPACE(__JM)
template <class charT>
class regfacet : public __JM_STD::locale::facet
{
public:
static __JM_STD::locale::id id;
regfacet(unsigned int i = 0);
jm_uintfast32_t RE_CALL lookup_classname(const charT* first, const charT* last)const;
bool RE_CALL lookup_collatename(re_str<charT>& s, const re_str<charT>& name)const;
unsigned int RE_CALL syntax_type(charT)const;
void RE_CALL update(const __JM_STD::locale&)const;
charT RE_CALL zero()const;
charT RE_CALL ten()const;
protected:
virtual jm_uintfast32_t RE_CALL do_lookup_classname(const charT* first, const charT* last)const = 0;
virtual bool RE_CALL do_lookup_collatename(re_str<charT>& s, const re_str<charT>& name)const = 0;
virtual unsigned int RE_CALL do_syntax_type(charT)const = 0;
virtual void RE_CALL do_update(const __JM_STD::locale&) = 0;
// required by Rogue Wave, not part of standard:
__JM_STD::locale::id& get_id()const { return id; }
~regfacet(){}
};
JM_TEMPLATE_SPECIALISE
class JM_IX_DECL regfacet<char> : public __JM_STD::locale::facet
{
public:
typedef __JM_STD::messages<char>::string_type string_type;
private:
unsigned char syntax_map[256];
string_type name;
char _zero, _ten;
__JM_STD::map<__JM_STD::string, unsigned long, __JM_STD::less<__JM_STD::string> > classes;
__JM_STD::map<re_str<char>, re_str<char>, __JM_STD::less<re_str<char> > > collating_elements;
regfacet(const regfacet&);
#ifdef RE_THREADS
critical_section cs;
#endif
public:
static __JM_STD::locale::id id;
regfacet(unsigned int i = 0);
jm_uintfast32_t RE_CALL lookup_classname(const char* first, const char* last)const { return do_lookup_classname(first, last); }
bool RE_CALL lookup_collatename(re_str<char>& s, const re_str<char>& name)const { return do_lookup_collatename(s, name); }
unsigned int RE_CALL syntax_type(char c)const { return do_syntax_type(c); }
void RE_CALL update(const __JM_STD::locale& l)const { const_cast<regfacet<char>*>(this)->do_update(l); }
char RE_CALL zero()const { return _zero; }
char RE_CALL ten()const { return _ten; }
protected:
virtual jm_uintfast32_t RE_CALL do_lookup_classname(const char* first, const char* last)const;
virtual bool RE_CALL do_lookup_collatename(re_str<char>& s, const re_str<char>& name)const;
virtual unsigned int RE_CALL do_syntax_type(char)const;
virtual void RE_CALL do_update(const __JM_STD::locale&);
// required by Rogue Wave, not part of standard:
__JM_STD::locale::id& get_id()const { return id; }
~regfacet();
};
JM_TEMPLATE_SPECIALISE
class JM_IX_DECL regfacet<wchar_t> : public __JM_STD::locale::facet
{
public:
typedef __JM_STD::messages<wchar_t>::string_type string_type;
private:
__JM_STD::messages<char>::string_type name;
struct syntax_map
{
wchar_t c;
unsigned int type;
};
__JM_STD::list<syntax_map> syntax;
wchar_t _zero, _ten;
__JM_STD::map<__JM_STD::wstring, unsigned long, __JM_STD::less<__JM_STD::wstring> > classes;
const __JM_STD::locale* ploc;
__JM_STD::map<re_str<wchar_t>, re_str<wchar_t>, __JM_STD::less<re_str<wchar_t> > > collating_elements;
regfacet(const regfacet&);
#ifdef RE_THREADS
critical_section cs;
#endif
public:
static __JM_STD::locale::id id;
regfacet(unsigned int i = 0);
jm_uintfast32_t RE_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const { return do_lookup_classname(first, last); }
bool RE_CALL lookup_collatename(re_str<wchar_t>& s, const re_str<wchar_t>& name)const { return do_lookup_collatename(s, name); }
unsigned int RE_CALL syntax_type(wchar_t c)const { return do_syntax_type(c); }
void RE_CALL update(const __JM_STD::locale& l)const { const_cast<regfacet<wchar_t>*>(this)->do_update(l); }
wchar_t RE_CALL zero()const { return _zero; }
wchar_t RE_CALL ten()const { return _ten; }
protected:
virtual jm_uintfast32_t RE_CALL do_lookup_classname(const wchar_t* first, const wchar_t* last)const;
virtual bool RE_CALL do_lookup_collatename(re_str<wchar_t>& s, const re_str<wchar_t>& name)const;
virtual unsigned int RE_CALL do_syntax_type(wchar_t)const;
virtual void RE_CALL do_update(const __JM_STD::locale&);
// required by Rogue Wave, not part of standard:
__JM_STD::locale::id& get_id()const { return id; }
~regfacet();
};
JM_END_NAMESPACE
#endif
#endif
+565
View File
@@ -0,0 +1,565 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE regfmt.h
* VERSION 2.12
*
* Provides formatting output routines for search and replace
* operations. Note this is an internal header file included
* by regex.h, do not include on its own.
*/
#ifndef REGFMT_H
#define REGFMT_H
JM_NAMESPACE(__JM)
template <class O, class I>
O RE_CALL re_copy_out(O out, I first, I last)
{
while(first != last)
{
*out = *first;
++out;
++first;
}
return out;
}
template <class charT>
void RE_CALL re_skip_format(const charT*& fmt
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef JM_NO_TEMPLATE_TYPENAME
typedef char_regex_traits<charT> re_traits_type;
#else
typedef typename char_regex_traits<charT> re_traits_type;
#endif
unsigned int parens = 0;
unsigned int c;
while(*fmt)
{
c = re_traits_type::syntax_type(*fmt MAYBE_PASS_LOCALE(l));
if((c == syntax_colon) && (parens == 0))
{
++fmt;
return;
}
else if(c == syntax_close_bracket)
{
if(parens == 0)
{
++fmt;
return;
}
--parens;
}
else if(c == syntax_open_bracket)
++parens;
else if(c == syntax_slash)
{
++fmt;
if(*fmt == 0)
return;
}
++fmt;
}
}
#ifdef JM_NO_OI_ASSIGN
//
// ugly hack for buggy output iterators
template <class T>
inline void oi_assign(T* p, T v)
{
jm_destroy(p);
jm_construct(p, v);
}
#else
template <class T>
inline void oi_assign(T* p, T v)
{
//
// if you get a compile time error in here then you either
// need to rewrite your output iterator to make it assignable
// (as is required by the standard), or define JM_NO_OI_ASSIGN
// to use the ugly hack above
*p = v;
}
#endif
#if defined(JM_NO_TEMPLATE_SWITCH_MERGE) && !defined(JM_NO_NAMESPACES)
//
// Ugly ugly hack,
// template don't merge if they contain switch statements so declare these
// templates in unnamed namespace (ie with internal linkage), each translation
// unit then gets its own local copy, it works seemlessly but bloats the app.
namespace{
#endif
//
// algorithm reg_format:
// takes the result of a match and a format string
// and merges them to produce a new string which
// is sent to an OutputIterator,
// __reg_format_aux does the actual work:
//
template <class OutputIterator, class iterator, class Allocator, class charT>
OutputIterator RE_CALL __reg_format_aux(OutputIterator out,
const reg_match<iterator, Allocator>& m,
const charT*& fmt,
bool isif
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& l
#endif
)
{
#ifdef JM_NO_TEMPLATE_TYPENAME
typedef char_regex_traits<charT> re_traits_type;
#else
typedef typename char_regex_traits<charT> re_traits_type;
#endif
const charT* fmt_end = fmt;
while(*fmt_end) ++ fmt_end;
while(*fmt)
{
switch(re_traits_type::syntax_type(*fmt MAYBE_PASS_LOCALE(l)))
{
case syntax_dollar:
++fmt;
if(*fmt == 0) // oops trailing $
{
--fmt;
*out = *fmt;
++out;
return out;
}
switch(re_traits_type::syntax_type(*fmt MAYBE_PASS_LOCALE(l)))
{
case syntax_start_buffer:
oi_assign(&out, re_copy_out(out, iterator(m[-1].first), iterator(m[-1].second)));
++fmt;
continue;
case syntax_end_buffer:
oi_assign(&out, re_copy_out(out, iterator(m[-2].first), iterator(m[-2].second)));
++fmt;
continue;
case syntax_digit:
{
unsigned int index = re_traits_type::toi(fmt, fmt_end, 10 MAYBE_PASS_LOCALE(l));
oi_assign(&out, re_copy_out(out, iterator(m[index].first), iterator(m[index].second)));
continue;
}
}
// anything else:
if(*fmt == '&')
{
oi_assign(&out, re_copy_out(out, iterator(m[0].first), iterator(m[0].second)));
++fmt;
}
else
{
// probably an error, treat as a literal '$'
--fmt;
*out = *fmt;
++out;
++fmt;
}
continue;
case syntax_slash:
{
// escape sequence:
charT c;
++fmt;
if(*fmt == 0)
{
--fmt;
*out = *fmt;
++out;
++fmt;
return out;
}
switch(re_traits_type::syntax_type(*fmt MAYBE_PASS_LOCALE(l)))
{
case syntax_a:
c = '\a';
++fmt;
break;
case syntax_f:
c = '\f';
++fmt;
break;
case syntax_n:
c = '\n';
++fmt;
break;
case syntax_r:
c = '\r';
++fmt;
break;
case syntax_t:
c = '\t';
++fmt;
break;
case syntax_v:
c = '\v';
++fmt;
break;
case syntax_x:
++fmt;
if(fmt == fmt_end)
{
*out = *--fmt;
++out;
return out;
}
// maybe have \x{ddd}
if(re_traits_type::syntax_type(*fmt MAYBE_PASS_LOCALE(l)) == syntax_open_brace)
{
++fmt;
if(fmt == fmt_end)
{
fmt -= 2;
*out = *fmt;
++out;
++fmt;
continue;
}
if(re_traits_type::is_class(*fmt, char_class_xdigit MAYBE_PASS_LOCALE(l)) == false)
{
fmt -= 2;
*out = *fmt;
++out;
++fmt;
continue;
}
c = (charT)re_traits_type::toi(fmt, fmt_end, -16 MAYBE_PASS_LOCALE(l));
if(re_traits_type::syntax_type(*fmt MAYBE_PASS_LOCALE(l)) != syntax_close_brace)
{
while(re_traits_type::syntax_type(*fmt MAYBE_PASS_LOCALE(l)) != syntax_slash)
--fmt;
++fmt;
*out = *fmt;
++out;
++fmt;
continue;
}
++fmt;
break;
}
else
{
if(re_traits_type::is_class(*fmt, char_class_xdigit MAYBE_PASS_LOCALE(l)) == false)
{
--fmt;
*out = *fmt;
++out;
++fmt;
continue;
}
c = (charT)re_traits_type::toi(fmt, fmt_end, -16 MAYBE_PASS_LOCALE(l));
}
break;
case syntax_c:
++fmt;
if(fmt == fmt_end)
{
--fmt;
*out = *fmt;
++out;
return out;
}
if(((typename re_traits_type::uchar_type)(*fmt) < (typename re_traits_type::uchar_type)'@')
|| ((typename re_traits_type::uchar_type)(*fmt) > (typename re_traits_type::uchar_type)127) )
{
--fmt;
*out = *fmt;
++out;
++fmt;
break;
}
c = (charT)((typename re_traits_type::uchar_type)(*fmt) - (typename re_traits_type::uchar_type)'@');
++fmt;
break;
case syntax_e:
c = (charT)27;
++fmt;
break;
case syntax_digit:
c = (charT)re_traits_type::toi(fmt, fmt_end, -8 MAYBE_PASS_LOCALE(l));
break;
default:
c = *fmt;
++fmt;
}
*out = c;
continue;
}
case syntax_open_bracket:
++fmt; // recurse
oi_assign(&out, __reg_format_aux(out, m, fmt, false MAYBE_PASS_LOCALE(l)));
continue;
case syntax_close_bracket:
++fmt; // return from recursion
return out;
case syntax_colon:
if(isif)
{
++fmt;
return out;
}
*out = *fmt;
++out;
++fmt;
continue;
case syntax_question:
{
++fmt;
if(*fmt == 0)
{
--fmt;
*out = *fmt;
++out;
++fmt;
return out;
}
unsigned int id = re_traits_type::toi(fmt, fmt_end, 10 MAYBE_PASS_LOCALE(l));
if(m[id].matched)
{
oi_assign(&out, __reg_format_aux(out, m, fmt, true MAYBE_PASS_LOCALE(l)));
if(re_traits_type::syntax_type(*(fmt-1) MAYBE_PASS_LOCALE(l)) == syntax_colon)
re_skip_format(fmt MAYBE_PASS_LOCALE(l));
}
else
{
re_skip_format(fmt MAYBE_PASS_LOCALE(l));
if(re_traits_type::syntax_type(*(fmt-1) MAYBE_PASS_LOCALE(l)) == syntax_colon)
oi_assign(&out, __reg_format_aux(out, m, fmt, true MAYBE_PASS_LOCALE(l)));
}
return out;
}
default:
*out = *fmt;
++out;
++fmt;
}
}
return out;
}
#if defined(JM_NO_TEMPLATE_SWITCH_MERGE) && !defined(JM_NO_NAMESPACES)
} // namespace
#endif
template <class OutputIterator, class iterator, class Allocator, class charT>
OutputIterator RE_CALL reg_format(OutputIterator out,
const reg_match<iterator, Allocator>& m,
const charT* fmt
#ifdef RE_LOCALE_CPP
, __JM_STD::locale locale_inst = __JM_STD::locale()
#endif
)
{
//
// start by updating the locale:
//
#if defined(RE_LOCALE_C) || defined(RE_LOCALE_W32)
static re_initialiser<charT> locale_initialiser;
locale_initialiser.update();
#else
if(JM_HAS_FACET(locale_inst, regfacet<charT>) == false)
{
#ifdef _MSC_VER
locale_inst = __JM_STD::_ADDFAC(locale_inst, new regfacet<charT>());
#else
locale_inst = __JM_STD::locale(locale_inst, new regfacet<charT>());
#endif
}
JM_USE_FACET(locale_inst, regfacet<charT>).update(locale_inst);
#endif
return __reg_format_aux(out, m, fmt, false MAYBE_PASS_LOCALE(locale_inst));
}
template <class S>
class string_out_iterator
{
S* out;
public:
string_out_iterator(S& s) : out(&s) {}
string_out_iterator& operator++() { return *this; }
string_out_iterator& operator++(int) { return *this; }
string_out_iterator& operator*() { return *this; }
string_out_iterator& operator=(typename S::value_type v)
{
out->append(1, v);
return *this;
}
};
#ifndef JM_NO_STRING_DEF_ARGS
template <class iterator, class Allocator, class charT>
__JM_STD::basic_string<charT> RE_CALL reg_format(const reg_match<iterator, Allocator>& m, const charT* fmt
#ifdef RE_LOCALE_CPP
, __JM_STD::locale locale_inst = __JM_STD::locale()
#endif
)
{
__JM_STD::basic_string<charT> result;
string_out_iterator<__JM_STD::basic_string<charT> > i(result);
reg_format(i, m, fmt MAYBE_PASS_LOCALE(locale_inst));
return result;
}
#elif !defined(JM_NO_STRING_H)
template <class iterator, class Allocator>
__JM_STD::string RE_CALL reg_format(const reg_match<iterator, Allocator>& m, const char* fmt
#ifdef RE_LOCALE_CPP
, __JM_STD::locale locale_inst = __JM_STD::locale()
#endif
)
{
__JM_STD::string result;
string_out_iterator<__JM_STD::string> i(result);
reg_format(i, m, fmt MAYBE_PASS_LOCALE(locale_inst));
return result;
}
#endif
template <class OutputIterator, class iterator, class charT, class Allocator>
class merge_out_predicate
{
OutputIterator* out;
iterator* last;
const charT* fmt;
bool copy_none;
#ifdef RE_LOCALE_CPP
const __JM_STD::locale& l;
#endif
public:
merge_out_predicate(OutputIterator& o, iterator& pi, const charT* f, bool c
#ifdef RE_LOCALE_CPP
, const __JM_STD::locale& loc
#endif
) : out(&o), last(&pi), fmt(f), copy_none(c)
#ifdef RE_LOCALE_CPP
, l(loc)
#endif
{}
~merge_out_predicate() {}
bool RE_CALL operator()(const __JM::reg_match<iterator, Allocator>& m)
{
const charT* f = fmt;
if(copy_none)
oi_assign(out, re_copy_out(*out, iterator(m[-1].first), iterator(m[-1].second)));
oi_assign(out, __reg_format_aux(*out, m, f, false MAYBE_PASS_LOCALE(l)));
*last = m[-2].first;
return true;
}
};
template <class OutputIterator, class iterator, class traits, class Allocator, class charT>
OutputIterator RE_CALL reg_merge(OutputIterator out,
iterator first,
iterator last,
const reg_expression<charT, traits, Allocator>& e,
const charT* fmt,
bool copy = true,
unsigned int flags = match_default)
{
//
// start by updating the locale:
//
#if defined(RE_LOCALE_C) || defined(RE_LOCALE_W32)
static re_initialiser<charT> locale_initialiser;
locale_initialiser.update();
#else
__JM_STD::locale locale_inst(e.locale());
if(JM_HAS_FACET(locale_inst, regfacet<charT>) == false)
{
#ifdef _MSC_VER
locale_inst = __JM_STD::_ADDFAC(locale_inst, new regfacet<charT>());
#else
locale_inst = __JM_STD::locale(locale_inst, new regfacet<charT>());
#endif
}
JM_USE_FACET(locale_inst, regfacet<charT>).update(locale_inst);
#endif
iterator l = first;
merge_out_predicate<OutputIterator, iterator, charT, Allocator> oi(out, l, fmt, copy MAYBE_PASS_LOCALE(locale_inst));
reg_grep(oi, first, last, e, flags);
return copy ? re_copy_out(out, l, last) : out;
}
#ifndef JM_NO_STRING_DEF_ARGS
template <class traits, class Allocator, class charT>
__JM_STD::basic_string<charT> RE_CALL reg_merge(const __JM_STD::basic_string<charT>& s,
const reg_expression<charT, traits, Allocator>& e,
const charT* fmt,
bool copy = true,
unsigned int flags = match_default)
{
__JM_STD::basic_string<charT> result;
string_out_iterator<__JM_STD::basic_string<charT> > i(result);
reg_merge(i, s.begin(), s.end(), e, fmt, copy, flags);
return result;
}
#elif !defined(JM_NO_STRING_H)
template <class traits, class Allocator>
__JM_STD::string RE_CALL reg_merge(const __JM_STD::string& s,
const reg_expression<char, traits, Allocator>& e,
const char* fmt,
bool copy = true,
unsigned int flags = match_default)
{
__JM_STD::string result;
string_out_iterator<__JM_STD::string> i(result);
reg_merge(i, s.begin(), s.end(), e, fmt, copy, flags);
return result;
}
#endif
JM_END_NAMESPACE
#endif
File diff suppressed because it is too large Load Diff
+3
View File
@@ -0,0 +1,3 @@
#ifndef __REGEX_H
#include <jm/regex.h>
#endif
+16
View File
@@ -0,0 +1,16 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#ifndef __REGEX_H
#ifdef _MSC_VER
#pragma warning(disable: 4786)
#pragma warning(disable: 4800)
#endif
#include <jm/regex.h>
#endif