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 245 by alloc, Sat Aug 18 15:51:42 2007 UTC

# Line 5 | Line 5 | interface
5   uses TypeDefs, Classes;
6  
7   function BoolToStr(bool: Boolean): String;
8 function HexToLong(hex: String): LongWord;
8   function Decode_Int(buffer: TByteData): LongWord;
9   function Encode_Int(input: LongWord): TByteData;
10   function Decode_Float(buffer: TByteData): Single;
11   function Encode_Float(input: Single): TByteData;
12 + function IntToBin(Value: Byte): String;
13   function DataToBin(Data: TByteData): String;
14   function BinToInt(bin: String): Byte;
15 + function MakeDatLink(FileID: Integer): Integer;
16 +
17 + function ReadString(Stream: TStream; Offset: Integer): String;
18  
19   function StringSmaller(string1, string2: String): Boolean;
20  
# Line 38 | Line 41 | type
41  
42  
43  
41
44   function BoolToStr(bool: Boolean): String;
45   begin
46    if bool then
# Line 48 | Line 50 | begin
50   end;
51  
52  
51
52
53 function HexToLong(hex: String): LongWord;
54
55  function NormalizeHexString(var hex: String): Boolean;
56  var
57    i: Byte;
58  begin
59    Result := True;
60    if hex[1] = '$' then
61    begin
62      for i := 1 to Length(hex) - 1 do
63        hex[i] := hex[i + 1];
64      SetLength(hex, Length(hex) - 1);
65    end;
66    if (hex[1] = '0') and (UpCase(hex[2]) = 'X') then
67    begin
68      for i := 1 to Length(hex) - 2 do
69        hex[i] := hex[i + 2];
70      SetLength(hex, Length(hex) - 2);
71    end;
72    if Length(hex) = 0 then
73      Result := False;
74  end;
75
76 begin
77  if NormalizeHexString(hex) then
78  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
98  else
99  begin
100    Result := 0;
101  end;
102 end;
103
104
105
106
53   function Decode_Int(buffer: TByteData): LongWord;
54   begin
55    Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256;
56   end;
57  
58  
113
114
59   function Encode_Int(input: LongWord): TByteData;
60   begin
61    SetLength(Result, 4);
# Line 125 | Line 69 | begin
69   end;
70  
71  
128
129
72   function Decode_Float(buffer: TByteData): Single;
73   var
74    _valueswitcher: TValueSwitcher;
# Line 138 | Line 80 | begin
80   end;
81  
82  
141
142
83   function Encode_Float(input: Single): TByteData;
84   var
85    _valueswitcher: TValueSwitcher;
# Line 149 | Line 89 | begin
89   end;
90  
91  
92 + function IntToBin(Value: Byte): String;
93 + var
94 +  i: Byte;
95 + begin
96 +  Result := '';
97 +  for i := 7 downto 0 do
98 +    Result := Result + IntToStr((Value shr i) and $01);
99 + end;
100  
101  
102   function DataToBin(Data: TByteData): String;
# Line 172 | Line 120 | begin
120   end;
121  
122  
175
176
123   function BinToInt(bin: String): Byte;
124   var
125    Add: Integer;
# Line 194 | Line 140 | begin
140   end;
141  
142  
143 + function MakeDatLink(FileID: Integer): Integer;
144 + begin
145 +  Result := FileID * 256 + 1;
146 + end;
147 +
148 +
149 +
150 +
151 + function ReadString(Stream: TStream; Offset: Integer): String;
152 + var
153 +  i: Integer;
154 +  c: Char;
155 + begin
156 +  if Assigned(Stream) then
157 +  begin
158 +    if Offset >= 0 then
159 +    begin
160 +      Result := '';
161 +      Stream.Seek(Offset, soFromBeginning);
162 +      repeat
163 +        Stream.Read(c, 1);
164 +        if Ord(c) > 0 then
165 +          Result := Result + c;
166 +      until Ord(c) = 0;
167 +    end;
168 +  end;
169 + end;
170 +
171  
172  
173   function FormatNumber(Value: LongWord; Width: Byte; leadingzeros: Char): String;
# 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)