add the boost regex sources and create the libboostregex lib

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4202 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2002-05-24 12:53:12 +00:00
parent f0e9dba2a4
commit 86a566a27d
21 changed files with 6190 additions and 11 deletions

View File

@ -1,7 +1,5 @@
AUTOMAKE_OPTIONS = foreign
DISTCLEANFILES= *.orig *.rej *~ *.bak core
MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
# SUBDIRS = libs
ETAGS_ARGS = --lang=c++
include $(top_srcdir)/config/common.am
EXTRA_DIST = boost libs
SUBDIRS = libs
EXTRA_DIST = boost

View File

@ -1,6 +1,3 @@
AUTOMAKE_OPTIONS = foreign
DISTCLEANFILES= *.orig *.rej *~ *.bak core
MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
SUBDIRS = regex
ETAGS_ARGS = --lang=c++
include $(top_srcdir)/config/common.am
SUBDIRS = regex

View File

@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@ -0,0 +1,4 @@
include $(top_srcdir)/config/common.am
SUBDIRS = src

View File

@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@ -0,0 +1,23 @@
include $(top_srcdir)/config/common.am
noinst_LTLIBRARIES = libboostregex.la
INCLUDES = $(BOOST_INCLUDES)
libboostregex_la_SOURCES = \
cpp_regex_traits.cpp \
cregex.cpp \
c_regex_traits_common.cpp \
c_regex_traits.cpp \
fileiter.cpp \
instances.cpp \
posix_api.cpp \
primary_transform.hpp
regex.cpp \
regex_debug.cpp \
regex_synch.cpp \
w32_regex_traits.cpp \
wide_posix_api.cpp \
winstances.cpp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,556 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: c_regex_traits_common.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Implements common code and data for the
* c_regex_traits<charT> traits classes.
*/
#define BOOST_REGEX_SOURCE
#include <clocale>
#include <cstdio>
#include <list>
#include <cctype>
#include <boost/regex/regex_traits.hpp>
#include <boost/regex/detail/regex_synch.hpp>
namespace boost{
namespace re_detail{
//
// these are the POSIX collating names:
//
BOOST_REGEX_DECL const char* def_coll_names[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "alert", "backspace", "tab", "newline",
"vertical-tab", "form-feed", "carriage-return", "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK",
"SYN", "ETB", "CAN", "EM", "SUB", "ESC", "IS4", "IS3", "IS2", "IS1", "space", "exclamation-mark",
"quotation-mark", "number-sign", "dollar-sign", "percent-sign", "ampersand", "apostrophe",
"left-parenthesis", "right-parenthesis", "asterisk", "plus-sign", "comma", "hyphen",
"period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"colon", "semicolon", "less-than-sign", "equals-sign", "greater-than-sign",
"question-mark", "commercial-at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "left-square-bracket", "backslash",
"right-square-bracket", "circumflex", "underscore", "grave-accent", "a", "b", "c", "d", "e", "f",
"g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "left-curly-bracket",
"vertical-line", "right-curly-bracket", "tilde", "DEL", "",
};
// these multi-character collating elements
// should keep most Western-European locales
// happy - we should really localise these a
// little more - but this will have to do for
// now:
BOOST_REGEX_DECL const char* def_multi_coll[] = {
"ae",
"Ae",
"AE",
"ch",
"Ch",
"CH",
"ll",
"Ll",
"LL",
"ss",
"Ss",
"SS",
"nj",
"Nj",
"NJ",
"dz",
"Dz",
"DZ",
"lj",
"Lj",
"LJ",
"",
};
BOOST_REGEX_DECL bool BOOST_REGEX_CALL re_lookup_def_collate_name(std::string& buf, const char* name)
{
BOOST_RE_GUARD_STACK
unsigned int i = 0;
while(*def_coll_names[i])
{
if(std::strcmp(def_coll_names[i], name) == 0)
{
buf = (char)i;
return true;
}
++i;
}
i = 0;
while(*def_multi_coll[i])
{
if(std::strcmp(def_multi_coll[i], name) == 0)
{
buf = def_multi_coll[i];
return true;
}
++i;
}
return false;
}
//
// messages:
BOOST_REGEX_DECL const char * re_default_error_messages[] =
{ "Success", /* REG_NOERROR */
"No match", /* REG_NOMATCH */
"Invalid regular expression", /* REG_BADPAT */
"Invalid collation character", /* REG_ECOLLATE */
"Invalid character class name", /* REG_ECTYPE */
"Trailing backslash", /* REG_EESCAPE */
"Invalid back reference", /* REG_ESUBREG */
"Unmatched [ or [^", /* REG_EBRACK */
"Unmatched ( or \\(", /* REG_EPAREN */
"Unmatched \\{", /* REG_EBRACE */
"Invalid content of \\{\\}", /* REG_BADBR */
"Invalid range end", /* REG_ERANGE */
"Memory exhausted", /* REG_ESPACE */
"Invalid preceding regular expression", /* REG_BADRPT */
"Premature end of regular expression", /* REG_EEND */
"Regular expression too big", /* REG_ESIZE */
"Unmatched ) or \\)", /* REG_ERPAREN */
"Empty expression", /* REG_EMPTY */
"Unknown error", /* REG_E_UNKNOWN */
"",
"",
"",
};
const mss default_messages[] = {
{ 100+ c_regex_traits<char>::syntax_open_bracket, "(", },
{ 100+ c_regex_traits<char>::syntax_close_bracket, ")", },
{ 100+ c_regex_traits<char>::syntax_dollar, "$", },
{ 100+ c_regex_traits<char>::syntax_caret, "^", },
{ 100+ c_regex_traits<char>::syntax_dot, ".", },
{ 100+ c_regex_traits<char>::syntax_star, "*", },
{ 100+ c_regex_traits<char>::syntax_plus, "+", },
{ 100+ c_regex_traits<char>::syntax_question, "?", },
{ 100+ c_regex_traits<char>::syntax_open_set, "[", },
{ 100+ c_regex_traits<char>::syntax_close_set, "]", },
{ 100+ c_regex_traits<char>::syntax_or, "|", },
{ 100+ c_regex_traits<char>::syntax_slash, "\\", },
{ 100+ c_regex_traits<char>::syntax_hash, "#", },
{ 100+ c_regex_traits<char>::syntax_dash, "-", },
{ 100+ c_regex_traits<char>::syntax_open_brace, "{", },
{ 100+ c_regex_traits<char>::syntax_close_brace, "}", },
{ 100+ c_regex_traits<char>::syntax_digit, "0123456789", },
{ 100+ c_regex_traits<char>::syntax_b, "b", },
{ 100+ c_regex_traits<char>::syntax_B, "B", },
{ 100+ c_regex_traits<char>::syntax_left_word, "<", },
{ 100+ c_regex_traits<char>::syntax_right_word, ">", },
{ 100+ c_regex_traits<char>::syntax_w, "w", },
{ 100+ c_regex_traits<char>::syntax_W, "W", },
{ 100+ c_regex_traits<char>::syntax_start_buffer, "`A", },
{ 100+ c_regex_traits<char>::syntax_end_buffer, "'z", },
{ 100+ c_regex_traits<char>::syntax_newline, "\n", },
{ 100+ c_regex_traits<char>::syntax_comma, ",", },
{ 100+ c_regex_traits<char>::syntax_a, "a", },
{ 100+ c_regex_traits<char>::syntax_f, "f", },
{ 100+ c_regex_traits<char>::syntax_n, "n", },
{ 100+ c_regex_traits<char>::syntax_r, "r", },
{ 100+ c_regex_traits<char>::syntax_t, "t", },
{ 100+ c_regex_traits<char>::syntax_v, "v", },
{ 100+ c_regex_traits<char>::syntax_x, "x", },
{ 100+ c_regex_traits<char>::syntax_c, "c", },
{ 100+ c_regex_traits<char>::syntax_colon, ":", },
{ 100+ c_regex_traits<char>::syntax_equal, "=", },
{ 100 + c_regex_traits<char>::syntax_e, "e", },
{ 100 + c_regex_traits<char>::syntax_l, "l", },
{ 100 + c_regex_traits<char>::syntax_L, "L", },
{ 100 + c_regex_traits<char>::syntax_u, "u", },
{ 100 + c_regex_traits<char>::syntax_U, "U", },
{ 100 + c_regex_traits<char>::syntax_s, "s", },
{ 100 + c_regex_traits<char>::syntax_S, "S", },
{ 100 + c_regex_traits<char>::syntax_d, "d", },
{ 100 + c_regex_traits<char>::syntax_D, "D", },
{ 100 + c_regex_traits<char>::syntax_E, "E", },
{ 100 + c_regex_traits<char>::syntax_Q, "Q", },
{ 100 + c_regex_traits<char>::syntax_X, "X", },
{ 100 + c_regex_traits<char>::syntax_C, "C", },
{ 100 + c_regex_traits<char>::syntax_Z, "Z", },
{ 100 + c_regex_traits<char>::syntax_G, "G", },
{ 100 + c_regex_traits<char>::syntax_not, "!", },
{ 0, "", },
};
BOOST_REGEX_DECL std::size_t BOOST_REGEX_CALL re_get_default_message(char* buf, std::size_t len, std::size_t id)
{
BOOST_RE_GUARD_STACK
const mss* pm = default_messages;
while(pm->id)
{
if(pm->id == id)
{
std::size_t size = re_strlen(pm->what) + 1;
if(size > len)
return size;
re_strcpy(buf, pm->what);
return size;
}
++pm;
}
if(buf && len)
*buf = 0;
return 1;
}
#ifndef BOOST_NO_WREGEX
const wchar_t combining_ranges[] = { 0x0300, 0x0361,
0x0483, 0x0486,
0x0903, 0x0903,
0x093E, 0x0940,
0x0949, 0x094C,
0x0982, 0x0983,
0x09BE, 0x09C0,
0x09C7, 0x09CC,
0x09D7, 0x09D7,
0x0A3E, 0x0A40,
0x0A83, 0x0A83,
0x0ABE, 0x0AC0,
0x0AC9, 0x0ACC,
0x0B02, 0x0B03,
0x0B3E, 0x0B3E,
0x0B40, 0x0B40,
0x0B47, 0x0B4C,
0x0B57, 0x0B57,
0x0B83, 0x0B83,
0x0BBE, 0x0BBF,
0x0BC1, 0x0BCC,
0x0BD7, 0x0BD7,
0x0C01, 0x0C03,
0x0C41, 0x0C44,
0x0C82, 0x0C83,
0x0CBE, 0x0CBE,
0x0CC0, 0x0CC4,
0x0CC7, 0x0CCB,
0x0CD5, 0x0CD6,
0x0D02, 0x0D03,
0x0D3E, 0x0D40,
0x0D46, 0x0D4C,
0x0D57, 0x0D57,
0x0F7F, 0x0F7F,
0x20D0, 0x20E1,
0x3099, 0x309A,
0xFE20, 0xFE23,
0xffff, 0xffff, };
BOOST_REGEX_DECL bool BOOST_REGEX_CALL is_combining(wchar_t c)
{
BOOST_RE_GUARD_STACK
const wchar_t* p = combining_ranges + 1;
while(*p < c) p += 2;
--p;
if((c >= *p) && (c <= *(p+1)))
return true;
return false;
}
BOOST_REGEX_DECL unsigned short wide_unicode_classes[] = {
c_traits_base::char_class_cntrl, // '' 0
c_traits_base::char_class_cntrl, // '' 1
c_traits_base::char_class_cntrl, // '' 2
c_traits_base::char_class_cntrl, // '' 3
c_traits_base::char_class_cntrl, // '' 4
c_traits_base::char_class_cntrl, // '' 5
c_traits_base::char_class_cntrl, // '' 6
c_traits_base::char_class_cntrl, // '' 7
c_traits_base::char_class_cntrl, // '' 8
c_traits_base::char_class_cntrl | c_traits_base::char_class_space | c_traits_base::char_class_blank, // '' 9
c_traits_base::char_class_cntrl | c_traits_base::char_class_space, // '' 10
c_traits_base::char_class_cntrl | c_traits_base::char_class_space, // '' 11
c_traits_base::char_class_cntrl | c_traits_base::char_class_space, // '' 12
c_traits_base::char_class_cntrl | c_traits_base::char_class_space, // '' 13
c_traits_base::char_class_cntrl, // '.' 14
c_traits_base::char_class_cntrl, // '.' 15
c_traits_base::char_class_cntrl, // '.' 16
c_traits_base::char_class_cntrl, // '.' 17
c_traits_base::char_class_cntrl, // '.' 18
c_traits_base::char_class_cntrl, // '.' 19
c_traits_base::char_class_cntrl, // '.' 20
c_traits_base::char_class_cntrl, // '.' 21
c_traits_base::char_class_cntrl, // '.' 22
c_traits_base::char_class_cntrl, // '.' 23
c_traits_base::char_class_cntrl, // '.' 24
c_traits_base::char_class_cntrl, // '' 25
c_traits_base::char_class_cntrl, // '' 26
c_traits_base::char_class_cntrl, // '' 27
c_traits_base::char_class_cntrl, // '.' 28
c_traits_base::char_class_cntrl, // '.' 29
c_traits_base::char_class_cntrl, // '.' 30
c_traits_base::char_class_cntrl, // '.' 31
c_traits_base::char_class_space | c_traits_base::char_class_blank, // ' ' 32
c_traits_base::char_class_punct, // '!' 33
c_traits_base::char_class_punct, // '"' 34
c_traits_base::char_class_punct, // '#' 35
c_traits_base::char_class_punct, // '$' 36
c_traits_base::char_class_punct, // '%' 37
c_traits_base::char_class_punct, // '&' 38
c_traits_base::char_class_punct, // ''' 39
c_traits_base::char_class_punct, // '(' 40
c_traits_base::char_class_punct, // ')' 41
c_traits_base::char_class_punct, // '*' 42
c_traits_base::char_class_punct, // '+' 43
c_traits_base::char_class_punct, // ',' 44
c_traits_base::char_class_punct, // '-' 45
c_traits_base::char_class_punct, // '.' 46
c_traits_base::char_class_punct, // '/' 47
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '0' 48
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '1' 49
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '2' 50
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '3' 51
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '4' 52
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '5' 53
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '6' 54
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '7' 55
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '8' 56
c_traits_base::char_class_digit | c_traits_base::char_class_xdigit, // '9' 57
c_traits_base::char_class_punct, // ':' 58
c_traits_base::char_class_punct, // ';' 59
c_traits_base::char_class_punct, // '<' 60
c_traits_base::char_class_punct, // '=' 61
c_traits_base::char_class_punct, // '>' 62
c_traits_base::char_class_punct, // '?' 63
c_traits_base::char_class_punct, // '@' 64
c_traits_base::char_class_alpha | c_traits_base::char_class_upper | c_traits_base::char_class_xdigit, // 'A' 65
c_traits_base::char_class_alpha | c_traits_base::char_class_upper | c_traits_base::char_class_xdigit, // 'B' 66
c_traits_base::char_class_alpha | c_traits_base::char_class_upper | c_traits_base::char_class_xdigit, // 'C' 67
c_traits_base::char_class_alpha | c_traits_base::char_class_upper | c_traits_base::char_class_xdigit, // 'D' 68
c_traits_base::char_class_alpha | c_traits_base::char_class_upper | c_traits_base::char_class_xdigit, // 'E' 69
c_traits_base::char_class_alpha | c_traits_base::char_class_upper | c_traits_base::char_class_xdigit, // 'F' 70
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'G' 71
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'H' 72
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'I' 73
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'J' 74
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'K' 75
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'L' 76
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'M' 77
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'N' 78
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'O' 79
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'P' 80
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Q' 81
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'R' 82
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'S' 83
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'T' 84
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'U' 85
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'V' 86
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'W' 87
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'X' 88
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Y' 89
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Z' 90
c_traits_base::char_class_punct, // '[' 91
c_traits_base::char_class_punct, // '\' 92
c_traits_base::char_class_punct, // ']' 93
c_traits_base::char_class_punct, // '^' 94
c_traits_base::char_class_punct | c_traits_base::char_class_underscore, // '_' 95
c_traits_base::char_class_punct, // '`' 96
c_traits_base::char_class_alpha | c_traits_base::char_class_lower | c_traits_base::char_class_xdigit, // 'a' 97
c_traits_base::char_class_alpha | c_traits_base::char_class_lower | c_traits_base::char_class_xdigit, // 'b' 98
c_traits_base::char_class_alpha | c_traits_base::char_class_lower | c_traits_base::char_class_xdigit, // 'c' 99
c_traits_base::char_class_alpha | c_traits_base::char_class_lower | c_traits_base::char_class_xdigit, // 'd' 100
c_traits_base::char_class_alpha | c_traits_base::char_class_lower | c_traits_base::char_class_xdigit, // 'e' 101
c_traits_base::char_class_alpha | c_traits_base::char_class_lower | c_traits_base::char_class_xdigit, // 'f' 102
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'g' 103
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'h' 104
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'i' 105
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'j' 106
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'k' 107
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'l' 108
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'm' 109
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'n' 110
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'o' 111
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'p' 112
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'q' 113
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'r' 114
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 's' 115
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 't' 116
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'u' 117
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'v' 118
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'w' 119
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'x' 120
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'y' 121
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'z' 122
c_traits_base::char_class_punct, // '{' 123
c_traits_base::char_class_punct, // '|' 124
c_traits_base::char_class_punct, // '}' 125
c_traits_base::char_class_punct, // '~' 126
c_traits_base::char_class_cntrl, // '' 127
c_traits_base::char_class_cntrl, // '€' 128
c_traits_base::char_class_cntrl, // '<27>' 129
c_traits_base::char_class_cntrl, // '' 130
c_traits_base::char_class_cntrl, // 'ƒ' 131
c_traits_base::char_class_cntrl, // '„' 132
c_traits_base::char_class_cntrl, // '…' 133
c_traits_base::char_class_cntrl, // '†' 134
c_traits_base::char_class_cntrl, // '‡' 135
c_traits_base::char_class_cntrl, // 'ˆ' 136
c_traits_base::char_class_cntrl, // '‰' 137
c_traits_base::char_class_cntrl, // 'Š' 138
c_traits_base::char_class_cntrl, // '' 139
c_traits_base::char_class_cntrl, // 'Œ' 140
c_traits_base::char_class_cntrl, // '<27>' 141
c_traits_base::char_class_cntrl, // 'Ž' 142
c_traits_base::char_class_cntrl, // '<27>' 143
c_traits_base::char_class_cntrl, // '<27>' 144
c_traits_base::char_class_cntrl, // '' 145
c_traits_base::char_class_cntrl, // '' 146
c_traits_base::char_class_cntrl, // '“' 147
c_traits_base::char_class_cntrl, // '”' 148
c_traits_base::char_class_cntrl, // '•' 149
c_traits_base::char_class_cntrl, // '' 150
c_traits_base::char_class_cntrl, // '—' 151
c_traits_base::char_class_cntrl, // '˜' 152
c_traits_base::char_class_cntrl, // '™' 153
c_traits_base::char_class_cntrl, // 'š' 154
c_traits_base::char_class_cntrl, // '' 155
c_traits_base::char_class_cntrl, // 'œ' 156
c_traits_base::char_class_cntrl, // '<27>' 157
c_traits_base::char_class_cntrl, // 'ž' 158
c_traits_base::char_class_cntrl, // 'Ÿ' 159
c_traits_base::char_class_space | c_traits_base::char_class_blank, // ' ' 160
c_traits_base::char_class_punct, // '¡' 161
c_traits_base::char_class_punct, // '¢' 162
c_traits_base::char_class_punct, // '£' 163
c_traits_base::char_class_punct, // '¤' 164
c_traits_base::char_class_punct, // '¥' 165
c_traits_base::char_class_punct, // '¦' 166
c_traits_base::char_class_punct, // '§' 167
c_traits_base::char_class_punct, // '¨' 168
c_traits_base::char_class_punct, // '©' 169
c_traits_base::char_class_punct, // 'ª' 170
c_traits_base::char_class_punct, // '«' 171
c_traits_base::char_class_punct, // '¬' 172
c_traits_base::char_class_punct, // '­' 173
c_traits_base::char_class_punct, // '®' 174
c_traits_base::char_class_punct, // '¯' 175
c_traits_base::char_class_punct, // '°' 176
c_traits_base::char_class_punct, // '±' 177
c_traits_base::char_class_punct, // '²' 178
c_traits_base::char_class_punct, // '³' 179
c_traits_base::char_class_punct, // '´' 180
c_traits_base::char_class_punct, // 'µ' 181
c_traits_base::char_class_punct, // '¶' 182
c_traits_base::char_class_punct, // '·' 183
c_traits_base::char_class_punct, // '¸' 184
c_traits_base::char_class_punct, // '¹' 185
c_traits_base::char_class_punct, // 'º' 186
c_traits_base::char_class_punct, // '»' 187
c_traits_base::char_class_punct, // '¼' 188
c_traits_base::char_class_punct, // '½' 189
c_traits_base::char_class_punct, // '¾' 190
c_traits_base::char_class_punct, // '¿' 191
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'À' 192
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Á' 193
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Â' 194
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ã' 195
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ä' 196
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Å' 197
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Æ' 198
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ç' 199
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'È' 200
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'É' 201
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ê' 202
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ë' 203
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ì' 204
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Í' 205
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Î' 206
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ï' 207
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ð' 208
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ñ' 209
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ò' 210
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ó' 211
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ô' 212
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Õ' 213
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ö' 214
c_traits_base::char_class_punct, // '×' 215
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ø' 216
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ù' 217
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ú' 218
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Û' 219
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ü' 220
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Ý' 221
c_traits_base::char_class_alpha | c_traits_base::char_class_upper, // 'Þ' 222
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ß' 223
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'à' 224
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'á' 225
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'â' 226
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ã' 227
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ä' 228
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'å' 229
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'æ' 230
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ç' 231
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'è' 232
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'é' 233
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ê' 234
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ë' 235
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ì' 236
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'í' 237
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'î' 238
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ï' 239
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ð' 240
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ñ' 241
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ò' 242
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ó' 243
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ô' 244
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'õ' 245
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ö' 246
c_traits_base::char_class_punct, // '÷' 247
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ø' 248
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ù' 249
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ú' 250
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'û' 251
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ü' 252
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ý' 253
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'þ' 254
c_traits_base::char_class_alpha | c_traits_base::char_class_lower, // 'ÿ' 255
};
BOOST_REGEX_DECL wchar_t wide_lower_case_map[] = {
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xd7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
#endif // BOOST_NO_WREGEX
} // namespace re_detail
} // namespace boost

View File

@ -0,0 +1,864 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: c_regex_traits.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Implements the cpp_regex_traits<charT> traits class
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex/config.hpp>
#ifndef BOOST_NO_STD_LOCALE
#include <clocale>
#include <locale>
#include <cstdio>
#include <list>
#include <cctype>
#include <iostream>
#include <map>
#include <boost/regex/regex_traits.hpp>
#include <boost/cregex.hpp>
#include <boost/scoped_array.hpp>
#include "primary_transform.hpp"
# ifdef BOOST_MSVC
# pragma warning(disable:4786)
# endif
namespace{
const unsigned int re_classes_max = 14;
const unsigned int char_set_size = CHAR_MAX - CHAR_MIN + 1;
boost::uint_fast32_t re_char_class_id[] = {
boost::re_detail::cpp_regex_traits_base::char_class_alnum,
boost::re_detail::cpp_regex_traits_base::char_class_alpha,
boost::re_detail::cpp_regex_traits_base::char_class_cntrl,
boost::re_detail::cpp_regex_traits_base::char_class_digit,
boost::re_detail::cpp_regex_traits_base::char_class_graph,
boost::re_detail::cpp_regex_traits_base::char_class_lower,
boost::re_detail::cpp_regex_traits_base::char_class_print,
boost::re_detail::cpp_regex_traits_base::char_class_punct,
boost::re_detail::cpp_regex_traits_base::char_class_space,
boost::re_detail::cpp_regex_traits_base::char_class_upper,
boost::re_detail::cpp_regex_traits_base::char_class_xdigit,
boost::re_detail::cpp_regex_traits_base::char_class_blank,
boost::re_detail::cpp_regex_traits_base::char_class_word,
boost::re_detail::cpp_regex_traits_base::char_class_unicode,
};
const char* re_char_class_names[] = {
"alnum",
"alpha",
"cntrl",
"digit",
"graph",
"lower",
"print",
"punct",
"space",
"upper",
"xdigit",
"blank",
"word",
"unicode",
};
template <class charT,
class traits = ::std::char_traits<charT> >
class parser_buf : public ::std::basic_streambuf<charT, traits>
{
typedef ::std::basic_streambuf<charT, traits> base_type;
typedef typename base_type::int_type int_type;
typedef typename base_type::char_type char_type;
typedef typename base_type::pos_type pos_type;
typedef ::std::streamsize streamsize;
typedef typename base_type::off_type off_type;
public:
parser_buf() : base_type() { setbuf(0, 0); }
const charT* getnext() { return this->gptr(); }
protected:
std::basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n);
typename parser_buf<charT, traits>::pos_type seekpos(pos_type sp, ::std::ios_base::openmode which);
typename parser_buf<charT, traits>::pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which);
private:
parser_buf& operator=(const parser_buf&);
parser_buf(const parser_buf&);
};
template<class charT, class traits>
std::basic_streambuf<charT, traits>*
parser_buf<charT, traits>::setbuf(char_type* s, streamsize n)
{
this->setg(s, s, s + n);
return this;
}
template<class charT, class traits>
typename parser_buf<charT, traits>::pos_type
parser_buf<charT, traits>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
{
typedef typename parser_buf<charT, traits>::pos_type pos_type;
if(which & ::std::ios_base::out)
return pos_type(off_type(-1));
std::ptrdiff_t size = this->egptr() - this->eback();
std::ptrdiff_t pos = this->gptr() - this->eback();
charT* g = this->eback();
switch(way)
{
case ::std::ios_base::beg:
if((off < 0) || (off > size))
return pos_type(off_type(-1));
else
this->setg(g, g + off, g + size);
case ::std::ios_base::end:
if((off < 0) || (off > size))
return pos_type(off_type(-1));
else
this->setg(g, g + size - off, g + size);
case ::std::ios_base::cur:
{
std::ptrdiff_t newpos = pos + off;
if((newpos < 0) || (newpos > size))
return pos_type(off_type(-1));
else
this->setg(g, g + newpos, g + size);
}
}
return static_cast<pos_type>(this->gptr() - this->eback());
}
template<class charT, class traits>
typename parser_buf<charT, traits>::pos_type
parser_buf<charT, traits>::seekpos(pos_type sp, ::std::ios_base::openmode which)
{
if(which & ::std::ios_base::out)
return pos_type(off_type(-1));
std::ptrdiff_t size = this->egptr() - this->eback();
charT* g = this->eback();
if(sp <= size)
{
this->setg(g, g + ::std::streamsize(sp), g + size);
}
return pos_type(off_type(-1));
}
} // namespace
namespace boost{
namespace re_detail{
template <>
struct message_data<char>
{
unsigned char syntax_map[CHAR_MAX-CHAR_MIN];
std::map<std::string, std::string, std::less<std::string> > collating_elements;
std::map<std::string, std::size_t, std::less<std::string> > classes;
//std::string _zero;
//std::string _ten;
parser_buf<char> sbuf;
std::istream is;
std::string error_strings[boost::REG_E_UNKNOWN+1];
message_data(const std::locale& l, const std::string& regex_message_catalogue);
private:
message_data(const message_data&);
message_data& operator=(const message_data&);
};
message_data<char>::message_data(const std::locale& l, const std::string& regex_message_catalogue)
: is(&sbuf)
{
is.imbue(l);
#ifndef BOOST_NO_STD_MESSAGES
const std::messages<char>* pm = 0;
std::messages<char>::catalog cat = -1;
if(regex_message_catalogue.size())
{
pm = &BOOST_USE_FACET(std::messages<char>, l);
cat = pm->open(regex_message_catalogue, l);
#ifndef BOOST_NO_EXCEPTIONS
if(cat < 0)
{
std::string m("Unable to open message catalog: ");
throw std::runtime_error(m + regex_message_catalogue);
}
#else
BOOST_REGEX_NOEH_ASSERT(cat >= 0);
#endif
}
#endif
std::memset(syntax_map, cpp_regex_traits<char>::syntax_char, 256);
unsigned i;
scoped_array<char> a;
std::size_t array_size = 0;
std::size_t new_size;
for(i = 1; i < cpp_regex_traits<char>::syntax_max; ++i)
{
new_size = re_get_default_message(0, 0, i+100);
if(new_size > array_size)
{
a.reset(new char[new_size]);
array_size = new_size;
}
re_get_default_message(a.get(), array_size, i+100);
std::string s = a.get();
#ifndef BOOST_NO_STD_MESSAGES
if((int)cat >= 0)
s = pm->get(cat, 0, i+100, s);
#endif
for(std::size_t j = 0; j < s.size(); ++j)
{
syntax_map[s[j]] = (unsigned char)(i);
}
}
#ifndef BOOST_NO_STD_MESSAGES
// load any custom collate names:
//
// for some reason Borland C++ Builder 6 won't let us use
// std::isspace(char, std::locale) unless we call it
// unqualifed - weird. This seems to be affecting other
// STLport users as well (gcc3.1+STLport5), so enable the
// workaround for all STLport users...
//
#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
using namespace std;
# define BOOST_REGEX_STD
#else
# define BOOST_REGEX_STD std::
#endif
std::string c1, c2;
i = 400;
if((int)cat >= 0)
{
c2 = pm->get(cat, 0, i, c1);
while(c2.size())
{
const char* p1, *p2, *p3, *p4;;
p1 = c2.c_str();
while(*p1 && BOOST_REGEX_STD isspace((char)*p1, l))++p1;
p2 = p1;
while(*p2 && !BOOST_REGEX_STD isspace((char)*p2, l))++p2;
p3 = p2;
while(*p3 && BOOST_REGEX_STD isspace((char)*p3, l))++p3;
p4 = p3;
while(*p4 && !BOOST_REGEX_STD isspace((char)*p4, l))++p4;
collating_elements[std::string(p1, p2)] = std::string(p3, p4);
++i;
c2 = pm->get(cat, 0, i, c1);
}
}
#endif
std::string m;
std::string s;
#ifndef BOOST_NO_STD_MESSAGES
if((int)cat >= 0)
{
for(i = 0; i < re_classes_max; ++i)
{
s = pm->get(cat, 0, i+300, m);
if(s.size())
classes[s] = i;
}
for(i = 0; i <= boost::REG_E_UNKNOWN ; ++i)
{
s = pm->get(cat, 0, i+200, m);
error_strings[i] = s;
}
}
if((int)cat >= 0)
pm->close(cat);
#endif
}
std::string BOOST_REGEX_CALL cpp_regex_traits_base::set_message_catalogue(const std::string& l)
{
if(sizeof(regex_message_cat) <= l.size())
return l;
std::string old(regex_message_cat);
std::strcpy(regex_message_cat, l.c_str());
return old;
}
char cpp_regex_traits_base::regex_message_cat[BOOST_REGEX_MAX_PATH] = {0};
} // namespace re_detail
cpp_regex_traits<char>::cpp_regex_traits()
{
pmd = new re_detail::message_data<char>(locale_inst, regex_message_cat);
psyntax = pmd->syntax_map;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
lower_map = new char[char_set_size];
BOOST_REGEX_NOEH_ASSERT(lower_map)
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete pmd;
throw;
}
#endif
for(unsigned int i = 0; i < char_set_size; ++i)
lower_map[i] = static_cast<char>(i);
pctype = &BOOST_USE_FACET(std::ctype<char>, locale_inst);
pctype->tolower(&lower_map[0], &lower_map[char_set_size]);
pcollate = &BOOST_USE_FACET(std::collate<char>, locale_inst);
sort_type = re_detail::find_sort_syntax(this, &(this->sort_delim));
}
cpp_regex_traits<char>::~cpp_regex_traits()
{
delete pmd;
delete[] lower_map;
}
int BOOST_REGEX_CALL cpp_regex_traits<char>::toi(char c)const
{
pmd->sbuf.pubsetbuf(&c, 1);
pmd->is.clear();
pmd->is >> std::dec;
int val;
if(pmd->is >> val)
{
return val;
}
else
return 0;
}
int BOOST_REGEX_CALL cpp_regex_traits<char>::toi(const char*& first, const char* last, int radix)const
{
pmd->sbuf.pubsetbuf(const_cast<char*>(first), static_cast<std::streamsize>(last-first));
pmd->is.clear();
if(std::abs(radix) == 16) pmd->is >> std::hex;
else if(std::abs(radix) == 8) pmd->is >> std::oct;
else pmd->is >> std::dec;
int val;
if(pmd->is >> val)
{
first = first + ((last - first) - pmd->sbuf.in_avail());
return val;
}
else
return 0;
}
boost::uint_fast32_t BOOST_REGEX_CALL cpp_regex_traits<char>::lookup_classname(const char* first, const char* last)const
{
BOOST_RE_GUARD_STACK
unsigned int i;
std::string s(first, last);
std::map<std::string, std::size_t, std::less<std::string> >::const_iterator pos = pmd->classes.find(s);
if(pos != pmd->classes.end())
return re_char_class_id[(*pos).second];
for(i = 0; i < re_classes_max; ++i)
{
if(s == re_char_class_names[i])
return re_char_class_id[i];
}
return 0;
}
bool BOOST_REGEX_CALL cpp_regex_traits<char>::lookup_collatename(std::string& s, const char* first, const char* last)const
{
BOOST_RE_GUARD_STACK
std::string name(first, last);
std::map<std::string, std::string, std::less<std::string > >::const_iterator pos = pmd->collating_elements.find(name);
if(pos != pmd->collating_elements.end())
{
s = (*pos).second;
return true;
}
return re_detail::re_lookup_def_collate_name(s, name.c_str());
}
void BOOST_REGEX_CALL cpp_regex_traits<char>::transform_primary(std::string& out, const std::string& in)const
{
transform(out, in);
switch(sort_type)
{
case re_detail::sort_C:
case re_detail::sort_unknown:
break;
case re_detail::sort_fixed:
if((unsigned)sort_delim < out.size())
out.erase((int)sort_delim);
break;
case re_detail::sort_delim:
for(unsigned int i = 0; i < out.size(); ++i)
{
if((out[i] == sort_delim) && (i+1 < out.size()))
{
out.erase(i+1);
break;
}
}
}
}
std::string BOOST_REGEX_CALL cpp_regex_traits<char>::error_string(unsigned id)const
{
if((id <= boost::REG_E_UNKNOWN) && (pmd->error_strings[id].size()))
return pmd->error_strings[id];
return boost::re_detail::re_default_error_messages[id];
}
cpp_regex_traits<char>::locale_type BOOST_REGEX_CALL cpp_regex_traits<char>::imbue(locale_type l)
{
locale_type old_l(locale_inst);
locale_inst = l;
re_detail::message_data<char>* npmd = new re_detail::message_data<char>(locale_inst, regex_message_cat);
delete pmd;
pmd = npmd;
psyntax = pmd->syntax_map;
for(unsigned int i = 0; i < char_set_size; ++i)
lower_map[i] = static_cast<char>(i);
pctype = &BOOST_USE_FACET(std::ctype<char>, locale_inst);
pctype->tolower(&lower_map[0], &lower_map[char_set_size]);
pcollate = &BOOST_USE_FACET(std::collate<char>, locale_inst);
sort_type = re_detail::find_sort_syntax(this, &(this->sort_delim));
return old_l;
}
#ifndef BOOST_NO_WREGEX
namespace re_detail{
std::string BOOST_REGEX_CALL to_narrow(const std::basic_string<wchar_t>& is, const std::codecvt<wchar_t, char, std::mbstate_t>& cvt)
{
BOOST_RE_GUARD_STACK
std::basic_string<wchar_t>::size_type bufsize = is.size() * 2;
//
// declare buffer first as VC6 workaround for internal compiler error!
char* pc = new char[bufsize];
scoped_array<char> t(pc);
#if defined(BOOST_MSVC) && !defined(DINKUMWARE_CE)
std::mbstate_t state = 0;
#else
std::mbstate_t state = std::mbstate_t();
#endif
const wchar_t* next_in;
char* next_out;
while(true)
{
switch(cvt.out(state, is.c_str(), is.c_str() + is.size(), next_in, t.get(), t.get() + bufsize, next_out))
{
case std::codecvt_base::ok:
return std::string(t.get(), next_out);
case std::codecvt_base::partial:
bufsize *= 2;
t.reset(new char[bufsize]);
continue;
case std::codecvt_base::error:
// not much we can do here but guess:
case std::codecvt_base::noconv:
std::string out;
for(unsigned i = 0; i < is.size(); ++i)
{
out.append(1, (char)is[i]);
}
return out;
}
}
}
std::wstring BOOST_REGEX_CALL to_wide(const std::string& is, const std::codecvt<wchar_t, char, std::mbstate_t>& cvt)
{
BOOST_RE_GUARD_STACK
std::string::size_type bufsize = is.size() + 2;
std::string::size_type maxsize = is.size() * 100;
//
// declare buffer first as VC6 workaround for internal compiler error!
wchar_t* pc = new wchar_t[bufsize];
scoped_array<wchar_t> t(pc);
#if defined(BOOST_MSVC) && !defined(DINKUMWARE_CE)
std::mbstate_t state = 0;
#else
std::mbstate_t state = std::mbstate_t();
#endif
wchar_t* next_out;
const char* next_in;
while(true)
{
switch(cvt.in(state, is.c_str(), is.c_str() + is.size(), next_in, t.get(), t.get() + bufsize, next_out))
{
case std::codecvt_base::ok:
return std::wstring(t.get(), next_out);
case std::codecvt_base::partial:
bufsize *= 2;
if(bufsize < maxsize)
{
t.reset(new wchar_t[bufsize]);
continue;
}
//
// error fall through:
case std::codecvt_base::error:
// not much we can do here but guess:
case std::codecvt_base::noconv:
std::wstring out;
for(unsigned i = 0; i < is.size(); ++i)
{
out.append(1, is[i]);
}
return out;
}
}
}
template <>
struct message_data<wchar_t>
{
#ifndef BOOST_NO_STD_MESSAGES
typedef std::messages<wchar_t>::string_type string_type;
#else
typedef std::wstring string_type;
#endif
string_type name;
struct syntax_map
{
wchar_t c;
unsigned int type;
};
std::list<syntax_map> syntax;
std::map<string_type, std::size_t> classes;
std::map<string_type, string_type> collating_elements;
unsigned char syntax_[CHAR_MAX-CHAR_MIN+1];
parser_buf<wchar_t> sbuf;
std::wistream is;
std::string error_strings[boost::REG_E_UNKNOWN+1];
message_data(const std::locale& l, const std::string& regex_message_catalogue);
private:
message_data(const message_data&);
message_data& operator=(const message_data&);
};
message_data<wchar_t>::message_data(const std::locale& l, const std::string& regex_message_catalogue)
: is(&sbuf)
{
is.imbue(l);
syntax_map m;
typedef std::codecvt<wchar_t, char, std::mbstate_t> cvt_type;
const cvt_type& cvt = BOOST_USE_FACET(cvt_type, l);
#ifndef BOOST_NO_STD_MESSAGES
const std::messages<wchar_t>& msgs = BOOST_USE_FACET(std::messages<wchar_t>, l);
std::messages<wchar_t>::catalog cat = -1;
if(regex_message_catalogue.size())
{
cat = msgs.open(regex_message_catalogue, l);
#ifndef BOOST_NO_EXCEPTIONS
if(cat < 0)
{
std::string m("Unable to open message catalog: ");
throw std::runtime_error(m + regex_message_catalogue);
}
#else
BOOST_REGEX_NOEH_ASSERT(cat >= 0);
#endif
}
#endif
scoped_array<char> a;
std::size_t array_size = 0;
std::size_t new_size;
std::size_t i;
std::memset(syntax_, cpp_regex_traits<wchar_t>::syntax_char, sizeof(syntax_));
for(i = 1; i < cpp_regex_traits<wchar_t>::syntax_max; ++i)
{
new_size = re_get_default_message(0, 0, i+100);
if(new_size > array_size)
{
a.reset(new char[new_size]);
array_size = new_size;
}
re_get_default_message(a.get(), array_size, i+100);
std::string ns = a.get();
string_type s = to_wide(ns, cvt);
#ifndef BOOST_NO_STD_MESSAGES
if((int)cat >= 0)
s = BOOST_USE_FACET(std::messages<wchar_t>, l).get(cat, 0, (int)i+100, s);
#endif
for(unsigned int j = 0; j < s.size(); ++j)
{
if((s[j] <= UCHAR_MAX) && (s[j] >= 0))
syntax_[s[j]] = static_cast<unsigned char>(i);
else
{
m.c = s[j];
m.type = static_cast<unsigned int>(i);
syntax.push_back(m);
}
}
}
#ifndef BOOST_NO_STD_MESSAGES
// load any custom collate names:
string_type c1, c2;
i = 400;
if((int)cat >= 0)
{
c2 = msgs.get(cat, 0, (int)i, c1);
while(c2.size())
{
const wchar_t* p1, *p2, *p3, *p4;;
p1 = c2.c_str();
while(*p1 && BOOST_REGEX_STD isspace((wchar_t)*p1, l))++p1;
p2 = p1;
while(*p2 && !BOOST_REGEX_STD isspace((wchar_t)*p2, l))++p2;
p3 = p2;
while(*p3 && BOOST_REGEX_STD isspace((wchar_t)*p3, l))++p3;
p4 = p3;
while(*p4 && !BOOST_REGEX_STD isspace((wchar_t)*p4, l))++p4;
collating_elements[std::basic_string<wchar_t>(p1, p2)] = std::basic_string<wchar_t>(p3, p4);
++i;
c2 = msgs.get(cat, 0, (int)i, c1);
}
}
if((int)cat >= 0)
{
c2.erase();
for(i = 0; i < re_classes_max; ++i)
{
c1 = msgs.get(cat, 0, static_cast<int>(i+300), c2);
if(c1.size())
classes[c1] = i;
}
for(i = 0; i <= boost::REG_E_UNKNOWN ; ++i)
{
c1 = msgs.get(cat, 0, static_cast<int>(i+200), c2);
error_strings[i] = to_narrow(c1, cvt);
}
}
if((int)cat >= 0)
msgs.close(cat);
#endif
}
} // namespace re_detail
unsigned int BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::do_syntax_type(size_type c)const
{
std::list<re_detail::message_data<wchar_t>::syntax_map>::const_iterator i, j;
i = pmd->syntax.begin();
j = pmd->syntax.end();
while(i != j)
{
if(((uchar_type)(*i).c) == c)
return (*i).type;
++i;
}
return 0;
}
void BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::transform_primary(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in)const
{
transform(out, in);
switch(sort_type)
{
case re_detail::sort_C:
case re_detail::sort_unknown:
break;
case re_detail::sort_fixed:
if((unsigned)sort_delim < out.size())
out.erase((int)sort_delim);
break;
case re_detail::sort_delim:
for(unsigned int i = 0; i < out.size(); ++i)
{
if((out[i] == sort_delim) && (i+1 < out.size()))
{
out.erase(i+1);
break;
}
}
}
}
int BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::toi(wchar_t c)const
{
pmd->sbuf.pubsetbuf(&c, 1);
pmd->is.clear();
pmd->is >> std::dec;
int val;
if(pmd->is >> val)
{
return val;
}
else
return 0;
}
int BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::toi(const wchar_t*& first, const wchar_t* last, int radix)const
{
pmd->sbuf.pubsetbuf(const_cast<wchar_t*>(first), static_cast<std::streamsize>(last-first));
pmd->is.clear();
if(std::abs(radix) == 16) pmd->is >> std::hex;
else if(std::abs(radix) == 8) pmd->is >> std::oct;
else pmd->is >> std::dec;
int val;
if(pmd->is >> val)
{
first = first + ((last - first) - pmd->sbuf.in_avail());
return val;
}
else
return 0;
}
boost::uint_fast32_t BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::lookup_classname(const wchar_t* first, const wchar_t* last)const
{
BOOST_RE_GUARD_STACK
unsigned int i;
std::wstring s(first, last);
std::map<std::wstring, std::size_t>::const_iterator pos = pmd->classes.find(s);
if(pos != pmd->classes.end())
return re_char_class_id[(*pos).second];
std::string ns = re_detail::to_narrow(s, *pcdv);
for(i = 0; i < re_classes_max; ++i)
{
if(ns == re_char_class_names[i])
return re_char_class_id[i];
}
return 0;
}
bool BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::lookup_collatename(std::basic_string<wchar_t>& s, const wchar_t* first, const wchar_t* last)const
{
BOOST_RE_GUARD_STACK
std::wstring name(first, last);
std::map<std::wstring, std::wstring>::const_iterator pos = pmd->collating_elements.find(name);
if(pos != pmd->collating_elements.end())
{
s = (*pos).second;
return true;
}
std::string ns = re_detail::to_narrow(name, *pcdv);
std::string ns2;
bool result = re_detail::re_lookup_def_collate_name(ns2, ns.c_str());
s = re_detail::to_wide(ns2, *pcdv);
return result;
}
std::string BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::error_string(unsigned id)const
{
if((id <= boost::REG_E_UNKNOWN) && (pmd->error_strings[id].size()))
return pmd->error_strings[id];
return boost::re_detail::re_default_error_messages[id];
}
cpp_regex_traits<wchar_t>::cpp_regex_traits()
{
pmd = new re_detail::message_data<wchar_t>(locale_inst, std::string(regex_message_cat));
psyntax = pmd->syntax_;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
lower_map = new wchar_t[char_set_size];
BOOST_REGEX_NOEH_ASSERT(lower_map)
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete pmd;
throw;
}
#endif
for(unsigned int i = 0; i < char_set_size; ++i)
lower_map[i] = static_cast<wchar_t>(i);
pctype = &BOOST_USE_FACET(std::ctype<wchar_t>, locale_inst);
pctype->tolower(&lower_map[0], &lower_map[char_set_size]);
pcollate = &BOOST_USE_FACET(std::collate<wchar_t>, locale_inst);
typedef std::codecvt<wchar_t, char, std::mbstate_t> cvt_t;
pcdv = &BOOST_USE_FACET(cvt_t, locale_inst);
sort_type = re_detail::find_sort_syntax(this, &(this->sort_delim));
}
cpp_regex_traits<wchar_t>::~cpp_regex_traits()
{
delete pmd;
delete[] lower_map;
}
cpp_regex_traits<wchar_t>::locale_type BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::imbue(locale_type l)
{
locale_type old_l(locale_inst);
locale_inst = l;
re_detail::message_data<wchar_t>* npmd = new re_detail::message_data<wchar_t>(locale_inst, std::string(regex_message_cat));
delete pmd;
pmd = npmd;
psyntax = pmd->syntax_;
for(unsigned int i = 0; i < char_set_size; ++i)
lower_map[i] = static_cast<wchar_t>(i);
pctype = &BOOST_USE_FACET(std::ctype<wchar_t>, locale_inst);
pctype->tolower(&lower_map[0], &lower_map[char_set_size]);
pcollate = &BOOST_USE_FACET(std::collate<wchar_t>, locale_inst);
typedef std::codecvt<wchar_t, char, std::mbstate_t> cvt_t;
pcdv = &BOOST_USE_FACET(cvt_t, locale_inst);
sort_type = re_detail::find_sort_syntax(this, &(this->sort_delim));
return old_l;
}
std::size_t BOOST_REGEX_CALL cpp_regex_traits<wchar_t>::strwiden(wchar_t *s1, std::size_t len, const char *s2)const
{
std::string s(s2);
std::wstring ws = re_detail::to_wide(s2, *pcdv);
if(len > ws.size())
std::wcscpy(s1, ws.c_str());
return ws.size()+1;
}
#endif // BOOST_NO_WREGEX
} // namespace boost
#endif

