libcore: Make str_eq not break with coretest
This commit is contained in:
parent
1fcfee674a
commit
3078830934
1 changed files with 17 additions and 0 deletions
|
@ -713,6 +713,7 @@ Section: Comparing strings
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// Bytewise slice equality
|
/// Bytewise slice equality
|
||||||
|
#[cfg(notest)]
|
||||||
#[lang="str_eq"]
|
#[lang="str_eq"]
|
||||||
pure fn eq_slice(a: &str, b: &str) -> bool {
|
pure fn eq_slice(a: &str, b: &str) -> bool {
|
||||||
do as_buf(a) |ap, alen| {
|
do as_buf(a) |ap, alen| {
|
||||||
|
@ -729,6 +730,22 @@ pure fn eq_slice(a: &str, b: &str) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pure fn eq_slice(a: &str, b: &str) -> bool {
|
||||||
|
do as_buf(a) |ap, alen| {
|
||||||
|
do as_buf(b) |bp, blen| {
|
||||||
|
if (alen != blen) { false }
|
||||||
|
else {
|
||||||
|
unsafe {
|
||||||
|
libc::memcmp(ap as *libc::c_void,
|
||||||
|
bp as *libc::c_void,
|
||||||
|
(alen - 1) as libc::size_t) == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Bytewise string equality
|
/// Bytewise string equality
|
||||||
pure fn eq(a: &~str, b: &~str) -> bool {
|
pure fn eq(a: &~str, b: &~str) -> bool {
|
||||||
eq_slice(*a, *b)
|
eq_slice(*a, *b)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue