mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-20 00:57:49 +01:00
Change signatures of SDP ParseFailed* functions
Change types of const std::string& arguments. Use absl::string_view for the reference to input, to prepare for parsing with less copies. Use std::string (passed by value) for the description, to support ownership transfer without copying. Bug: None Change-Id: I4358b42bb824e4eb7a5ac9b64d44db1b9b022bab Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/223667 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34721}
This commit is contained in:
parent
9367cff59b
commit
a820cc226e
1 changed files with 25 additions and 25 deletions
|
@ -396,12 +396,12 @@ static void RemoveInvalidRidsFromSimulcast(
|
|||
// The line starting at `line_start` of `message` is the failing line.
|
||||
// The reason for the failure should be provided in the `description`.
|
||||
// An example of a description could be "unknown character".
|
||||
static bool ParseFailed(const std::string& message,
|
||||
static bool ParseFailed(absl::string_view message,
|
||||
size_t line_start,
|
||||
const std::string& description,
|
||||
std::string description,
|
||||
SdpParseError* error) {
|
||||
// Get the first line of `message` from `line_start`.
|
||||
std::string first_line;
|
||||
absl::string_view first_line;
|
||||
size_t line_end = message.find(kNewLine, line_start);
|
||||
if (line_end != std::string::npos) {
|
||||
if (line_end > 0 && (message.at(line_end - 1) == kReturnChar)) {
|
||||
|
@ -412,72 +412,72 @@ static bool ParseFailed(const std::string& message,
|
|||
first_line = message.substr(line_start);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
error->line = first_line;
|
||||
error->description = description;
|
||||
}
|
||||
RTC_LOG(LS_ERROR) << "Failed to parse: \"" << first_line
|
||||
<< "\". Reason: " << description;
|
||||
if (error) {
|
||||
error->line = std::string(first_line);
|
||||
error->description = std::move(description);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// `line` is the failing line. The reason for the failure should be
|
||||
// provided in the `description`.
|
||||
static bool ParseFailed(const std::string& line,
|
||||
const std::string& description,
|
||||
static bool ParseFailed(absl::string_view line,
|
||||
std::string description,
|
||||
SdpParseError* error) {
|
||||
return ParseFailed(line, 0, description, error);
|
||||
return ParseFailed(line, 0, std::move(description), error);
|
||||
}
|
||||
|
||||
// Parses failure where the failing SDP line isn't know or there are multiple
|
||||
// failing lines.
|
||||
static bool ParseFailed(const std::string& description, SdpParseError* error) {
|
||||
return ParseFailed("", description, error);
|
||||
static bool ParseFailed(std::string description, SdpParseError* error) {
|
||||
return ParseFailed("", std::move(description), error);
|
||||
}
|
||||
|
||||
// `line` is the failing line. The failure is due to the fact that `line`
|
||||
// doesn't have `expected_fields` fields.
|
||||
static bool ParseFailedExpectFieldNum(const std::string& line,
|
||||
static bool ParseFailedExpectFieldNum(absl::string_view line,
|
||||
int expected_fields,
|
||||
SdpParseError* error) {
|
||||
rtc::StringBuilder description;
|
||||
description << "Expects " << expected_fields << " fields.";
|
||||
return ParseFailed(line, description.str(), error);
|
||||
return ParseFailed(line, description.Release(), error);
|
||||
}
|
||||
|
||||
// `line` is the failing line. The failure is due to the fact that `line` has
|
||||
// less than `expected_min_fields` fields.
|
||||
static bool ParseFailedExpectMinFieldNum(const std::string& line,
|
||||
static bool ParseFailedExpectMinFieldNum(absl::string_view line,
|
||||
int expected_min_fields,
|
||||
SdpParseError* error) {
|
||||
rtc::StringBuilder description;
|
||||
description << "Expects at least " << expected_min_fields << " fields.";
|
||||
return ParseFailed(line, description.str(), error);
|
||||
return ParseFailed(line, description.Release(), error);
|
||||
}
|
||||
|
||||
// `line` is the failing line. The failure is due to the fact that it failed to
|
||||
// get the value of `attribute`.
|
||||
static bool ParseFailedGetValue(const std::string& line,
|
||||
static bool ParseFailedGetValue(absl::string_view line,
|
||||
const std::string& attribute,
|
||||
SdpParseError* error) {
|
||||
rtc::StringBuilder description;
|
||||
description << "Failed to get the value of attribute: " << attribute;
|
||||
return ParseFailed(line, description.str(), error);
|
||||
return ParseFailed(line, description.Release(), error);
|
||||
}
|
||||
|
||||
// The line starting at `line_start` of `message` is the failing line. The
|
||||
// failure is due to the line type (e.g. the "m" part of the "m-line")
|
||||
// not matching what is expected. The expected line type should be
|
||||
// provided as `line_type`.
|
||||
static bool ParseFailedExpectLine(const std::string& message,
|
||||
static bool ParseFailedExpectLine(absl::string_view message,
|
||||
size_t line_start,
|
||||
const char line_type,
|
||||
const std::string& line_value,
|
||||
absl::string_view line_value,
|
||||
SdpParseError* error) {
|
||||
rtc::StringBuilder description;
|
||||
description << "Expect line: " << std::string(1, line_type) << "="
|
||||
<< line_value;
|
||||
return ParseFailed(message, line_start, description.str(), error);
|
||||
return ParseFailed(message, line_start, description.Release(), error);
|
||||
}
|
||||
|
||||
static bool AddLine(const std::string& line, std::string* message) {
|
||||
|
@ -638,7 +638,7 @@ static bool GetSingleTokenValue(const std::string& message,
|
|||
if (strspn(value->c_str(), kLegalTokenCharacters) != value->size()) {
|
||||
rtc::StringBuilder description;
|
||||
description << "Illegal character found in the value of " << attribute;
|
||||
return ParseFailed(message, description.str(), error);
|
||||
return ParseFailed(message, description.Release(), error);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -657,7 +657,7 @@ static bool GetValueFromString(const std::string& line,
|
|||
if (!rtc::FromString(s, t)) {
|
||||
rtc::StringBuilder description;
|
||||
description << "Invalid value: " << s << ".";
|
||||
return ParseFailed(line, description.str(), error);
|
||||
return ParseFailed(line, description.Release(), error);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1080,7 +1080,7 @@ bool ParseCandidate(const std::string& message,
|
|||
description << "Expect line: " << kAttributeCandidate
|
||||
<< ":"
|
||||
"<candidate-str>";
|
||||
return ParseFailed(first_line, 0, description.str(), error);
|
||||
return ParseFailed(first_line, 0, description.Release(), error);
|
||||
} else {
|
||||
return ParseFailedExpectLine(first_line, 0, kLineTypeAttributes,
|
||||
kAttributeCandidate, error);
|
||||
|
@ -3426,7 +3426,7 @@ bool ParseSsrcAttribute(const std::string& line,
|
|||
rtc::StringBuilder description;
|
||||
description << "Failed to get the ssrc attribute value from " << field2
|
||||
<< ". Expected format <attribute>:<value>.";
|
||||
return ParseFailed(line, description.str(), error);
|
||||
return ParseFailed(line, description.Release(), error);
|
||||
}
|
||||
|
||||
// Check if there's already an item for this `ssrc_id`. Create a new one if
|
||||
|
|
Loading…
Reference in a new issue