View File

@ -0,0 +1,657 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: cregex.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Implements high level class boost::RexEx
*/
#define BOOST_REGEX_SOURCE
#include <boost/cregex.hpp>
#include <boost/regex.hpp>
#if !defined(BOOST_NO_STD_STRING)
#include <map>
#include <list>
#include <boost/regex/detail/fileiter.hpp>
#include <cstdio>
namespace boost{
#ifdef __BORLANDC__
#if __BORLANDC__ < 0x530
//
// we need to instantiate the vector classes we use
// since declaring a reference to type doesn't seem to
// do the job...
std::vector<std::size_t> inst1;
std::vector<std::string> inst2;
#endif
#endif
namespace{
template <class iterator>
std::string to_string(iterator i, iterator j)
{
BOOST_RE_GUARD_STACK
std::string s;
while(i != j)
{
s.append(1, *i);
++i;
}
return s;
}
inline std::string to_string(const char* i, const char* j)
{
return std::string(i, j);
}
}
namespace re_detail{
class RegExData
{
public:
enum type
{
type_pc,
type_pf,
type_copy
};
regex e;
cmatch m;
#ifndef BOOST_REGEX_NO_FILEITER
match_results<mapfile::iterator, regex::allocator_type> fm;
#endif
type t;
const char* pbase;
unsigned line;
#ifndef BOOST_REGEX_NO_FILEITER
mapfile::iterator fbase;
#endif
std::map<int, std::string, std::less<int> > strings;
std::map<int, std::ptrdiff_t, std::less<int> > positions;
void update();
void clean();
RegExData() : e(), m(),
#ifndef BOOST_REGEX_NO_FILEITER
fm(),
#endif
t(type_copy), pbase(0), line(0),
#ifndef BOOST_REGEX_NO_FILEITER
fbase(),
#endif
strings(), positions() {}
};
void RegExData::update()
{
BOOST_RE_GUARD_STACK
strings.erase(strings.begin(), strings.end());
positions.erase(positions.begin(), positions.end());
if(t == type_pc)
{
for(unsigned int i = 0; i < m.size(); ++i)
{
if(m[i].matched) strings[i] = std::string(m[i].first, m[i].second);
positions[i] = m[i].matched ? m[i].first - pbase : -1;
}
line = m.line();
}
#ifndef BOOST_REGEX_NO_FILEITER
else
{
for(unsigned int i = 0; i < fm.size(); ++i)
{
if(fm[i].matched) strings[i] = to_string(fm[i].first, fm[i].second);
positions[i] = fm[i].matched ? fm[i].first - fbase : -1;
}
line = fm.line();
}
#endif
t = type_copy;
}
void RegExData::clean()
{
BOOST_RE_GUARD_STACK
#ifndef BOOST_REGEX_NO_FILEITER
fbase = mapfile::iterator();
fm = match_results<mapfile::iterator, regex::allocator_type>();
#endif
}
} // namespace
RegEx::RegEx()
{
BOOST_RE_GUARD_STACK
pdata = new re_detail::RegExData();
}
RegEx::RegEx(const RegEx& o)
{
BOOST_RE_GUARD_STACK
pdata = new re_detail::RegExData(*(o.pdata));
}
RegEx::~RegEx()
{
BOOST_RE_GUARD_STACK
delete pdata;
}
RegEx::RegEx(const char* c, bool icase)
{
BOOST_RE_GUARD_STACK
pdata = new re_detail::RegExData();
SetExpression(c, icase);
}
RegEx::RegEx(const std::string& s, bool icase)
{
BOOST_RE_GUARD_STACK
pdata = new re_detail::RegExData();
SetExpression(s.c_str(), icase);
}
RegEx& RegEx::operator=(const RegEx& o)
{
BOOST_RE_GUARD_STACK
*pdata = *(o.pdata);
return *this;
}
RegEx& RegEx::operator=(const char* p)
{
BOOST_RE_GUARD_STACK
SetExpression(p, false);
return *this;
}
unsigned int RegEx::SetExpression(const char* p, bool icase)
{
BOOST_RE_GUARD_STACK
boost::uint_fast32_t f = icase ? regbase::normal | regbase::use_except | regbase::icase : regbase::normal | regbase::use_except;
return pdata->e.set_expression(p, f);
}
unsigned int RegEx::error_code()const
{
return pdata->e.error_code();
}
std::string RegEx::Expression()const
{
BOOST_RE_GUARD_STACK
return pdata->e.expression();
}
//
// now matching operators:
//
bool RegEx::Match(const char* p, unsigned int flags)
{
BOOST_RE_GUARD_STACK
pdata->t = re_detail::RegExData::type_pc;
pdata->pbase = p;
const char* end = p;
while(*end)++end;
if(regex_match(p, end, pdata->m, pdata->e, flags))
{
pdata->update();
return true;
}
return false;
}
bool RegEx::Search(const char* p, unsigned int flags)
{
BOOST_RE_GUARD_STACK
pdata->t = re_detail::RegExData::type_pc;
pdata->pbase = p;
const char* end = p;
while(*end)++end;
if(regex_search(p, end, pdata->m, pdata->e, flags))
{
pdata->update();
return true;
}
return false;
}
namespace re_detail{
struct pred1
{
GrepCallback cb;
RegEx* pe;
pred1(GrepCallback c, RegEx* i) : cb(c), pe(i) {}
bool operator()(const cmatch& m)
{
pe->pdata->m = m;
return cb(*pe);
}
};
}
unsigned int RegEx::Grep(GrepCallback cb, const char* p, unsigned int flags)
{
BOOST_RE_GUARD_STACK
pdata->t = re_detail::RegExData::type_pc;
pdata->pbase = p;
const char* end = p;
while(*end)++end;
unsigned int result = regex_grep(re_detail::pred1(cb, this), p, end, pdata->e, flags);
if(result)
pdata->update();
return result;
}
namespace re_detail{
struct pred2
{
std::vector<std::string>& v;
RegEx* pe;
pred2(std::vector<std::string>& o, RegEx* e) : v(o), pe(e) {}
bool operator()(const cmatch& m)
{
pe->pdata->m = m;
v.push_back(std::string(m[0].first, m[0].second));
return true;
}
private:
pred2& operator=(const pred2&);
};
}
unsigned int RegEx::Grep(std::vector<std::string>& v, const char* p, unsigned int flags)
{
BOOST_RE_GUARD_STACK
pdata->t = re_detail::RegExData::type_pc;
pdata->pbase = p;
const char* end = p;
while(*end)++end;
unsigned int result = regex_grep(re_detail::pred2(v, this), p, end, pdata->e, flags);
if(result)
pdata->update();
return result;
}
namespace re_detail{
struct pred3
{
std::vector<std::size_t>& v;
const char* base;
RegEx* pe;
pred3(std::vector<std::size_t>& o, const char* pb, RegEx* p) : v(o), base(pb), pe(p) {}
bool operator()(const cmatch& m)
{
pe->pdata->m = m;
v.push_back(static_cast<std::size_t>(m[0].first - base));
return true;
}
private:
pred3& operator=(const pred3&);
};
}
unsigned int RegEx::Grep(std::vector<std::size_t>& v, const char* p, unsigned int flags)
{
BOOST_RE_GUARD_STACK
pdata->t = re_detail::RegExData::type_pc;
pdata->pbase = p;
const char* end = p;
while(*end)++end;
unsigned int result = regex_grep(re_detail::pred3(v, p, this), p, end, pdata->e, flags);
if(result)
pdata->update();
return result;
}
#ifndef BOOST_REGEX_NO_FILEITER
namespace re_detail{
struct pred4
{
GrepFileCallback cb;
RegEx* pe;
const char* file;
bool ok;
pred4(GrepFileCallback c, RegEx* i, const char* f) : cb(c), pe(i), file(f), ok(true) {}
bool operator()(const match_results<mapfile::iterator, regex::allocator_type>& m)
{
pe->pdata->t = RegExData::type_pf;
pe->pdata->fm = m;
pe->pdata->update();
ok = cb(file, *pe);
return ok;
}
};
}
namespace{
void BuildFileList(std::list<std::string>* pl, const char* files, bool recurse)
{
BOOST_RE_GUARD_STACK
file_iterator start(files);
file_iterator end;
if(recurse)
{
// go through sub directories:
char buf[MAX_PATH];
std::strcpy(buf, start.root());
if(*buf == 0)
{
std::strcpy(buf, ".");
std::strcat(buf, directory_iterator::separator());
std::strcat(buf, "*");
}
else
{
std::strcat(buf, directory_iterator::separator());
std::strcat(buf, "*");
}
directory_iterator dstart(buf);
directory_iterator dend;
// now get the file mask bit of "files":
const char* ptr = files;
while(*ptr) ++ptr;
while((ptr != files) && (*ptr != *directory_iterator::separator()) && (*ptr != '/'))--ptr;
if(ptr != files) ++ptr;
while(dstart != dend)
{
std::sprintf(buf, "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
BuildFileList(pl, buf, recurse);
++dstart;
}
}
while(start != end)
{
pl->push_back(*start);
++start;
}
}
}
unsigned int RegEx::GrepFiles(GrepFileCallback cb, const char* files, bool recurse, unsigned int flags)
{
BOOST_RE_GUARD_STACK
unsigned int result = 0;
std::list<std::string> file_list;
BuildFileList(&file_list, files, recurse);
std::list<std::string>::iterator start, end;
start = file_list.begin();
end = file_list.end();
while(start != end)
{
mapfile map((*start).c_str());
pdata->t = re_detail::RegExData::type_pf;
pdata->fbase = map.begin();
re_detail::pred4 pred(cb, this, (*start).c_str());
int r = regex_grep(pred, map.begin(), map.end(), pdata->e, flags);
result += r;
++start;
pdata->clean();
if(pred.ok == false)
return result;
}
return result;
}
unsigned int RegEx::FindFiles(FindFilesCallback cb, const char* files, bool recurse, unsigned int flags)
{
BOOST_RE_GUARD_STACK
unsigned int result = 0;
std::list<std::string> file_list;
BuildFileList(&file_list, files, recurse);
std::list<std::string>::iterator start, end;
start = file_list.begin();
end = file_list.end();
while(start != end)
{
mapfile map((*start).c_str());
pdata->t = re_detail::RegExData::type_pf;
pdata->fbase = map.begin();
if(regex_search(map.begin(), map.end(), pdata->fm, pdata->e, flags))
{
++result;
if(false == cb((*start).c_str()))
return result;
}
//pdata->update();
++start;
//pdata->clean();
}
return result;
}
#endif
std::string RegEx::Merge(const std::string& in, const std::string& fmt,
bool copy, unsigned int flags)
{
std::string result;
re_detail::string_out_iterator<std::string> i(result);
if(!copy) flags |= format_no_copy;
regex_merge(i, in.begin(), in.end(), pdata->e, fmt.c_str(), flags);
return result;
}
std::string RegEx::Merge(const char* in, const char* fmt,
bool copy, unsigned int flags)
{
std::string result;
if(!copy) flags |= format_no_copy;
re_detail::string_out_iterator<std::string> i(result);
regex_merge(i, in, in + std::strlen(in), pdata->e, fmt, flags);
return result;
}
std::size_t RegEx::Split(std::vector<std::string>& v,
std::string& s,
unsigned flags,
unsigned max_count)
{
return regex_split(std::back_inserter(v), s, pdata->e, flags, max_count);
}
//
// now operators for returning what matched in more detail:
//
std::size_t RegEx::Position(int i)const
{
BOOST_RE_GUARD_STACK
switch(pdata->t)
{
case re_detail::RegExData::type_pc:
return pdata->m[i].matched ? pdata->m[i].first - pdata->pbase : RegEx::npos;
#ifndef BOOST_REGEX_NO_FILEITER
case re_detail::RegExData::type_pf:
return pdata->fm[i].matched ? pdata->fm[i].first - pdata->fbase : RegEx::npos;
#endif
case re_detail::RegExData::type_copy:
{
std::map<int, std::ptrdiff_t, std::less<int> >::iterator pos = pdata->positions.find(i);
if(pos == pdata->positions.end())
return RegEx::npos;
return (*pos).second;
}
}
return RegEx::npos;
}
unsigned int RegEx::Line()const
{
BOOST_RE_GUARD_STACK
switch(pdata->t)
{
case re_detail::RegExData::type_pc:
return pdata->m[0].matched ? pdata->m.line() : RegEx::npos;
#ifndef BOOST_REGEX_NO_FILEITER
case re_detail::RegExData::type_pf:
return pdata->fm[0].matched ? pdata->fm.line() : RegEx::npos;
#endif
case re_detail::RegExData::type_copy:
{
return pdata->line;
}
}
return RegEx::npos;
}
unsigned int RegEx::Marks()const
{
BOOST_RE_GUARD_STACK
return pdata->e.mark_count();
}
std::size_t RegEx::Length(int i)const
{
BOOST_RE_GUARD_STACK
switch(pdata->t)
{
case re_detail::RegExData::type_pc:
return pdata->m[i].matched ? pdata->m[i].second - pdata->m[i].first : RegEx::npos;
#ifndef BOOST_REGEX_NO_FILEITER
case re_detail::RegExData::type_pf:
return pdata->fm[i].matched ? pdata->fm[i].second - pdata->fm[i].first : RegEx::npos;
#endif
case re_detail::RegExData::type_copy:
{
std::map<int, std::string, std::less<int> >::iterator pos = pdata->strings.find(i);
if(pos == pdata->strings.end())
return RegEx::npos;
return (*pos).second.size();
}
}
return RegEx::npos;
}
bool RegEx::Matched(int i)const
{
BOOST_RE_GUARD_STACK
switch(pdata->t)
{
case re_detail::RegExData::type_pc:
return pdata->m[i].matched;
#ifndef BOOST_REGEX_NO_FILEITER
case re_detail::RegExData::type_pf:
return pdata->fm[i].matched;
#endif
case re_detail::RegExData::type_copy:
{
std::map<int, std::string, std::less<int> >::iterator pos = pdata->strings.find(i);
if(pos == pdata->strings.end())
return false;
return true;
}
}
return false;
}
std::string RegEx::What(int i)const
{
BOOST_RE_GUARD_STACK
std::string result;
switch(pdata->t)
{
case re_detail::RegExData::type_pc:
if(pdata->m[i].matched)
result.assign(pdata->m[i].first, pdata->m[i].second);
break;
case re_detail::RegExData::type_pf:
if(pdata->m[i].matched)
result.assign(to_string(pdata->m[i].first, pdata->m[i].second));
break;
case re_detail::RegExData::type_copy:
{
std::map<int, std::string, std::less<int> >::iterator pos = pdata->strings.find(i);
if(pos != pdata->strings.end())
result = (*pos).second;
break;
}
}
return result;
}
const unsigned int RegEx::npos = ~0u;
} // namespace boost
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) && (__BORLANDC__ <= 0x551) && !defined(_RWSTD_COMPILE_INSTANTIATE)
//
// this is an ugly hack to work around an ugly problem:
// by default this file will produce unresolved externals during
// linking unless _RWSTD_COMPILE_INSTANTIATE is defined (Borland bug).
// However if _RWSTD_COMPILE_INSTANTIATE is defined then we get separate
// copies of basic_string's static data in the RTL and this DLL, this messes
// with basic_string's memory management and results in run-time crashes,
// Oh sweet joy of Catch 22....
//
namespace std{
template<> template<>
basic_string<char>&
basic_string<char>::replace<const char*>(char* f1, char* f2, const char* i1, const char* i2)
{
unsigned insert_pos = f1 - begin();
unsigned remove_len = f2 - f1;
unsigned insert_len = i2 - i1;
unsigned org_size = size();
if(insert_len > remove_len)
{
append(insert_len-remove_len, ' ');
std::copy_backward(begin() + insert_pos + remove_len, begin() + org_size, end());
std::copy(i1, i2, begin() + insert_pos);
}
else
{
std::copy(begin() + insert_pos + remove_len, begin() + org_size, begin() + insert_pos + insert_len);
std::copy(i1, i2, begin() + insert_pos);
erase(size() + insert_len - remove_len);
}
return *this;
}
}
#endif
#endif

