-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pg/Serial: pass std::string_view to Parse()
- Loading branch information
1 parent
7ee4d53
commit 6f890f1
Showing
2 changed files
with
12 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,32 +3,30 @@ | |
// author: Max Kellermann <[email protected]> | ||
|
||
#include "Serial.hxx" | ||
#include "util/NumberParser.hxx" | ||
|
||
#include <stdexcept> | ||
#include <cstdlib> | ||
|
||
namespace Pg { | ||
|
||
Serial | ||
Serial::Parse(const char *s) | ||
Serial::Parse(std::string_view s) | ||
{ | ||
char *endptr; | ||
auto value = std::strtoul(s, &endptr, 10); | ||
if (endptr == s || *endptr != 0) | ||
const auto value = ParseInteger<value_type>(s); | ||
if (!value) | ||
throw std::invalid_argument("Failed to parse serial"); | ||
|
||
return Serial(value); | ||
return Serial{*value}; | ||
} | ||
|
||
BigSerial | ||
BigSerial::Parse(const char *s) | ||
BigSerial::Parse(std::string_view s) | ||
{ | ||
char *endptr; | ||
auto value = std::strtoul(s, &endptr, 10); | ||
if (endptr == s || *endptr != 0) | ||
const auto value = ParseInteger<value_type>(s); | ||
if (!value) | ||
throw std::invalid_argument("Failed to parse serial"); | ||
|
||
return BigSerial{value}; | ||
return BigSerial{*value}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters