}
Args
-Args::from_string(const std::string& command)
+Args::from_string(std::string_view command)
{
Args args;
for (const std::string& word : Util::split_into_strings(command, " \t\r\n")) {
Args(Args&& other) noexcept;
static Args from_argv(int argc, const char* const* argv);
- static Args from_string(const std::string& command);
+ static Args from_string(std::string_view command);
static std::optional<Args>
from_atfile(const std::string& filename,
}
void
-AtomicFile::write(const std::string& data)
+AtomicFile::write(std::string_view data)
{
if (fwrite(data.data(), data.size(), 1, m_stream) != 1) {
throw core::Error(
FILE* stream();
- void write(const std::string& data);
+ void write(std::string_view data);
void write(nonstd::span<const uint8_t> data);
// Close the temporary file and rename it to the destination file. Note: The
}
std::optional<std::string>
-rewrite_source_paths(const Context& ctx, const std::string& file_content)
+rewrite_source_paths(const Context& ctx, std::string_view file_content)
{
ASSERT(!ctx.config.base_dir().empty());
std::string escape_filename(std::string_view filename);
-std::optional<std::string>
-rewrite_source_paths(const Context& ctx, const std::string& file_content);
+std::optional<std::string> rewrite_source_paths(const Context& ctx,
+ std::string_view file_content);
void make_paths_relative_in_output_dep(const Context& ctx);
}
uint64_t
-parse_duration(const std::string& duration)
+parse_duration(std::string_view duration)
{
uint64_t factor = 0;
char last_ch = duration.empty() ? '\0' : duration[duration.length() - 1];
}
void
-send_to_fd(const Context& ctx, const std::string& text, int fd)
+send_to_fd(const Context& ctx, std::string_view text, int fd)
{
- const std::string* text_to_send = &text;
+ std::string_view text_to_send = text;
std::string modified_text;
#ifdef _WIN32
if (ctx.args_info.strip_diagnostics_colors) {
try {
modified_text = strip_ansi_csi_seqs(text);
- text_to_send = &modified_text;
+ text_to_send = modified_text;
} catch (const core::Error&) {
// Ignore.
}
}
if (ctx.config.absolute_paths_in_stderr()) {
- modified_text = rewrite_stderr_to_absolute_paths(*text_to_send);
- text_to_send = &modified_text;
+ modified_text = rewrite_stderr_to_absolute_paths(text_to_send);
+ text_to_send = modified_text;
}
const auto result =
- util::write_fd(fd, text_to_send->data(), text_to_send->length());
+ util::write_fd(fd, text_to_send.data(), text_to_send.length());
if (!result) {
throw core::Error(FMT("Failed to write to {}: {}", fd, result.error()));
}
// Parse `duration`, an unsigned integer with d (days) or s (seconds) suffix,
// into seconds. Throws `core::Error` on error.
-uint64_t parse_duration(const std::string& duration);
+uint64_t parse_duration(std::string_view duration);
// Parse a "size value", i.e. a string that can end in k, M, G, T (10-based
// suffixes) or Ki, Mi, Gi, Ti (2-based suffixes). For backward compatibility, K
// sequences if `ctx.args_info.strip_diagnostics_colors` is true and rewriting
// paths to absolute if `ctx.config.absolute_paths_in_stderr` is true. Throws
// `core::Error` on error.
-void send_to_fd(const Context& ctx, const std::string& text, int fd);
+void send_to_fd(const Context& ctx, std::string_view text, int fd);
// Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
void set_cloexec_flag(int fd);
}
nonstd::expected<int64_t, std::string>
-parse_signed(const std::string& value,
+parse_signed(std::string_view value,
const std::optional<int64_t> min_value,
const std::optional<int64_t> max_value,
const std::string_view description)
}
nonstd::expected<mode_t, std::string>
-parse_umask(const std::string& value)
+parse_umask(std::string_view value)
{
return util::parse_unsigned(value, 0, 0777, "umask", 8);
}
nonstd::expected<uint64_t, std::string>
-parse_unsigned(const std::string& value,
+parse_unsigned(std::string_view value,
const std::optional<uint64_t> min_value,
const std::optional<uint64_t> max_value,
const std::string_view description,
// `max_value` default to min and max values of int64_t. `description` is
// included in the error message for range violations.
nonstd::expected<int64_t, std::string>
-parse_signed(const std::string& value,
+parse_signed(std::string_view value,
std::optional<int64_t> min_value = std::nullopt,
std::optional<int64_t> max_value = std::nullopt,
std::string_view description = "integer");
// Parse `value` (an octal integer).
-nonstd::expected<mode_t, std::string> parse_umask(const std::string& value);
+nonstd::expected<mode_t, std::string> parse_umask(std::string_view value);
// Parse a string into an unsigned integer.
//
// `min_value` and `max_value` default to min and max values of uint64_t.
// `description` is included in the error message for range violations.
nonstd::expected<uint64_t, std::string>
-parse_unsigned(const std::string& value,
+parse_unsigned(std::string_view value,
std::optional<uint64_t> min_value = std::nullopt,
std::optional<uint64_t> max_value = std::nullopt,
std::string_view description = "integer",