View File

@ -0,0 +1,902 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: fileiter.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Implements file io primitives + directory searching for class boost::RegEx.
*/
#define BOOST_REGEX_SOURCE
#include <climits>
#include <stdexcept>
#include <boost/regex/detail/fileiter.hpp>
#ifndef BOOST_REGEX_NO_FILEITER
#if defined(__CYGWIN__) || defined(__CYGWIN32__)
#include <sys/cygwin.h>
#endif
#ifdef BOOST_MSVC
# pragma warning(disable: 4800)
#endif
namespace boost{
namespace re_detail{
// start with the operating system specific stuff:
#if (defined(__BORLANDC__) || defined(BOOST_REGEX_FI_WIN32_DIR) || defined(BOOST_MSVC)) && !defined(BOOST_RE_NO_WIN32)
// platform is DOS or Windows
// directories are separated with '\\'
// and names are insensitive of case
const char* _fi_sep = "\\";
const char* _fi_sep_alt = "/";
#define BOOST_REGEX_FI_TRANSLATE(c) std::tolower(c)
#else
// platform is not DOS or Windows
// directories are separated with '/'
// and names are sensitive of case
const char* _fi_sep = "/";
const char* _fi_sep_alt = _fi_sep;
#define BOOST_REGEX_FI_TRANSLATE(c) c
#endif
#ifdef BOOST_REGEX_FI_WIN32_MAP
void mapfile::open(const char* file)
{
BOOST_RE_GUARD_STACK
#if defined(__CYGWIN__)||defined(__CYGWIN32__)
char win32file[ MAX_PATH ];
cygwin_conv_to_win32_path( file, win32file );
hfile = CreateFileA(win32file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
#else
hfile = CreateFileA(file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
#endif
if(hfile != INVALID_HANDLE_VALUE)
{
hmap = CreateFileMapping(hfile, 0, PAGE_READONLY, 0, 0, 0);
if((hmap == INVALID_HANDLE_VALUE) || (hmap == NULL))
{
CloseHandle(hfile);
hmap = 0;
hfile = 0;
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to create file mapping.");
#else
BOOST_REGEX_NOEH_ASSERT(hmap != INVALID_HANDLE_VALUE);
#endif
}
_first = static_cast<const char*>(MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0));
if(_first == 0)
{
CloseHandle(hmap);
CloseHandle(hfile);
hmap = 0;
hfile = 0;
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to create file mapping.");
#else
BOOST_REGEX_NOEH_ASSERT(_first != 0);
#endif
}
_last = _first + GetFileSize(hfile, 0);
}
else
{
hfile = 0;
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to open file.");
#else
BOOST_REGEX_NOEH_ASSERT(hfile != INVALID_HANDLE_VALUE);
#endif
}
}
void mapfile::close()
{
BOOST_RE_GUARD_STACK
if(hfile != INVALID_HANDLE_VALUE)
{
UnmapViewOfFile((void*)_first);
CloseHandle(hmap);
CloseHandle(hfile);
hmap = hfile = 0;
_first = _last = 0;
}
}
#elif !defined(BOOST_RE_NO_STL)
mapfile_iterator& mapfile_iterator::operator = (const mapfile_iterator& i)
{
BOOST_RE_GUARD_STACK
if(file && node)
file->unlock(node);
file = i.file;
node = i.node;
offset = i.offset;
if(file)
file->lock(node);
return *this;
}
mapfile_iterator& mapfile_iterator::operator++ ()
{
BOOST_RE_GUARD_STACK
if((++offset == mapfile::buf_size) && file)
{
++node;
offset = 0;
file->lock(node);
file->unlock(node-1);
}
return *this;
}
mapfile_iterator mapfile_iterator::operator++ (int)
{
BOOST_RE_GUARD_STACK
mapfile_iterator temp(*this);
if((++offset == mapfile::buf_size) && file)
{
++node;
offset = 0;
file->lock(node);
file->unlock(node-1);
}
return temp;
}
mapfile_iterator& mapfile_iterator::operator-- ()
{
BOOST_RE_GUARD_STACK
if((offset == 0) && file)
{
--node;
offset = mapfile::buf_size - 1;
file->lock(node);
file->unlock(node + 1);
}
else
--offset;
return *this;
}
mapfile_iterator mapfile_iterator::operator-- (int)
{
BOOST_RE_GUARD_STACK
mapfile_iterator temp(*this);
if((offset == 0) && file)
{
--node;
offset = mapfile::buf_size - 1;
file->lock(node);
file->unlock(node + 1);
}
else
--offset;
return temp;
}
mapfile_iterator operator + (const mapfile_iterator& i, long off)
{
BOOST_RE_GUARD_STACK
mapfile_iterator temp(i);
temp += off;
return temp;
}
mapfile_iterator operator - (const mapfile_iterator& i, long off)
{
BOOST_RE_GUARD_STACK
mapfile_iterator temp(i);
temp -= off;
return temp;
}
mapfile::iterator mapfile::begin()const
{
BOOST_RE_GUARD_STACK
return mapfile_iterator(this, 0);
}
mapfile::iterator mapfile::end()const
{
BOOST_RE_GUARD_STACK
return mapfile_iterator(this, _size);
}
void mapfile::lock(pointer* node)const
{
BOOST_RE_GUARD_STACK
assert(node >= _first);
assert(node <= _last);
if(node < _last)
{
if(*node == 0)
{
if(condemed.empty())
{
*node = new char[sizeof(int) + buf_size];
*(reinterpret_cast<int*>(*node)) = 1;
}
else
{
pointer* p = condemed.front();
condemed.pop_front();
*node = *p;
*p = 0;
*(reinterpret_cast<int*>(*node)) = 1;
}
std::fseek(hfile, (node - _first) * buf_size, SEEK_SET);
if(node == _last - 1)
std::fread(*node + sizeof(int), _size % buf_size, 1, hfile);
else
std::fread(*node + sizeof(int), buf_size, 1, hfile);
}
else
{
if(*reinterpret_cast<int*>(*node) == 0)
{
*reinterpret_cast<int*>(*node) = 1;
condemed.remove(node);
}
else
++(*reinterpret_cast<int*>(*node));
}
}
}
void mapfile::unlock(pointer* node)const
{
BOOST_RE_GUARD_STACK
assert(node >= _first);
assert(node <= _last);
if(node < _last)
{
if(--(*reinterpret_cast<int*>(*node)) == 0)
{
condemed.push_back(node);
}
}
}
long int get_file_length(std::FILE* hfile)
{
BOOST_RE_GUARD_STACK
long int result;
std::fseek(hfile, 0, SEEK_END);
result = std::ftell(hfile);
std::fseek(hfile, 0, SEEK_SET);
return result;
}
void mapfile::open(const char* file)
{
BOOST_RE_GUARD_STACK
hfile = std::fopen(file, "rb");
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
if(hfile != 0)
{
_size = get_file_length(hfile);
long cnodes = (_size + buf_size - 1) / buf_size;
// check that number of nodes is not too high:
if(cnodes > (long)((INT_MAX) / sizeof(pointer*)))
{
std::fclose(hfile);
hfile = 0;
_size = 0;
return;
}
_first = new pointer[(int)cnodes];
_last = _first + cnodes;
std::memset(_first, 0, cnodes*sizeof(pointer));
}
else
{
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to open file.");
#else
BOOST_REGEX_NOEH_ASSERT(hfile != 0);
#endif
}
#ifndef BOOST_NO_EXCEPTIONS
}catch(...)
{ close(); throw; }
#endif
}
void mapfile::close()
{
BOOST_RE_GUARD_STACK
if(hfile != 0)
{
pointer* p = _first;
while(p != _last)
{
if(*p)
delete[] *p;
++p;
}
delete[] _first;
_size = 0;
_first = _last = 0;
std::fclose(hfile);
hfile = 0;
condemed.erase(condemed.begin(), condemed.end());
}
}
#endif
file_iterator::file_iterator()
{
BOOST_RE_GUARD_STACK
_root = _path = 0;
ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
_root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
ptr = _path;
*_path = 0;
*_root = 0;
ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->hf = _fi_invalid_handle;
ref->count = 1;
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete[] _root;
delete[] _path;
delete ref;
throw;
}
#endif
}
file_iterator::file_iterator(const char* wild)
{
BOOST_RE_GUARD_STACK
_root = _path = 0;
ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
_root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, wild);
ptr = _root;
while(*ptr)++ptr;
while((ptr > _root) && (*ptr != *_fi_sep) && (*ptr != *_fi_sep_alt))--ptr;
#if 0
*ptr = 0;
std::strcpy(_path, _root);
if(*_path == 0)
std::strcpy(_path, ".");
std::strcat(_path, _fi_sep);
ptr = _path + std::strlen(_path);
#else
if((ptr == _root) && ( (*ptr== *_fi_sep) || (*ptr==*_fi_sep_alt) ) )
{
_root[1]='\0';
std::strcpy(_path, _root);
ptr = _path + std::strlen(_path);
}
else
{
*ptr = 0;
std::strcpy(_path, _root);
if(*_path == 0)
std::strcpy(_path, ".");
std::strcat(_path, _fi_sep);
ptr = _path + std::strlen(_path);
}
#endif
ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->hf = FindFirstFileA(wild, &(ref->_data));
ref->count = 1;
if(ref->hf == _fi_invalid_handle)
{
*_path = 0;
ptr = _path;
}
else
{
std::strcpy(ptr, ref->_data.cFileName);
if(ref->_data.dwFileAttributes & _fi_dir)
next();
}
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete[] _root;
delete[] _path;
delete ref;
throw;
}
#endif
}
file_iterator::file_iterator(const file_iterator& other)
{
BOOST_RE_GUARD_STACK
_root = _path = 0;
ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
_root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, other._root);
std::strcpy(_path, other._path);
ptr = _path + (other.ptr - other._path);
ref = other.ref;
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete[] _root;
delete[] _path;
throw;
}
#endif
++(ref->count);
}
file_iterator& file_iterator::operator=(const file_iterator& other)
{
BOOST_RE_GUARD_STACK
std::strcpy(_root, other._root);
std::strcpy(_path, other._path);
ptr = _path + (other.ptr - other._path);
if(--(ref->count) == 0)
{
if(ref->hf != _fi_invalid_handle)
FindClose(ref->hf);
delete ref;
}
ref = other.ref;
++(ref->count);
return *this;
}
file_iterator::~file_iterator()
{
BOOST_RE_GUARD_STACK
delete[] _root;
delete[] _path;
if(--(ref->count) == 0)
{
if(ref->hf != _fi_invalid_handle)
FindClose(ref->hf);
delete ref;
}
}
file_iterator file_iterator::operator++(int)
{
BOOST_RE_GUARD_STACK
file_iterator temp(*this);
next();
return temp;
}
void file_iterator::next()
{
BOOST_RE_GUARD_STACK
if(ref->hf != _fi_invalid_handle)
{
bool cont = true;
while(cont)
{
cont = FindNextFileA(ref->hf, &(ref->_data));
if(cont && ((ref->_data.dwFileAttributes & _fi_dir) == 0))
break;
}
if(!cont)
{
// end of sequence
FindClose(ref->hf);
ref->hf = _fi_invalid_handle;
*_path = 0;
ptr = _path;
}
else
std::strcpy(ptr, ref->_data.cFileName);
}
}
directory_iterator::directory_iterator()
{
BOOST_RE_GUARD_STACK
_root = _path = 0;
ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
_root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
ptr = _path;
*_path = 0;
*_root = 0;
ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->hf = _fi_invalid_handle;
ref->count = 1;
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete[] _root;
delete[] _path;
delete ref;
throw;
}
#endif
}
directory_iterator::directory_iterator(const char* wild)
{
BOOST_RE_GUARD_STACK
_root = _path = 0;
ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
_root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, wild);
ptr = _root;
while(*ptr)++ptr;
while((ptr > _root) && (*ptr != *_fi_sep) && (*ptr != *_fi_sep_alt))--ptr;
#if 0
*ptr = 0;
std::strcpy(_path, _root);
if(*_path == 0)
std::strcpy(_path, ".");
std::strcat(_path, _fi_sep);
ptr = _path + std::strlen(_path);
#else
if((ptr == _root) && ( (*ptr== *_fi_sep) || (*ptr==*_fi_sep_alt) ) )
{
_root[1]='\0';
std::strcpy(_path, _root);
ptr = _path + std::strlen(_path);
}
else
{
*ptr = 0;
std::strcpy(_path, _root);
if(*_path == 0)
std::strcpy(_path, ".");
std::strcat(_path, _fi_sep);
ptr = _path + std::strlen(_path);
}
#endif
ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->count = 1;
ref->hf = FindFirstFileA(wild, &(ref->_data));
if(ref->hf == _fi_invalid_handle)
{
*_path = 0;
ptr = _path;
}
else
{
std::strcpy(ptr, ref->_data.cFileName);
if(((ref->_data.dwFileAttributes & _fi_dir) == 0) || (std::strcmp(ref->_data.cFileName, ".") == 0) || (std::strcmp(ref->_data.cFileName, "..") == 0))
next();
}
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete[] _root;
delete[] _path;
delete ref;
throw;
}
#endif
}
directory_iterator::~directory_iterator()
{
BOOST_RE_GUARD_STACK
delete[] _root;
delete[] _path;
if(--(ref->count) == 0)
{
if(ref->hf != _fi_invalid_handle)
FindClose(ref->hf);
delete ref;
}
}
directory_iterator::directory_iterator(const directory_iterator& other)
{
BOOST_RE_GUARD_STACK
_root = _path = 0;
ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
_root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, other._root);
std::strcpy(_path, other._path);
ptr = _path + (other.ptr - other._path);
ref = other.ref;
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete[] _root;
delete[] _path;
throw;
}
#endif
++(ref->count);
}
directory_iterator& directory_iterator::operator=(const directory_iterator& other)
{
BOOST_RE_GUARD_STACK
std::strcpy(_root, other._root);
std::strcpy(_path, other._path);
ptr = _path + (other.ptr - other._path);
if(--(ref->count) == 0)
{
if(ref->hf != _fi_invalid_handle)
FindClose(ref->hf);
delete ref;
}
ref = other.ref;
++(ref->count);
return *this;
}
directory_iterator directory_iterator::operator++(int)
{
BOOST_RE_GUARD_STACK
directory_iterator temp(*this);
next();
return temp;
}
void directory_iterator::next()
{
BOOST_RE_GUARD_STACK
if(ref->hf != _fi_invalid_handle)
{
bool cont = true;
while(cont)
{
cont = FindNextFileA(ref->hf, &(ref->_data));
if(cont && (ref->_data.dwFileAttributes & _fi_dir))
{
if(std::strcmp(ref->_data.cFileName, ".") && std::strcmp(ref->_data.cFileName, ".."))
break;
}
}
if(!cont)
{
// end of sequence
FindClose(ref->hf);
ref->hf = _fi_invalid_handle;
*_path = 0;
ptr = _path;
}
else
std::strcpy(ptr, ref->_data.cFileName);
}
}
#ifdef BOOST_REGEX_FI_POSIX_DIR
struct _fi_priv_data
{
char root[MAX_PATH];
char* mask;
DIR* d;
_fi_priv_data(const char* p);
};
_fi_priv_data::_fi_priv_data(const char* p)
{
BOOST_RE_GUARD_STACK
std::strcpy(root, p);
mask = root;
while(*mask) ++mask;
while((mask > root) && (*mask != *_fi_sep) && (*mask != *_fi_sep_alt)) --mask;
if(mask == root && ((*mask== *_fi_sep) || (*mask == *_fi_sep_alt)) )
{
root[1] = '\0';
std::strcpy(root+2, p+1);
mask = root+2;
}
else if(mask == root)
{
root[0] = '.';
root[1] = '\0';
std::strcpy(root+2, p);
mask = root+2;
}
else
{
*mask = 0;
++mask;
}
}
bool iswild(const char* mask, const char* name)
{
BOOST_RE_GUARD_STACK
while(*mask && *name)
{
switch(*mask)
{
case '?':
++name;
++mask;
continue;
case '*':
++mask;
if(*mask == 0)
return true;
while(*name)
{
if(iswild(mask, name))
return true;
++name;
}
return false;
case '.':
if(0 == *name)
{
++mask;
continue;
}
// fall through:
default:
if(BOOST_REGEX_FI_TRANSLATE(*mask) != BOOST_REGEX_FI_TRANSLATE(*name))
return false;
++mask;
++name;
continue;
}
}
if(*mask != *name)
return false;
return true;
}
unsigned _fi_attributes(const char* root, const char* name)
{
BOOST_RE_GUARD_STACK
char buf[MAX_PATH];
if( ( (root[0] == *_fi_sep) || (root[0] == *_fi_sep_alt) ) && (root[1] == '\0') )
std::sprintf(buf, "%s%s", root, name);
else
std::sprintf(buf, "%s%s%s", root, _fi_sep, name);
DIR* d = opendir(buf);
if(d)
{
closedir(d);
return _fi_dir;
}
return 0;
}
_fi_find_handle _fi_FindFirstFile(const char* lpFileName, _fi_find_data* lpFindFileData)
{
BOOST_RE_GUARD_STACK
_fi_find_handle dat = new _fi_priv_data(lpFileName);
DIR* h = opendir(dat->root);
dat->d = h;
if(h != 0)
{
if(_fi_FindNextFile(dat, lpFindFileData))
return dat;
}
delete dat;
return 0;
}
bool _fi_FindNextFile(_fi_find_handle dat, _fi_find_data* lpFindFileData)
{
BOOST_RE_GUARD_STACK
dirent* d;
do
{
d = readdir(dat->d);
} while(d && !iswild(dat->mask, d->d_name));
if(d)
{
std::strcpy(lpFindFileData->cFileName, d->d_name);
lpFindFileData->dwFileAttributes = _fi_attributes(dat->root, d->d_name);
return true;
}
return false;
}
bool _fi_FindClose(_fi_find_handle dat)
{
BOOST_RE_GUARD_STACK
closedir(dat->d);
delete dat;
return true;
}
#endif
} // namespace re_detail
} // namspace boost
#endif // BOOST_REGEX_NO_FILEITER

View File

@ -0,0 +1,36 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: instances.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: regex narrow character template instances.
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex/config.hpp>
#if !defined(BOOST_REGEX_NO_EXTERNAL_TEMPLATES)
#define BOOST_REGEX_NARROW_INSTANTIATE
#ifdef __BORLANDC__
#pragma hrdstop
#endif
#include <boost/regex.hpp>
#endif

View File

@ -0,0 +1,237 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: posix_api.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Implements the Posix API wrappers.
*/
#define BOOST_REGEX_SOURCE
#include <cstdio>
#include <boost/regex.hpp>
namespace boost{
namespace{
unsigned int magic_value = 25631;
const char* names[] = {"REG_NOERROR", "REG_NOMATCH", "REG_BADPAT", "REG_ECOLLATE",
"REG_ECTYPE", "REG_EESCAPE", "REG_ESUBREG", "REG_EBRACK",
"REG_EPAREN", "REG_EBRACE", "REG_BADBR", "REG_ERANGE",
"REG_ESPACE", "REG_BADRPT", "REG_EMPTY", "REG_E_UNKNOWN"};
} // namespace
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA* expression, const char* ptr, int f)
{
BOOST_RE_GUARD_STACK
if(expression->re_magic != magic_value)
{
expression->guts = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
expression->guts = new regex();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
return REG_ESPACE;
}
#else
if(0 == expression->guts)
return REG_E_MEMORY;
#endif
}
// set default flags:
boost::uint_fast32_t flags = (f & REG_EXTENDED) ? regbase::extended : regbase::basic;
expression->eflags = (f & REG_NEWLINE) ? match_not_dot_newline : 0;
// and translate those that are actually set:
if(f & REG_NOCOLLATE)
flags |= regbase::nocollate;
if(f & REG_NOSUB)
expression->eflags |= match_any;
if(f & REG_NOSPEC)
flags |= regbase::literal;
if(f & REG_ICASE)
flags |= regbase::icase;
if(f & REG_ESCAPE_IN_LISTS)
flags |= regbase::escape_in_lists;
if(f & REG_NEWLINE_ALT)
flags |= regbase::newline_alt;
const char* p2;
if(f & REG_PEND)
p2 = expression->re_endp;
else p2 = ptr + std::strlen(ptr);
int result;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
expression->re_magic = magic_value;
static_cast<regex*>(expression->guts)->set_expression(ptr, p2, flags);
expression->re_nsub = static_cast<regex*>(expression->guts)->mark_count() - 1;
result = static_cast<regex*>(expression->guts)->error_code();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
result = REG_E_UNKNOWN;
}
#endif
if(result)
regfreeA(expression);
return result;
}
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int code, const regex_tA* e, char* buf, regsize_t buf_size)
{
BOOST_RE_GUARD_STACK
std::size_t result = 0;
if(code & REG_ITOA)
{
code &= ~REG_ITOA;
if(code <= REG_E_UNKNOWN)
{
result = std::strlen(names[code]) + 1;
if(buf_size >= result)
std::strcpy(buf, names[code]);
return result;
}
return result;
}
if(code == REG_ATOI)
{
char localbuf[5];
if(e == 0)
return 0;
for(int i = 0; i <= REG_E_UNKNOWN; ++i)
{
if(std::strcmp(e->re_endp, names[i]) == 0)
{
std::sprintf(localbuf, "%d", i);
if(std::strlen(localbuf) < buf_size)
std::strcpy(buf, localbuf);
return std::strlen(localbuf) + 1;
}
}
std::sprintf(localbuf, "%d", 0);
if(std::strlen(localbuf) < buf_size)
std::strcpy(buf, localbuf);
return std::strlen(localbuf) + 1;
}
if(code <= REG_E_UNKNOWN)
{
std::string p;
if((e) && (e->re_magic == magic_value))
p = static_cast<regex*>(e->guts)->get_traits().error_string(code);
else
{
boost::regex_traits<char> t;
p = t.error_string(code);
}
std::size_t len = p.size();
if(len < buf_size)
{
std::strcpy(buf, p.c_str());
}
return len + 1;
}
if(buf_size)
*buf = 0;
return 0;
}
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA* expression, const char* buf, regsize_t n, regmatch_t* array, int eflags)
{
BOOST_RE_GUARD_STACK
bool result = false;
boost::uint_fast32_t flags = match_default | expression->eflags;
const char* end;
const char* start;
cmatch m;
if(eflags & REG_NOTBOL)
flags |= match_not_bol;
if(eflags & REG_NOTEOL)
flags |= match_not_eol;
if(eflags & REG_STARTEND)
{
start = buf + array[0].rm_so;
end = buf + array[0].rm_eo;
}
else
{
start = buf;
end = buf + std::strlen(buf);
}
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
if(expression->re_magic == magic_value)
{
result = regex_search(start, end, m, *static_cast<regex*>(expression->guts), flags);
}
else
return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
return REG_E_UNKNOWN;
}
#endif
if(result)
{
// extract what matched:
unsigned int i;
for(i = 0; (i < n) && (i < expression->re_nsub + 1); ++i)
{
array[i].rm_so = (m[i].matched == false) ? -1 : (m[i].first - buf);
array[i].rm_eo = (m[i].matched == false) ? -1 : (m[i].second - buf);
}
// and set anything else to -1:
for(i = expression->re_nsub + 1; i < n; ++i)
{
array[i].rm_so = -1;
array[i].rm_eo = -1;
}
return 0;
}
return REG_NOMATCH;
}
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA* expression)
{
BOOST_RE_GUARD_STACK
if(expression->re_magic == magic_value)
{
delete static_cast<regex*>(expression->guts);
}
expression->re_magic = 0;
}
} // namespace boost

