mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Made File::getRelativePathFrom() return '.' if comparing two identical folders.
This commit is contained in:
parent
51d5572220
commit
d3bb833f0e
1 changed files with 18 additions and 15 deletions
|
|
@ -865,7 +865,7 @@ static int countNumberOfSeparators (String::CharPointerType s)
|
|||
|
||||
for (;;)
|
||||
{
|
||||
const juce_wchar c = s.getAndAdvance();
|
||||
auto c = s.getAndAdvance();
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
|
|
@ -877,28 +877,31 @@ static int countNumberOfSeparators (String::CharPointerType s)
|
|||
return num;
|
||||
}
|
||||
|
||||
String File::getRelativePathFrom (const File& dir) const
|
||||
String File::getRelativePathFrom (const File& dir) const
|
||||
{
|
||||
String thisPath (fullPath);
|
||||
if (dir == *this)
|
||||
return ".";
|
||||
|
||||
auto thisPath = fullPath;
|
||||
|
||||
while (thisPath.endsWithChar (separator))
|
||||
thisPath = thisPath.dropLastCharacters (1);
|
||||
|
||||
String dirPath (addTrailingSeparator (dir.existsAsFile() ? dir.getParentDirectory().getFullPathName()
|
||||
: dir.fullPath));
|
||||
auto dirPath = addTrailingSeparator (dir.existsAsFile() ? dir.getParentDirectory().getFullPathName()
|
||||
: dir.fullPath);
|
||||
|
||||
int commonBitLength = 0;
|
||||
String::CharPointerType thisPathAfterCommon (thisPath.getCharPointer());
|
||||
String::CharPointerType dirPathAfterCommon (dirPath.getCharPointer());
|
||||
auto thisPathAfterCommon = thisPath.getCharPointer();
|
||||
auto dirPathAfterCommon = dirPath.getCharPointer();
|
||||
|
||||
{
|
||||
String::CharPointerType thisPathIter (thisPath.getCharPointer());
|
||||
String::CharPointerType dirPathIter (dirPath.getCharPointer());
|
||||
auto thisPathIter = thisPath.getCharPointer();
|
||||
auto dirPathIter = dirPath.getCharPointer();
|
||||
|
||||
for (int i = 0;;)
|
||||
{
|
||||
const juce_wchar c1 = thisPathIter.getAndAdvance();
|
||||
const juce_wchar c2 = dirPathIter.getAndAdvance();
|
||||
auto c1 = thisPathIter.getAndAdvance();
|
||||
auto c2 = dirPathIter.getAndAdvance();
|
||||
|
||||
#if NAMES_ARE_CASE_SENSITIVE
|
||||
if (c1 != c2
|
||||
|
|
@ -923,7 +926,7 @@ String File::getRelativePathFrom (const File& dir) const
|
|||
if (commonBitLength == 0 || (commonBitLength == 1 && thisPath[1] == separator))
|
||||
return fullPath;
|
||||
|
||||
const int numUpDirectoriesNeeded = countNumberOfSeparators (dirPathAfterCommon);
|
||||
auto numUpDirectoriesNeeded = countNumberOfSeparators (dirPathAfterCommon);
|
||||
|
||||
if (numUpDirectoriesNeeded == 0)
|
||||
return thisPathAfterCommon;
|
||||
|
|
@ -940,9 +943,9 @@ String File::getRelativePathFrom (const File& dir) const
|
|||
//==============================================================================
|
||||
File File::createTempFile (StringRef fileNameEnding)
|
||||
{
|
||||
const File tempFile (getSpecialLocation (tempDirectory)
|
||||
.getChildFile ("temp_" + String::toHexString (Random::getSystemRandom().nextInt()))
|
||||
.withFileExtension (fileNameEnding));
|
||||
auto tempFile = getSpecialLocation (tempDirectory)
|
||||
.getChildFile ("temp_" + String::toHexString (Random::getSystemRandom().nextInt()))
|
||||
.withFileExtension (fileNameEnding);
|
||||
|
||||
if (tempFile.exists())
|
||||
return createTempFile (fileNameEnding);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue