libluna: Add PathParser::has_next()

This commit is contained in:
apio 2023-05-20 16:39:18 +02:00
parent 9bb5371e8c
commit b75bd4cd14
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 12 additions and 1 deletions

View File

@ -3,6 +3,11 @@
#include <luna/Heap.h>
#include <luna/String.h>
static inline bool is_not_delim(char c)
{
return c && c != '/';
}
class PathParser
{
public:
@ -27,6 +32,11 @@ class PathParser
return is_absolute(StringView { m_original });
}
bool has_next() const
{
return m_already_called_next ? (bool)m_strtok_saved_state : is_not_delim(*m_copy);
}
Result<String> basename();
Result<String> dirname();
@ -38,4 +48,5 @@ class PathParser
const char* m_original { nullptr };
char* m_copy { nullptr };
bool m_already_called_next { false };
char* m_strtok_saved_state { nullptr };
};

View File

@ -27,7 +27,7 @@ PathParser::~PathParser()
Option<const char*> PathParser::next()
{
char* result = strtok(m_already_called_next ? nullptr : m_copy, "/");
char* result = strtok_r(m_already_called_next ? nullptr : m_copy, "/", &m_strtok_saved_state);
m_already_called_next = true;
if (!result) return {};