View File

@ -0,0 +1,120 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: primary_transform.hpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Heuristically determines the sort string format in use
* by the current locale.
*/
namespace boost{
namespace re_detail{
enum{
sort_C,
sort_fixed,
sort_delim,
sort_unknown
};
template <class S, class charT>
unsigned count_chars(const S& s, charT c)
{
unsigned int count = 0;
for(unsigned pos = 0; pos < s.size(); ++pos)
{
if(s[pos] == c) ++count;
}
return count;
}
template <class traits, class charT>
unsigned find_sort_syntax(const traits* pt, charT* delim)
{
//
// compare 'a' with 'A' to see how similar they are,
// should really use a-accute but we can't portably do that,
//
typedef typename traits::string_type string_type;
typedef typename traits::char_type char_type;
// Suppress incorrect warning for MSVC
(void)pt;
string_type a(1, (char_type)'a');
string_type sa;
pt->transform(sa, a);
if(sa == a)
{
*delim = 0;
return sort_C;
}
string_type A(1, (char_type)'A');
string_type sA;
pt->transform(sA, A);
string_type c(1, (char_type)';');
string_type sc;
pt->transform(sc, c);
int pos = 0;
while((pos <= static_cast<int>(sa.size())) && (pos <= static_cast<int>(sA.size())) && (sa[pos] == sA[pos])) ++pos;
--pos;
if(pos < 0)
{
*delim = 0;
return sort_unknown;
}
//
// at this point sa[pos] is either the end of a fixed with field
// or the character that acts as a delimiter:
//
charT maybe_delim = sa[pos];
if((pos != 0) && (count_chars(sa, maybe_delim) == count_chars(sA, maybe_delim)) && (count_chars(sa, maybe_delim) == count_chars(c, maybe_delim)))
{
*delim = maybe_delim;
return sort_delim;
}
//
// OK doen't look like a delimiter, try for fixed width field:
//
if((sa.size() == sA.size()) && (sa.size() == c.size()))
{
// note assumes that the fixed width field is less than
// numeric_limits<charT>::max(), should be true for all types
// I can't imagine 127 character fields...
*delim = static_cast<charT>(++pos);
return sort_fixed;
}
//
// don't know what it is:
//
*delim = 0;
return sort_unknown;
}
} // namespace re_detail
} // namespace boost

