Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ set(ARROW_UTIL_SRCS
util/ree_util.cc
util/secure_string.cc
util/string.cc
util/string_builder.cc
util/string_util.cc
util/task_group.cc
util/tdigest.cc
util/thread_pool.cc
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/arrow/flight/transport/grpc/util_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "arrow/flight/types.h"
#include "arrow/status.h"
#include "arrow/util/string.h"
#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"

namespace arrow {

Expand Down Expand Up @@ -134,9 +134,10 @@ static TransportStatus TransportStatusFromGrpc(const ::grpc::Status& grpc_status
return TransportStatus{TransportStatusCode::kUnauthenticated,
grpc_status.error_message()};
default:
return TransportStatus{TransportStatusCode::kUnknown,
util::StringBuilder("(", grpc_status.error_code(), ")",
grpc_status.error_message())};
return TransportStatus{
TransportStatusCode::kUnknown,
arrow::internal::JoinToString("(", grpc_status.error_code(), ")",
grpc_status.error_message())};
}
}

Expand Down
12 changes: 6 additions & 6 deletions cpp/src/arrow/flight/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "arrow/util/formatting.h"
#include "arrow/util/logging.h"
#include "arrow/util/string.h"
#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"
#include "arrow/util/uri.h"

namespace arrow {
Expand Down Expand Up @@ -189,8 +189,8 @@ static std::ostream& operator<<(std::ostream& os, std::map<std::string, T> m) {
// Wrapper types for Flight RPC protobuf messages

std::string BasicAuth::ToString() const {
return arrow::util::StringBuilder("<BasicAuth username='", username,
"' password=(redacted)>");
return arrow::internal::JoinToString("<BasicAuth username='", username,
"' password=(redacted)>");
}

bool BasicAuth::Equals(const BasicAuth& other) const {
Expand Down Expand Up @@ -886,8 +886,8 @@ Status FlightPayload::Validate() const {
}

std::string ActionType::ToString() const {
return arrow::util::StringBuilder("<ActionType type='", type, "' description='",
description, "'>");
return arrow::internal::JoinToString("<ActionType type='", type, "' description='",
description, "'>");
}

const ActionType ActionType::kCancelFlightInfo =
Expand Down Expand Up @@ -930,7 +930,7 @@ arrow::Status ActionType::Deserialize(std::string_view serialized, ActionType* o
}

std::string Criteria::ToString() const {
return arrow::util::StringBuilder("<Criteria expression='", expression, "'>");
return arrow::internal::JoinToString("<Criteria expression='", expression, "'>");
}

bool Criteria::Equals(const Criteria& other) const {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ arrow_util_srcs = [
'util/mutex.cc',
'util/ree_util.cc',
'util/string.cc',
'util/string_builder.cc',
'util/string_util.cc',
'util/task_group.cc',
'util/tdigest.cc',
'util/thread_pool.cc',
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "arrow/util/compare.h"
#include "arrow/util/macros.h"
#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"
#include "arrow/util/visibility.h"

#ifdef ARROW_EXTRA_ERROR_CONTEXT
Expand Down Expand Up @@ -181,13 +181,13 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status

template <typename... Args>
static Status FromArgs(StatusCode code, Args&&... args) {
return Status(code, util::StringBuilder(std::forward<Args>(args)...));
return Status(code, internal::JoinToString(std::forward<Args>(args)...));
}

template <typename... Args>
static Status FromDetailAndArgs(StatusCode code, std::shared_ptr<StatusDetail> detail,
Args&&... args) {
return Status(code, util::StringBuilder(std::forward<Args>(args)...),
return Status(code, internal::JoinToString(std::forward<Args>(args)...),
std::move(detail));
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/testing/gtest_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "arrow/type_fwd.h"
#include "arrow/type_traits.h"
#include "arrow/util/macros.h"
#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"
#include "arrow/util/type_fwd.h"

// NOTE: failing must be inline in the macros below, to get correct file / line number
Expand Down Expand Up @@ -142,7 +142,7 @@
// A generalized version of GTest's SCOPED_TRACE that takes arbitrary arguments.
// ARROW_SCOPED_TRACE("some variable = ", some_variable, ...)

#define ARROW_SCOPED_TRACE(...) SCOPED_TRACE(::arrow::util::StringBuilder(__VA_ARGS__))
#define ARROW_SCOPED_TRACE(...) SCOPED_TRACE(::arrow::internal::JoinToString(__VA_ARGS__))

namespace arrow {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "arrow/util/endian.h"
#include "arrow/util/functional.h"
#include "arrow/util/span.h"
#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"
#include "arrow/util/visibility.h"

namespace arrow {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/bitset_stack_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "arrow/util/compare.h"
#include "arrow/util/functional.h"
#include "arrow/util/macros.h"
#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"
#include "arrow/util/type_traits.h"
#include "arrow/util/visibility.h"

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ install_headers(
'simd.h',
'small_vector.h',
'span.h',
'string_builder.h',
'string_util.h',
'string.h',
'task_group.h',
'test_common.h',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"

#include <memory>
#include <sstream>

namespace arrow {

namespace util {
namespace detail {
namespace internal {

StringStreamWrapper::StringStreamWrapper()
: sstream_(std::make_unique<std::ostringstream>()), ostream_(*sstream_) {}
Expand All @@ -32,6 +30,5 @@ StringStreamWrapper::~StringStreamWrapper() {}

std::string StringStreamWrapper::str() { return sstream_->str(); }

} // namespace detail
} // namespace util
} // namespace internal
} // namespace arrow
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
#include "arrow/util/visibility.h"

namespace arrow {
namespace util {

namespace detail {
namespace internal {

class ARROW_EXPORT StringStreamWrapper {
public:
Expand All @@ -43,31 +42,24 @@ class ARROW_EXPORT StringStreamWrapper {
std::ostream& ostream_;
};

} // namespace detail

template <typename Head>
void StringBuilderRecursive(std::ostream& stream, Head&& head) {
if constexpr (std::is_floating_point_v<std::decay_t<Head>>) {
// Avoid losing precision when printing floating point numbers
stream << std::to_string(head);
} else {
stream << head;
}
}

template <typename Head, typename... Tail>
void StringBuilderRecursive(std::ostream& stream, Head&& head, Tail&&... tail) {
StringBuilderRecursive(stream, std::forward<Head>(head));
StringBuilderRecursive(stream, std::forward<Tail>(tail)...);
}

template <typename... Args>
std::string StringBuilder(Args&&... args) {
detail::StringStreamWrapper ss;
StringBuilderRecursive(ss.stream(), std::forward<Args>(args)...);
std::string JoinToString(Args&&... args) {
StringStreamWrapper ss;
(
[&ss](auto&& arg) {
// Avoid losing precision when printing floating point numbers
if constexpr (std::is_floating_point_v<std::decay_t<decltype(arg)>>) {
ss.stream() << std::to_string(arg);
} else {
ss.stream() << arg;
}
}(std::forward<Args>(args)),
...);
return ss.str();
}
} // namespace internal

namespace util {
/// CRTP helper for declaring string representation. Defines operator<<
template <typename T>
class ToStringOstreamable {
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/parquet/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <utility>

#include "arrow/type_fwd.h"
#include "arrow/util/string_builder.h"
#include "arrow/util/string_util.h"
#include "parquet/platform.h"

// PARQUET-1085
Expand Down Expand Up @@ -100,7 +100,7 @@ class ParquetException : public std::exception {

template <typename... Args>
explicit ParquetException(Args&&... args)
: msg_(::arrow::util::StringBuilder(std::forward<Args>(args)...)) {}
: msg_(::arrow::internal::JoinToString(std::forward<Args>(args)...)) {}

explicit ParquetException(std::string msg) : msg_(std::move(msg)) {}

Expand Down
Loading