Browse Source

compiler: replace string codepage comparison to numeric. store codepage as number in current settings

git-svn-id: trunk@19144 -
paul 14 years ago
parent
commit
4d3da666db

+ 2 - 4
compiler/globals.pas

@@ -108,8 +108,6 @@ interface
 
 
     type
-       tcodepagestring = string[20];
-
        { this is written to ppus during token recording for generics so it must be packed }
        tsettings = packed record
          alignment       : talignmentinfo;
@@ -137,7 +135,7 @@ interface
          asmmode         : tasmmode;
          interfacetype   : tinterfacetypes;
          defproccall     : tproccalloption;
-         sourcecodepage  : tcodepagestring;
+         sourcecodepage  : tstringencoding;
 
          minfpconstprec  : tfloattype;
 
@@ -430,7 +428,7 @@ interface
         asmmode : asmmode_standard;
         interfacetype : it_interfacecom;
         defproccall : pocall_default;
-        sourcecodepage : '8859-1';
+        sourcecodepage : 28591;
         minfpconstprec : s32real;
 
         disabledircache : false;

+ 2 - 1
compiler/globtype.pas

@@ -513,7 +513,8 @@ interface
       end;
   {$endif}
 
-      tstringencoding = word;
+       tstringencoding = Word;
+       tcodepagestring = string[20];
 
     const
        { link options }

+ 6 - 6
compiler/ncnv.pas

@@ -1038,7 +1038,7 @@ implementation
             ((tstringdef(resultdef).stringtype in [st_widestring,st_unicodestring]) or
              (torddef(left.resultdef).ordtype=uchar) or
              ((torddef(left.resultdef).ordtype=uwidechar) and
-              (current_settings.sourcecodepage<>'utf8')
+              (current_settings.sourcecodepage<>CP_UTF8)
              )
             )
              { widechar >=128 is destroyed }
@@ -1059,7 +1059,7 @@ implementation
                 begin
                   if (torddef(left.resultdef).ordtype=uwidechar) then
                    begin
-                    if (current_settings.sourcecodepage<>'utf8') then
+                    if (current_settings.sourcecodepage<>CP_UTF8) then
                       hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue)))
                     else
                      begin
@@ -1141,7 +1141,7 @@ implementation
             )
            ) and
            ((tstringdef(left.resultdef).stringtype in [st_unicodestring,st_widestring]) and
-            (current_settings.sourcecodepage<>'utf8')
+            (current_settings.sourcecodepage<>CP_UTF8)
            ) then
           begin
             tstringconstnode(left).changestringtype(resultdef);
@@ -1193,13 +1193,13 @@ implementation
          if (left.nodetype=ordconstn) and
             ((torddef(resultdef).ordtype<>uchar) or
              (torddef(left.resultdef).ordtype<>uwidechar) or
-             (current_settings.sourcecodepage<>'utf8'))
+             (current_settings.sourcecodepage<>CP_UTF8))
              { >= 128 is replaced by '?' currently -> loses information }
              {(tordconstnode(left).value.uvalue<128))} then
            begin
              if (torddef(resultdef).ordtype=uchar) and
                 (torddef(left.resultdef).ordtype=uwidechar) and
-                (current_settings.sourcecodepage<>'utf8') then
+                (current_settings.sourcecodepage<>CP_UTF8) then
               begin
                 hp:=cordconstnode.create(
                       ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue))),
@@ -2274,7 +2274,7 @@ implementation
                 ((not is_widechararray(left.resultdef) and
                   not is_wide_or_unicode_string(left.resultdef)) or
                  (tstringdef(resultdef).stringtype in [st_widestring,st_unicodestring]) or
-                 (current_settings.sourcecodepage<>'utf8')
+                 (current_settings.sourcecodepage<>CP_UTF8)
                 )
                  { non-ascii chars would be replaced with '?' -> loses info }
                  {not hasnonasciichars(pcompilerwidestring(tstringconstnode(left).value_str)))}

+ 2 - 2
compiler/ncon.pas

@@ -1003,7 +1003,7 @@ implementation
             not(tstringdef(def).stringtype in [st_widestring,st_unicodestring]) then
             begin
               if (tstringdef(def).encoding=CP_UTF8) or
