JS_CompareStrings 编辑
Compare two JS strings.
Syntax
bool
JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2,
int32_t *result);
Name | Type | Description |
---|---|---|
cx | JSContext * | The context to which both strings must belong. |
str1 | JSString * | First string to compare. |
str2 | JSString * | Second string to compare. |
result | int32_t * | The out parameter. See description for value of *result . |
Description
JS_CompareStrings
compares two JS strings, str1
and str2
. If the strings are identical in content and length, JS_CompareStrings
stores 0
in *result
. If str1
is less than str2
, *result
is less than 0. If str1
is greater than str2
, *result
is greater than 0.
On success the function returns JS_TRUE
. On error, it returns JS_FALSE
and the value in result
is unchanged.
This function imposes a total order on all JavaScript strings, the same order imposed by the JavaScript string comparison operators (<
, <=
, >
, >=
), as described in ECMA 262-3 § 11.8.5. As the standard says:
The comparison of strings uses a simple lexicographic ordering on sequences of code point value values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode specification. Therefore strings that are canonically equal according to the Unicode standard could test as unequal.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论