Remove ref from std::string_view (#215)
This commit is contained in:
parent
589e0e098b
commit
7a2bbd4bb3
@ -61,7 +61,9 @@ Checks: '*,
|
||||
-readability-magic-numbers,
|
||||
-readability-named-parameter,
|
||||
-misc-no-recursion,
|
||||
-concurrency-mt-unsafe'
|
||||
-concurrency-mt-unsafe,
|
||||
-bugprone-easily-swappable-parameters'
|
||||
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: 'src/.*'
|
||||
AnalyzeTemporaryDtors: false
|
||||
|
@ -170,7 +170,7 @@ enum class CsvParserState {
|
||||
EXPECT_DELIMITER,
|
||||
};
|
||||
|
||||
bool SubstringStartsWith(const std::string_view &str, size_t pos, const std::string_view &what) {
|
||||
bool SubstringStartsWith(const std::string_view str, size_t pos, const std::string_view what) {
|
||||
return memgraph::utils::StartsWith(memgraph::utils::Substr(str, pos), what);
|
||||
}
|
||||
|
||||
|
@ -310,11 +310,11 @@ class DbAccessor final {
|
||||
return std::make_optional<VertexAccessor>(*value);
|
||||
}
|
||||
|
||||
storage::PropertyId NameToProperty(const std::string_view &name) { return accessor_->NameToProperty(name); }
|
||||
storage::PropertyId NameToProperty(const std::string_view name) { return accessor_->NameToProperty(name); }
|
||||
|
||||
storage::LabelId NameToLabel(const std::string_view &name) { return accessor_->NameToLabel(name); }
|
||||
storage::LabelId NameToLabel(const std::string_view name) { return accessor_->NameToLabel(name); }
|
||||
|
||||
storage::EdgeTypeId NameToEdgeType(const std::string_view &name) { return accessor_->NameToEdgeType(name); }
|
||||
storage::EdgeTypeId NameToEdgeType(const std::string_view name) { return accessor_->NameToEdgeType(name); }
|
||||
|
||||
const std::string &PropertyToName(storage::PropertyId prop) const { return accessor_->PropertyToName(prop); }
|
||||
|
||||
|
@ -46,7 +46,7 @@ const char *kInternalPropertyId = "__mg_id__";
|
||||
const char *kInternalVertexLabel = "__mg_vertex__";
|
||||
|
||||
/// A helper function that escapes label, edge type and property names.
|
||||
std::string EscapeName(const std::string_view &value) {
|
||||
std::string EscapeName(const std::string_view value) {
|
||||
std::string out;
|
||||
out.reserve(value.size() + 2);
|
||||
out.append(1, '`');
|
||||
|
@ -716,7 +716,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
}
|
||||
|
||||
template <class TRecordAccessor>
|
||||
storage::PropertyValue GetProperty(const TRecordAccessor &record_accessor, const std::string_view &name) {
|
||||
storage::PropertyValue GetProperty(const TRecordAccessor &record_accessor, const std::string_view name) {
|
||||
auto maybe_prop = record_accessor.GetProperty(view_, dba_->NameToProperty(name));
|
||||
if (maybe_prop.HasError() && maybe_prop.GetError() == storage::Error::NONEXISTENT_OBJECT) {
|
||||
// This is a very nasty and temporary hack in order to make MERGE work.
|
||||
|
@ -3697,7 +3697,7 @@ std::unordered_map<std::string, int64_t> CallProcedure::GetAndResetCounters() {
|
||||
|
||||
namespace {
|
||||
|
||||
void CallCustomProcedure(const std::string_view &fully_qualified_procedure_name, const mgp_proc &proc,
|
||||
void CallCustomProcedure(const std::string_view fully_qualified_procedure_name, const mgp_proc &proc,
|
||||
const std::vector<Expression *> &args, mgp_graph &graph, ExpressionEvaluator *evaluator,
|
||||
utils::MemoryResource *memory, std::optional<size_t> memory_limit, mgp_result *result) {
|
||||
static_assert(std::uses_allocator_v<mgp_value, utils::Allocator<mgp_value>>,
|
||||
|
@ -1054,7 +1054,7 @@ std::unique_ptr<Module> LoadModuleFromFile(const std::filesystem::path &path) {
|
||||
|
||||
} // namespace
|
||||
|
||||
bool ModuleRegistry::RegisterModule(const std::string_view &name, std::unique_ptr<Module> module) {
|
||||
bool ModuleRegistry::RegisterModule(const std::string_view name, std::unique_ptr<Module> module) {
|
||||
MG_ASSERT(!name.empty(), "Module name cannot be empty");
|
||||
MG_ASSERT(module, "Tried to register an invalid module");
|
||||
if (modules_.find(name) != modules_.end()) {
|
||||
@ -1163,7 +1163,7 @@ void ModuleRegistry::UnloadAndLoadModulesFromDirectories() {
|
||||
}
|
||||
}
|
||||
|
||||
ModulePtr ModuleRegistry::GetModuleNamed(const std::string_view &name) const {
|
||||
ModulePtr ModuleRegistry::GetModuleNamed(const std::string_view name) const {
|
||||
std::shared_lock<utils::RWLock> guard(lock_);
|
||||
auto found_it = modules_.find(name);
|
||||
if (found_it == modules_.end()) return nullptr;
|
||||
|
@ -77,7 +77,7 @@ class ModuleRegistry final {
|
||||
mutable utils::RWLock lock_{utils::RWLock::Priority::WRITE};
|
||||
std::unique_ptr<utils::MemoryResource> shared_{std::make_unique<utils::ResourceWithOutOfMemoryException>()};
|
||||
|
||||
bool RegisterModule(const std::string_view &name, std::unique_ptr<Module> module);
|
||||
bool RegisterModule(std::string_view name, std::unique_ptr<Module> module);
|
||||
|
||||
void DoUnloadAllModules();
|
||||
|
||||
@ -105,7 +105,7 @@ class ModuleRegistry final {
|
||||
///
|
||||
/// Return true if the module was loaded or reloaded successfully, false
|
||||
/// otherwise.
|
||||
bool LoadOrReloadModuleFromName(const std::string_view name);
|
||||
bool LoadOrReloadModuleFromName(std::string_view name);
|
||||
|
||||
/// Atomically unload all modules and then load all possible modules from the
|
||||
/// set directories.
|
||||
@ -115,7 +115,7 @@ class ModuleRegistry final {
|
||||
|
||||
/// Find a module with given name or return nullptr.
|
||||
/// Takes a read lock.
|
||||
ModulePtr GetModuleNamed(const std::string_view &name) const;
|
||||
ModulePtr GetModuleNamed(std::string_view name) const;
|
||||
|
||||
/// Remove all loaded (non-builtin) modules.
|
||||
/// Takes a write lock.
|
||||
@ -175,7 +175,7 @@ extern ModuleRegistry gModuleRegistry;
|
||||
/// inside this function. ModulePtr must be kept alive to make sure it won't be
|
||||
/// unloaded.
|
||||
std::optional<std::pair<procedure::ModulePtr, const mgp_proc *>> FindProcedure(
|
||||
const ModuleRegistry &module_registry, const std::string_view fully_qualified_procedure_name,
|
||||
const ModuleRegistry &module_registry, std::string_view fully_qualified_procedure_name,
|
||||
utils::MemoryResource *memory);
|
||||
|
||||
/// Return the ModulePtr and `mgp_trans *` of the found transformation after resolving
|
||||
@ -183,7 +183,7 @@ std::optional<std::pair<procedure::ModulePtr, const mgp_proc *>> FindProcedure(
|
||||
/// inside this function. ModulePtr must be kept alive to make sure it won't be
|
||||
/// unloaded.
|
||||
std::optional<std::pair<procedure::ModulePtr, const mgp_trans *>> FindTransformation(
|
||||
const ModuleRegistry &module_registry, const std::string_view fully_qualified_transformation_name,
|
||||
const ModuleRegistry &module_registry, std::string_view fully_qualified_transformation_name,
|
||||
utils::MemoryResource *memory);
|
||||
|
||||
/// Return the ModulePtr and `mgp_func *` of the found function after resolving
|
||||
@ -191,7 +191,7 @@ std::optional<std::pair<procedure::ModulePtr, const mgp_trans *>> FindTransforma
|
||||
/// std::nullopt is returned. `memory` is used for temporary allocations
|
||||
/// inside this function. ModulePtr must be kept alive to make sure it won't be unloaded.
|
||||
std::optional<std::pair<procedure::ModulePtr, const mgp_func *>> FindFunction(
|
||||
const ModuleRegistry &module_registry, const std::string_view fully_qualified_function_name,
|
||||
const ModuleRegistry &module_registry, std::string_view fully_qualified_function_name,
|
||||
utils::MemoryResource *memory);
|
||||
|
||||
template <typename T>
|
||||
|
@ -407,7 +407,7 @@ DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(int, Int, int_v)
|
||||
DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(bool, Bool, bool_v)
|
||||
DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(int64_t, Int, int_v)
|
||||
DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(double, Double, double_v)
|
||||
DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(const std::string_view &, String, string_v)
|
||||
DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(const std::string_view, String, string_v)
|
||||
DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(const TypedValue::TVector &, List, list_v)
|
||||
|
||||
TypedValue &TypedValue::operator=(const std::vector<TypedValue> &other) {
|
||||
|
@ -185,7 +185,7 @@ class TypedValue {
|
||||
new (&string_v) TString(value, memory_);
|
||||
}
|
||||
|
||||
explicit TypedValue(const std::string_view &value, utils::MemoryResource *memory = utils::NewDeleteResource())
|
||||
explicit TypedValue(const std::string_view value, utils::MemoryResource *memory = utils::NewDeleteResource())
|
||||
: memory_(memory), type_(Type::String) {
|
||||
new (&string_v) TString(value, memory_);
|
||||
}
|
||||
@ -420,7 +420,7 @@ class TypedValue {
|
||||
TypedValue &operator=(bool);
|
||||
TypedValue &operator=(int64_t);
|
||||
TypedValue &operator=(double);
|
||||
TypedValue &operator=(const std::string_view &);
|
||||
TypedValue &operator=(std::string_view);
|
||||
TypedValue &operator=(const TVector &);
|
||||
TypedValue &operator=(const std::vector<TypedValue> &);
|
||||
TypedValue &operator=(const TMap &);
|
||||
|
@ -166,7 +166,7 @@ inline void Save(const char *obj, Builder *builder) {
|
||||
builder->Save(reinterpret_cast<const uint8_t *>(obj), size);
|
||||
}
|
||||
|
||||
inline void Save(const std::string_view &obj, Builder *builder) {
|
||||
inline void Save(const std::string_view obj, Builder *builder) {
|
||||
uint64_t size = obj.size();
|
||||
Save(size, builder);
|
||||
builder->Save(reinterpret_cast<const uint8_t *>(obj.data()), size);
|
||||
|
@ -27,7 +27,7 @@ void WriteSize(Encoder *encoder, uint64_t size) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Encoder::Initialize(const std::filesystem::path &path, const std::string_view &magic, uint64_t version) {
|
||||
void Encoder::Initialize(const std::filesystem::path &path, const std::string_view magic, uint64_t version) {
|
||||
file_.Open(path, utils::OutputFile::Mode::OVERWRITE_EXISTING);
|
||||
Write(reinterpret_cast<const uint8_t *>(magic.data()), magic.size());
|
||||
auto version_encoded = utils::HostToLittleEndian(version);
|
||||
@ -73,7 +73,7 @@ void Encoder::WriteDouble(double value) {
|
||||
Write(reinterpret_cast<const uint8_t *>(&value_uint), sizeof(value_uint));
|
||||
}
|
||||
|
||||
void Encoder::WriteString(const std::string_view &value) {
|
||||
void Encoder::WriteString(const std::string_view value) {
|
||||
WriteMarker(Marker::TYPE_STRING);
|
||||
WriteSize(this, value.size());
|
||||
Write(reinterpret_cast<const uint8_t *>(value.data()), value.size());
|
||||
|
@ -34,14 +34,14 @@ class BaseEncoder {
|
||||
virtual void WriteBool(bool value) = 0;
|
||||
virtual void WriteUint(uint64_t value) = 0;
|
||||
virtual void WriteDouble(double value) = 0;
|
||||
virtual void WriteString(const std::string_view &value) = 0;
|
||||
virtual void WriteString(std::string_view value) = 0;
|
||||
virtual void WritePropertyValue(const PropertyValue &value) = 0;
|
||||
};
|
||||
|
||||
/// Encoder that is used to generate a snapshot/WAL.
|
||||
class Encoder final : public BaseEncoder {
|
||||
public:
|
||||
void Initialize(const std::filesystem::path &path, const std::string_view &magic, uint64_t version);
|
||||
void Initialize(const std::filesystem::path &path, std::string_view magic, uint64_t version);
|
||||
|
||||
void OpenExisting(const std::filesystem::path &path);
|
||||
|
||||
@ -54,7 +54,7 @@ class Encoder final : public BaseEncoder {
|
||||
void WriteBool(bool value) override;
|
||||
void WriteUint(uint64_t value) override;
|
||||
void WriteDouble(double value) override;
|
||||
void WriteString(const std::string_view &value) override;
|
||||
void WriteString(std::string_view value) override;
|
||||
void WritePropertyValue(const PropertyValue &value) override;
|
||||
|
||||
uint64_t GetPosition();
|
||||
|
@ -29,8 +29,8 @@ class NameIdMapper final {
|
||||
bool operator<(const MapNameToId &other) { return name < other.name; }
|
||||
bool operator==(const MapNameToId &other) { return name == other.name; }
|
||||
|
||||
bool operator<(const std::string_view &other) { return name < other; }
|
||||
bool operator==(const std::string_view &other) { return name == other; }
|
||||
bool operator<(const std::string_view other) const { return name < other; }
|
||||
bool operator==(const std::string_view other) const { return name == other; }
|
||||
};
|
||||
|
||||
struct MapIdToName {
|
||||
@ -46,7 +46,7 @@ class NameIdMapper final {
|
||||
|
||||
public:
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
uint64_t NameToId(const std::string_view &name) {
|
||||
uint64_t NameToId(const std::string_view name) {
|
||||
auto name_to_id_acc = name_to_id_.access();
|
||||
auto found = name_to_id_acc.find(name);
|
||||
uint64_t id;
|
||||
|
@ -30,7 +30,7 @@ void Encoder::WriteDouble(double value) {
|
||||
slk::Save(value, builder_);
|
||||
}
|
||||
|
||||
void Encoder::WriteString(const std::string_view &value) {
|
||||
void Encoder::WriteString(const std::string_view value) {
|
||||
WriteMarker(durability::Marker::TYPE_STRING);
|
||||
slk::Save(value, builder_);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class Encoder final : public durability::BaseEncoder {
|
||||
|
||||
void WriteDouble(double value) override;
|
||||
|
||||
void WriteString(const std::string_view &value) override;
|
||||
void WriteString(std::string_view value) override;
|
||||
|
||||
void WritePropertyValue(const PropertyValue &value) override;
|
||||
|
||||
|
@ -812,11 +812,11 @@ const std::string &Storage::Accessor::EdgeTypeToName(EdgeTypeId edge_type) const
|
||||
return storage_->EdgeTypeToName(edge_type);
|
||||
}
|
||||
|
||||
LabelId Storage::Accessor::NameToLabel(const std::string_view &name) { return storage_->NameToLabel(name); }
|
||||
LabelId Storage::Accessor::NameToLabel(const std::string_view name) { return storage_->NameToLabel(name); }
|
||||
|
||||
PropertyId Storage::Accessor::NameToProperty(const std::string_view &name) { return storage_->NameToProperty(name); }
|
||||
PropertyId Storage::Accessor::NameToProperty(const std::string_view name) { return storage_->NameToProperty(name); }
|
||||
|
||||
EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string_view &name) { return storage_->NameToEdgeType(name); }
|
||||
EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string_view name) { return storage_->NameToEdgeType(name); }
|
||||
|
||||
void Storage::Accessor::AdvanceCommand() { ++transaction_.command_id; }
|
||||
|
||||
@ -1121,13 +1121,13 @@ const std::string &Storage::EdgeTypeToName(EdgeTypeId edge_type) const {
|
||||
return name_id_mapper_.IdToName(edge_type.AsUint());
|
||||
}
|
||||
|
||||
LabelId Storage::NameToLabel(const std::string_view &name) { return LabelId::FromUint(name_id_mapper_.NameToId(name)); }
|
||||
LabelId Storage::NameToLabel(const std::string_view name) { return LabelId::FromUint(name_id_mapper_.NameToId(name)); }
|
||||
|
||||
PropertyId Storage::NameToProperty(const std::string_view &name) {
|
||||
PropertyId Storage::NameToProperty(const std::string_view name) {
|
||||
return PropertyId::FromUint(name_id_mapper_.NameToId(name));
|
||||
}
|
||||
|
||||
EdgeTypeId Storage::NameToEdgeType(const std::string_view &name) {
|
||||
EdgeTypeId Storage::NameToEdgeType(const std::string_view name) {
|
||||
return EdgeTypeId::FromUint(name_id_mapper_.NameToId(name));
|
||||
}
|
||||
|
||||
|
@ -283,13 +283,13 @@ class Storage final {
|
||||
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const;
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
LabelId NameToLabel(const std::string_view &name);
|
||||
LabelId NameToLabel(std::string_view name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
PropertyId NameToProperty(const std::string_view &name);
|
||||
PropertyId NameToProperty(std::string_view name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
EdgeTypeId NameToEdgeType(const std::string_view &name);
|
||||
EdgeTypeId NameToEdgeType(std::string_view name);
|
||||
|
||||
bool LabelIndexExists(LabelId label) const { return storage_->indices_.label_index.IndexExists(label); }
|
||||
|
||||
@ -343,13 +343,13 @@ class Storage final {
|
||||
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const;
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
LabelId NameToLabel(const std::string_view &name);
|
||||
LabelId NameToLabel(std::string_view name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
PropertyId NameToProperty(const std::string_view &name);
|
||||
PropertyId NameToProperty(std::string_view name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
EdgeTypeId NameToEdgeType(const std::string_view &name);
|
||||
EdgeTypeId NameToEdgeType(std::string_view name);
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
bool CreateIndex(LabelId label, std::optional<uint64_t> desired_commit_timestamp = {});
|
||||
|
@ -370,7 +370,7 @@ void OutputFile::Write(const uint8_t *data, size_t size) {
|
||||
}
|
||||
|
||||
void OutputFile::Write(const char *data, size_t size) { Write(reinterpret_cast<const uint8_t *>(data), size); }
|
||||
void OutputFile::Write(const std::string_view &data) { Write(data.data(), data.size()); }
|
||||
void OutputFile::Write(const std::string_view data) { Write(data.data(), data.size()); }
|
||||
|
||||
size_t OutputFile::SeekFile(const Position position, const ssize_t offset) {
|
||||
int whence;
|
||||
|
@ -209,7 +209,7 @@ class OutputFile {
|
||||
/// the program.
|
||||
void Write(const uint8_t *data, size_t size);
|
||||
void Write(const char *data, size_t size);
|
||||
void Write(const std::string_view &data);
|
||||
void Write(std::string_view data);
|
||||
|
||||
/// This method gets the current absolute position in the file. On failure and
|
||||
/// misuse it crashes the program.
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
namespace memgraph::utils {
|
||||
|
||||
inline uint64_t Fnv(const std::string_view &s) {
|
||||
inline uint64_t Fnv(const std::string_view s) {
|
||||
// fnv1a is recommended so use it as the default implementation.
|
||||
uint64_t hash = 14695981039346656037UL;
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
namespace memgraph::utils {
|
||||
|
||||
/** Remove whitespace characters from the start of a string. */
|
||||
inline std::string_view LTrim(const std::string_view &s) {
|
||||
inline std::string_view LTrim(const std::string_view s) {
|
||||
size_t start = 0;
|
||||
while (start < s.size() && isspace(s[start])) {
|
||||
++start;
|
||||
@ -38,7 +38,7 @@ inline std::string_view LTrim(const std::string_view &s) {
|
||||
}
|
||||
|
||||
/** Remove characters found in `chars` from the start of a string. */
|
||||
inline std::string_view LTrim(const std::string_view &s, const std::string_view &chars) {
|
||||
inline std::string_view LTrim(const std::string_view s, const std::string_view chars) {
|
||||
size_t start = 0;
|
||||
while (start < s.size() && chars.find(s[start]) != std::string::npos) {
|
||||
++start;
|
||||
@ -47,7 +47,7 @@ inline std::string_view LTrim(const std::string_view &s, const std::string_view
|
||||
}
|
||||
|
||||
/** Remove whitespace characters from the end of a string. */
|
||||
inline std::string_view RTrim(const std::string_view &s) {
|
||||
inline std::string_view RTrim(const std::string_view s) {
|
||||
size_t count = s.size();
|
||||
while (count > static_cast<size_t>(0) && isspace(s[count - 1])) {
|
||||
--count;
|
||||
@ -56,7 +56,7 @@ inline std::string_view RTrim(const std::string_view &s) {
|
||||
}
|
||||
|
||||
/** Remove characters found in `chars` from the end of a string. */
|
||||
inline std::string_view RTrim(const std::string_view &s, const std::string_view &chars) {
|
||||
inline std::string_view RTrim(const std::string_view s, const std::string_view chars) {
|
||||
size_t count = s.size();
|
||||
while (count > static_cast<size_t>(0) && chars.find(s[count - 1]) != std::string::npos) {
|
||||
--count;
|
||||
@ -65,7 +65,7 @@ inline std::string_view RTrim(const std::string_view &s, const std::string_view
|
||||
}
|
||||
|
||||
/** Remove whitespace characters from the start and from the end of a string. */
|
||||
inline std::string_view Trim(const std::string_view &s) {
|
||||
inline std::string_view Trim(const std::string_view s) {
|
||||
size_t start = 0;
|
||||
size_t count = s.size();
|
||||
while (start < s.size() && isspace(s[start])) {
|
||||
@ -78,7 +78,7 @@ inline std::string_view Trim(const std::string_view &s) {
|
||||
}
|
||||
|
||||
/** Remove characters found in `chars` from the start and the end of `s`. */
|
||||
inline std::string_view Trim(const std::string_view &s, const std::string_view &chars) {
|
||||
inline std::string_view Trim(const std::string_view s, const std::string_view chars) {
|
||||
size_t start = 0;
|
||||
size_t count = s.size();
|
||||
while (start < s.size() && chars.find(s[start]) != std::string::npos) {
|
||||
@ -97,7 +97,7 @@ inline std::string_view Trim(const std::string_view &s, const std::string_view &
|
||||
*/
|
||||
template <class TAllocator>
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *ToLowerCase(
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view &s) {
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view s) {
|
||||
out->resize(s.size());
|
||||
std::transform(s.begin(), s.end(), out->begin(), [](char c) { return tolower(c); });
|
||||
return out;
|
||||
@ -107,7 +107,7 @@ std::basic_string<char, std::char_traits<char>, TAllocator> *ToLowerCase(
|
||||
* Lowercase all characters of a string.
|
||||
* Transformation is locale independent.
|
||||
*/
|
||||
inline std::string ToLowerCase(const std::string_view &s) {
|
||||
inline std::string ToLowerCase(const std::string_view s) {
|
||||
std::string res;
|
||||
ToLowerCase(&res, s);
|
||||
return res;
|
||||
@ -120,7 +120,7 @@ inline std::string ToLowerCase(const std::string_view &s) {
|
||||
*/
|
||||
template <class TAllocator>
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *ToUpperCase(
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view &s) {
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view s) {
|
||||
out->resize(s.size());
|
||||
std::transform(s.begin(), s.end(), out->begin(), [](char c) { return toupper(c); });
|
||||
return out;
|
||||
@ -130,7 +130,7 @@ std::basic_string<char, std::char_traits<char>, TAllocator> *ToUpperCase(
|
||||
* Uppercase all characters of a string and store the result in `out`.
|
||||
* Transformation is locale independent.
|
||||
*/
|
||||
inline std::string ToUpperCase(const std::string_view &s) {
|
||||
inline std::string ToUpperCase(const std::string_view s) {
|
||||
std::string res;
|
||||
ToUpperCase(&res, s);
|
||||
return res;
|
||||
@ -143,7 +143,7 @@ inline std::string ToUpperCase(const std::string_view &s) {
|
||||
template <class TCollection, class TAllocator>
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *Join(
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const TCollection &strings,
|
||||
const std::string_view &separator) {
|
||||
const std::string_view separator) {
|
||||
out->clear();
|
||||
if (strings.empty()) return out;
|
||||
int64_t total_size = 0;
|
||||
@ -163,7 +163,7 @@ std::basic_string<char, std::char_traits<char>, TAllocator> *Join(
|
||||
/**
|
||||
* Join the `strings` collection separated by a given separator.
|
||||
*/
|
||||
inline std::string Join(const std::vector<std::string> &strings, const std::string_view &separator) {
|
||||
inline std::string Join(const std::vector<std::string> &strings, const std::string_view separator) {
|
||||
std::string res;
|
||||
Join(&res, strings, separator);
|
||||
return res;
|
||||
@ -175,8 +175,8 @@ inline std::string Join(const std::vector<std::string> &strings, const std::stri
|
||||
*/
|
||||
template <class TAllocator>
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *Replace(
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view &src,
|
||||
const std::string_view &match, const std::string_view &replacement) {
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view src,
|
||||
const std::string_view match, const std::string_view replacement) {
|
||||
// TODO: This could be implemented much more efficiently.
|
||||
*out = src;
|
||||
for (size_t pos = out->find(match); pos != std::string::npos; pos = out->find(match, pos + replacement.size())) {
|
||||
@ -186,8 +186,8 @@ std::basic_string<char, std::char_traits<char>, TAllocator> *Replace(
|
||||
}
|
||||
|
||||
/** Replace all occurrences of `match` in `src` with `replacement`. */
|
||||
inline std::string Replace(const std::string_view &src, const std::string_view &match,
|
||||
const std::string_view &replacement) {
|
||||
inline std::string Replace(const std::string_view src, const std::string_view match,
|
||||
const std::string_view replacement) {
|
||||
std::string res;
|
||||
Replace(&res, src, match, replacement);
|
||||
return res;
|
||||
@ -200,8 +200,8 @@ inline std::string Replace(const std::string_view &src, const std::string_view &
|
||||
* @return pointer to `out`.
|
||||
*/
|
||||
template <class TString, class TAllocator>
|
||||
std::vector<TString, TAllocator> *Split(std::vector<TString, TAllocator> *out, const std::string_view &src,
|
||||
const std::string_view &delimiter, int splits = -1) {
|
||||
std::vector<TString, TAllocator> *Split(std::vector<TString, TAllocator> *out, const std::string_view src,
|
||||
const std::string_view delimiter, int splits = -1) {
|
||||
out->clear();
|
||||
if (src.empty()) return out;
|
||||
size_t index = 0;
|
||||
@ -220,7 +220,7 @@ std::vector<TString, TAllocator> *Split(std::vector<TString, TAllocator> *out, c
|
||||
* The vector will have at most `splits` + 1 elements. Negative value of
|
||||
* `splits` indicates to perform all possible splits.
|
||||
*/
|
||||
inline std::vector<std::string> Split(const std::string_view &src, const std::string_view &delimiter, int splits = -1) {
|
||||
inline std::vector<std::string> Split(const std::string_view src, const std::string_view delimiter, int splits = -1) {
|
||||
std::vector<std::string> res;
|
||||
Split(&res, src, delimiter, splits);
|
||||
return res;
|
||||
@ -234,7 +234,7 @@ inline std::vector<std::string> Split(const std::string_view &src, const std::st
|
||||
* @return pointer to `out`.
|
||||
*/
|
||||
template <class TString, class TAllocator>
|
||||
std::vector<TString, TAllocator> *Split(std::vector<TString, TAllocator> *out, const std::string_view &src) {
|
||||
std::vector<TString, TAllocator> *Split(std::vector<TString, TAllocator> *out, const std::string_view src) {
|
||||
out->clear();
|
||||
if (src.empty()) return out;
|
||||
// TODO: Investigate how much regex allocate and perhaps replace with custom
|
||||
@ -256,7 +256,7 @@ std::vector<TString, TAllocator> *Split(std::vector<TString, TAllocator> *out, c
|
||||
* Additionally, the result will not contain empty strings at the start or end
|
||||
* as if the string was trimmed before splitting.
|
||||
*/
|
||||
inline std::vector<std::string> Split(const std::string_view &src) {
|
||||
inline std::vector<std::string> Split(const std::string_view src) {
|
||||
std::vector<std::string> res;
|
||||
Split(&res, src);
|
||||
return res;
|
||||
@ -271,8 +271,8 @@ inline std::vector<std::string> Split(const std::string_view &src) {
|
||||
* @return pointer to `out`.
|
||||
*/
|
||||
template <class TString, class TAllocator>
|
||||
std::vector<TString, TAllocator> *RSplit(std::vector<TString, TAllocator> *out, const std::string_view &src,
|
||||
const std::string_view &delimiter, int splits = -1) {
|
||||
std::vector<TString, TAllocator> *RSplit(std::vector<TString, TAllocator> *out, const std::string_view src,
|
||||
const std::string_view delimiter, int splits = -1) {
|
||||
out->clear();
|
||||
if (src.empty()) return out;
|
||||
size_t index = src.size();
|
||||
@ -295,8 +295,7 @@ std::vector<TString, TAllocator> *RSplit(std::vector<TString, TAllocator> *out,
|
||||
* have at most `splits` + 1 elements. Negative value of `splits` indicates to
|
||||
* perform all possible splits.
|
||||
*/
|
||||
inline std::vector<std::string> RSplit(const std::string_view &src, const std::string_view &delimiter,
|
||||
int splits = -1) {
|
||||
inline std::vector<std::string> RSplit(const std::string_view src, const std::string_view delimiter, int splits = -1) {
|
||||
std::vector<std::string> res;
|
||||
RSplit(&res, src, delimiter, splits);
|
||||
return res;
|
||||
@ -309,7 +308,7 @@ inline std::vector<std::string> RSplit(const std::string_view &src, const std::s
|
||||
*
|
||||
* @throw BasicException if unable to parse the whole string.
|
||||
*/
|
||||
inline int64_t ParseInt(const std::string_view &s) {
|
||||
inline int64_t ParseInt(const std::string_view s) {
|
||||
// stol would be nicer but it uses current locale so we shouldn't use it.
|
||||
int64_t t = 0;
|
||||
// NOTE: Constructing std::istringstream will make a copy of the string, which
|
||||
@ -336,7 +335,7 @@ inline int64_t ParseInt(const std::string_view &s) {
|
||||
*
|
||||
* @throw BasicException if unable to parse the whole string.
|
||||
*/
|
||||
inline double ParseDouble(const std::string_view &s) {
|
||||
inline double ParseDouble(const std::string_view s) {
|
||||
// stod would be nicer but it uses current locale so we shouldn't use it.
|
||||
double t = 0.0;
|
||||
// NOTE: Constructing std::istringstream will make a copy of the string, which
|
||||
@ -357,17 +356,17 @@ inline double ParseDouble(const std::string_view &s) {
|
||||
}
|
||||
|
||||
/** Check if the given string `s` ends with the given `suffix`. */
|
||||
inline bool EndsWith(const std::string_view &s, const std::string_view &suffix) {
|
||||
inline bool EndsWith(const std::string_view s, const std::string_view suffix) {
|
||||
return s.size() >= suffix.size() && s.compare(s.size() - suffix.size(), std::string::npos, suffix) == 0;
|
||||
}
|
||||
|
||||
/** Check if the given string `s` starts with the given `prefix`. */
|
||||
inline bool StartsWith(const std::string_view &s, const std::string_view &prefix) {
|
||||
inline bool StartsWith(const std::string_view s, const std::string_view prefix) {
|
||||
return s.size() >= prefix.size() && s.compare(0, prefix.size(), prefix) == 0;
|
||||
}
|
||||
|
||||
/** Perform case-insensitive string equality test. */
|
||||
inline bool IEquals(const std::string_view &lhs, const std::string_view &rhs) {
|
||||
inline bool IEquals(const std::string_view lhs, const std::string_view rhs) {
|
||||
if (lhs.size() != rhs.size()) return false;
|
||||
for (size_t i = 0; i < lhs.size(); ++i) {
|
||||
if (tolower(lhs[i]) != tolower(rhs[i])) return false;
|
||||
@ -406,7 +405,7 @@ inline std::string RandomString(size_t length) {
|
||||
*/
|
||||
template <class TAllocator>
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *Escape(
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view &src) {
|
||||
std::basic_string<char, std::char_traits<char>, TAllocator> *out, const std::string_view src) {
|
||||
out->clear();
|
||||
out->reserve(src.size() + 2);
|
||||
out->append(1, '"');
|
||||
@ -433,7 +432,7 @@ std::basic_string<char, std::char_traits<char>, TAllocator> *Escape(
|
||||
}
|
||||
|
||||
/** Escape all whitespace and quotation characters in the given string. */
|
||||
inline std::string Escape(const std::string_view &src) {
|
||||
inline std::string Escape(const std::string_view src) {
|
||||
std::string res;
|
||||
Escape(&res, src);
|
||||
return res;
|
||||
@ -445,7 +444,7 @@ inline std::string Escape(const std::string_view &src) {
|
||||
* clamped to a valid interval. Therefore, this function never throws
|
||||
* std::out_of_range, unlike std::basic_string::substr.
|
||||
*/
|
||||
inline std::string_view Substr(const std::string_view &string, size_t pos = 0, size_t count = std::string::npos) {
|
||||
inline std::string_view Substr(const std::string_view string, size_t pos = 0, size_t count = std::string::npos) {
|
||||
if (pos >= string.size()) return std::string_view(string.data(), 0);
|
||||
auto len = std::min(string.size() - pos, count);
|
||||
return string.substr(pos, len);
|
||||
|
@ -3044,7 +3044,7 @@ void CheckParsedCallProcedure(const CypherQuery &query, Base &ast_generator,
|
||||
}
|
||||
std::vector<std::string> args_as_str{};
|
||||
std::transform(args.begin(), args.end(), std::back_inserter(args_as_str),
|
||||
[](const std::string_view &arg) { return std::string{arg}; });
|
||||
[](const std::string_view arg) { return std::string{arg}; });
|
||||
EXPECT_EQ(identifier_names, args_as_str);
|
||||
EXPECT_EQ(identifier_names, call_proc->result_fields_);
|
||||
ASSERT_EQ(call_proc->is_write_, type == ProcedureType::WRITE);
|
||||
|
Loading…
Reference in New Issue
Block a user