OEMCrypto and OPK v20 prerelease initial commit

This commit is contained in:
Matt Feddersen
2025-05-20 20:30:59 -07:00
parent 98dfef4389
commit a2b9e085e9
193 changed files with 22480 additions and 3275 deletions

View File

@@ -0,0 +1,89 @@
// Copyright 2024 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
#ifndef WVCDM_UTIL_STRING_UTILS_H_
#define WVCDM_UTIL_STRING_UTILS_H_
#include <string>
#include <vector>
// Small set of simple string utilities.
//
// It is inspired by Python strings and Abseil. The CDM tends to not
// be too fancy with its use of templated containers; none of the
// Abseil container magic is not provided, nor are the fancy templated
// configurations.
namespace wvutil {
// Splits a string into several substrings based on the provided
// delimiter.
//
// Special cases:
// - An empty delimiter will split the string into each character.
std::vector<std::string> StringSplit(const std::string& s, char delim);
std::vector<std::string> StringSplit(const std::string& s,
const std::string& delim);
std::vector<std::string> StringSplit(const std::string& s, const char* delim);
// Joins a list of strings into a single string, using the specified
// "glue" character(s) between tokens. Note: |glue| can be empty.
std::string StringJoin(const std::vector<std::string>& tokens, char glue);
std::string StringJoin(const std::vector<std::string>& tokens,
const std::string& glue = "");
std::string StringJoin(const std::vector<std::string>& tokens,
const char* glue);
// Counts the number of instances of |needle| sequences found in the
// |haystack|.
//
// Special cases:
// - An empty needle will return the length of |haystack| plus 1,
// including for an empty string.
// Note: This is a convention used by many string utility
// libraries.
size_t StringCount(const std::string& haystack, char needle);
size_t StringCount(const std::string& haystack, const std::string& needle);
size_t StringCount(const std::string& haystack, const char* needle);
// Checks if any instances of |needle| sequences found in the |haystack|.
//
// Special cases:
// - An empty |needle| is always present, even if |haystack| is empty.
// Note: This is a convention used by many string utility
// libraries.
bool StringContains(const std::string& haystack, char needle);
bool StringContains(const std::string& haystack, const std::string& needle);
bool StringContains(const std::string& haystack, const char* needle);
// Checks if the |needle| sequences found at the beginning of |haystack|.
//
// Special cases:
// - An empty |needle| is always present, even if |haystack| is empty.
// Note: This is a convention used by many string utility
// libraries.
bool StringStartsWith(const std::string& haystack, char needle);
bool StringStartsWith(const std::string& haystack, const std::string& needle);
bool StringStartsWith(const std::string& haystack, const char* needle);
// Checks if the |needle| sequences found at the end of |haystack|.
//
// Special cases:
// - An empty |needle| is always present, even if |haystack| is empty.
// Note: This is a convention used by many string utility
// libraries.
bool StringEndsWith(const std::string& haystack, char needle);
bool StringEndsWith(const std::string& haystack, const std::string& needle);
bool StringEndsWith(const std::string& haystack, const char* needle);
// Removes any leading or trailing white space from the provided string.
std::string StringTrim(const std::string& s);
// Checks if the vector of strings contains any instance of the
// specified |needle|.
//
// Note: Unlike the other utilities, an empty |needle| is treated
// as a value.
bool StringVecContains(const std::vector<std::string>& haystack,
const std::string& needle);
} // namespace wvutil
#endif // WVCDM_UTIL_STRING_UTILS_H_