#include "perfetto/ext/base/string_utils.h"
#include <locale.h>
#include <stdarg.h>
#include <string.h>
#include <algorithm>
#if PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
#include <xlocale.h>
#elif PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
#include <Windows.h>
#endif
#include <cinttypes>
#include "perfetto/base/compiler.h"
#include "perfetto/base/logging.h"
namespace perfetto {
namespace base {
double StrToD(const char* nptr, char** endptr) { … }
bool StartsWith(const std::string& str, const std::string& prefix) { … }
bool StartsWithAny(const std::string& str,
const std::vector<std::string>& prefixes) { … }
bool EndsWith(const std::string& str, const std::string& suffix) { … }
bool Contains(const std::string& haystack, const std::string& needle) { … }
bool Contains(const std::string& haystack, const char needle) { … }
size_t Find(const StringView& needle, const StringView& haystack) { … }
bool CaseInsensitiveEqual(const std::string& first, const std::string& second) { … }
std::string Join(const std::vector<std::string>& parts,
const std::string& delim) { … }
std::vector<std::string> SplitString(const std::string& text,
const std::string& delimiter) { … }
std::string TrimWhitespace(const std::string& str) { … }
std::string StripPrefix(const std::string& str, const std::string& prefix) { … }
std::string StripSuffix(const std::string& str, const std::string& suffix) { … }
std::string ToUpper(const std::string& str) { … }
std::string ToLower(const std::string& str) { … }
std::string ToHex(const char* data, size_t size) { … }
std::string IntToHexString(uint32_t number) { … }
std::string Uint64ToHexString(uint64_t number) { … }
std::string Uint64ToHexStringNoPrefix(uint64_t number) { … }
std::string StripChars(const std::string& str,
const std::string& chars,
char replacement) { … }
std::string ReplaceAll(std::string str,
const std::string& to_replace,
const std::string& replacement) { … }
#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
bool WideToUTF8(const std::wstring& source, std::string& output) {
if (source.empty() ||
source.size() > static_cast<size_t>(std::numeric_limits<int>::max())) {
return false;
}
int size = ::WideCharToMultiByte(CP_UTF8, 0, &source[0],
static_cast<int>(source.size()), nullptr, 0,
nullptr, nullptr);
output.assign(static_cast<size_t>(size), '\0');
if (::WideCharToMultiByte(CP_UTF8, 0, &source[0],
static_cast<int>(source.size()), &output[0], size,
nullptr, nullptr) != size) {
return false;
}
return true;
}
#endif
#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
bool UTF8ToWide(const std::string& source, std::wstring& output) {
if (source.empty() ||
source.size() > static_cast<size_t>(std::numeric_limits<int>::max())) {
return false;
}
int size = ::MultiByteToWideChar(CP_UTF8, 0, &source[0],
static_cast<int>(source.size()), nullptr, 0);
output.assign(static_cast<size_t>(size), L'\0');
if (::MultiByteToWideChar(CP_UTF8, 0, &source[0],
static_cast<int>(source.size()), &output[0],
size) != size) {
return false;
}
return true;
}
#endif
size_t SprintfTrunc(char* dst, size_t dst_size, const char* fmt, ...) { … }
std::optional<LineWithOffset> FindLineWithOffset(base::StringView str,
uint32_t offset) { … }
}
}