瀏覽代碼

rtl: move some CP_xxx constants from syswin into systemh for generic use, redeclare UTF8Sting, RawByteString using constant identifiers instead of pure numbers. replace comparison with $ffff codepage to CP_NONE

git-svn-id: trunk@19354 -
paul 14 年之前
父節點
當前提交
836889fc64
共有 5 個文件被更改,包括 34 次插入26 次删除
  1. 16 16
      rtl/inc/astrings.inc
  2. 13 2
      rtl/inc/systemh.inc
  3. 3 3
      rtl/inc/ustrings.inc
  4. 2 2
      rtl/inc/wstrings.inc
  5. 0 3
      rtl/win/syswin.inc

+ 16 - 16
rtl/inc/astrings.inc

@@ -203,10 +203,10 @@ Var
 begin
   { if codepages are differ then concat using unicodestring }
   S1CP:=StringCodePage(S1);
-  if (S1CP=$ffff) or (S1CP=0) then
+  if (S1CP=CP_NONE) or (S1CP=0) then
     S1CP:=DefaultSystemCodePage;
   S2CP:=StringCodePage(S2);
-  if (S2CP=$ffff) or (S2CP=0) then
+  if (S2CP=CP_NONE) or (S2CP=0) then
     S2CP:=DefaultSystemCodePage;
 {$ifdef FPC_HAS_CPSTRING}
   if (Pointer(DestS)=nil) then
@@ -216,7 +216,7 @@ begin
 {$else FPC_HAS_CPSTRING}
   DestCP:=StringCodePage(DestS);
 {$endif FPC_HAS_CPSTRING}
-  if (DestCP=$ffff) or (DestCP=0) then
+  if (DestCP=CP_NONE) or (DestCP=0) then
     DestCP:=DefaultSystemCodePage;
   if (S1CP<>DestCP) or (S2CP<>DestCP) then
     begin
@@ -291,7 +291,7 @@ begin
 {$else FPC_HAS_CPSTRING}
   DestCP:=StringCodePage(DestS);
 {$endif FPC_HAS_CPSTRING}
-  if (DestCP=$ffff) or (DestCP=0) then
+  if (DestCP=CP_NONE) or (DestCP=0) then
     DestCP:=DefaultSystemCodePage;
   sameCP:=true;
   lowstart:=low(sarr);
@@ -308,7 +308,7 @@ begin
       U:='';
       for i:=lowstart to high(sarr) do begin
         tmpCP:=StringCodePage(sarr[i]);
-        if (tmpCP=$ffff) or (tmpCP=0) then
+        if (tmpCP=CP_NONE) or (tmpCP=0) then
           begin
             tmpStr:=sarr[i];
             SetCodePage(tmpStr,DefaultSystemCodePage,False);
@@ -407,7 +407,7 @@ begin
   Size:=Length(S);
   if Size>0 then
     begin
-      if (cp=0) or (cp=$ffff) then
+      if (cp=0) or (cp=CP_NONE) then
         cp:=DefaultSystemCodePage;
       if (StringCodePage(S)=cp) then
         begin
@@ -487,7 +487,7 @@ Var
 {$endif FPC_HAS_CPSTRING}
 begin
 {$ifdef FPC_HAS_CPSTRING}
-  if (cp=0) or (cp=$ffff) then
+  if (cp=0) or (cp=CP_NONE) then
     cp:=DefaultSystemCodePage;
 {$else FPC_HAS_CPSTRING}
   cp:=DefaultSystemCodePage;
@@ -511,7 +511,7 @@ var
 {$endif FPC_HAS_CPSTRING}
 begin
 {$ifdef FPC_HAS_CPSTRING}
-  if (cp=0) or (cp=$ffff) then
+  if (cp=0) or (cp=CP_NONE) then
     cp:=DefaultSystemCodePage;
 {$else FPC_HAS_CPSTRING}
   cp:=DefaultSystemCodePage;
@@ -539,7 +539,7 @@ begin
   if L > 0 then
     begin
 {$ifdef FPC_HAS_CPSTRING}
-      if (cp=0) or (cp=$ffff) then
+      if (cp=0) or (cp=CP_NONE) then
         cp:=DefaultSystemCodePage;
 {$else FPC_HAS_CPSTRING}
       cp:=DefaultSystemCodePage;
@@ -574,7 +574,7 @@ begin
   if i > 0 then
     begin
 {$ifdef FPC_HAS_CPSTRING}
-      if (cp=0) or (cp=$ffff) then
+      if (cp=0) or (cp=CP_NONE) then
         cp:=DefaultSystemCodePage;
 {$else FPC_HAS_CPSTRING}
       cp:=DefaultSystemCodePage;
@@ -672,10 +672,10 @@ begin
   else
     begin
       r1:=S1;
-      if (cp1=$ffff) or (cp1=0) then
+      if (cp1=CP_NONE) or (cp1=0) then
         SetCodePage(r1,DefaultSystemCodePage,false);
       r2:=S2;
-      if (cp2=$ffff) or (cp2=0) then
+      if (cp2=CP_NONE) or (cp2=0) then
         SetCodePage(r2,DefaultSystemCodePage,false);
       //convert them to utf8 then compare
       SetCodePage(r1,65001);
@@ -715,10 +715,10 @@ begin
   else
     begin
       r1:=S1;
-      if (cp1=$ffff) or (cp1=0) then
+      if (cp1=CP_NONE) or (cp1=0) then
         SetCodePage(r1,DefaultSystemCodePage,false);
       r2:=S2;
