hedgewars/uFLUtils.pas
branchqmlfrontend
changeset 10757 f71275973737
parent 10616 20a2d5e6930a
equal deleted inserted replaced
10754:8dd1cf1be5a2 10757:f71275973737
     4 function str2PChar(const s: shortstring): PChar;
     4 function str2PChar(const s: shortstring): PChar;
     5 function intToStr(n: LongInt): shortstring;
     5 function intToStr(n: LongInt): shortstring;
     6 function strToInt(s: shortstring): LongInt;
     6 function strToInt(s: shortstring): LongInt;
     7 function midStr(s: shortstring; pos: byte): shortstring;
     7 function midStr(s: shortstring; pos: byte): shortstring;
     8 procedure underScore2Space(var s: shortstring);
     8 procedure underScore2Space(var s: shortstring);
       
     9 function readInt(name, input: shortstring; var value: LongInt): boolean;
       
    10 function readBool(name, input: shortstring; var value: boolean): boolean;
     9 
    11 
    10 implementation
    12 implementation
    11 
    13 
    12 var
    14 var
    13     str2PCharBuffer: array[0..255] of char;
    15     str2PCharBuffer: array[0..255] of char;
    43 begin
    45 begin
    44     for i:= length(s) downto 1 do
    46     for i:= length(s) downto 1 do
    45         if s[i] = '_' then s[i]:= ' '
    47         if s[i] = '_' then s[i]:= ' '
    46 end;
    48 end;
    47 
    49 
       
    50 function readInt(name, input: shortstring; var value: LongInt): boolean;
       
    51 var l: LongInt;
       
    52 begin
       
    53     name:= name + '=';
       
    54     l:= length(name);
       
    55 
       
    56     if copy(input, 1, l) = name then
       
    57     begin
       
    58         value:= strToInt(midStr(input, l + 1));
       
    59         readInt:= true
       
    60     end
       
    61     else
       
    62         readInt:= false
       
    63 end;
       
    64 
       
    65 function readBool(name, input: shortstring; var value: boolean): boolean;
       
    66 var l: LongInt;
       
    67 begin
       
    68     name:= name + '=';
       
    69     l:= length(name);
       
    70 
       
    71     if copy(input, 1, l) = name then
       
    72     begin
       
    73         value:= (length(input) > l) and (input[l + 1] <> 'f');
       
    74         readBool:= true
       
    75     end
       
    76     else
       
    77         readBool:= false
       
    78 end;
       
    79 
    48 end.
    80 end.