Skip to content

Commit

Permalink
libcore: Path manipulation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent c88840c commit f8b0314
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doomsday/libs/core/include/de/data/string.h
Expand Up @@ -245,6 +245,7 @@ class DE_PUBLIC String : public IByteArray
{
return startsWithSc_String(&_str, cstr, cs);
}
bool beginsWith(Char ch, Sensitivity cs = CaseSensitive) const;
bool endsWith(char ch, Sensitivity cs = CaseSensitive) const
{
return endsWith(SingleChar{ch, 0}, cs);
Expand Down Expand Up @@ -274,6 +275,8 @@ class DE_PUBLIC String : public IByteArray
List<String> split(Char ch) const;
List<String> split(const String &separator) const { return split(separator.c_str()); }
List<String> split(const RegExp &regExp) const;
List<CString> splitRef(const char *separator) const;
List<CString> splitRef(Char ch) const;

String operator+(const char *) const;
String operator+(const CString &) const;
Expand Down
16 changes: 15 additions & 1 deletion doomsday/libs/core/src/data/path.cpp
Expand Up @@ -168,7 +168,7 @@ DE_PIMPL_NOREF(Path)
}

/**
* Build the segment array by parsing the path. when the path is modified,
* Build the segment array by splitting the path. When the path is modified,
* the existing map is invalidated and needs to be remapped.
*/
void parse()
Expand All @@ -188,6 +188,19 @@ DE_PIMPL_NOREF(Path)
return;
}

const auto parts = path.splitRef(separator);
for (auto p = parts.rbegin(); p != parts.rend(); ++p)
{
allocSegment(*p);
}

// We expect an empty segment in the beginning for absolute paths.
if (path.beginsWith(separator))
{
allocSegment(emptyPath);
}

#if 0
const char * segBegin = path.c_str();
String::const_reverse_iterator segEnd = path.rbegin();

Expand Down Expand Up @@ -226,6 +239,7 @@ DE_PIMPL_NOREF(Path)
{
allocSegment(emptyPath);
}
#endif

DE_ASSERT(segmentCount > 0);
}
Expand Down
26 changes: 26 additions & 0 deletions doomsday/libs/core/src/data/string.cpp
Expand Up @@ -199,6 +199,13 @@ int String::count(char ch) const
return num;
}

bool String::beginsWith(Char ch, Sensitivity cs) const
{
iMultibyteChar mb;
init_MultibyteChar(&mb, ch);
return beginsWith(mb.bytes, cs);
}

String String::substr(CharPos pos, dsize count) const
{
return String::take(mid_String(&_str, pos.index, count));
Expand Down Expand Up @@ -252,6 +259,25 @@ List<String> String::split(const char *separator) const
return parts;
}

List<CString> String::splitRef(const char *separator) const
{
List<CString> parts;
iRangecc seg{};
iRangecc str{constBegin_String(&_str), constEnd_String(&_str)};
while (nextSplit_Rangecc(&str, separator, &seg))
{
parts << CString(seg.start, seg.end);
}
return parts;
}

List<CString> String::splitRef(Char ch) const
{
iMultibyteChar mb;
init_MultibyteChar(&mb, ch);
return splitRef(mb.bytes);
}

List<String> String::split(Char ch) const
{
iMultibyteChar mb;
Expand Down
5 changes: 3 additions & 2 deletions doomsday/libs/core/src/filesys/folder.cpp
Expand Up @@ -40,7 +40,7 @@ FolderPopulationAudience audienceForFolderPopulation; // public
namespace internal {

static TaskPool populateTasks;
static bool enableBackgroundPopulation = true;
static bool enableBackgroundPopulation = false; //true;

/// Forwards internal folder population notifications to the public audience.
struct PopulationNotifier : DE_OBSERVES(TaskPool, Done)
Expand Down Expand Up @@ -480,7 +480,8 @@ bool Folder::has(String const &name) const

File &Folder::add(File *file)
{
DE_ASSERT(file != 0);
DE_ASSERT(file != nullptr);
DE_ASSERT(!file->name().contains('/'));

if (has(file->name()))
{
Expand Down

0 comments on commit f8b0314

Please sign in to comment.