Skip to content

Commit

Permalink
Merge #595
Browse files Browse the repository at this point in the history
595: Clean up `string_util` module r=msimberg a=aurianer

Part of #16 

Co-authored-by: aurianer <aurianer@cscs.ch>
  • Loading branch information
bors[bot] and aurianer authored Feb 14, 2023
2 parents 8273635 + 750ce6b commit 1250cbe
Show file tree
Hide file tree
Showing 29 changed files with 275 additions and 304 deletions.
4 changes: 2 additions & 2 deletions .inshpect.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ patterns = [
{ pattern = '\bstd::error_(code|condition|category)\b', include = 'system_error' },
{ pattern = '\bstd::system_error\b', include = 'system_error' },
{ pattern = '\bpika::intrusive_ptr\b', include = 'pika/memory/intrusive_ptr.hpp' },
{ pattern = '\bpika::util::from_string\b', include = 'pika/string_util/from_string.hpp' },
{ pattern = '\bpika::util::to_string\b', include = 'pika/string_util/to_string.hpp' },
{ pattern = '\bpika::detail::from_string\b', include = 'pika/string_util/from_string.hpp' },
{ pattern = '\bpika::detail::to_string\b', include = 'pika/string_util/to_string.hpp' },
{ pattern = '\bPIKA_PP_CAT\b', include = 'pika/preprocessor/cat.hpp' },
{ pattern = '\bPIKA_PP_EXPAND\b', include = 'pika/preprocessor/expand.hpp' },
{ pattern = '\bPIKA_PP_NARGS\b', include = 'pika/preprocessor/nargs.hpp' },
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/pipeline1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct pipeline
if (std::regex_match(item, regex))
{
auto trim = [](std::string const& s) {
return pika::string_util::trim_copy(s);
return pika::detail::trim_copy(s);
};

pika::async(trim, std::move(item))
Expand Down
7 changes: 4 additions & 3 deletions libs/pika/command_line_handling/src/command_line_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ namespace pika::detail {
}
else
{
default_threads = pika::util::from_string<std::size_t>(threads_str);
default_threads =
pika::detail::from_string<std::size_t>(threads_str);
}

std::size_t threads =
Expand All @@ -292,7 +293,7 @@ namespace pika::detail {
}
else
{
threads = pika::util::from_string<std::size_t>(threads_str);
threads = pika::detail::from_string<std::size_t>(threads_str);
}

if (threads == 0)
Expand Down Expand Up @@ -368,7 +369,7 @@ namespace pika::detail {
}
else
{
num_cores = pika::util::from_string<std::size_t>(cores_str);
num_cores = pika::detail::from_string<std::size_t>(cores_str);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace pika::detail {
if (vm.count("pika:print-bind"))
{
std::size_t num_threads =
pika::util::from_string<std::size_t>(
pika::detail::from_string<std::size_t>(
ini.get_entry("pika.os_threads", 1));
handle_print_bind(num_threads);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/pika/ini/include/pika/ini/ini.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ namespace pika::util {
std::string get_entry(std::string const& key, T dflt) const
{
std::unique_lock<mutex_type> l(mtx_);
return get_entry(l, key, pika::util::to_string(dflt));
return get_entry(l, key, pika::detail::to_string(dflt));
}

void add_notification_callback(
Expand Down
3 changes: 1 addition & 2 deletions libs/pika/ini/src/ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@ namespace pika::util {
using string_vector = std::vector<std::string>;

string_vector split_key;
pika::string_util::split(
split_key, key, pika::string_util::is_any_of("."));
pika::detail::split(split_key, key, pika::detail::is_any_of("."));

std::string sk = split_key.back();
split_key.pop_back();
Expand Down
4 changes: 2 additions & 2 deletions libs/pika/init_runtime/tests/unit/config_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ void test_get_entry()
{
std::string val = pika::get_config_entry("pika.localities", "42");
PIKA_TEST(!val.empty());
PIKA_TEST_EQ(pika::util::from_string<int>(val), 1);
PIKA_TEST_EQ(pika::detail::from_string<int>(val), 1);

val = pika::get_config_entry("pika.localities", 42);
PIKA_TEST(!val.empty());
PIKA_TEST_EQ(pika::util::from_string<int>(val), 1);
PIKA_TEST_EQ(pika::detail::from_string<int>(val), 1);
}

std::atomic<bool> invoked_callback(false);
Expand Down
4 changes: 2 additions & 2 deletions libs/pika/logging/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace pika::util {
{
try
{
int env_val = pika::util::from_string<int>(env);
int env_val = pika::detail::from_string<int>(env);
if (env_val < 0)
return pika::util::logging::level::disable_all;

Expand All @@ -62,7 +62,7 @@ namespace pika::util {
}
return pika::util::logging::level::debug;
}
catch (pika::util::bad_lexical_cast const&)
catch (pika::detail::bad_lexical_cast const&)
{
return pika::util::logging::level::disable_all;
}
Expand Down
6 changes: 3 additions & 3 deletions libs/pika/prefix/src/find_prefix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ namespace pika::util {
{
std::vector<std::string> path_dirs;

pika::string_util::split(path_dirs, epath,
pika::string_util::is_any_of(":"),
pika::string_util::token_compress_mode::on);
pika::detail::split(path_dirs, epath,
pika::detail::is_any_of(":"),
pika::detail::token_compress_mode::on);

for (std::uint64_t i = 0; i < path_dirs.size(); ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion libs/pika/program_options/examples/regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void validate(
std::smatch match;
if (regex_match(s, match, r))
{
v = std::any(magic_number(pika::util::from_string<int>(match[1])));
v = std::any(magic_number(pika::detail::from_string<int>(match[1])));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ namespace pika::program_options {
std::basic_string<Char> s(validators::get_single_string(xs));
try
{
v = std::any(pika::util::from_string<T>(s));
v = std::any(pika::detail::from_string<T>(s));
}
catch (const pika::util::bad_lexical_cast&)
catch (const pika::detail::bad_lexical_cast&)
{
throw invalid_option_value(s);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ namespace pika::program_options {
validate(a, cv, (T*) nullptr, 0);
tv->push_back(std::any_cast<T>(a));
}
catch (const pika::util::bad_lexical_cast& /*e*/)
catch (const pika::detail::bad_lexical_cast& /*e*/)
{
throw invalid_option_value(s[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace pika::program_options {
typed_value* default_value(const T& v)
{
m_default_value = std::any(v);
m_default_value_as_text = pika::util::to_string(v);
m_default_value_as_text = pika::detail::to_string(v);
return this;
}

Expand All @@ -234,7 +234,7 @@ namespace pika::program_options {
typed_value* implicit_value(const T& v)
{
m_implicit_value = std::any(v);
m_implicit_value_as_text = pika::util::to_string(v);
m_implicit_value_as_text = pika::detail::to_string(v);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/pika/resource_partitioner/src/detail_partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ namespace pika::resource::detail {
if (!default_scheduler_mode_str.empty())
{
default_scheduler_mode_ =
threads::scheduler_mode(pika::util::from_string<std::size_t>(
threads::scheduler_mode(pika::detail::from_string<std::size_t>(
default_scheduler_mode_str));
PIKA_ASSERT_MSG((default_scheduler_mode_ &
~threads::scheduler_mode::all_flags) ==
Expand Down
4 changes: 2 additions & 2 deletions libs/pika/runtime/src/custom_exception_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace pika {
// return a string holding a formatted message.
std::string diagnostic_information(pika::exception_info const& xi)
{
int const verbosity = util::from_string<int>(
int const verbosity = detail::from_string<int>(
get_config_entry("pika.exception_verbosity", "1"));

std::ostringstream strm;
Expand Down Expand Up @@ -377,7 +377,7 @@ namespace pika {
std::int64_t pid = ::getpid();

std::size_t const trace_depth =
util::from_string<std::size_t>(get_config_entry(
detail::from_string<std::size_t>(get_config_entry(
"pika.trace_depth", PIKA_HAVE_THREAD_BACKTRACE_DEPTH));

pika::debug::detail::backtrace bt(trace_depth);
Expand Down
8 changes: 4 additions & 4 deletions libs/pika/runtime/src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace pika {

if (get_config_entry("pika.diagnostics_on_terminate", "1") == "1")
{
int const verbosity = util::from_string<int>(
int const verbosity = detail::from_string<int>(
get_config_entry("pika.exception_verbosity", "1"));

if (verbosity >= 2)
Expand All @@ -89,7 +89,7 @@ namespace pika {
if (verbosity >= 1)
{
std::size_t const trace_depth =
util::from_string<std::size_t>(get_config_entry(
detail::from_string<std::size_t>(get_config_entry(
"pika.trace_depth", PIKA_HAVE_THREAD_BACKTRACE_DEPTH));
std::cerr << "{stack-trace}: "
<< pika::debug::detail::trace(trace_depth) << "\n";
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace pika {

if (get_config_entry("pika.diagnostics_on_terminate", "1") == "1")
{
int const verbosity = util::from_string<int>(
int const verbosity = detail::from_string<int>(
get_config_entry("pika.exception_verbosity", "1"));

char* reason = strsignal(signum);
Expand All @@ -164,7 +164,7 @@ namespace pika {
if (verbosity >= 1)
{
std::size_t const trace_depth =
util::from_string<std::size_t>(get_config_entry(
detail::from_string<std::size_t>(get_config_entry(
"pika.trace_depth", PIKA_HAVE_THREAD_BACKTRACE_DEPTH));
std::cerr << "{stack-trace}: "
<< pika::debug::detail::trace(trace_depth) << "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <pika/config/warnings_prefix.hpp>

namespace pika::util {
namespace pika::detail {
class PIKA_EXPORT bad_lexical_cast : public std::bad_cast
{
public:
Expand Down Expand Up @@ -50,19 +50,15 @@ namespace pika::util {
std::type_info const* target;
};

namespace detail {
[[noreturn]] PIKA_EXPORT void throw_bad_lexical_cast(
std::type_info const& source_type, std::type_info const& target_type);

[[noreturn]] PIKA_EXPORT void throw_bad_lexical_cast(
std::type_info const& source_type,
std::type_info const& target_type);

template <typename Source, typename Target>
[[noreturn]] inline Target throw_bad_lexical_cast()
{
detail::throw_bad_lexical_cast(typeid(Source), typeid(Target));
}
} // namespace detail
template <typename Source, typename Target>
[[noreturn]] inline Target throw_bad_lexical_cast()
{
throw_bad_lexical_cast(typeid(Source), typeid(Target));
}

} // namespace pika::util
} // namespace pika::detail

#include <pika/config/warnings_suffix.hpp>
4 changes: 2 additions & 2 deletions libs/pika/string_util/include/pika/string_util/case_conv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include <cctype>
#include <string>

namespace pika::string_util {
namespace pika::detail {
template <typename CharT, class Traits, class Alloc>
void to_lower(std::basic_string<CharT, Traits, Alloc>& s)
{
std::transform(std::begin(s), std::end(s), std::begin(s),
[](int c) { return std::tolower(c); });
}
} // namespace pika::string_util
} // namespace pika::detail
35 changes: 13 additions & 22 deletions libs/pika/string_util/include/pika/string_util/classification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,29 @@
#include <cctype>
#include <string>

namespace pika::string_util {
namespace detail {
template <typename CharT, typename Traits, typename Allocator>
struct is_any_of_pred
namespace pika::detail {
template <typename CharT, typename Traits, typename Allocator>
struct is_any_of_pred
{
bool operator()(int c) const noexcept
{
bool operator()(int c) const noexcept
{
return chars.find(c) != std::string::npos;
}
return chars.find(c) != std::string::npos;
}

std::basic_string<CharT, Traits, Allocator> chars;
};
} // namespace detail
std::basic_string<CharT, Traits, Allocator> chars;
};

template <typename CharT, typename Traits, typename Allocator>
detail::is_any_of_pred<CharT, Traits, Allocator>
is_any_of_pred<CharT, Traits, Allocator>
is_any_of(std::basic_string<CharT, Traits, Allocator> const& chars)
{
return detail::is_any_of_pred<CharT, Traits, Allocator>{chars};
return is_any_of_pred<CharT, Traits, Allocator>{chars};
}

inline auto is_any_of(char const* chars)
{
return detail::is_any_of_pred<char, std::char_traits<char>,
return is_any_of_pred<char, std::char_traits<char>,
std::allocator<char>>{std::string{chars}};
}

struct is_space
{
bool operator()(int c) const noexcept
{
return std::isspace(c);
}
};
} // namespace pika::string_util
} // namespace pika::detail
Loading

0 comments on commit 1250cbe

Please sign in to comment.