libpaspcre2
1.0.0
libpaspcre2 คือการผูก Delphi และวัตถุ Pascal สำหรับไลบรารีนิพจน์ทั่วไปที่เข้ากันได้กับ Perl (PCRE2) ไลบรารีเป็นชุดของฟังก์ชั่นที่ใช้การจับคู่รูปแบบการแสดงออกปกติโดยใช้ไวยากรณ์และความหมายเดียวกันกับ Perl 5
ห้องสมุดได้รับการทดสอบสำหรับ
รับแหล่งที่มาและเพิ่มไดเรกทอรี ต้นฉบับ ไปยังเส้นทางการค้นหาโครงการ สำหรับ FPC เพิ่มไดเรกทอรี ต้นฉบับ ลงในไฟล์ fpc.cfg
โคลนที่เก็บ git clone https://github.com/isemenkov/libpaspcre2
เพิ่มหน่วยที่คุณต้องการใช้ในประโยค uses
กรอบการทดสอบประกอบด้วยส่วนผสมต่อไปนี้:
unit-testsไฟล์ libpaspcre2.pas มีส่วนหัวที่แปล PCRE2 เพื่อใช้ไลบรารีนี้ในโปรแกรม Pascal คุณสามารถค้นหาเอกสาร C API ได้ที่เว็บไซต์ www.pcre.org
uses
libpaspcre2, utils.api.cstring;
var
re : pcre2_code_8;
rc : Integer;
pattern, subject : PCRE2_SPTR8;
error_buffer : string[ 255 ];
subject_length : Int64;
error_number : Integer;
error_offset : PCRE2_SIZE;
ovector : PPCRE2_SIZE;
match_data : ppcre2_match_data_8;
substring : string;
begin
pattern := PCRE2_SPTR8(API.CString.Create( ' (?:D|^)(5[1-5][0-9]{2}(?: |-|)[0-9]{4} ' +
' (?: |-|)[0-9]{4}(?: |-|)[0-9]{4})(?:D|$) ' ).ToPAnsiChar);
subject := PCRE2_SPTR8(API.CString.Create( ' 5111 2222 3333 4444 ' ).ToPAnsiChar);
subject_length := API.CString.Create( ' 5111 2222 3333 4444 ' ).Length;
re := pcre2_compile_8(pattern, PCRE2_ZERO_TERMINATED, 0 , @error_number, @error_offset, nil );
if re = nil then
begin
pcre2_get_error_message_8(error_number, PPCRE2_UCHAR8(@error_buffer[ 0 ]), 256 );
Fail(Format( ' PCRE2 compilation failed at offset %d: %s ' , [error_offset, error_buffer]));
end ;
match_data := pcre2_match_data_create_from_pattern_8(re, nil );
rc := pcre2_match_8(re, subject, subject_length, 0 , 0 , match_data, nil );
if rc < 0 then
begin
case rc of
PCRE2_ERROR_NOMATCH :
begin
pcre2_match_data_free_8(match_data);
pcre2_code_free_8(re);
Fail( ' No match ' );
end ;
end ;
end ;
{
ovector := pcre2_get_ovector_pointer_8(match_data);
if ovector^ > (ovector + 1)^ then
Fail('Error');
substring := Copy(PChar(subject), ovector^, (ovector + 1)^ - ovector^);
pcre2_match_data_free_8(match_data);
pcre2_code_free_8(re);
}
end ;