HDRS
integer_to_string.h
DEPENDS
+ libc.src.__support.CPP.span
libc.src.__support.CPP.string_view
libc.src.__support.CPP.type_traits
)
HDRS
span.h
DEPENDS
+ .array
.type_traits
)
HDRS
stringstream.h
DEPENDS
- .array_ref
+ .span
.string_view
libc.src.__support.integer_to_string
)
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_STRINGSTREAM_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_STRINGSTREAM_H
-#include "ArrayRef.h"
#include "StringView.h"
+#include "span.h"
#include "type_traits.h"
#include "src/__support/integer_to_string.h"
// without any dynamic memory allocation. There is no requirement to mimic the
// C++ standard library class std::stringstream.
class StringStream {
- MutableArrayRef<char> data;
+ span<char> data;
size_t write_ptr = 0; // The current write pointer
bool err = false; // If an error occurs while writing
static constexpr char ENDS = '\0';
// Create a string stream which will write into |buf|.
- constexpr StringStream(const MutableArrayRef<char> &buf) : data(buf) {}
+ constexpr StringStream(const span<char> &buf) : data(buf) {}
// Return a StringView to the current characters in the stream. If a
// null terminator was not explicitly written, then the return value
HDRS
dir.h
DEPENDS
- libc.src.__support.CPP.array_ref
+ libc.src.__support.CPP.span
libc.src.__support.threads.mutex
)
struct ::dirent *Dir::read() {
MutexLock lock(&mutex);
if (readptr >= fillsize) {
- fillsize = platform_fetch_dirents(
- fd, cpp::MutableArrayRef<uint8_t>(buffer, BUFSIZE));
+ fillsize = platform_fetch_dirents(fd, buffer);
if (fillsize == 0)
return nullptr;
readptr = 0;
#ifndef LLVM_LIBC_SRC_SUPPORT_FILE_DIR_H
#define LLVM_LIBC_SRC_SUPPORT_FILE_DIR_H
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/__support/threads/mutex.h"
#include <dirent.h>
// Platform specific function which will fetch dirents in to buffer.
// Returns the number of bytes written into buffer
-size_t platform_fetch_dirents(int fd, cpp::MutableArrayRef<uint8_t> buffer);
+size_t platform_fetch_dirents(int fd, cpp::span<uint8_t> buffer);
// This class is designed to allow implementation of the POSIX dirent.h API.
// By itself, it is platform independent but calls platform specific
return fd;
}
-size_t platform_fetch_dirents(int fd, cpp::MutableArrayRef<uint8_t> buffer) {
+size_t platform_fetch_dirents(int fd, cpp::span<uint8_t> buffer) {
long size =
__llvm_libc::syscall(SYS_getdents, fd, buffer.data(), buffer.size());
if (size < 0) {
#ifndef LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H
#define LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H
-#include "src/__support/CPP/ArrayRef.h"
#include "src/__support/CPP/StringView.h"
#include "src/__support/CPP/optional.h"
+#include "src/__support/CPP/span.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
// auto str = IntegerToString::convert<30>(a, b30buf);
class IntegerToString {
static cpp::StringView convert_uintmax(uintmax_t uval,
- cpp::MutableArrayRef<char> &buffer,
+ cpp::span<char> &buffer,
bool lowercase,
const uint8_t conv_base) {
const char a = lowercase ? 'a' : 'A';
return cpp::StringView(buffer.data() + buffer.size() - len, len);
}
- static cpp::StringView convert_intmax(intmax_t val,
- cpp::MutableArrayRef<char> &buffer,
+ static cpp::StringView convert_intmax(intmax_t val, cpp::span<char> &buffer,
bool lowercase,
const uint8_t conv_base) {
if (val >= 0)
template <uint8_t BASE, typename T,
cpp::enable_if_t<2 <= BASE && BASE <= 36 && cpp::is_integral_v<T>,
int> = 0>
- static cpp::optional<cpp::StringView>
- convert(T val, cpp::MutableArrayRef<char> buffer, bool lowercase = true) {
+ static cpp::optional<cpp::StringView> convert(T val, cpp::span<char> buffer,
+ bool lowercase = true) {
if (buffer.size() < bufsize<BASE, T>())
return cpp::optional<cpp::StringView>();
if (cpp::is_signed_v<T>)
}
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
- static cpp::optional<cpp::StringView> dec(T val,
- cpp::MutableArrayRef<char> buffer) {
+ static cpp::optional<cpp::StringView> dec(T val, cpp::span<char> buffer) {
return convert<10>(val, buffer);
}
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
- static cpp::optional<cpp::StringView>
- hex(T val, cpp::MutableArrayRef<char> buffer, bool lowercase = true) {
+ static cpp::optional<cpp::StringView> hex(T val, cpp::span<char> buffer,
+ bool lowercase = true) {
return convert<16>(val, buffer, lowercase);
}
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
- static cpp::optional<cpp::StringView> oct(T val,
- cpp::MutableArrayRef<char> buffer) {
+ static cpp::optional<cpp::StringView> oct(T val, cpp::span<char> buffer) {
return convert<8>(val, buffer);
}
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
- static cpp::optional<cpp::StringView> bin(T val,
- cpp::MutableArrayRef<char> buffer) {
+ static cpp::optional<cpp::StringView> bin(T val, cpp::span<char> buffer) {
return convert<2>(val, buffer);
}
};
pthread_setname_np.h
DEPENDS
libc.include.pthread
- libc.src.__support.CPP.array_ref
- libc.src.__support.CPP.string_view
+ libc.src.__support.CPP.span
+ libc.src.__support.CPP.stringstream
libc.src.__support.threads.thread
)
#include "pthread_getname_np.h"
-#include "src/__support/CPP/ArrayRef.h"
-#include "src/__support/CPP/StringView.h"
+#include "src/__support/CPP/span.h"
+#include "src/__support/CPP/stringstream.h"
#include "src/__support/common.h"
#include "src/__support/threads/thread.h"
LLVM_LIBC_FUNCTION(int, pthread_getname_np,
(pthread_t th, char *buf, size_t len)) {
auto *thread = reinterpret_cast<__llvm_libc::Thread *>(&th);
- cpp::MutableArrayRef<char> name_buf(buf, len);
+ cpp::span<char> name_buf(buf, len);
cpp::StringStream name_stream(name_buf);
return thread->get_name(name_stream);
}
DEPENDS
.writer
.core_structs
- libc.src.__support.integer_to_string
libc.src.__support.CPP.limits
+ libc.src.__support.CPP.span
libc.src.__support.CPP.string_view
libc.src.__support.FPUtil.fputil
+ libc.src.__support.integer_to_string
)
#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_INT_CONVERTER_H
#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_INT_CONVERTER_H
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/__support/CPP/StringView.h"
#include "src/__support/integer_to_string.h"
#include "src/stdio/printf_core/converter_utils.h"
constexpr bool inline is_lower(char a) { return (a & 32) > 0; }
cpp::optional<cpp::StringView> inline num_to_strview(
- uintmax_t num, cpp::MutableArrayRef<char> bufref, char conv_name) {
+ uintmax_t num, cpp::span<char> bufref, char conv_name) {
if (to_lower(conv_name) == 'x') {
return IntegerToString::hex(num, bufref, is_lower(conv_name));
} else if (conv_name == 'o') {
SRCS
stringstream_test.cpp
DEPENDS
- libc.src.__support.CPP.array_ref
+ libc.src.__support.CPP.span
libc.src.__support.CPP.stringstream
)
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/__support/CPP/stringstream.h"
#include "utils/UnitTest/Test.h"
-using __llvm_libc::cpp::MutableArrayRef;
+using __llvm_libc::cpp::span;
using __llvm_libc::cpp::StringStream;
TEST(LlvmLibcStringStreamTest, Simple) {
char buf[256];
- MutableArrayRef<char> bufref(reinterpret_cast<void *>(buf), 256);
- StringStream ss1(bufref);
+ StringStream ss1(buf);
ss1 << "Hello, Stream - " << int(123) << StringStream::ENDS;
ASSERT_FALSE(ss1.overflow());
ASSERT_STREQ(ss1.str().data(), "Hello, Stream - 123");
- StringStream ss2(bufref);
+ StringStream ss2(buf);
ss2 << 'a' << 'b' << 'c' << StringStream::ENDS;
ASSERT_FALSE(ss2.overflow());
ASSERT_STREQ(ss2.str().data(), "abc");
TEST(LlvmLibcStringStreamTest, Overflow) {
constexpr size_t BUFSIZE = 8;
char buf[BUFSIZE];
- MutableArrayRef<char> bufref(reinterpret_cast<void *>(buf), BUFSIZE);
- StringStream ss1(bufref);
+ StringStream ss1(buf);
ss1 << "Hello, Stream - " << int(123) << StringStream::ENDS;
ASSERT_TRUE(ss1.overflow());
ASSERT_EQ(ss1.str().size(), BUFSIZE);
- StringStream ss2(bufref);
+ StringStream ss2(buf);
ss2 << "7777777";
ASSERT_FALSE(ss2.overflow());
ASSERT_EQ(ss2.str().size(), size_t(7));
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/string/stpncpy.h"
#include "utils/UnitTest/Test.h"
#include <stddef.h> // For size_t.
class LlvmLibcStpncpyTest : public __llvm_libc::testing::Test {
public:
- void check_stpncpy(__llvm_libc::cpp::MutableArrayRef<char> dst,
- const __llvm_libc::cpp::ArrayRef<char> src, size_t n,
- const __llvm_libc::cpp::ArrayRef<char> expected,
+ void check_stpncpy(__llvm_libc::cpp::span<char> dst,
+ const __llvm_libc::cpp::span<const char> src, size_t n,
+ const __llvm_libc::cpp::span<const char> expected,
size_t expectedCopied) {
// Making sure we don't overflow buffer.
ASSERT_GE(dst.size(), n);