Juha Manninen wrote:
> 
> Is there such a function hidden somewhere in FPC/Lazarus vast amount of code?

I wouldn't know, but I have my own version of trimming long paths and
rather use ellipse (...) to denote hidden information. Using Unicode, the
'...' could probably be reduced to one unicode character (…).

See attached test program with path trim function. Maybe it could be useful
 to you.


Sample output:

$ ./trimming_long_paths
/Users/milipili/Projec...r1/pixie/client/src/pixie/pixie.lpi
/home/graemeg/programm..._AdrsBook_MGM/Demo_AdrsBook_MGM.lpi


The trim function can be told how long to make the resulting text, which
side to trim from and how long the remaining (right side) text should be.
Above I used a limit of 60 characters and 35 character on the right of the
ellipse.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

program triming_long_paths;
{$mode objfpc}

uses sysutils;

function CutString(const s: UTF8String; const maxLen: integer = 30; 
    const rightSide: boolean = false; const rightSideLen: integer = 8
    ): UTF8String;
var 
  i : integer;
begin
   if (0 = maxLen) or (length(s) < maxLen) or (rightSideLen > maxLen- 4) then
   begin
       result := s;
       exit;
   end;

   if rightSide then
   begin
       i := maxLen - (rightSideLen + 3);
       result := TrimRight(leftStr(s, i)) + '...' + TrimLeft(rightStr(s, rightSideLen));
   end 
   else
     result := leftStr(s, maxLen - 3) + '...';
end;



const 
  LONG_PATH : UTF8String = '/Users/milipili/Projects/anotherFolder/folder0/folder1/pixie/client/src/pixie/pixie.lpi';

begin
  WriteLn(CutString(LONG_PATH, 60, true, 35)); // /Users/milipili/Projec...r1/pixie/client/src/pixie/pixie.lpi
  writeln(CutString('/home/graemeg/programming/3rdParty/tiOPF2/Source/Demos/WorkInProgress/Demo_31_AdrsBook_MGM/Demo_AdrsBook_MGM.lpi',
    60, true, 35));
end.

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to