mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:17:44 +00:00
AK: Add InputStream abstraction and InputMemoryStream implementation.
This commit is contained in:
parent
75cde94c6a
commit
5bfa7749c3
4 changed files with 307 additions and 0 deletions
23
AK/String.h
23
AK/String.h
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Stream.h>
|
||||
#include <AK/StringImpl.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <AK/Traits.h>
|
||||
|
@ -275,6 +276,28 @@ bool operator<=(const char*, const String&);
|
|||
|
||||
String escape_html_entities(const StringView& html);
|
||||
|
||||
inline InputMemoryStream& operator>>(InputMemoryStream& stream, String& string)
|
||||
{
|
||||
// FIXME: There was some talking about a generic lexer class?
|
||||
|
||||
const auto start = stream.offset();
|
||||
|
||||
while (!stream.eof() && stream.m_bytes[stream.m_offset]) {
|
||||
++stream.m_offset;
|
||||
}
|
||||
|
||||
if (stream.eof()) {
|
||||
stream.m_error = true;
|
||||
stream.m_offset = start;
|
||||
string = nullptr;
|
||||
} else {
|
||||
string = String { stream.bytes().slice(start, stream.offset() - start) };
|
||||
++stream.m_offset;
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::CaseInsensitiveStringTraits;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue