Don't Use StringStream When It's Overkill
(This is a merge of http://go/wvgerrit/76063) Now that we have C++11, many places that do string formatting or parsing can be replaced with std::to_string() or one of the std::sto*() family of functions. This patch updates places that do simple stringifying or parsing to use these functions. Some parts of the code are left untouched because they were using StringStream to do more complex actions, such as constructing more complex output or checking the status of the parsing. Bug: 120599938 Test: CE CDM Unit Tests Test: Android Unit Tests Change-Id: I482dc234ecd7c6014fa9b6874387ff51e04b772f
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "cdm_engine.h"
|
||||
#include "clock.h"
|
||||
@@ -607,9 +606,8 @@ CdmResponseType CdmSession::QueryOemCryptoSessionId(
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << crypto_session_->oec_session_id();
|
||||
(*query_response)[QUERY_KEY_OEMCRYPTO_SESSION_ID] = ss.str();
|
||||
(*query_response)[QUERY_KEY_OEMCRYPTO_SESSION_ID] =
|
||||
std::to_string(crypto_session_->oec_session_id());
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "client_identification.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "crypto_session.h"
|
||||
#include "license_protocol.pb.h"
|
||||
@@ -146,9 +146,8 @@ CdmResponseType ClientIdentification::Prepare(
|
||||
}
|
||||
client_info = client_id->add_client_info();
|
||||
client_info->set_name(kKeyOemCryptoSecurityPatchLevel);
|
||||
std::stringstream ss;
|
||||
ss << (uint32_t)crypto_session_->GetSecurityPatchLevel();
|
||||
client_info->set_value(ss.str());
|
||||
client_info->set_value(
|
||||
std::to_string((uint32_t)crypto_session_->GetSecurityPatchLevel()));
|
||||
|
||||
if (!provider_client_token.empty()) {
|
||||
client_id->set_provider_client_token(provider_client_token);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "initialization_data.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "buffer_reader.h"
|
||||
#include "cdm_engine.h"
|
||||
@@ -721,13 +721,7 @@ bool InitializationData::DetectEntitlementPreference(
|
||||
if (oec_version_string.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t oec_version_int = 0;
|
||||
std::istringstream parse_int;
|
||||
parse_int.str(oec_version_string);
|
||||
parse_int >> oec_version_int;
|
||||
|
||||
return oec_version_int >= 14;
|
||||
return std::stoul(oec_version_string) >= 14;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "policy_engine.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "clock.h"
|
||||
#include "log.h"
|
||||
@@ -271,7 +271,6 @@ void PolicyEngine::NotifySessionExpiration() {
|
||||
}
|
||||
|
||||
CdmResponseType PolicyEngine::Query(CdmQueryMap* query_response) {
|
||||
std::stringstream ss;
|
||||
int64_t current_time = GetCurrentTime();
|
||||
|
||||
if (license_state_ == kLicenseStateInitial) {
|
||||
@@ -288,11 +287,10 @@ CdmResponseType PolicyEngine::Query(CdmQueryMap* query_response) {
|
||||
policy_.can_persist() ? QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
(*query_response)[QUERY_KEY_RENEW_ALLOWED] =
|
||||
policy_.can_renew() ? QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
ss << GetLicenseOrRentalDurationRemaining(current_time);
|
||||
(*query_response)[QUERY_KEY_LICENSE_DURATION_REMAINING] = ss.str();
|
||||
ss.str("");
|
||||
ss << GetPlaybackDurationRemaining(current_time);
|
||||
(*query_response)[QUERY_KEY_PLAYBACK_DURATION_REMAINING] = ss.str();
|
||||
(*query_response)[QUERY_KEY_LICENSE_DURATION_REMAINING] =
|
||||
std::to_string(GetLicenseOrRentalDurationRemaining(current_time));
|
||||
(*query_response)[QUERY_KEY_PLAYBACK_DURATION_REMAINING] =
|
||||
std::to_string(GetPlaybackDurationRemaining(current_time));
|
||||
(*query_response)[QUERY_KEY_RENEWAL_SERVER_URL] =
|
||||
policy_.renewal_server_url();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user