Skip to content

Commit

Permalink
Fix FormatFileName
Browse files Browse the repository at this point in the history
修复当文件名以连续的点、空格、点结尾 (例如"abc . . ")时,无法完全去除开头/结尾的点和空格
需要额外处理当文件名都是非法字符的情况
  • Loading branch information
MoguCloud authored Dec 31, 2022
1 parent eef382c commit d8b747a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/DownKyi.Core/Utils/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,22 @@ public static string FormatFileName(string originName)
destName = Regex.Replace(destName, @"\p{C}+", string.Empty);

// 移除前导和尾部的空白字符、dot符
return destName.Trim('.').Trim();
int i, j;
for (i = 0; i < destName.Length; i++)
{
if (destName[i] != ' ' && destName[i] != '.')
{
break;
}
}
for (j = destName.Length - 1; j >= 0; j--)
{
if (destName[j] != ' ' && destName[j] != '.')
{
break;
}
}
return destName.Substring(i, j - i + 1);
}

}
Expand Down

0 comments on commit d8b747a

Please sign in to comment.