比较和排序 Unicode 文件名

发布于 2024-08-22 01:17:16 字数 486 浏览 1 评论 0原文

使用 Delphi 2007 和 TMS 组件来实现 Unicode 实用程序和接口(不能升级到 Delphi 2009 以支持 Unicode)。

我将文件名列表存储在字符串列表(TTntStringList)中。它已排序且不区分大小写。默认排序例程使用 CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, ...) 来比较字符串(对于 Find 也是如此)。然而,这是一个问题,因为这会将 dummyss.txt 与 dummyß.txt 等同起来(例如),但在 NTFS 上,将这两个文件放在同一文件夹中是完全合法的,即它们被视为不同的名称。

我的理解是,在 Vista 及更高版本上,比较文件名的正确方法是使用 CompareStringOrdinal。这是正确的吗?

在 Vista 之前的系统上,正确的方法是什么?我相信它应该是 CompareStringW(LOCALE_INVARIANT, ...) 但我不完全确定。

谢谢

Using Delphi 2007 and TMS components for Unicode utils and interface (upgrading to Delphi 2009 for Unicode support is not an option).

I'm storing a list of filenames in a string list (TTntStringList). It's sorted and case insensitive. The default sort routine uses CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, ...) to compare strings (and the same for Find). However, this is a problem because that will equate dummyss.txt with dummyß.txt (for example), but on NTFS it's perfectly legal to have those two files in the same folder, i.e. they are treated as different names.

My understanding is that on Vista and newer, the correct way to compare filenames is to use CompareStringOrdinal. Is this correct?

On pre-Vista systems, what would be the correct way? I believe it should be CompareStringW(LOCALE_INVARIANT, ...) but I'm not entirely sure.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫罗兰の梦幻 2024-08-29 01:17:16

引用自 MSDN 文章 在应用程序中处理排序

CompareStringOrdinal 比较两个
用于测试二进制的 Unicode 字符串
平等,而不是语言
平等。此类的例子
非语言字符串是 NTFS 文件
名字,...

CompareStringOrdinal 需要 Windows Vista 或更高版本。

编辑:是的,似乎在 Vista 之前的 Windows 中您可以使用 < a href="http://msdn.microsoft.com/en-us/library/ms804321.aspx" rel="nofollow noreferrer">RtlCompareUnicodeString 也由 CompareStringOrdinal 内部使用,并且自 Windows 起可用新台币。

Quote from MSDN article Handling Sorting in Your Applications:

CompareStringOrdinal compares two
Unicode strings to test for binary
equality, as opposed to linguistic
equality. Examples of such
non-linguistic strings are NTFS file
names, ...

CompareStringOrdinal requires Windows Vista or later.

Edit: Yes, it seems that in pre-Vista Windows you can use RtlCompareUnicodeString which is used internally by CompareStringOrdinal, too, and is available since Windows NT.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文