📄 pcre.pas
字号:
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is pcre.pas. }
{ }
{ The Initial Developer of the Original Code is Peter Thornqvist. }
{ Portions created by Peter Thornqvist are Copyright (C) of Peter Thornqvist. All rights reserved. }
{ Portions created by University of Cambridge are }
{ Copyright (C) 1997-2001 by University of Cambridge. }
{ }
{ Contributor(s): }
{ Robert Rossmair (rrossmair) }
{ Mario R. Carro }
{ Florent Ouchet (outchy) }
{ }
{ The latest release of PCRE is always available from }
{ ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-xxx.tar.gz }
{ }
{ Modified by Jan Goyvaerts for use with TPerlRegEx }
{ TPerlRegEx is available at http://www.regular-expressions.info/delphi.html }
{ }
{**************************************************************************************************}
{ }
{ Header conversion of pcre.h }
{ }
{**************************************************************************************************}
unit pcre;
interface
(*************************************************
* Perl-Compatible Regular Expressions *
*************************************************)
{$WEAKPACKAGEUNIT ON}
//**JG** Link PCRE using
{$IFDEF UNICODE}
// For Delphi 2009 and later, we link the OBJ files with PCRE 7.7.
{$DEFINE PCRE_STATICLINK}
{$ELSE}
// For Delphi 2007 and earlier, we use pcre3.dll
// The reason is that if we link the OBJ files, an internal compiler error occurs when Delphi tries to link the component into your application
// You can use PCRE_STATICLINK with Delphi 2007, but then you have to put the component into a runtime package
{$DEFINE PCRE_LINKDLL}
{$ENDIF}
{$IFDEF PCRE_LINKDLL}
// The supplied pcre3.dll compiled PCRE 7.0 using the C calling convention
// This DLL was obtained at http://gnuwin32.sourceforge.net/packages/pcre.htm
{$DEFINE PCRE_EXPORT_CDECL}
{$ENDIF}
(*$HPPEMIT '#include "pcre.h"'*)
const
MAX_PATTERN_LENGTH = $10003;
{$EXTERNALSYM MAX_PATTERN_LENGTH}
MAX_QUANTIFY_REPEAT = $10000;
{$EXTERNALSYM MAX_QUANTIFY_REPEAT}
MAX_CAPTURE_COUNT = $FFFF;
{$EXTERNALSYM MAX_CAPTURE_COUNT}
MAX_NESTING_DEPTH = 200;
{$EXTERNALSYM MAX_NESTING_DEPTH}
const
(* Options *)
PCRE_CASELESS = $00000001;
{$EXTERNALSYM PCRE_CASELESS}
PCRE_MULTILINE = $00000002;
{$EXTERNALSYM PCRE_MULTILINE}
PCRE_DOTALL = $00000004;
{$EXTERNALSYM PCRE_DOTALL}
PCRE_EXTENDED = $00000008;
{$EXTERNALSYM PCRE_EXTENDED}
PCRE_ANCHORED = $00000010;
{$EXTERNALSYM PCRE_ANCHORED}
PCRE_DOLLAR_ENDONLY = $00000020;
{$EXTERNALSYM PCRE_DOLLAR_ENDONLY}
PCRE_EXTRA = $00000040;
{$EXTERNALSYM PCRE_EXTRA}
PCRE_NOTBOL = $00000080;
{$EXTERNALSYM PCRE_NOTBOL}
PCRE_NOTEOL = $00000100;
{$EXTERNALSYM PCRE_NOTEOL}
PCRE_UNGREEDY = $00000200;
{$EXTERNALSYM PCRE_UNGREEDY}
PCRE_NOTEMPTY = $00000400;
{$EXTERNALSYM PCRE_NOTEMPTY}
PCRE_UTF8 = $00000800;
{$EXTERNALSYM PCRE_UTF8}
PCRE_NO_AUTO_CAPTURE = $00001000;
{$EXTERNALSYM PCRE_NO_AUTO_CAPTURE}
PCRE_NO_UTF8_CHECK = $00002000;
{$EXTERNALSYM PCRE_NO_UTF8_CHECK}
PCRE_AUTO_CALLOUT = $00004000;
{$EXTERNALSYM PCRE_AUTO_CALLOUT}
PCRE_PARTIAL = $00008000;
{$EXTERNALSYM PCRE_PARTIAL}
PCRE_DFA_SHORTEST = $00010000;
{$EXTERNALSYM PCRE_DFA_SHORTEST}
PCRE_DFA_RESTART = $00020000;
{$EXTERNALSYM PCRE_DFA_RESTART}
PCRE_FIRSTLINE = $00040000;
{$EXTERNALSYM PCRE_FIRSTLINE}
PCRE_DUPNAMES = $00080000;
{$EXTERNALSYM PCRE_DUPNAMES}
PCRE_NEWLINE_CR = $00100000;
{$EXTERNALSYM PCRE_NEWLINE_CR}
PCRE_NEWLINE_LF = $00200000;
{$EXTERNALSYM PCRE_NEWLINE_LF}
PCRE_NEWLINE_CRLF = $00300000;
{$EXTERNALSYM PCRE_NEWLINE_CRLF}
PCRE_NEWLINE_ANY = $00400000;
{$EXTERNALSYM PCRE_NEWLINE_ANY}
PCRE_NEWLINE_ANYCRLF = $00500000;
{$EXTERNALSYM PCRE_NEWLINE_ANYCRLF}
PCRE_BSR_ANYCRLF = $00800000;
{$EXTERNALSYM PCRE_BSR_ANYCRLF}
PCRE_BSR_UNICODE = $01000000;
{$EXTERNALSYM PCRE_BSR_UNICODE}
PCRE_JAVASCRIPT_COMPAT = $02000000;
{$EXTERNALSYM PCRE_JAVASCRIPT_COMPAT}
(* Exec-time and get-time error codes *)
PCRE_ERROR_NOMATCH = -1;
{$EXTERNALSYM PCRE_ERROR_NOMATCH}
PCRE_ERROR_NULL = -2;
{$EXTERNALSYM PCRE_ERROR_NULL}
PCRE_ERROR_BADOPTION = -3;
{$EXTERNALSYM PCRE_ERROR_BADOPTION}
PCRE_ERROR_BADMAGIC = -4;
{$EXTERNALSYM PCRE_ERROR_BADMAGIC}
PCRE_ERROR_UNKNOWN_NODE = -5;
{$EXTERNALSYM PCRE_ERROR_UNKNOWN_NODE}
PCRE_ERROR_NOMEMORY = -6;
{$EXTERNALSYM PCRE_ERROR_NOMEMORY}
PCRE_ERROR_NOSUBSTRING = -7;
{$EXTERNALSYM PCRE_ERROR_NOSUBSTRING}
PCRE_ERROR_MATCHLIMIT = -8;
{$EXTERNALSYM PCRE_ERROR_MATCHLIMIT}
PCRE_ERROR_CALLOUT = -9; (* Never used by PCRE itself *)
{$EXTERNALSYM PCRE_ERROR_CALLOUT}
PCRE_ERROR_BADUTF8 = -10;
{$EXTERNALSYM PCRE_ERROR_BADUTF8}
PCRE_ERROR_BADUTF8_OFFSET = -11;
{$EXTERNALSYM PCRE_ERROR_BADUTF8_OFFSET}
PCRE_ERROR_PARTIAL = -12;
{$EXTERNALSYM PCRE_ERROR_PARTIAL}
PCRE_ERROR_BADPARTIAL = -13;
{$EXTERNALSYM PCRE_ERROR_BADPARTIAL}
PCRE_ERROR_INTERNAL = -14;
{$EXTERNALSYM PCRE_ERROR_INTERNAL}
PCRE_ERROR_BADCOUNT = -15;
{$EXTERNALSYM PCRE_ERROR_BADCOUNT}
PCRE_ERROR_DFA_UITEM = -16;
{$EXTERNALSYM PCRE_ERROR_DFA_UITEM}
PCRE_ERROR_DFA_UCOND = -17;
{$EXTERNALSYM PCRE_ERROR_DFA_UCOND}
PCRE_ERROR_DFA_UMLIMIT = -18;
{$EXTERNALSYM PCRE_ERROR_DFA_UMLIMIT}
PCRE_ERROR_DFA_WSSIZE = -19;
{$EXTERNALSYM PCRE_ERROR_DFA_WSSIZE}
PCRE_ERROR_DFA_RECURSE = -20;
{$EXTERNALSYM PCRE_ERROR_DFA_RECURSE}
PCRE_ERROR_RECURSIONLIMIT = -21;
{$EXTERNALSYM PCRE_ERROR_RECURSIONLIMIT}
PCRE_ERROR_NULLWSLIMIT = -22; (* No longer actually used *)
{$EXTERNALSYM PCRE_ERROR_NULLWSLIMIT}
PCRE_ERROR_BADNEWLINE = -23;
{$EXTERNALSYM PCRE_ERROR_BADNEWLINE}
(* Request types for pcre_fullinfo() *)
PCRE_INFO_OPTIONS = 0;
{$EXTERNALSYM PCRE_INFO_OPTIONS}
PCRE_INFO_SIZE = 1;
{$EXTERNALSYM PCRE_INFO_SIZE}
PCRE_INFO_CAPTURECOUNT = 2;
{$EXTERNALSYM PCRE_INFO_CAPTURECOUNT}
PCRE_INFO_BACKREFMAX = 3;
{$EXTERNALSYM PCRE_INFO_BACKREFMAX}
PCRE_INFO_FIRSTCHAR = 4;
{$EXTERNALSYM PCRE_INFO_FIRSTCHAR}
PCRE_INFO_FIRSTTABLE = 5;
{$EXTERNALSYM PCRE_INFO_FIRSTTABLE}
PCRE_INFO_LASTLITERAL = 6;
{$EXTERNALSYM PCRE_INFO_LASTLITERAL}
PCRE_INFO_NAMEENTRYSIZE = 7;
{$EXTERNALSYM PCRE_INFO_NAMEENTRYSIZE}
PCRE_INFO_NAMECOUNT = 8;
{$EXTERNALSYM PCRE_INFO_NAMECOUNT}
PCRE_INFO_NAMETABLE = 9;
{$EXTERNALSYM PCRE_INFO_NAMETABLE}
PCRE_INFO_STUDYSIZE = 10;
{$EXTERNALSYM PCRE_INFO_STUDYSIZE}
PCRE_INFO_DEFAULT_TABLES = 11;
{$EXTERNALSYM PCRE_INFO_DEFAULT_TABLES}
PCRE_INFO_OKPARTIAL = 12;
{$EXTERNALSYM PCRE_INFO_OKPARTIAL}
PCRE_INFO_JCHANGED = 13;
{$EXTERNALSYM PCRE_INFO_JCHANGED}
PCRE_INFO_HASCRORLF = 14;
{$EXTERNALSYM PCRE_INFO_HASCRORLF}
(* Request types for pcre_config() *)
PCRE_CONFIG_UTF8 = 0;
{$EXTERNALSYM PCRE_CONFIG_UTF8}
PCRE_CONFIG_NEWLINE = 1;
{$EXTERNALSYM PCRE_CONFIG_NEWLINE}
PCRE_CONFIG_LINK_SIZE = 2;
{$EXTERNALSYM PCRE_CONFIG_LINK_SIZE}
PCRE_CONFIG_POSIX_MALLOC_THRESHOLD = 3;
{$EXTERNALSYM PCRE_CONFIG_POSIX_MALLOC_THRESHOLD}
PCRE_CONFIG_MATCH_LIMIT = 4;
{$EXTERNALSYM PCRE_CONFIG_MATCH_LIMIT}
PCRE_CONFIG_STACKRECURSE = 5;
{$EXTERNALSYM PCRE_CONFIG_STACKRECURSE}
PCRE_CONFIG_UNICODE_PROPERTIES = 6;
{$EXTERNALSYM PCRE_CONFIG_UNICODE_PROPERTIES}
PCRE_CONFIG_MATCH_LIMIT_RECURSION = 7;
{$EXTERNALSYM PCRE_CONFIG_MATCH_LIMIT_RECURSION}
PCRE_CONFIG_BSR = 8;
{$EXTERNALSYM PCRE_CONFIG_BSR}
(* Bit flags for the pcre_extra structure *)
PCRE_EXTRA_STUDY_DATA = $0001;
{$EXTERNALSYM PCRE_EXTRA_STUDY_DATA}
PCRE_EXTRA_MATCH_LIMIT = $0002;
{$EXTERNALSYM PCRE_EXTRA_MATCH_LIMIT}
PCRE_EXTRA_CALLOUT_DATA = $0004;
{$EXTERNALSYM PCRE_EXTRA_CALLOUT_DATA}
PCRE_EXTRA_TABLES = $0008;
{$EXTERNALSYM PCRE_EXTRA_TABLES}
PCRE_EXTRA_MATCH_LIMIT_RECURSION = $0010;
{$EXTERNALSYM PCRE_EXTRA_MATCH_LIMIT_RECURSION}
type
(* Types *)
PPAnsiChar = ^PAnsiChar;
{$EXTERNALSYM PPAnsiChar}
PPPAnsiChar = ^PPAnsiChar;
{$EXTERNALSYM PPPAnsiChar}
PInteger = ^Integer;
{$EXTERNALSYM PInteger}
real_pcre = packed record
{magic_number: Longword;
size: Integer;
tables: PAnsiChar;
options: Longword;
top_bracket: Word;
top_backref: word;
first_char: PAnsiChar;
req_char: PAnsiChar;
code: array [0..0] of Char;}
end;
TPCRE = real_pcre;
PPCRE = ^TPCRE;
real_pcre_extra = packed record
{options: PAnsiChar;
start_bits: array [0..31] of Char;}
flags: Cardinal; (* Bits for which fields are set *)
study_data: Pointer; (* Opaque data from pcre_study() *)
match_limit: Cardinal; (* Maximum number of calls to match() *)
callout_data: Pointer; (* Data passed back in callouts *)
tables: PAnsiChar; (* Pointer to character tables *)
match_limit_recursion: Cardinal; (* Max recursive calls to match() *)
end;
TPCREExtra = real_pcre_extra;
PPCREExtra = ^TPCREExtra;
pcre_callout_block = packed record
version: Integer; (* Identifies version of block *)
(* ------------------------ Version 0 ------------------------------- *)
callout_number: Integer; (* Number compiled into pattern *)
offset_vector: PInteger; (* The offset vector *)
subject: PAnsiChar; (* The subject being matched *)
subject_length: Integer; (* The length of the subject *)
start_match: Integer; (* Offset to start of this match attempt *)
current_position: Integer; (* Where we currently are in the subject *)
capture_top: Integer; (* Max current capture *)
capture_last: Integer; (* Most recently closed capture *)
callout_data: Pointer; (* Data passed in with the call *)
(* ------------------- Added for Version 1 -------------------------- *)
pattern_position: Integer; (* Offset to next item in the pattern *)
next_item_length: Integer; (* Length of next item in the pattern *)
(* ------------------------------------------------------------------ *)
end;
pcre_malloc_callback = function(Size: Integer): Pointer; {$IFDEF PCRE_EXPORT_CDECL} cdecl; {$ENDIF PCRE_EXPORT_CDECL}
{$EXTERNALSYM pcre_malloc_callback}
pcre_free_callback = procedure(P: Pointer); {$IFDEF PCRE_EXPORT_CDECL} cdecl; {$ENDIF PCRE_EXPORT_CDECL}
{$EXTERNALSYM pcre_free_callback}
pcre_stack_malloc_callback = function(Size: Integer): Pointer; {$IFDEF PCRE_EXPORT_CDECL} cdecl; {$ENDIF PCRE_EXPORT_CDECL}
{$EXTERNALSYM pcre_stack_malloc_callback}
pcre_stack_free_callback = procedure(P: Pointer); {$IFDEF PCRE_EXPORT_CDECL} cdecl; {$ENDIF PCRE_EXPORT_CDECL}
{$EXTERNALSYM pcre_stack_free_callback}
pcre_callout_callback = function(var callout_block: pcre_callout_block): Integer; {$IFDEF PCRE_EXPORT_CDECL} cdecl; {$ENDIF PCRE_EXPORT_CDECL}
{$EXTERNALSYM pcre_callout_callback}
var
// renamed from "pcre_X" to "pcre_X_func" to allow functions with name "pcre_X" to be
// declared in implementation when static linked
pcre_malloc_func: ^pcre_malloc_callback = nil;
{$EXTERNALSYM pcre_malloc_func}
pcre_free_func: ^pcre_free_callback = nil;
{$EXTERNALSYM pcre_free_func}
pcre_stack_malloc_func: ^pcre_stack_malloc_callback = nil;
{$EXTERNALSYM pcre_stack_malloc_func}
pcre_stack_free_func: ^pcre_stack_free_callback = nil;
{$EXTERNALSYM pcre_stack_free_func}
pcre_callout_func: ^pcre_callout_callback = nil;
{$EXTERNALSYM pcre_callout_func}
procedure SetPCREMallocCallback(const Value: pcre_malloc_callback);
{$EXTERNALSYM SetPCREMallocCallback}
function GetPCREMallocCallback: pcre_malloc_callback;
{$EXTERNALSYM GetPCREMallocCallback}
function CallPCREMalloc(Size: Integer): Pointer;
{$EXTERNALSYM CallPCREMalloc}
procedure SetPCREFreeCallback(const Value: pcre_free_callback);
{$EXTERNALSYM SetPCREFreeCallback}
function GetPCREFreeCallback: pcre_free_callback;
{$EXTERNALSYM GetPCREFreeCallback}
procedure CallPCREFree(P: Pointer);
{$EXTERNALSYM CallPCREFree}
procedure SetPCREStackMallocCallback(const Value: pcre_stack_malloc_callback);
{$EXTERNALSYM SetPCREStackMallocCallback}
function GetPCREStackMallocCallback: pcre_stack_malloc_callback;
{$EXTERNALSYM GetPCREStackMallocCallback}
function CallPCREStackMalloc(Size: Integer): Pointer;
{$EXTERNALSYM CallPCREStackMalloc}
procedure SetPCREStackFreeCallback(const Value: pcre_stack_free_callback);
{$EXTERNALSYM SetPCREStackFreeCallback}
function GetPCREStackFreeCallback: pcre_stack_free_callback;
{$EXTERNALSYM GetPCREStackFreeCallback}
procedure CallPCREStackFree(P: Pointer);
{$EXTERNALSYM CallPCREStackFree}
procedure SetPCRECalloutCallback(const Value: pcre_callout_callback);
{$EXTERNALSYM SetPCRECalloutCallback}
function GetPCRECalloutCallback: pcre_callout_callback;
{$EXTERNALSYM GetPCRECalloutCallback}
function CallPCRECallout(var callout_block: pcre_callout_block): Integer;
{$EXTERNALSYM CallPCRECallout}
type
TPCRELibNotLoadedHandler = procedure; {$IFDEF PCRE_EXPORT_CDECL} cdecl; {$ENDIF PCRE_EXPORT_CDECL}
var
// Value to initialize function pointers below with, in case LoadPCRE fails
// or UnloadPCRE is called. Typically the handler will raise an exception.
LibNotLoadedHandler: TPCRELibNotLoadedHandler = nil;
(* Functions *)
{$IFNDEF PCRE_LINKONREQUEST}
// static link and static dll import
function pcre_compile(const pattern: PAnsiChar; options: Integer;
const errptr: PPAnsiChar; erroffset: PInteger; const tableptr: PAnsiChar): PPCRE;
{$IFDEF PCRE_EXPORT_CDECL} cdecl; {$ENDIF PCRE_EXPORT_CDECL}
{$EXTERNALSYM pcre_compile}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -