2018-08-21 05:27:52 +00:00
|
|
|
// Copyright 2017-2018 ccls Authors
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2017-02-17 09:57:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
2017-04-17 07:06:01 +00:00
|
|
|
|
2018-02-07 05:26:38 +00:00
|
|
|
#include <iterator>
|
2017-02-17 09:57:44 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-07-07 23:56:47 +00:00
|
|
|
namespace llvm {
|
|
|
|
class StringRef;
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
namespace ccls {
|
2018-03-31 18:32:28 +00:00
|
|
|
uint64_t HashUsr(std::string_view s);
|
2018-07-07 23:56:47 +00:00
|
|
|
uint64_t HashUsr(llvm::StringRef s);
|
2018-01-13 19:39:06 +00:00
|
|
|
|
2017-03-31 04:15:42 +00:00
|
|
|
// Returns true if |value| starts/ends with |start| or |ending|.
|
2018-03-29 23:57:10 +00:00
|
|
|
bool StartsWith(std::string_view value, std::string_view start);
|
|
|
|
bool EndsWith(std::string_view value, std::string_view ending);
|
2018-08-09 17:08:14 +00:00
|
|
|
bool EndsWithAny(std::string_view s, const std::vector<std::string> &ss);
|
|
|
|
bool FindAnyPartial(const std::string &value,
|
|
|
|
const std::vector<std::string> &values);
|
2018-01-11 02:33:20 +00:00
|
|
|
|
2018-08-09 17:08:14 +00:00
|
|
|
std::vector<std::string> SplitString(const std::string &str,
|
|
|
|
const std::string &delimiter);
|
2017-05-19 01:14:53 +00:00
|
|
|
|
2018-08-09 17:08:14 +00:00
|
|
|
std::string LowerPathIfInsensitive(const std::string &path);
|
2017-05-22 07:14:11 +00:00
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
// Ensures that |path| ends in a slash.
|
2018-08-09 17:08:14 +00:00
|
|
|
void EnsureEndsInSlash(std::string &path);
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2017-12-02 05:07:30 +00:00
|
|
|
// Converts a file path to one that can be used as filename.
|
|
|
|
// e.g. foo/bar.c => foo_bar.c
|
|
|
|
std::string EscapeFileName(std::string path);
|
|
|
|
|
2018-09-22 08:37:00 +00:00
|
|
|
std::string ResolveIfRelative(const std::string &directory,
|
|
|
|
const std::string &path);
|
|
|
|
|
2018-09-20 07:31:23 +00:00
|
|
|
std::optional<int64_t> LastWriteTime(const std::string &path);
|
2018-08-09 17:08:14 +00:00
|
|
|
std::optional<std::string> ReadContent(const std::string &filename);
|
|
|
|
void WriteToFile(const std::string &filename, const std::string &content);
|
2017-03-04 01:45:20 +00:00
|
|
|
|
2018-08-09 17:08:14 +00:00
|
|
|
int ReverseSubseqMatch(std::string_view pat, std::string_view text,
|
2018-06-01 03:06:09 +00:00
|
|
|
int case_sensitivity);
|
|
|
|
|
2017-03-16 07:36:49 +00:00
|
|
|
// http://stackoverflow.com/a/38140932
|
|
|
|
//
|
|
|
|
// struct SomeHashKey {
|
|
|
|
// std::string key1;
|
|
|
|
// std::string key2;
|
|
|
|
// bool key3;
|
|
|
|
// };
|
|
|
|
// MAKE_HASHABLE(SomeHashKey, t.key1, t.key2, t.key3)
|
|
|
|
|
2018-08-09 17:08:14 +00:00
|
|
|
inline void hash_combine(std::size_t &seed) {}
|
2017-03-16 07:36:49 +00:00
|
|
|
|
|
|
|
template <typename T, typename... Rest>
|
2018-08-09 17:08:14 +00:00
|
|
|
inline void hash_combine(std::size_t &seed, const T &v, Rest... rest) {
|
2017-03-16 07:36:49 +00:00
|
|
|
std::hash<T> hasher;
|
|
|
|
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
|
|
|
hash_combine(seed, rest...);
|
|
|
|
}
|
|
|
|
|
2018-08-09 17:08:14 +00:00
|
|
|
#define MAKE_HASHABLE(type, ...) \
|
|
|
|
namespace std { \
|
|
|
|
template <> struct hash<type> { \
|
|
|
|
std::size_t operator()(const type &t) const { \
|
|
|
|
std::size_t ret = 0; \
|
2018-10-28 17:49:31 +00:00
|
|
|
ccls::hash_combine(ret, __VA_ARGS__); \
|
2018-08-09 17:08:14 +00:00
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
}; \
|
2017-09-22 01:14:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 17:10:57 +00:00
|
|
|
std::string GetDefaultResourceDirectory();
|
2018-10-28 17:49:31 +00:00
|
|
|
} // namespace ccls
|