View File

@ -0,0 +1,60 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: regex.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Misc boost::regbase member funnctions.
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex.hpp>
namespace boost{
//
// fix: these are declared out of line here to ensure
// that dll builds contain the Virtual table for these
// types - this ensures that exceptions can be thrown
// from the dll and caught in an exe.
bad_pattern::~bad_pattern() throw() {}
bad_expression::~bad_expression() throw() {}
regbase::regbase()
: _flags(regbase::failbit){}
regbase::regbase(const regbase& b)
: _flags(b._flags){}
} // namespace boost
#if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_BUILD_DLL)
int WINAPI DllEntryPoint(HINSTANCE , unsigned long , void*)
{
return 1;
}
#endif

View File

@ -0,0 +1,218 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: regex_debug.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Misc. debugging helpers.
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex/config.hpp>
#ifdef BOOST_REGEX_DEBUG
#ifdef BOOST_MSVC
#include <crtdbg.h>
#endif
#include <boost/regex/detail/regex_raw_buffer.hpp>
#include <boost/regex.hpp>
#ifndef BOOST_RE_OLD_IOSTREAM
#include <ostream>
#else
#include <ostream.h>
#endif
namespace boost { namespace re_detail {
std::ostream& operator<<(std::ostream& s, syntax_element_type x)
{
return s << static_cast<unsigned long>(x);
}
}} // namespace boost::re_detail
namespace {
char b1[32] = {0,};
char guard_pattern[32]
= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, };
char b2[32] = {0,};
static const int guard_size = 32;
bool check_pattern(void* p)
{
return p ? memcmp(p, guard_pattern, guard_size) : 0;
}
inline unsigned maxi(unsigned i, unsigned j)
{
return i < j ? j : i;
}
unsigned int allocated = 0;
struct init
{
init();
~init();
};
init::init()
{
#ifdef BOOST_MSVC
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_DELAY_FREE_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
#endif
}
init::~init()
{
}
init i;
void* get_mem(size_t n)
{
++allocated;
char* p = (char*)malloc(n + guard_size * 2 + maxi(sizeof(int) + sizeof(void*), boost::re_detail::padding_size) + boost::re_detail::padding_size);
char* base = p;
p = (char*)((std::ptrdiff_t)(p + boost::re_detail::padding_mask) & ~boost::re_detail::padding_mask);
std::memcpy(p + maxi(sizeof(int) + sizeof(void*), boost::re_detail::padding_size), guard_pattern, guard_size);
std::memcpy(p + maxi(sizeof(int) + sizeof(void*), boost::re_detail::padding_size) + guard_size + n, guard_pattern, guard_size);
*(int*)p = n;
*(void**)(p + sizeof(int)) = base;
return p + guard_size + maxi(sizeof(int) + sizeof(void*), boost::re_detail::padding_size);
}
void free_mem(void* b)
{
if(b)
{
char* p = (char*)b;
p -= (guard_size + maxi(sizeof(int) + sizeof(void*), boost::re_detail::padding_size));
if(check_pattern(p + maxi(sizeof(int) + sizeof(void*), boost::re_detail::padding_size)) || check_pattern(p + maxi(sizeof(int) + sizeof(void*), boost::re_detail::padding_size) + guard_size + *(int*)p))
{
cerr << "Error: freed memory has been written past end..." << endl;
}
free(*(void**)(p + sizeof(int)));
--allocated;
}
}
} // namespace
void* operator new(size_t n)
{
return get_mem(n);
}
void* operator new[](size_t n)
{
return get_mem(n);
}
void operator delete(void* p)
{
free_mem(p);
}
void operator delete[](void* p)
{
free_mem(p);
}
#include <set>
namespace boost{
namespace re_detail{
std::set<debug_guard*, std::less<debug_guard*> >* patterns = 0;
int pattern_count = 0;
void check_patterns(const char* f, int l)
{
if(pattern_count)
{
std::set<debug_guard*, std::less<debug_guard*> >::iterator i, j;
i = patterns->begin();
j = patterns->end();
while(i != j)
{
if(check_pattern((void*)(*i)->g1) || check_pattern((*i)->g2) || check_pattern((void*)(*i)->pc) || check_pattern((*i)->pnc))
{
cerr << "Error: static memory corruption at " << hex << *i << dec << " in " << (*i)->file << "@" << (*i)->line << " called from " << f << "@" << l << endl;
}
++i;
}
}
}
debug_guard::debug_guard(const char* f, int l, const char* p1, char* p2)
{
if(++pattern_count == 1)
patterns = new std::set<debug_guard*, std::less<debug_guard*> >;
file = f;
line = l;
std::memcpy(g1, guard_pattern, guard_size);
std::memcpy(g2, guard_pattern, guard_size);
if(p1)
{
pc = p1;
}
else
pc = 0;
if(p2)
{
pnc = p2;
std::memcpy(pnc, guard_pattern, guard_size);
}
else
pnc = 0;
patterns->insert(this);
}
debug_guard::~debug_guard()
{
check_patterns(file, line);
if(check_pattern(g1) || check_pattern(g2))
{
cerr << "Error: memory corruption " << file << "@" << line << endl;
}
patterns->erase(this);
if(--pattern_count == 0)
{
delete patterns;
patterns = 0;
}
}
} // namespace re_detail
} // namespace boost
#endif

