ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Global/Functions.pas
(Generate patch)

Comparing:
oup/rewrite/Global/Functions.pas (file contents), Revision 97 by alloc, Mon Jan 22 23:05:45 2007 UTC vs.
oup/current/Global/Functions.pas (file contents), Revision 111 by alloc, Wed Feb 21 03:28:48 2007 UTC

# Line 10 | Line 10 | function Decode_Int(buffer: TByteData):
10   function Encode_Int(input: LongWord): TByteData;
11   function Decode_Float(buffer: TByteData): Single;
12   function Encode_Float(input: Single): TByteData;
13 + function IntToBin(Value: Byte): String;
14   function DataToBin(Data: TByteData): String;
15   function BinToInt(bin: String): Byte;
16  
# Line 38 | Line 39 | type
39  
40  
41  
41
42   function BoolToStr(bool: Boolean): String;
43   begin
44    if bool then
# Line 48 | Line 48 | begin
48   end;
49  
50  
51
52
51   function HexToLong(hex: String): LongWord;
52  
53    function NormalizeHexString(var hex: String): Boolean;
# Line 75 | Line 73 | function HexToLong(hex: String): LongWor
73  
74   begin
75    if NormalizeHexString(hex) then
76 <  begin
79 <    Result := StrToInt(hex);
80 < {
81 <    hex    := UpperCase(hex);
82 <    Result := 0;
83 <    for i := 1 to Length(hex) do
84 <    begin
85 <      Result := Result shl 4;
86 <      case hex[i] of
87 <        '0'..'9':
88 <          Result := Result + Ord(hex[i]) - 48;
89 <        'A'..'F':
90 <          Result := Result + Ord(hex[i]) - 55;
91 <        else
92 <          Result := 0;
93 <          Exit;
94 <      end;
95 <    end;
96 < }
97 <  end
76 >    Result := StrToInt(hex)
77    else
99  begin
78      Result := 0;
101  end;
79   end;
80  
81  
105
106
82   function Decode_Int(buffer: TByteData): LongWord;
83   begin
84    Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256;
85   end;
86  
87  
113
114
88   function Encode_Int(input: LongWord): TByteData;
89   begin
90    SetLength(Result, 4);
# Line 125 | Line 98 | begin
98   end;
99  
100  
128
129
101   function Decode_Float(buffer: TByteData): Single;
102   var
103    _valueswitcher: TValueSwitcher;
# Line 138 | Line 109 | begin
109   end;
110  
111  
141
142
112   function Encode_Float(input: Single): TByteData;
113   var
114    _valueswitcher: TValueSwitcher;
# Line 149 | Line 118 | begin
118   end;
119  
120  
121 + function IntToBin(Value: Byte): String;
122 + var
123 +  i: Byte;
124 + begin
125 +  Result := '';
126 +  for i := 7 downto 0 do
127 +    Result := Result + IntToStr((Value shr i) and $01);
128 + end;
129  
130  
131   function DataToBin(Data: TByteData): String;
# Line 172 | Line 149 | begin
149   end;
150  
151  
175
176
152   function BinToInt(bin: String): Byte;
153   var
154    Add: Integer;
# Line 195 | Line 170 | end;
170  
171  
172  
198
173   function FormatNumber(Value: LongWord; Width: Byte; leadingzeros: Char): String;
174   begin
175    Result := AnsiReplaceStr(Format('%' + IntToStr(Width) + 'u', [Value]), ' ', leadingzeros);
# Line 227 | Line 201 | end;
201   function CreateHexString(Data: TByteData; HexOnly: Boolean): String;
202   var
203    string_build, ascii_version: String;
204 <  i: LongWord;
204 >  i: Integer;
205   begin
206    string_build  := '';
207    ascii_version := '';
# Line 260 | Line 234 | end;
234  
235   function DecodeHexString(hex: String): TByteData;
236   var
237 <  i: LongWord;
237 >  i: Integer;
238   begin
239    SetLength(Result, Length(hex) div 2);
240    for i := 0 to Length(Result) do

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)