Explorar el Código

* Val can handle hexadecimal just fine, no need for specialized routines.

git-svn-id: trunk@3495 -
daniel hace 19 años
padre
commit
46d5b2fce5
Se han modificado 2 ficheros con 27 adiciones y 64 borrados
  1. 27 26
      ide/fpini.pas
  2. 0 38
      ide/wutils.pas

+ 27 - 26
ide/fpini.pas

@@ -213,33 +213,34 @@ begin
   PaletteToStr:=C;
 end;
 
-function StrToPalette(S: string): string;
-var I,P,X: integer;
-    C: string;
-    Hex: boolean;
-    OK: boolean;
+function strtopalette(S: string): string;
+
+{Converts a string in palette string format, i.e #$41#$42#$43 or
+#65#66#67 to an actual format.}
+
+var i,p,x,len:byte;
+    code:integer;
+
 begin
-  C:=''; I:=1;
-  OK:=S<>'';
-  while OK and (I<=length(S)) and (S[I]='#') do
-  begin
-    Inc(I); Hex:=false;
-    if S[I]='$' then begin Inc(I); Hex:=true; end;
-    P:=Pos('#',copy(S,I,High(S))); if P>0 then P:=I+P-1 else P:=length(S)+1;
-    if Hex=false then
-      begin
-        X:=StrToInt(copy(S,I,P-I));
-        OK:=(LastStrToIntResult=0) and (0<=X) and (X<=High(S));
-      end
-    else
-      begin
-        X:=HexToInt(copy(S,I,P-I));
-        OK:=(LastHexToIntResult=0) and (0<=X) and (X<=255);
-      end;
-    if OK then C:=C+chr(X);
-    Inc(I,P-I);
-  end;
-  StrToPalette:=C;
+  i:=1;
+  len:=0;
+  while (i<=length(S)) and (s[i]='#') do
+    begin
+      s[i]:=#0;
+      inc(i);
+      p:=pos('#',s);
+      if p=0 then
+        p:=length(s)
+      else
+        p:=p-i;
+      val(copy(s,i,p),x,code); {Val supports hexadecimal.}
+      if code<>0 then
+        break;
+      inc(len);
+      strtopalette[len]:=char(X);
+      inc(i,p);
+    end;
+  strtopalette[0]:=char(len);
 end;
 
 {$ifndef NODEBUG}

+ 0 - 38
ide/wutils.pas

@@ -144,8 +144,6 @@ function StrToInt(const S: string): longint;
 function StrToCard(const S: string): cardinal;
 function FloatToStr(D: Double; Decimals: byte): string;
 function FloatToStrL(D: Double; Decimals: byte; MinLen: byte): string;
-function HexToInt(S: string): longint;
-function HexToCard(S: string): cardinal;
 function GetStr(P: PString): string;
 function GetPChar(P: PChar): string;
 function BoolToStr(B: boolean; const TrueS, FalseS: string): string;
@@ -467,42 +465,6 @@ begin
   StrToCard:=L;
 end;
 
-function HexToInt(S: string): longint;
-var L,I: longint;
-    C: char;
-const HexNums: string[16] = '0123456789ABCDEF';
-begin
-  S:=Trim(S); L:=0; I:=1; LastHexToIntResult:=0;
-  while (I<=length(S)) and (LastHexToIntResult=0) do
-  begin
-    C:=Upcase(S[I]);
-    if C in['0'..'9','A'..'F'] then
-    begin
-      L:=L*16+(Pos(C,HexNums)-1);
-    end else LastHexToIntResult:=I;
-    Inc(I);
-  end;
-  HexToInt:=L;
-end;
-
-function HexToCard(S: string): cardinal;
-var L,I: cardinal;
-    C: char;
-const HexNums: string[16] = '0123456789ABCDEF';
-begin
-  S:=Trim(S); L:=0; I:=1; LastHexToCardResult:=0;
-  while (I<=length(S)) and (LastHexToCardResult=0) do
-  begin
-    C:=Upcase(S[I]);
-    if C in['0'..'9','A'..'F'] then
-    begin
-      L:=L*16+(Pos(C,HexNums)-1);
-    end else LastHexToCardResult:=I;
-    Inc(I);
-  end;
-  HexToCard:=L;
-end;
-
 function FloatToStr(D: Double; Decimals: byte): string;
 var S: string;
     L: byte;