* Set ICU data dir if it is not set by the system. It fixes issues on newer Android versions.

* Added more predefined ICU versions.

git-svn-id: trunk@39865 -
This commit is contained in:
yury 2018-10-06 13:28:37 +00:00
parent 46b89f0ef9
commit 212eca24d1

View File

@ -50,12 +50,13 @@ var
u_strToLower: function (dest: PUnicodeChar; destCapacity: int32_t; src: PUnicodeChar; srcLength: int32_t; locale: PAnsiChar; var pErrorCode: UErrorCode): int32_t; cdecl;
u_strCompare: function (s1: PUnicodeChar; length1: int32_t; s2: PUnicodeChar; length2: int32_t; codePointOrder: UBool): int32_t; cdecl;
u_strCaseCompare: function (s1: PUnicodeChar; length1: int32_t; s2: PUnicodeChar; length2: int32_t; options: uint32_t; var pErrorCode: UErrorCode): int32_t; cdecl;
u_getDataDirectory: function(): PAnsiChar; cdecl;
u_setDataDirectory: procedure(directory: PAnsiChar); cdecl;
ucol_open: function(loc: PAnsiChar; var status: UErrorCode): PUCollator; cdecl;
ucol_close: procedure (coll: PUCollator); cdecl;
ucol_strcoll: function (coll: PUCollator; source: PUnicodeChar; sourceLength: int32_t; target: PUnicodeChar; targetLength: int32_t): int32_t; cdecl;
ucol_setStrength: procedure (coll: PUCollator; strength: int32_t); cdecl;
u_errorName: function (code: UErrorCode): PAnsiChar; cdecl;
threadvar
ThreadDataInited: boolean;
@ -496,12 +497,13 @@ end;
function LoadICU: boolean;
const
ICUver: array [1..9] of ansistring = ('3_8', '4_2', '44', '46', '48', '50', '51', '53', '55');
ICUver: array [1..12] of ansistring = ('3_8', '4_2', '44', '46', '48', '50', '51', '53', '55', '56', '58', '60');
TestProcName = 'ucnv_open';
var
i: longint;
s: ansistring;
dir: PAnsiChar;
begin
Result:=False;
{$ifdef android}
@ -543,6 +545,7 @@ begin
// Trying versionless name
if GetProcedureAddress(hlibICU, TestProcName) = nil then begin
// Unable to get ICU version
SysLogWrite(ANDROID_LOG_ERROR, 'cwstring: Unable to get ICU version.');
UnloadICU;
exit;
end;
@ -558,13 +561,19 @@ begin
if not GetIcuProc('u_strToLower', u_strToLower) then exit;
if not GetIcuProc('u_strCompare', u_strCompare) then exit;
if not GetIcuProc('u_strCaseCompare', u_strCaseCompare) then exit;
if not GetIcuProc('u_errorName', u_errorName) then exit;
if not GetIcuProc('u_getDataDirectory', u_getDataDirectory) then exit;
if not GetIcuProc('u_setDataDirectory', u_setDataDirectory) then exit;
if not GetIcuProc('ucol_open', ucol_open, 1) then exit;
if not GetIcuProc('ucol_close', ucol_close, 1) then exit;
if not GetIcuProc('ucol_strcoll', ucol_strcoll, 1) then exit;
if not GetIcuProc('ucol_setStrength', ucol_setStrength, 1) then exit;
// Checking if ICU data dir is set
dir:=u_getDataDirectory();
if (dir = nil) or (dir^ = #0) then
u_setDataDirectory('/system/usr/icu');
Result:=True;
end;