View File

@ -0,0 +1,69 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: regex_synch.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Thread synch helper functions, for regular
* expression library.
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex/detail/regex_synch.hpp>
namespace boost{
namespace re_detail{
void BOOST_REGEX_CALL re_init_threads()
{
BOOST_RE_GUARD_STACK
#ifdef BOOST_HAS_THREADS
if(p_re_lock == 0)
p_re_lock = new critical_section();
cs_guard g(*p_re_lock);
++re_lock_count;
#endif
}
void BOOST_REGEX_CALL re_free_threads()
{
BOOST_RE_GUARD_STACK
#ifdef BOOST_HAS_THREADS
cs_guard g(*p_re_lock);
--re_lock_count;
if(re_lock_count == 0)
{
g.acquire(false);
delete p_re_lock;
p_re_lock = 0;
}
#endif
}
#ifdef BOOST_HAS_THREADS
BOOST_REGEX_DECL critical_section* p_re_lock = 0;
BOOST_REGEX_DECL unsigned int re_lock_count = 0;
#endif
} // namespace re_detail
} // namespace boost

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,246 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: wide_posix_api.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Implements the wide character POSIX API wrappers.
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex/config.hpp>
#ifndef BOOST_NO_WREGEX
#include <boost/regex.hpp>
#include <cwchar>
#include <cstring>
#include <cstdio>
namespace boost{
namespace {
unsigned int wmagic_value = 28631;
const wchar_t* wnames[] = {L"REG_NOERROR", L"REG_NOMATCH", L"REG_BADPAT", L"REG_ECOLLATE",
L"REG_ECTYPE", L"REG_EESCAPE", L"REG_ESUBREG", L"REG_EBRACK",
L"REG_EPAREN", L"REG_EBRACE", L"REG_BADBR", L"REG_ERANGE",
L"REG_ESPACE", L"REG_BADRPT", L"REG_EMPTY", L"REG_E_UNKNOWN"};
}
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wchar_t* ptr, int f)
{
BOOST_RE_GUARD_STACK
if(expression->re_magic != wmagic_value)
{
expression->guts = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
expression->guts = new wregex();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
return REG_ESPACE;
}
#else
if(0 == expression->guts)
return REG_E_MEMORY;
#endif
}
// set default flags:
boost::uint_fast32_t flags = (f & REG_EXTENDED) ? regbase::extended : regbase::basic;
expression->eflags = (f & REG_NEWLINE) ? match_not_dot_newline : 0;
// and translate those that are actually set:
if(f & REG_NOCOLLATE)
flags |= regbase::nocollate;
if(f & REG_NOSUB)
expression->eflags |= match_any;
if(f & REG_NOSPEC)
flags |= regbase::literal;
if(f & REG_ICASE)
flags |= regbase::icase;
if(f & REG_ESCAPE_IN_LISTS)
flags |= regbase::escape_in_lists;
if(f & REG_NEWLINE_ALT)
flags |= regbase::newline_alt;
const wchar_t* p2;
if(f & REG_PEND)
p2 = expression->re_endp;
else p2 = ptr + std::wcslen(ptr);
int result;
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
expression->re_magic = wmagic_value;
static_cast<wregex*>(expression->guts)->set_expression(ptr, p2, flags);
expression->re_nsub = static_cast<wregex*>(expression->guts)->mark_count() - 1;
result = static_cast<wregex*>(expression->guts)->error_code();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
result = REG_E_UNKNOWN;
}
#endif
if(result)
regfreeW(expression);
return result;
}
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW* e, wchar_t* buf, regsize_t buf_size)
{
BOOST_RE_GUARD_STACK
std::size_t result = 0;
if(code & REG_ITOA)
{
code &= ~REG_ITOA;
if(code <= REG_E_UNKNOWN)
{
result = std::wcslen(wnames[code]) + 1;
if(buf_size >= result)
std::wcscpy(buf, wnames[code]);
return result;
}
return result;
}
#if !defined(BOOST_NO_SWPRINTF)
if(code == REG_ATOI)
{
wchar_t localbuf[5];
if(e == 0)
return 0;
for(int i = 0; i <= REG_E_UNKNOWN; ++i)
{
if(std::wcscmp(e->re_endp, wnames[i]) == 0)
{
std::swprintf(localbuf, 5, L"%d", i);
if(std::wcslen(localbuf) < buf_size)
std::wcscpy(buf, localbuf);
return std::wcslen(localbuf) + 1;
}
}
std::swprintf(localbuf, 5, L"%d", 0);
if(std::wcslen(localbuf) < buf_size)
std::wcscpy(buf, localbuf);
return std::wcslen(localbuf) + 1;
}
#endif
if(code <= REG_E_UNKNOWN)
{
regex_traits<wchar_t> rt;
const regex_traits<wchar_t>* pt = &rt;
if(e && (e->re_magic == wmagic_value))
pt = &static_cast<wregex*>(e->guts)->get_traits();
(void)pt; // warning suppression
std::string p = pt->error_string(code);
std::size_t len = pt->strwiden(static_cast<wchar_t*>(0), 0, p.c_str());
if(len < buf_size)
{
pt->strwiden(buf, buf_size, p.c_str());
}
return len + 1;
}
if(buf_size)
*buf = 0;
return 0;
}
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW* expression, const wchar_t* buf, regsize_t n, regmatch_t* array, int eflags)
{
BOOST_RE_GUARD_STACK
bool result = false;
boost::uint_fast32_t flags = match_default | expression->eflags;
const wchar_t* end;
const wchar_t* start;
wcmatch m;
if(eflags & REG_NOTBOL)
flags |= match_not_bol;
if(eflags & REG_NOTEOL)
flags |= match_not_eol;
if(eflags & REG_STARTEND)
{
start = buf + array[0].rm_so;
end = buf + array[0].rm_eo;
}
else
{
start = buf;
end = buf + std::wcslen(buf);
}
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
if(expression->re_magic == wmagic_value)
{
result = regex_search(start, end, m, *static_cast<wregex*>(expression->guts), flags);
}
else
return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
return REG_E_UNKNOWN;
}
#endif
if(result)
{
// extract what matched:
unsigned int i;
for(i = 0; (i < n) && (i < expression->re_nsub + 1); ++i)
{
array[i].rm_so = (m[i].matched == false) ? -1 : (m[i].first - buf);
array[i].rm_eo = (m[i].matched == false) ? -1 : (m[i].second - buf);
}
// and set anything else to -1:
for(i = expression->re_nsub + 1; i < n; ++i)
{
array[i].rm_so = -1;
array[i].rm_eo = -1;
}
return 0;
}
return REG_NOMATCH;
}
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW* expression)
{
BOOST_RE_GUARD_STACK
if(expression->re_magic == wmagic_value)
{
delete static_cast<wregex*>(expression->guts);
}
expression->re_magic = 0;
}
} // namespace boost;
#endif

View File

@ -0,0 +1,36 @@
/*
*
* Copyright (c) 1998-2002
* 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.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: winstances.cpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: regex wide character template instances.
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex/config.hpp>
#if !defined(BOOST_NO_WREGEX) && !defined(BOOST_REGEX_NO_EXTERNAL_TEMPLATES)
#define BOOST_REGEX_WIDE_INSTANTIATE
#ifdef __BORLANDC__
#pragma hrdstop
#endif
#include <boost/regex.hpp>
#endif

View File

@ -356,6 +356,9 @@ AC_SUBST(VERSION_INFO)
AC_CONFIG_SUBDIRS(sigc++ lib lib/reLyX)
AC_OUTPUT([Makefile \
boost/Makefile \
boost/libs/Makefile \
boost/libs/regex/Makefile \
boost/libs/regex/src/Makefile \
config/Makefile \
development/lyx.spec \
lib/Makefile \