为什么AnsiSameText不是ANSI? [英] Why AnsiSameText is not ANSI?
问题描述
函数AnsiSameText(const S1,S2:string):Boolean
我在这里缺少什么?
在AnsiStrings单元中有一个ANSI函数,但是为什么这个(在Sysutils中)被称为'ansi'?
在旧版本的Delphi中,前Unicode,有两套字符串比较功能:
-
SameText
,CompareText
等。这些执行的比较忽略了区域设置。 -
AnsiSameText
,AnsiCompareText
等。这些执行比较,考虑到区域设置。
当引入Unicode时,这些在 string
上运行的函数现在可以使用UTF-16数据。为了向后兼容,它们保留相同的名称,并以相同的方式表现。那就是 SameText
不考虑语言环境,但是 AnsiSameText
。
所以,虽然这些名字是误导性的,但是 Ansi
前缀只是表示该功能是区域设置的。对于什么是值得的,在我看来,即使在Unicode前的Delphi中, Ansi
前缀也很差。
语言环境重要的原因是不同的语言环境对字母顺序有不同的规则。
One would believe, looking at the name, that AnsiSameText defined in SysUtils (Delphi XE) will receive ANSI strings as parameters but the function is defined like this:
function AnsiSameText(const S1, S2: string): Boolean
What am I missing here?
There is an ANSI function in AnsiStrings unit, but still why is this one (in Sysutils) called 'ansi'?
In older versions of Delphi, pre-Unicode, there were two sets of string comparison functions:
SameText
,CompareText
, etc. These performed comparisons that ignore locale.AnsiSameText
,AnsiCompareText
, etc. These performed comparisons that took locale into account.
When Unicode was introduced, these functions, which operate on string
, now operate on UTF-16 data. For the sake of backwards compatibility, they retain the same names, and behave in the same way. That is SameText
does not account for locale, but AnsiSameText
does.
So, whilst the names are misleading, the Ansi
prefix simply indicates that the function is locale aware. For what it is worth, in my view the Ansi
prefix is poor even in pre-Unicode Delphi.
The reason that locale is important is that different locales have different rules for letter ordering.
这篇关于为什么AnsiSameText不是ANSI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!