@@ -44,8 +44,8 @@ inline void CharArrayFromFormat(char (&out)[Count], const char* format, ...)
// Good
std::string ArrayToString(const u8* data, u32 size, int line_len = 20, bool spaces = true);

std::string StripSpaces(const std::string& s);
std::string StripQuotes(const std::string& s);
std::string_view StripSpaces(std::string_view s);
std::string_view StripQuotes(std::string_view s);

bool TryParse(const std::string& str, bool* output);
bool TryParse(const std::string& str, u16* output);
@@ -107,50 +107,50 @@ std::string HexDump(const u8* data, size_t size);
// TODO: kill this
bool AsciiToHex(const std::string& _szValue, u32& result);

std::string TabsToSpaces(int tab_size, const std::string& in);
std::string TabsToSpaces(int tab_size, std::string str);

std::vector<std::string> SplitString(const std::string& str, char delim);
std::string JoinStrings(const std::vector<std::string>& strings, const std::string& delimiter);

// "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe"
bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename,
std::string* _pExtension);
bool SplitPath(std::string_view full_path, std::string* path, std::string* filename,
std::string* extension);

void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path,
const std::string& _Filename);
std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest);
void BuildCompleteFilename(std::string& complete_filename, std::string_view path,
std::string_view filename);
std::string ReplaceAll(std::string result, std::string_view src, std::string_view dest);

bool StringBeginsWith(const std::string& str, const std::string& begin);
bool StringEndsWith(const std::string& str, const std::string& end);
bool StringBeginsWith(std::string_view str, std::string_view begin);
bool StringEndsWith(std::string_view str, std::string_view end);
void StringPopBackIf(std::string* s, char c);

std::string CP1252ToUTF8(const std::string& str);
std::string SHIFTJISToUTF8(const std::string& str);
std::string UTF8ToSHIFTJIS(const std::string& str);
std::string UTF16ToUTF8(const std::wstring& str);
std::string CP1252ToUTF8(std::string_view str);
std::string SHIFTJISToUTF8(std::string_view str);
std::string UTF8ToSHIFTJIS(std::string_view str);
std::string UTF16ToUTF8(std::wstring_view str);
std::string UTF16BEToUTF8(const char16_t* str, size_t max_size); // Stops at \0

#ifdef _WIN32

std::wstring UTF8ToUTF16(const std::string& str);
std::wstring UTF8ToUTF16(std::string_view str);

#ifdef _UNICODE
inline std::string TStrToUTF8(const std::wstring& str)
inline std::string TStrToUTF8(std::wstring_view str)
{
return UTF16ToUTF8(str);
}

inline std::wstring UTF8ToTStr(const std::string& str)
inline std::wstring UTF8ToTStr(std::string_view str)
{
return UTF8ToUTF16(str);
}
#else
inline std::string TStrToUTF8(const std::string& str)
inline std::string TStrToUTF8(std::string_view str)
{
return str;
}

inline std::string UTF8ToTStr(const std::string& str)
inline std::string UTF8ToTStr(std::string_view str)
{
return str;
}
@@ -8,6 +8,7 @@
#include <cstring>
#include <map>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

@@ -298,7 +299,7 @@ bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad)
// Detect two columns with three columns fallback
if (column_count == 0)
{
const std::string stripped_line = StripSpaces(line);
const std::string_view stripped_line = StripSpaces(line);
if (std::count(stripped_line.begin(), stripped_line.end(), ' ') == 1)
column_count = 2;
else
@@ -7,6 +7,8 @@
#include <cstddef>
#include <fstream>
#include <functional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>

@@ -39,7 +41,7 @@ static Map LoadMap(const std::string& file_path)
const size_t equals_index = line.find('=');
if (equals_index != std::string::npos)
{
const std::string game_id = StripSpaces(line.substr(0, equals_index));
const std::string_view game_id = StripSpaces(line.substr(0, equals_index));
if (game_id.length() >= 4)
map.emplace(game_id, StripSpaces(line.substr(equals_index + 1)));
}
@@ -4,6 +4,8 @@

#include "DolphinQt/Settings/USBDeviceAddToWhitelistDialog.h"

#include <string_view>

#include <QButtonGroup>
#include <QDialog>
#include <QDialogButtonBox>
@@ -27,7 +29,7 @@

#include "UICommon/USBUtils.h"

static bool IsValidUSBIDString(const std::string& string)
static bool IsValidUSBIDString(std::string_view string)
{
if (string.empty() || string.length() > 4)
return false;
@@ -124,8 +126,8 @@ void USBDeviceAddToWhitelistDialog::RefreshDeviceList()

void USBDeviceAddToWhitelistDialog::AddUSBDeviceToWhitelist()
{
const std::string vid_string = StripSpaces(device_vid_textbox->text().toStdString());
const std::string pid_string = StripSpaces(device_pid_textbox->text().toStdString());
const std::string_view vid_string = StripSpaces(device_vid_textbox->text().toStdString());
const std::string_view pid_string = StripSpaces(device_pid_textbox->text().toStdString());
if (!IsValidUSBIDString(vid_string))
{
// i18n: Here, VID means Vendor ID (for a USB device).
@@ -151,8 +153,8 @@ void USBDeviceAddToWhitelistDialog::AddUSBDeviceToWhitelist()
return;
}

const u16 vid = static_cast<u16>(std::stoul(vid_string, nullptr, 16));
const u16 pid = static_cast<u16>(std::stoul(pid_string, nullptr, 16));
const u16 vid = static_cast<u16>(std::stoul(std::string(vid_string), nullptr, 16));
const u16 pid = static_cast<u16>(std::stoul(std::string(pid_string), nullptr, 16));

if (SConfig::GetInstance().IsUSBDeviceWhitelisted({vid, pid}))
{
@@ -141,7 +141,7 @@ static void DeviceDebugPrint(IOHIDDeviceRef device)
{
const NSString* name = reinterpret_cast<const NSString*>(
IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductKey)));
return (name != nullptr) ? StripSpaces([name UTF8String]) : "Unknown device";
return (name != nullptr) ? std::string(StripSpaces([name UTF8String])) : "Unknown device";
}

static void DeviceRemovalCallback(void* inContext, IOReturn inResult, void* inSender,
@@ -164,7 +164,7 @@
{
std::ostringstream s;
s << IOHIDElementGetUsage(m_element);
return std::string("Button ") + StripSpaces(s.str());
return std::string("Button ").append(StripSpaces(s.str()));
}

Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir)
@@ -313,7 +313,7 @@ std::string evdevDevice::Button::GetName() const
{
const char* name = libevdev_event_code_get_name(EV_KEY, m_code);
if (name)
return StripSpaces(name);
return std::string(StripSpaces(name));
}
// But controllers use codes above 0x100, and the standard label often doesn't match.
// We are better off with Button 0 and so on.
@@ -32,7 +32,7 @@ std::vector<std::string> GetProfilesFromSetting(const std::string& setting, cons
std::vector<std::string> result;
for (const std::string& setting_choice : setting_choices)
{
const std::string path = root + StripSpaces(setting_choice);
const std::string path = root + std::string(StripSpaces(setting_choice));
if (File::IsDirectory(path))
{
const auto files_under_directory = Common::DoFileSearch({path}, {".ini"}, true);
@@ -6,6 +6,7 @@

#include <sstream>
#include <string>
#include <string_view>

#include "Common/Assert.h"
#include "Common/CommonPaths.h"
@@ -117,16 +118,15 @@ void PostProcessingConfiguration::LoadOptions(const std::string& code)
GLSLStringOption* current_strings = nullptr;
while (!in.eof())
{
std::string line;

if (std::getline(in, line))
std::string line_str;
if (std::getline(in, line_str))
{
std::string_view line = line_str;

#ifndef _WIN32
// Check for CRLF eol and convert it to LF
if (!line.empty() && line.at(line.size() - 1) == '\r')
{
line.erase(line.size() - 1);
}
line.remove_suffix(1);
#endif

if (!line.empty())
@@ -138,8 +138,8 @@ void PostProcessingConfiguration::LoadOptions(const std::string& code)
if (endpos != std::string::npos)
{
// New section!
std::string sub = line.substr(1, endpos - 1);
option_strings.push_back({sub});
std::string_view sub = line.substr(1, endpos - 1);
option_strings.push_back({std::string(sub)});
current_strings = &option_strings.back();
}
}