StringTools.Truncate() does not truncate in the middle when the input type is Path

Hi!

Truncates the specified input string to the requested number of characters.
The optional type argument specifies the truncation type. Valid values are:
0 truncate on the right
1 truncate on the left
2 truncate in the middle
If not specified, the default is 2 if input is a Path object, otherwise the default is 0.

The doc says that the truncation type defaults to 2 when the parameter is a Path object, but it actually truncates on the right side.

var fsu = DOpus.FSUtil();
var pathStr = "C:/aaa/bbb/ccc/ddd/eee/fff/ggg/hhh/iii"
DOpus.Output("type of 'pathStr':" + DOpus.TypeOf(pathStr));
var path =  fsu.NewPath(pathStr);
DOpus.Output( "type of 'path' :" + DOpus.TypeOf(path))
var st = DOpus.Create().StringTools;
DOpus.Output(st.truncate(path,30));
DOpus.Output(st.truncate(pathStr,30,2));
DOpus.Output(st.truncate(path,30,2));

// output:
//   type of 'pathStr':string
//   type of 'path' :object.Path
//   C:\aaa\bbb\ccc\ddd\eee\fff\...
//   C:/aaa/bbb/ccc/ddd/eee/.../iii
//   C:\aaa\bbb\ccc\ddd\eee\...\iii

And the evaluator function is correct.

pathStr = "C:/aaa/bbb/ccc/ddd/eee/fff/ggg/hhh/iii";
path = pathStr as path;
Output(TypeOf(path));
Output(TypeOf(pathStr));
Output(Truncate(path,30));
Output(Truncate(pathStr,30));
// output:
//   path
//   str
//   C:/aaa/bbb/ccc/ddd/eee/.../iii
//   C:/aaa/bbb/ccc/ddd/eee/fff/...
Directory Opus 13.20.2 (Beta) Build 9410 x64
OS 10.0 (B:26200 P:2 T:1) SP 0.0
Windows 11 Pro 25H2

seems like a bug :thinking:

Thanks for the report, that has been fixed for the next update.

2 Likes