Anyway, the improvements now mean that it's robust for all buffer sizes between [0, strlen(path)] and beyond. So, you can do all of the following:
std::string path = "H:\\xyz\\mno\\abcdef.ghi";
char buffer[101];
// returns the number required (22)
winstl::path_squeeze(path, static_cast
// returns 1; buffer == ""
winstl::path_squeeze(path, buffer, 1);
// returns 2; buffer == "a"
winstl::path_squeeze(path, buffer, 2);
// returns 5; buffer == "abcd"
winstl::path_squeeze(path, buffer, 5);
// returns 6; buffer == "a...i"
winstl::path_squeeze(path, buffer, 6);
// returns 9; buffer == "ab...ghi"
winstl::path_squeeze(path, buffer, 9);
// returns 10; buffer == "abc...ghi"
winstl::path_squeeze(path, buffer, 10);
// returns 11; buffer == "abcdef.ghi"
winstl::path_squeeze(path, buffer, 11);
// returns 11; buffer == "abcdef.ghi"
winstl::path_squeeze(path, buffer, 12);
// returns 11; buffer == "abcdef.ghi"
winstl::path_squeeze(path, buffer, 17);
// returns 18; buffer == "H:\\...\\abcdef.ghi"
winstl::path_squeeze(path, buffer, 18);
// returns 19; buffer == "H:\\x...\\abcdef.ghi"
winstl::path_squeeze(path, buffer, 19);
// returns 20; buffer == "H:\\xy...\\abcdef.ghi"
winstl::path_squeeze(path, buffer, 20);
// returns 21; buffer == "H:\\xyz...\\abcdef.ghi"
winstl::path_squeeze(path, buffer, 21);
// returns 22; buffer == "H:\\xyz\\mno\\abcdef.ghi"
winstl::path_squeeze(path, buffer, 22);
// returns 22; buffer == "H:\\xyz\\mno\\abcdef.ghi"
winstl::path_squeeze(path, buffer, 23);
No comments:
Post a Comment