1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

LibCore: Change DateTime format strings to be StringViews

There's no need to allocate a String for these. Note the "string"
parameter of DateTime::parse is left as a String for now; the parser is
currently using strtol which needs a NUL-terminated string. This method
can likely be rewritten with GenericLexer.
This commit is contained in:
Timothy Flynn 2022-01-28 14:26:43 -05:00 committed by Linus Groh
parent 9c80430eea
commit b387ac56b6
2 changed files with 5 additions and 4 deletions

View file

@ -83,7 +83,7 @@ void DateTime::set_time(int year, int month, int day, int hour, int minute, int
m_second = tm.tm_sec;
}
String DateTime::to_string(const String& format) const
String DateTime::to_string(StringView format) const
{
const char wday_short_names[7][4] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
@ -261,7 +261,7 @@ String DateTime::to_string(const String& format) const
return builder.build();
}
Optional<DateTime> DateTime::parse(const String& format, const String& string)
Optional<DateTime> DateTime::parse(StringView format, const String& string)
{
unsigned format_pos = 0;
unsigned string_pos = 0;