From d589e6221ffcafc077eeefaa60cdc3e33a800558 Mon Sep 17 00:00:00 2001 From: s_alexander Date: Sat, 5 Dec 2009 12:26:00 +0000 Subject: added autodetection of utf8 used w3c regex to match all song lines whether they are utf8 lines and decode it on match as utf8 and as latin1 otherwise git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1964 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UTextEncoding.pas | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/base/UTextEncoding.pas') diff --git a/src/base/UTextEncoding.pas b/src/base/UTextEncoding.pas index bb3d0f1a..79e5a297 100644 --- a/src/base/UTextEncoding.pas +++ b/src/base/UTextEncoding.pas @@ -42,7 +42,9 @@ type encLocale, // current locale (needs cwstring on linux) encUTF8, // UTF-8 encCP1250, // Windows-1250 Central/Eastern Europe (used by Ultrastar) - encCP1252 // Windows-1252 Western Europe (used by UltraStar Deluxe < 1.1) + encCP1252, // Windows-1252 Western Europe (used by UltraStar Deluxe < 1.1) + encAuto // try to match the w3c regex and decode as unicode on match + // and as fallback if not match ); const @@ -88,7 +90,9 @@ function EncodingName(Encoding: TEncoding): AnsiString; implementation uses - StrUtils; + StrUtils, + pcre, + ULog; type IEncoder = interface @@ -229,6 +233,7 @@ end; {$I ../encoding/UTF8.inc} {$I ../encoding/CP1250.inc} {$I ../encoding/CP1252.inc} +{$I ../encoding/Auto.inc} initialization Encoders[encLocale] := TEncoderLocale.Create; @@ -236,4 +241,7 @@ initialization Encoders[encCP1250] := TEncoderCP1250.Create; Encoders[encCP1252] := TEncoderCP1252.Create; + // use USDX < 1.1 encoding for backward compatibility (encCP1252) + Encoders[encAuto] := TEncoderAuto.Create(Encoders[encUTF8], Encoders[encCP1252]); + end. -- cgit v1.2.3