-      if (cp2=$ffff) or (cp2=0) then
+      if (cp2=CP_NONE) or (cp2=0) then
         SetCodePage(r2,DefaultSystemCodePage,false);
       //convert them to utf8 then compare
       SetCodePage(r1,65001);
@@ -771,7 +771,7 @@ begin
          GetMem(Pointer(S),AnsiRecLen+L);
          PAnsiRec(S)^.Ref:=1;
 {$ifdef FPC_HAS_CPSTRING}
-         if (cp=0) or (cp=$ffff) then
+         if (cp=0) or (cp=CP_NONE) then
            cp:=DefaultSystemCodePage;
          PAnsiRec(S)^.CodePage:=cp;
 {$else}
@@ -1236,7 +1236,7 @@ begin
   Dec(Index);
   SetLength(Temp,Length(Source)+LS);
   cp:=StringCodePage(S);
-  if (cp=0) or (cp=$ffff) then
+  if (cp=0) or (cp=CP_NONE) then
     cp:=DefaultSystemCodePage;
   SetCodePage(Temp,cp,false);
   If Index>0 then

+ 13 - 2
rtl/inc/systemh.inc

@@ -273,6 +273,17 @@ Type
   PPChar              = ^PChar;
   PPPChar             = ^PPChar;
 
+{ some values which are used in RTL for TSystemCodePage type }
+const
+  CP_ACP     = 0;     // default to ANSI code page
+  CP_UTF16   = 1200;  // utf-16
+  CP_UTF16BE = 1201;  // unicodeFFFE
+  CP_UTF7    = 65000; // utf-7
+  CP_UTF8    = 65001; // utf-8
+  CP_ASCII   = 20127; // us-ascii
+  CP_NONE    = $FFFF; // rawbytestring encoding
+
+type
   { AnsiChar is equivalent of Char, so we need
     to use type renamings }
   TAnsiChar           = Char;
@@ -291,14 +302,14 @@ Type
   UCS4String          = array of UCS4Char;
 
 {$ifdef FPC_HAS_CPSTRING}
-  UTF8String          = type AnsiString(65001);
+  UTF8String          = type AnsiString(CP_UTF8);
 {$else FPC_HAS_CPSTRING}
   UTF8String          = type ansistring;
 {$endif FPC_HAS_CPSTRING}
   PUTF8String         = ^UTF8String;
 
 {$ifdef FPC_HAS_CPSTRING}
-  RawByteString       = type AnsiString($ffff);
+  RawByteString       = type AnsiString(CP_NONE);
 {$else FPC_HAS_CPSTRING}
   RawByteString       = ansistring;
 {$endif FPC_HAS_CPSTRING}

+ 3 - 3
rtl/inc/ustrings.inc

@@ -313,7 +313,7 @@ begin
   Size:=Length(S2);
   if Size>0 then
   begin
-    if (cp=$ffff) or (cp=0) then
+    if (cp=CP_NONE) or (cp=0) then
       cp:=DefaultSystemCodePage;
     widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Pointer(S2)),result,cp,Size);
   end;
@@ -333,7 +333,7 @@ begin
   if Size>0 then
   begin
     cp:=StringCodePage(S2);
-    if (cp=$ffff) or (cp=0) then
+    if (cp=CP_NONE) or (cp=0) then
       cp:=DefaultSystemCodePage;
     widestringmanager.Ansi2UnicodeMoveProc(PChar(S2),cp,result,Size);
   end;
@@ -797,7 +797,7 @@ begin
 {$ifndef FPC_HAS_CPSTRING}
   cp:=DefaultSystemCodePage;
 {$endif FPC_HAS_CPSTRING}     
-  if (cp=$ffff) or (cp=0) then
+  if (cp=CP_NONE) or (cp=0) then
     cp:=DefaultSystemCodePage;
   widestringmanager.Unicode2AnsiMoveProc(@c, fpc_UChar_To_AnsiStr, cp, 1);
 end;

+ 2 - 2
rtl/inc/wstrings.inc

@@ -267,7 +267,7 @@ begin
   Size:=Length(S2);
   if Size>0 then
   begin
-    if (cp=$ffff) or (cp=0) then
+    if (cp=CP_NONE) or (cp=0) then
       cp:=DefaultSystemCodePage;
     widestringmanager.Wide2AnsiMoveProc(PWideChar(Pointer(S2)),result,cp,Size);
   end;
@@ -287,7 +287,7 @@ begin
   if Size>0 then
   begin
     cp:=StringCodePage(S2);
-    if (cp=$ffff) or (cp=0) then
+    if (cp=CP_NONE) or (cp=0) then
       cp:=DefaultSystemCodePage;
     widestringmanager.Ansi2WideMoveProc(PChar(S2),cp,result,Size);
   end;

+ 0 - 3
rtl/win/syswin.inc

@@ -532,9 +532,6 @@ function GetProcessID: SizeUInt;
 const
   { MultiByteToWideChar  }
   MB_PRECOMPOSED = 1;
-  CP_ACP = 0;
-  CP_UTF16 = 1200;
-  CP_UTF8 = 65001;
   WC_NO_BEST_FIT_CHARS = $400;
 
 function MultiByteToWideChar(CodePage:UINT; dwFlags:DWORD; lpMultiByteStr:PChar; cchMultiByte:longint; lpWideCharStr:PWideChar;cchWideChar:longint):longint;