-                 (current_settings.sourcecodepage='utf8') then
+                 (current_settings.sourcecodepage=CP_UTF8) then
                 begin
                   pw:=pcompilerwidestring(value_str);
                   l:=(getlengthwidestring(pw)*4)+1;
@@ -1034,7 +1034,7 @@ implementation
               if (cst_type = cst_ansistring) then
                 cp2:=tstringdef(resultdef).encoding
               else if (cst_type in [cst_shortstring,cst_conststring,cst_longstring]) then
-                cp2:=codepagebyname(current_settings.sourcecodepage);
+                cp2:=current_settings.sourcecodepage;
               if cpavailable(cp1) and cpavailable(cp2) then
                 changecodepage(value_str,len,cp1,value_str,cp2);
             end;

+ 2 - 2
compiler/options.pas

@@ -867,11 +867,11 @@ begin
                  'c' :
                    begin
                      if (upper(more)='UTF8') or (upper(more)='UTF-8') then
-                        init_settings.sourcecodepage:='utf8'
+                        init_settings.sourcecodepage:=CP_UTF8
                      else if not(cpavailable(more)) then
                        Message1(option_code_page_not_available,more)
                      else
-                       init_settings.sourcecodepage:=more;
+                       init_settings.sourcecodepage:=codepagebyname(more);
                    end;
                  'C' :
                    RCCompiler := More;

+ 1 - 1
compiler/ptconst.pas

@@ -949,7 +949,7 @@ implementation
                     ca:=@ch;
                     len:=1;
                   end
-               else if is_constwidecharnode(n) and (current_settings.sourcecodepage<>'utf8') then
+               else if is_constwidecharnode(n) and (current_settings.sourcecodepage<>CP_UTF8) then
                   begin
                     case char_size of
                       1:

+ 2 - 2
compiler/scandir.pas

@@ -1373,11 +1373,11 @@ unit scandir;
              current_scanner.skipspace;
              s:=current_scanner.readcomment;
              if (upper(s)='UTF8') or (upper(s)='UTF-8') then
-               current_settings.sourcecodepage:='utf8'
+               current_settings.sourcecodepage:=CP_UTF8
              else if not(cpavailable(s)) then
                Message1(option_code_page_not_available,s)
              else
-               current_settings.sourcecodepage:=s;
+               current_settings.sourcecodepage:=codepagebyname(s);
           end;
       end;
 

+ 3 - 3
compiler/scanner.pas

@@ -2488,7 +2488,7 @@ In case not, the value returned can be arbitrary.
                      begin
                        inc(inputpointer,3);
                        message(scan_c_switching_to_utf8);
-                       current_settings.sourcecodepage:='utf8';
+                       current_settings.sourcecodepage:=CP_UTF8;
                      end;
 
                    line_no:=1;
@@ -4085,7 +4085,7 @@ In case not, the value returned can be arbitrary.
                                end;
                            end;
                            { interpret as utf-8 string? }
-                           if (ord(c)>=$80) and (current_settings.sourcecodepage='utf8') then
+                           if (ord(c)>=$80) and (current_settings.sourcecodepage=CP_UTF8) then
                              begin
                                { convert existing string to an utf-8 string }
                                if not iswidestring then
@@ -4132,7 +4132,7 @@ In case not, the value returned can be arbitrary.
                              end
                            else if iswidestring then
                              begin
-                               if current_settings.sourcecodepage='utf8' then
+                               if current_settings.sourcecodepage=CP_UTF8 then
                                  concatwidestringchar(patternw,ord(c))
                                else
                                  concatwidestringchar(patternw,asciichar2unicode(c))

+ 2 - 2
compiler/widestr.pas

@@ -169,7 +169,7 @@ unit widestr;
       var
          m : punicodemap;
       begin
-         if (current_settings.sourcecodepage <> 'utf8') then
+         if (current_settings.sourcecodepage <> CP_UTF8) then
            begin
              m:=getmap(current_settings.sourcecodepage);
              asciichar2unicode:=getunicode(c,m);
@@ -200,7 +200,7 @@ unit widestr;
          setlengthwidestring(r,l);
          source:=p;
          dest:=tcompilerwidecharptr(r^.data);
-         if (current_settings.sourcecodepage <> 'utf8') then
+         if (current_settings.sourcecodepage <> CP_UTF8) then
            begin
              for i:=1 to l do
                 begin