mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use data() instead of c_str(), if no NUL termination is needed.
parent
9e90d4ed79
commit
9cf36dac39
|
@ -135,7 +135,7 @@ void MusicDriver_Cocoa::PlaySong(const MusicSongInfo &song)
|
|||
}
|
||||
|
||||
std::string os_file = OTTD2FS(filename);
|
||||
CFAutoRelease<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*)os_file.c_str(), os_file.length(), false));
|
||||
CFAutoRelease<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*)os_file.data(), os_file.length(), false));
|
||||
|
||||
if (MusicSequenceFileLoad(_sequence, url.get(), kMusicSequenceFile_AnyType, 0) != noErr) {
|
||||
Debug(driver, 0, "cocoa_m: Failed to load MIDI file");
|
||||
|
|
|
@ -254,7 +254,7 @@ void NetworkHTTPRequest::Connect()
|
|||
} else {
|
||||
/* When the payload starts with a '{', it is a JSON payload. */
|
||||
LPCWSTR content_type = data.starts_with("{") ? L"Content-Type: application/json\r\n" : L"Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
WinHttpSendRequest(this->request, content_type, -1, const_cast<char *>(data.c_str()), static_cast<DWORD>(data.size()), static_cast<DWORD>(data.size()), reinterpret_cast<DWORD_PTR>(this));
|
||||
WinHttpSendRequest(this->request, content_type, -1, const_cast<char *>(data.data()), static_cast<DWORD>(data.size()), static_cast<DWORD>(data.size()), reinterpret_cast<DWORD_PTR>(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ std::optional<std::string> GetClipboardContents()
|
|||
void OSOpenBrowser(const std::string &url)
|
||||
{
|
||||
/* Implementation in pre.js */
|
||||
EM_ASM({ if (window["openttd_open_url"]) window.openttd_open_url($0, $1) }, url.c_str(), url.size());
|
||||
EM_ASM({ if (window["openttd_open_url"]) window.openttd_open_url($0, $1) }, url.data(), url.size());
|
||||
}
|
||||
#elif !defined( __APPLE__)
|
||||
void OSOpenBrowser(const std::string &url)
|
||||
|
|
|
@ -428,7 +428,7 @@ void Win32SetCurrentLocaleName(std::string iso_code)
|
|||
}
|
||||
}
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, iso_code.c_str(), -1, _cur_iso_locale, static_cast<int>(std::size(_cur_iso_locale)));
|
||||
MultiByteToWideChar(CP_UTF8, 0, iso_code.data(), static_cast<int>(iso_code.size()), _cur_iso_locale, static_cast<int>(std::size(_cur_iso_locale)));
|
||||
}
|
||||
|
||||
int OTTDStringCompare(std::string_view s1, std::string_view s2)
|
||||
|
@ -461,11 +461,11 @@ int OTTDStringCompare(std::string_view s1, std::string_view s2)
|
|||
|
||||
/* CompareStringEx takes UTF-16 strings, even in ANSI-builds. */
|
||||
if (_CompareStringEx != nullptr) {
|
||||
int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1.c_str(), len_s1, str_s2.c_str(), len_s2, nullptr, nullptr, 0);
|
||||
int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1.data(), len_s1, str_s2.data(), len_s2, nullptr, nullptr, 0);
|
||||
if (result != 0) return result;
|
||||
}
|
||||
|
||||
return CompareString(MAKELCID(_current_language->winlangid, SORT_DEFAULT), NORM_IGNORECASE, str_s1.c_str(), len_s1, str_s2.c_str(), len_s2);
|
||||
return CompareString(MAKELCID(_current_language->winlangid, SORT_DEFAULT), NORM_IGNORECASE, str_s1.data(), len_s1, str_s2.data(), len_s2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,8 +28,8 @@ template <typename Tpf> void DumpState(Tpf &pf1, Tpf &pf2)
|
|||
auto f2 = FileHandle::Open("yapf2.txt"sv, "wt");
|
||||
assert(f1.has_value());
|
||||
assert(f2.has_value());
|
||||
fwrite(dmp1.m_out.c_str(), 1, dmp1.m_out.size(), *f1);
|
||||
fwrite(dmp2.m_out.c_str(), 1, dmp2.m_out.size(), *f2);
|
||||
fwrite(dmp1.m_out.data(), 1, dmp1.m_out.size(), *f1);
|
||||
fwrite(dmp2.m_out.data(), 1, dmp2.m_out.size(), *f2);
|
||||
}
|
||||
|
||||
template <class Types>
|
||||
|
|
|
@ -1043,7 +1043,7 @@ static void SlStdString(void *ptr, VarType conv)
|
|||
case SLA_SAVE: {
|
||||
size_t len = str->length();
|
||||
SlWriteArrayLength(len);
|
||||
SlCopyBytes(const_cast<void *>(static_cast<const void *>(str->c_str())), len);
|
||||
SlCopyBytes(const_cast<void *>(static_cast<const void *>(str->data())), len);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ void Script_CreateDummyInfo(HSQUIRRELVM vm, std::string_view type, std::string_v
|
|||
sq_pushroottable(vm);
|
||||
|
||||
/* Load and run the script */
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script.c_str(), dummy_script.size(), "dummy", SQTrue))) {
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script.data(), dummy_script.size(), "dummy", SQTrue))) {
|
||||
sq_push(vm, -2);
|
||||
if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
|
||||
sq_pop(vm, 1);
|
||||
|
@ -101,7 +101,7 @@ void Script_CreateDummy(HSQUIRRELVM vm, StringID string, std::string_view type)
|
|||
|
||||
/* 3) Finally we load and run the script */
|
||||
sq_pushroottable(vm);
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script.c_str(), dummy_script.size(), "dummy", SQTrue))) {
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script.data(), dummy_script.size(), "dummy", SQTrue))) {
|
||||
sq_push(vm, -2);
|
||||
if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
|
||||
sq_pop(vm, 1);
|
||||
|
|
|
@ -64,7 +64,7 @@ static std::optional<std::string> TestScriptAdminMakeJSON(std::string_view squir
|
|||
sq_pop(vm, 1);
|
||||
|
||||
/* Compile the snippet. */
|
||||
REQUIRE(sq_compilebuffer(vm, buffer.c_str(), buffer.size(), "test", SQTrue) == SQ_OK);
|
||||
REQUIRE(sq_compilebuffer(vm, buffer.data(), buffer.size(), "test", SQTrue) == SQ_OK);
|
||||
/* Execute the snippet, capturing the return value. */
|
||||
sq_pushroottable(vm);
|
||||
REQUIRE(sq_call(vm, 1, SQTrue, SQTrue) == SQ_OK);
|
||||
|
|
Loading…
Reference in New Issue