hedgewars/uUtils.pas
changeset 13980 3183c4dc6e53
parent 13879 6b2c87490f0a
child 14057 1a85afba813d
equal deleted inserted replaced
13979:6938cab93016 13980:3183c4dc6e53
    28 
    28 
    29 procedure SplitBySpace(var a, b: shortstring);
    29 procedure SplitBySpace(var a, b: shortstring);
    30 procedure SplitByChar(var a, b: shortstring; c: char);
    30 procedure SplitByChar(var a, b: shortstring; c: char);
    31 procedure SplitByCharA(var a, b: ansistring; c: char);
    31 procedure SplitByCharA(var a, b: ansistring; c: char);
    32 
    32 
       
    33 procedure EscapeCharA(var a: ansistring; e: char);
       
    34 procedure UnEscapeCharA(var a: ansistring; e: char);
       
    35 
    33 function ExtractFileDir(s: shortstring) : shortstring;
    36 function ExtractFileDir(s: shortstring) : shortstring;
    34 function ExtractFileName(s: shortstring) : shortstring;
    37 function ExtractFileName(s: shortstring) : shortstring;
    35 
    38 
    36 function  EnumToStr(const en : TGearType) : shortstring; overload;
    39 function  EnumToStr(const en : TGearType) : shortstring; overload;
    37 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
    40 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
   248     begin
   251     begin
   249     b:= copy(a, i + 1, Length(a) - i);
   252     b:= copy(a, i + 1, Length(a) - i);
   250     SetLengthA(a, Pred(i));
   253     SetLengthA(a, Pred(i));
   251     end else b:= '';
   254     end else b:= '';
   252 end; { SplitByCharA }
   255 end; { SplitByCharA }
       
   256 
       
   257 // In the ansistring a, escapes all instances of
       
   258 // '\e' with an ASCII ESC character, where e is
       
   259 // a char chosen by you.
       
   260 procedure EscapeCharA(var a: ansistring; e: char);
       
   261 var i: LongInt;
       
   262 begin
       
   263 repeat
       
   264     i:= Pos(e, a);
       
   265     if (i > 1) and (a[i - 1] = '\') then
       
   266         begin
       
   267         a[i]:= ^[; // ASCII ESC
       
   268         Delete(a, i - 1, 1);
       
   269         end
       
   270     else
       
   271         break;
       
   272 until (i <= 0);
       
   273 end; { EscapeCharA }
       
   274 
       
   275 // Unescapes a previously escaped string and inserts
       
   276 // e back into the string. e is a char chosen by you.
       
   277 procedure UnEscapeCharA(var a: ansistring; e: char);
       
   278 var i: LongInt;
       
   279 begin
       
   280 repeat
       
   281     i:= Pos(^[, a); // ASCII ESC
       
   282     if (i > 0) then
       
   283         begin
       
   284         a[i]:= e;
       
   285         end
       
   286     else
       
   287         break;
       
   288 until (i <= 0);
       
   289 end; { UnEscapeCharA }
   253 
   290 
   254 function EnumToStr(const en : TGearType) : shortstring; overload;
   291 function EnumToStr(const en : TGearType) : shortstring; overload;
   255 begin
   292 begin
   256 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   293 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   257 end;
   294 end;