Why AnsiSameText is not ANSI?

后端 未结 1 791
夕颜
夕颜 2021-01-13 15:00

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:

相关标签:
1条回答
  • 2021-01-13 15:35

    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.

    0 讨论(0)
提交回复
热议问题