Commit 4ed6dca6 authored by Emma Turner's avatar Emma Turner

implements wcsrchr from wchar.h

parent f3ba7e8d
......@@ -430,9 +430,19 @@ pub extern "C" fn wcspbrk(ws1: *const wchar_t, ws2: *const wchar_t) -> *mut wcha
unimplemented!();
}
// #[no_mangle]
pub extern "C" fn wcsrchr(ws1: *const wchar_t, ws2: wchar_t) -> *mut wchar_t {
unimplemented!();
#[no_mangle]
pub unsafe extern "C" fn wcsrchr(ws1: *const wchar_t, wc: wchar_t) -> *mut wchar_t {
let mut last_matching_wc = 0 as *const wchar_t;
let mut i = 0;
while *ws1.add(i) != 0 {
if *ws1.add(i) == wc {
last_matching_wc = ws1.add(i);
}
i += 1;
}
last_matching_wc as *mut wchar_t
}
// #[no_mangle]
......
......@@ -87,7 +87,8 @@ EXPECT_BINS=\
wchar/mbsrtowcs \
wchar/putwchar \
wchar/wcrtomb \
wchar/wcscspn
wchar/wcscspn \
wchar/wcsrchr
# Binaries that may generate varied output
BINS=\
......
#include <assert.h>
#include <wchar.h>
int main() {
wchar_t *s;
assert(wcsrchr(L"", L'a') == NULL);
s = L"a";
assert(wcsrchr(s, L'a') == s);
s = L"aa";
assert(wcsrchr(s, L'a') == s + 1);
s = L"aab";
assert(wcsrchr(s, L'a') == s + 1);
s = L"abcdef!\"£$%^e&*";
assert(wcsrchr(s, L'g') == NULL);
assert(wcsrchr(s, L'\"') == s + 7);
assert(wcsrchr(s, L'e') == s + 12);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment