libluna: Add PathParser::has_next()
This commit is contained in:
parent
9bb5371e8c
commit
b75bd4cd14
@ -3,6 +3,11 @@
|
|||||||
#include <luna/Heap.h>
|
#include <luna/Heap.h>
|
||||||
#include <luna/String.h>
|
#include <luna/String.h>
|
||||||
|
|
||||||
|
static inline bool is_not_delim(char c)
|
||||||
|
{
|
||||||
|
return c && c != '/';
|
||||||
|
}
|
||||||
|
|
||||||
class PathParser
|
class PathParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -27,6 +32,11 @@ class PathParser
|
|||||||
return is_absolute(StringView { m_original });
|
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> basename();
|
||||||
Result<String> dirname();
|
Result<String> dirname();
|
||||||
|
|
||||||
@ -38,4 +48,5 @@ class PathParser
|
|||||||
const char* m_original { nullptr };
|
const char* m_original { nullptr };
|
||||||
char* m_copy { nullptr };
|
char* m_copy { nullptr };
|
||||||
bool m_already_called_next { false };
|
bool m_already_called_next { false };
|
||||||
|
char* m_strtok_saved_state { nullptr };
|
||||||
};
|
};
|
||||||
|
@ -27,7 +27,7 @@ PathParser::~PathParser()
|
|||||||
|
|
||||||
Option<const char*> PathParser::next()
|
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;
|
m_already_called_next = true;
|
||||||
|
|
||||||
if (!result) return {};
|
if (!result) return {};
|
||||||
|
Loading…
Reference in New Issue
Block a user