Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

php - Detect if PCRE was built without the --enable-unicode-properties or --enable-utf8 configuration switches

I've a PHP library that uses a number of regular expressions featuring the P expressions for multibyte strings, e.g.

((((?:P{M}p{M}*)+?)|('[^']*')|("[^"]*"))!)?$?([a-z]{1,3})$?(d+)

While this works on most builds, I've had a few reports of the regexp returning an error.

Depending on Operating platform, the error messages from PCRE are:

Compilation failed: PCRE does not support L, l, N, P, p, U, u, or X at offset n

or

Compilation failed: support for P, p, and X has not been compiled at offset n

I know that I can probably test a regexp at the beginning of my code that uses P, and trap for a returned error, then use that response to set a compatibility flag and provide a degraded (non UTF-8) regexp without the P within the main body of my code based on that compatibility flag.

I was wondering if there was any simpler way to identify whether PCRE had been built without the --enable-unicode-properties or --enable-utf8 configuration switches. PHP provides access to PCRE_VERSION constant, but that won't help identify whether P support is enabled or not.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Other than trying it, I think the only way is to use the pcretest command line tool, with the -C option (compile-time options):

bash-4.1.5$ pcretest -C
   No UTF-8 support
   No Unicode properties support
   Newline sequence is LF
   R matches all Unicode newlines
   Internal link size = 2
   POSIX malloc threshold = 10
   Default match limit = 10000000
   Default recursion depth limit = 10000000
   Match recursion uses stack

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...