From 4ee7b4e7e2a8bc9ac10c163d76fef7fa6f9aa579 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 21 Aug 2013 15:44:31 +0000 Subject: [PATCH] rtl: code refactoring by Inoussa (mantis #0024898) git-svn-id: trunk@25320 - --- rtl/objpas/fpwidestring.pp | 72 ++++++++++++-------------------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/rtl/objpas/fpwidestring.pp b/rtl/objpas/fpwidestring.pp index 2260312a36..10cc0a80a8 100644 --- a/rtl/objpas/fpwidestring.pp +++ b/rtl/objpas/fpwidestring.pp @@ -88,6 +88,21 @@ begin current_Map:=nil; end; +function FindMap(const cp: TSystemCodePage): punicodemap;inline; +begin + if (cp=DefaultSystemCodePage) then + begin + { update current_Map in case the DefaultSystemCodePage has been changed } + if (current_DefaultSystemCodePage<>DefaultSystemCodePage) or not Assigned(current_Map) then + begin + FiniThread; + InitThread; + end; + Result:=current_Map; + end + else + Result:=getmap(cp); +end; { return value: -1 if incomplete or invalid code point @@ -245,18 +260,7 @@ begin exit; end; - if (cp=DefaultSystemCodePage) then - begin - { update current_Map in case the DefaultSystemCodePage has been changed } - if (current_DefaultSystemCodePage<>DefaultSystemCodePage) or not Assigned(current_Map) then - begin - FiniThread; - InitThread; - end; - locMap:=current_Map; - end - else - locMap:=getmap(cp); + locMap:=FindMap(cp); if (locMap=nil) then begin DefaultUnicode2AnsiMove(source,dest,DefaultSystemCodePage,len); @@ -318,18 +322,7 @@ begin exit; end; - if (cp=DefaultSystemCodePage) then - begin - { update current_Map in case the DefaultSystemCodePage has been changed } - if (current_DefaultSystemCodePage<>DefaultSystemCodePage) or not Assigned(current_Map) then - begin - FiniThread; - InitThread; - end; - locMap:=current_Map; - end - else - locMap:=getmap(cp); + locMap:=FindMap(cp); if (locMap=nil) then begin DefaultAnsi2UnicodeMove(source,DefaultSystemCodePage,dest,len); @@ -353,18 +346,7 @@ begin exit; end; - if (cp=DefaultSystemCodePage) then - begin - { update current_Map in case the DefaultSystemCodePage has been changed } - if (current_DefaultSystemCodePage<>DefaultSystemCodePage) or not Assigned(current_Map) then - begin - FiniThread; - InitThread; - end; - locMap:=current_Map; - end - else - locMap:=getmap(cp); + locMap:=FindMap(cp); if (locMap=nil) then begin DefaultAnsi2WideMove(source,DefaultSystemCodePage,dest,len); @@ -499,13 +481,8 @@ begin UnicodeToUtf8(@Result[1],slen,@us[1],ulen); exit; end; - - if (current_DefaultSystemCodePage<>DefaultSystemCodePage) or not Assigned(current_Map) then - begin - FiniThread; - InitThread; - end; - locMap:=current_Map; + + locMap:=FindMap(DefaultSystemCodePage); if (locMap=nil) then exit(System.UpCase(s)); @@ -571,12 +548,7 @@ begin UnicodeToUtf8(@Result[1],slen,@us[1],ulen); exit; end; - if (current_DefaultSystemCodePage<>DefaultSystemCodePage) or not Assigned(current_Map) then - begin - FiniThread; - InitThread; - end; - locMap:=current_Map; + locMap:=FindMap(DefaultSystemCodePage); if (locMap=nil) then exit(System.LowerCase(s)); @@ -714,7 +686,7 @@ end; function StrCompAnsiString(S1, S2: PChar): PtrInt; var - l1,l2,l : PtrInt; + l1,l2 : PtrInt; begin l1:=strlen(S1); l2:=strlen(S2);