-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[libc] Add support for 'string.h' locale variants #105719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===-- Implementation of strcoll_l ---------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/string/strcoll_l.h" | ||
|
||
#include "src/__support/common.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
// TODO: Add support for locales. | ||
LLVM_LIBC_FUNCTION(int, strcoll_l, | ||
(const char *left, const char *right, locale_t)) { | ||
for (; *left && *left == *right; ++left, ++right) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add an assert to check that the locale passed is the default C locale? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we expose asserts in entrypoints? I'm unsure if people would prefer it be ignored or terminate their program. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fair, this is fine for now then. We should add something to the docs explaining that this is the behavior though. |
||
; | ||
return static_cast<int>(*left) - static_cast<int>(*right); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation header for strcoll_l ---------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_STRING_STRCOLL_L_H | ||
#define LLVM_LIBC_SRC_STRING_STRCOLL_L_H | ||
|
||
#include "include/llvm-libc-types/locale_t.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
int strcoll_l(const char *left, const char *right, locale_t locale); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_STRING_STRCOLL_L_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===-- Implementation of strxfrm_l ---------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/string/strxfrm_l.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/string/memory_utils/inline_memcpy.h" | ||
#include "src/string/string_utils.h" | ||
|
||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
// TODO: Add support for locales. | ||
LLVM_LIBC_FUNCTION(size_t, strxfrm_l, | ||
(char *__restrict dest, const char *__restrict src, size_t n, | ||
locale_t)) { | ||
size_t len = internal::string_length(src); | ||
if (n > len) | ||
inline_memcpy(dest, src, len + 1); | ||
return len; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===-- Implementation header for strxfrm_l ---------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_STRING_STRXFRM_L_H | ||
#define LLVM_LIBC_SRC_STRING_STRXFRM_L_H | ||
|
||
#include "include/llvm-libc-types/locale_t.h" | ||
#include "src/__support/macros/config.h" | ||
#include <stddef.h> // For size_t | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
size_t strxfrm_l(char *__restrict dest, const char *__restrict src, size_t n, | ||
locale_t locale); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_STRING_STRXFRM_L_H |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two functions are
POSIX
(2008), notstdc
.