Commit 74e33f8f authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

MediaFragmentURIParser: Use WTF::CString and char for UTF-8 data.

8-bit WTF::String and LChar are expected to be used for Latin-1 data, rather
than UTF-8. Using CString and char is more idiomatic, and as a bonus, avoids
a copy (since String::Utf8 returns a CString already).

Change-Id: I5a4f726d4980a143793cd88cc80f79fb7375ea72
Reviewed-on: https://chromium-review.googlesource.com/521965
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478690}
parent 16557b3a
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "core/html/media/MediaFragmentURIParser.h" #include "core/html/media/MediaFragmentURIParser.h"
#include "platform/wtf/text/CString.h"
#include "platform/wtf/text/StringBuilder.h" #include "platform/wtf/text/StringBuilder.h"
#include "platform/wtf/text/WTFString.h" #include "platform/wtf/text/WTFString.h"
...@@ -33,7 +32,7 @@ namespace blink { ...@@ -33,7 +32,7 @@ namespace blink {
const unsigned kNptIdentiferLength = 4; // "npt:" const unsigned kNptIdentiferLength = 4; // "npt:"
static String CollectDigits(const LChar* input, static String CollectDigits(const char* input,
unsigned length, unsigned length,
unsigned& position) { unsigned& position) {
StringBuilder digits; StringBuilder digits;
...@@ -45,7 +44,7 @@ static String CollectDigits(const LChar* input, ...@@ -45,7 +44,7 @@ static String CollectDigits(const LChar* input,
return digits.ToString(); return digits.ToString();
} }
static String CollectFraction(const LChar* input, static String CollectFraction(const char* input,
unsigned length, unsigned length,
unsigned& position) { unsigned& position) {
StringBuilder digits; StringBuilder digits;
...@@ -125,17 +124,19 @@ void MediaFragmentURIParser::ParseFragments() { ...@@ -125,17 +124,19 @@ void MediaFragmentURIParser::ParseFragments() {
// UTF-8. If either name or value are not valid UTF-8 strings, then // UTF-8. If either name or value are not valid UTF-8 strings, then
// remove the name-value pair from the list. // remove the name-value pair from the list.
bool valid_utf8 = true; bool valid_utf8 = true;
CString utf8_name;
if (!name.IsEmpty()) { if (!name.IsEmpty()) {
name = name.Utf8(kStrictUTF8Conversion).data(); utf8_name = name.Utf8(kStrictUTF8Conversion);
valid_utf8 = !name.IsEmpty(); valid_utf8 = !utf8_name.IsNull();
} }
CString utf8_value;
if (valid_utf8 && !value.IsEmpty()) { if (valid_utf8 && !value.IsEmpty()) {
value = value.Utf8(kStrictUTF8Conversion).data(); utf8_value = value.Utf8(kStrictUTF8Conversion);
valid_utf8 = !value.IsEmpty(); valid_utf8 = !utf8_value.IsNull();
} }
if (valid_utf8) if (valid_utf8)
fragments_.push_back(std::make_pair(name, value)); fragments_.emplace_back(std::move(utf8_name), std::move(utf8_value));
offset = parameter_end + 1; offset = parameter_end + 1;
} }
...@@ -150,9 +151,6 @@ void MediaFragmentURIParser::ParseTimeFragment() { ...@@ -150,9 +151,6 @@ void MediaFragmentURIParser::ParseTimeFragment() {
time_format_ = kInvalid; time_format_ = kInvalid;
for (const auto& fragment : fragments_) { for (const auto& fragment : fragments_) {
DCHECK(fragment.first.Is8Bit());
DCHECK(fragment.second.Is8Bit());
// http://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec/#naming-time // http://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec/#naming-time
// Temporal clipping is denoted by the name t, and specified as an interval // Temporal clipping is denoted by the name t, and specified as an interval
// with a begin time and an end time // with a begin time and an end time
...@@ -168,8 +166,8 @@ void MediaFragmentURIParser::ParseTimeFragment() { ...@@ -168,8 +166,8 @@ void MediaFragmentURIParser::ParseTimeFragment() {
double start = std::numeric_limits<double>::quiet_NaN(); double start = std::numeric_limits<double>::quiet_NaN();
double end = std::numeric_limits<double>::quiet_NaN(); double end = std::numeric_limits<double>::quiet_NaN();
if (ParseNPTFragment(fragment.second.Characters8(), if (ParseNPTFragment(fragment.second.data(), fragment.second.length(),
fragment.second.length(), start, end)) { start, end)) {
start_time_ = start; start_time_ = start;
end_time_ = end; end_time_ = end;
time_format_ = kNormalPlayTime; time_format_ = kNormalPlayTime;
...@@ -186,7 +184,7 @@ void MediaFragmentURIParser::ParseTimeFragment() { ...@@ -186,7 +184,7 @@ void MediaFragmentURIParser::ParseTimeFragment() {
fragments_.clear(); fragments_.clear();
} }
bool MediaFragmentURIParser::ParseNPTFragment(const LChar* time_string, bool MediaFragmentURIParser::ParseNPTFragment(const char* time_string,
unsigned length, unsigned length,
double& start_time, double& start_time,
double& end_time) { double& end_time) {
...@@ -228,7 +226,7 @@ bool MediaFragmentURIParser::ParseNPTFragment(const LChar* time_string, ...@@ -228,7 +226,7 @@ bool MediaFragmentURIParser::ParseNPTFragment(const LChar* time_string,
return true; return true;
} }
bool MediaFragmentURIParser::ParseNPTTime(const LChar* time_string, bool MediaFragmentURIParser::ParseNPTTime(const char* time_string,
unsigned length, unsigned length,
unsigned& offset, unsigned& offset,
double& time) { double& time) {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "platform/weborigin/KURL.h" #include "platform/weborigin/KURL.h"
#include "platform/wtf/Allocator.h" #include "platform/wtf/Allocator.h"
#include "platform/wtf/Vector.h" #include "platform/wtf/Vector.h"
#include "platform/wtf/text/CString.h"
namespace blink { namespace blink {
...@@ -54,11 +55,11 @@ class MediaFragmentURIParser final { ...@@ -54,11 +55,11 @@ class MediaFragmentURIParser final {
kWallClockTimeCode kWallClockTimeCode
}; };
void ParseTimeFragment(); void ParseTimeFragment();
bool ParseNPTFragment(const LChar*, bool ParseNPTFragment(const char*,
unsigned length, unsigned length,
double& start_time, double& start_time,
double& end_time); double& end_time);
bool ParseNPTTime(const LChar*, bool ParseNPTTime(const char*,
unsigned length, unsigned length,
unsigned& offset, unsigned& offset,
double& time); double& time);
...@@ -67,7 +68,7 @@ class MediaFragmentURIParser final { ...@@ -67,7 +68,7 @@ class MediaFragmentURIParser final {
TimeFormat time_format_; TimeFormat time_format_;
double start_time_; double start_time_;
double end_time_; double end_time_;
Vector<std::pair<String, String>> fragments_; Vector<std::pair<CString, CString>> fragments_;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment