implements wcsrchr from wchar.h

This commit is contained in:
emturner
2019-02-25 22:53:11 +00:00
parent f3ba7e8d8e
commit 4ed6dca61d
5 changed files with 39 additions and 4 deletions
+13 -3
View File
@@ -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]
+2 -1
View File
@@ -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=\
View File
View File
+24
View File
@@ -0,0 +1,24 @@
#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;
}