Compare commits
3 Commits
257c2ffd0a
...
e378d8ee2f
Author | SHA1 | Date | |
---|---|---|---|
e378d8ee2f | |||
c075aa77b9 | |||
dcc6bbf055 |
@ -100,9 +100,12 @@ static Result<void> load_service(StringView path)
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
auto line = TRY(file->read_line(false));
|
auto line = TRY(file->read_line());
|
||||||
if (line.is_empty()) break;
|
if (line.is_empty()) break;
|
||||||
|
|
||||||
|
line.trim("\n");
|
||||||
|
if (line.is_empty()) continue;
|
||||||
|
|
||||||
auto parts = TRY(line.split_once('='));
|
auto parts = TRY(line.split_once('='));
|
||||||
if (parts.size() < 2 || parts[0].is_empty() || parts[1].is_empty())
|
if (parts.size() < 2 || parts[0].is_empty() || parts[1].is_empty())
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,8 @@ class String
|
|||||||
return view().split_once(delim);
|
return view().split_once(delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trim(StringView delim);
|
||||||
|
|
||||||
static Result<String> format(const String& fmt, ...);
|
static Result<String> format(const String& fmt, ...);
|
||||||
static Result<String> format(StringView fmt, ...);
|
static Result<String> format(StringView fmt, ...);
|
||||||
|
|
||||||
|
@ -80,6 +80,25 @@ Result<Vector<String>> String::split(StringView delim) const
|
|||||||
return view().split(delim);
|
return view().split(delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void String::trim(StringView delim)
|
||||||
|
{
|
||||||
|
isize i = (isize)m_length;
|
||||||
|
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
char c = chars()[i];
|
||||||
|
if (!strchr(delim.chars(), c)) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (m_inline) m_inline_storage[i] = '\0';
|
||||||
|
else
|
||||||
|
m_string[i] = '\0';
|
||||||
|
|
||||||
|
m_length = (usize)i;
|
||||||
|
}
|
||||||
|
|
||||||
const char& String::operator[](usize index) const
|
const char& String::operator[](usize index) const
|
||||||
{
|
{
|
||||||
expect(index < m_length, "index out of range");
|
expect(index < m_length, "index out of range");
|
||||||
|
@ -33,7 +33,7 @@ namespace os
|
|||||||
Result<void> write(StringView str);
|
Result<void> write(StringView str);
|
||||||
Result<void> write(const Buffer& buf);
|
Result<void> write(const Buffer& buf);
|
||||||
|
|
||||||
Result<String> read_line(bool keep_newline = true);
|
Result<String> read_line();
|
||||||
|
|
||||||
Result<void> read(Buffer& buf, usize size);
|
Result<void> read(Buffer& buf, usize size);
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ namespace os
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<String> File::read_line(bool keep_newline)
|
Result<String> File::read_line()
|
||||||
{
|
{
|
||||||
Vector<char> data;
|
Vector<char> data;
|
||||||
|
|
||||||
@ -121,11 +121,7 @@ namespace os
|
|||||||
|
|
||||||
TRY(data.try_append((char)current));
|
TRY(data.try_append((char)current));
|
||||||
|
|
||||||
if (current == '\n')
|
if (current == '\n') break;
|
||||||
{
|
|
||||||
if (!keep_newline) data.try_pop();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.size()) return String {};
|
if (!data.size()) return String {};
|
||||||
|
Loading…
Reference in New Issue
Block a user