mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
Path: Add an in-place version of path::native.
This reflects the common use case of nativizing a prepared path. The existing version invokes undefined behavior if input = output, add an assert to catch that case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -173,6 +173,13 @@ void append(SmallVectorImpl<char> &path,
|
|||||||
/// @param result Holds the result of the transformation.
|
/// @param result Holds the result of the transformation.
|
||||||
void native(const Twine &path, SmallVectorImpl<char> &result);
|
void native(const Twine &path, SmallVectorImpl<char> &result);
|
||||||
|
|
||||||
|
/// Convert path to the native form in place. This is used to give paths to
|
||||||
|
/// users and operating system calls in the platform's normal way. For example,
|
||||||
|
/// on Windows all '/' are converted to '\'.
|
||||||
|
///
|
||||||
|
/// @param path A path that is transformed to native format.
|
||||||
|
void native(SmallVectorImpl<char> &path);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Lexical Observers
|
/// @name Lexical Observers
|
||||||
/// @{
|
/// @{
|
||||||
|
@@ -449,23 +449,18 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void native(const Twine &path, SmallVectorImpl<char> &result) {
|
void native(const Twine &path, SmallVectorImpl<char> &result) {
|
||||||
|
assert((!path.isSingleStringRef() ||
|
||||||
|
path.getSingleStringRef().data() != result.data()) &&
|
||||||
|
"path and result are not allowed to overlap!");
|
||||||
// Clear result.
|
// Clear result.
|
||||||
result.clear();
|
result.clear();
|
||||||
#ifdef LLVM_ON_WIN32
|
|
||||||
SmallString<128> path_storage;
|
|
||||||
StringRef p = path.toStringRef(path_storage);
|
|
||||||
result.reserve(p.size());
|
|
||||||
for (StringRef::const_iterator i = p.begin(),
|
|
||||||
e = p.end();
|
|
||||||
i != e;
|
|
||||||
++i) {
|
|
||||||
if (*i == '/')
|
|
||||||
result.push_back('\\');
|
|
||||||
else
|
|
||||||
result.push_back(*i);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
path.toVector(result);
|
path.toVector(result);
|
||||||
|
native(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void native(SmallVectorImpl<char> &path) {
|
||||||
|
#ifdef LLVM_ON_WIN32
|
||||||
|
std::replace(path.begin(), path.end(), '/', '\\');
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user