From 4c927bd3abb27cb477db47b42c368d356c7002cb Mon Sep 17 00:00:00 2001 From: s_alexander Date: Sat, 5 Dec 2009 12:26:56 +0000 Subject: disable autodetection, if pcre-lib did not load if the pcre-lib could not be load, do not try to compile the regex and so do not execute the regex and allways use the fallback encoding git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1966 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/encoding/Auto.inc | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/encoding/Auto.inc b/src/encoding/Auto.inc index bf512f95..3d415095 100644 --- a/src/encoding/Auto.inc +++ b/src/encoding/Auto.inc @@ -75,27 +75,28 @@ begin self.UTF8Encoder := UTF8Encoder; // Load and initialize PCRE Library - LoadPCRE(); - SetPCREMallocCallback(PCREGetMem); - SetPCREFreeCallback(PCREFreeMem); - - // compile regex - self.Regex := pcre_compile('\A([\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*\z', 0, @Error, @ErrorOffset, nil); - - if self.Regex = Nil then - begin - writeln('ERROR: UTF8 Regex compilation failed: ', AnsiString(Error), ' at ', ErrorOffset); - end - else + if LoadPCRE() then begin - // if compiled successfull, try to get more informations the speed up the matching - self.RegexExtra := pcre_study(self.Regex, 0, @Error); + // compile regex + self.Regex := pcre_compile('\A([\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*\z', 0, @Error, @ErrorOffset, nil); - if Error <> Nil then + if self.Regex = Nil then begin - writeln('ERROR: UTF8 Regex study failed: ', AnsiString(Error)); + writeln('ERROR: UTF8 Regex compilation failed: ', AnsiString(Error), ' at ', ErrorOffset); + end + else + begin + // if compiled successfull, try to get more informations the speed up the matching + self.RegexExtra := pcre_study(self.Regex, 0, @Error); + + if Error <> Nil then + begin + writeln('ERROR: UTF8 Regex study failed: ', AnsiString(Error)); + end; end; - end; + end + else + writeln('ERROR: pcre not loaded. utf-8 autodetection will not work.'); end; function TEncoderAuto.GetName(): AnsiString; -- cgit v1.2.3