Export media_cas_packager_sdk
This commit is contained in:
36
common/string_util.cc
Normal file
36
common/string_util.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2018 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common/string_util.h"
|
||||
|
||||
#include <bitset>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "util/status.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace string_util {
|
||||
|
||||
util::Status BitsetStringToBinaryString(const std::string& bitset, std::string* output) {
|
||||
if (output == nullptr) {
|
||||
return util::Status(util::error::INTERNAL, "output is nullptr.");
|
||||
}
|
||||
|
||||
std::stringstream sstream(bitset);
|
||||
for (size_t i = 0; i < bitset.size(); i += 8) {
|
||||
std::bitset<8> bits;
|
||||
sstream >> bits;
|
||||
char c = static_cast<char>(bits.to_ulong());
|
||||
*output += c;
|
||||
}
|
||||
|
||||
return util::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace string_util
|
||||
} // namespace widevine
|
||||
Reference in New Issue
Block a user