news
About Elegant Chaos
info
About me and my friends
people
Software from Elegant Chaos
software
Other stuff...
stuff

FL_ShortPath

Revision 1
Revised on 18/03/95 19:12

Description

Return a short version of a path name, for displaying in limited space. Takes the path itself, and an optional limit saying how long a path should be before it gets truncated (the default is 20 characters if this parameter isn't used).

This routine checks to see whether the path is too long. If it is, it takes the words before the first colon, and the words after the last colon, and replaces the bit in the middle with "::".

Note that this may still result in a string that is larger than the limit size that was passed.


Code

function FL_ShortPath path,limit
  -- returns abbreviated version of a path (for display)
  
  -- if limit isn't passed, use default limit of 20
  if limit is empty then
    put 20 into limit
  end if
  
  -- if path is longer than the limit, truncate it
  if length(path) > limit then
    get the itemDelimiter
    set the itemDelimiter to ":"
    put first item of path into start
    put last item of path into finish
    put start & ":...:" & finish into path
    set the itemDelimiter to it
  end if
  
  -- return path, possible modified
  return path
end FL_ShortPath