mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-02 13:01:18 +12:00
Replace basic_string<> of betype with std::vector (#1601)
This commit is contained in:
parent
2f02fda9ea
commit
c8ffff8f41
6 changed files with 25 additions and 17 deletions
|
@ -132,7 +132,7 @@ namespace iosu
|
||||||
|
|
||||||
void convertMultiByteStringToBigEndianWidechar(const char* input, uint16be* output, sint32 maxOutputLength)
|
void convertMultiByteStringToBigEndianWidechar(const char* input, uint16be* output, sint32 maxOutputLength)
|
||||||
{
|
{
|
||||||
std::basic_string<uint16be> beStr = StringHelpers::FromUtf8(input);
|
std::vector<uint16be> beStr = StringHelpers::FromUtf8(input);
|
||||||
if (beStr.size() >= maxOutputLength - 1)
|
if (beStr.size() >= maxOutputLength - 1)
|
||||||
beStr.resize(maxOutputLength-1);
|
beStr.resize(maxOutputLength-1);
|
||||||
for (size_t i = 0; i < beStr.size(); i++)
|
for (size_t i = 0; i < beStr.size(); i++)
|
||||||
|
@ -723,7 +723,7 @@ namespace iosu
|
||||||
{
|
{
|
||||||
if(numVecIn != 0 || numVecOut != 1)
|
if(numVecIn != 0 || numVecOut != 1)
|
||||||
return FPResult_InvalidIPCParam;
|
return FPResult_InvalidIPCParam;
|
||||||
std::basic_string<uint16be> myComment;
|
std::vector<uint16be> myComment;
|
||||||
if(g_fpd.nexFriendSession)
|
if(g_fpd.nexFriendSession)
|
||||||
{
|
{
|
||||||
if(vecOut->size != MY_COMMENT_LENGTH * sizeof(uint16be))
|
if(vecOut->size != MY_COMMENT_LENGTH * sizeof(uint16be))
|
||||||
|
@ -735,8 +735,8 @@ namespace iosu
|
||||||
g_fpd.nexFriendSession->getMyComment(myNexComment);
|
g_fpd.nexFriendSession->getMyComment(myNexComment);
|
||||||
myComment = StringHelpers::FromUtf8(myNexComment.commentString);
|
myComment = StringHelpers::FromUtf8(myNexComment.commentString);
|
||||||
}
|
}
|
||||||
myComment.insert(0, 1, '\0');
|
myComment.insert(myComment.begin(), '\0');
|
||||||
memcpy(vecOut->basePhys.GetPtr(), myComment.c_str(), MY_COMMENT_LENGTH * sizeof(uint16be));
|
memcpy(vecOut->basePhys.GetPtr(), myComment.data(), MY_COMMENT_LENGTH * sizeof(uint16be));
|
||||||
return FPResult_Ok;
|
return FPResult_Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,8 @@ namespace nn
|
||||||
|
|
||||||
if (name.size() != 0)
|
if (name.size() != 0)
|
||||||
{
|
{
|
||||||
auto name_utf16 = StringHelpers::FromUtf8(name).substr(0, 128);
|
auto name_utf16 = StringHelpers::FromUtf8(name);
|
||||||
|
name_utf16.resize(std::min<size_t>(name_utf16.size(), 128));
|
||||||
if (name_utf16.size() != 0)
|
if (name_utf16.size() != 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < name_utf16.size(); i++)
|
for (int i = 0; i < name_utf16.size(); i++)
|
||||||
|
@ -160,7 +161,8 @@ namespace nn
|
||||||
|
|
||||||
if (description.size() != 0)
|
if (description.size() != 0)
|
||||||
{
|
{
|
||||||
auto description_utf16 = StringHelpers::FromUtf8(description).substr(0, 256);
|
auto description_utf16 = StringHelpers::FromUtf8(description);
|
||||||
|
description_utf16.resize(std::min<size_t>(description_utf16.size(), 256));
|
||||||
if (description_utf16.size() != 0)
|
if (description_utf16.size() != 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < description_utf16.size(); i++)
|
for (int i = 0; i < description_utf16.size(); i++)
|
||||||
|
@ -206,7 +208,8 @@ namespace nn
|
||||||
|
|
||||||
if (screen_name.size() != 0)
|
if (screen_name.size() != 0)
|
||||||
{
|
{
|
||||||
auto screen_name_utf16 = StringHelpers::FromUtf8(screen_name).substr(0, 32);
|
auto screen_name_utf16 = StringHelpers::FromUtf8(screen_name);
|
||||||
|
screen_name_utf16.resize(std::min<size_t>(screen_name_utf16.size(), 32));
|
||||||
if (screen_name_utf16.size() != 0)
|
if (screen_name_utf16.size() != 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < screen_name_utf16.size(); i++)
|
for (int i = 0; i < screen_name_utf16.size(); i++)
|
||||||
|
|
|
@ -250,7 +250,8 @@ namespace nn
|
||||||
|
|
||||||
if (name.size() != 0)
|
if (name.size() != 0)
|
||||||
{
|
{
|
||||||
auto name_utf16 = StringHelpers::FromUtf8(name).substr(0, 128);
|
auto name_utf16 = StringHelpers::FromUtf8(name);
|
||||||
|
name_utf16.resize(std::min<size_t>(name_utf16.size(), 128));
|
||||||
if (name_utf16.size() != 0)
|
if (name_utf16.size() != 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < name_utf16.size(); i++)
|
for (int i = 0; i < name_utf16.size(); i++)
|
||||||
|
@ -265,7 +266,8 @@ namespace nn
|
||||||
|
|
||||||
if (description.size() != 0)
|
if (description.size() != 0)
|
||||||
{
|
{
|
||||||
auto description_utf16 = StringHelpers::FromUtf8(description).substr(0, 256);
|
auto description_utf16 = StringHelpers::FromUtf8(description);
|
||||||
|
description_utf16.resize(std::min<size_t>(description_utf16.size(), 256));
|
||||||
if (description_utf16.size() != 0)
|
if (description_utf16.size() != 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < description_utf16.size(); i++)
|
for (int i = 0; i < description_utf16.size(); i++)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "nn_olv_UploadFavoriteTypes.h"
|
#include "nn_olv_UploadFavoriteTypes.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace nn
|
namespace nn
|
||||||
{
|
{
|
||||||
|
@ -115,7 +116,8 @@ namespace nn
|
||||||
|
|
||||||
if (name.size() != 0)
|
if (name.size() != 0)
|
||||||
{
|
{
|
||||||
auto name_utf16 = StringHelpers::FromUtf8(name).substr(0, 128);
|
auto name_utf16 = StringHelpers::FromUtf8(name);
|
||||||
|
name_utf16.resize(std::min<size_t>(name_utf16.size(), 128));
|
||||||
if (name_utf16.size() != 0)
|
if (name_utf16.size() != 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < name_utf16.size(); i++)
|
for (int i = 0; i < name_utf16.size(); i++)
|
||||||
|
@ -130,7 +132,8 @@ namespace nn
|
||||||
|
|
||||||
if (description.size() != 0)
|
if (description.size() != 0)
|
||||||
{
|
{
|
||||||
auto description_utf16 = StringHelpers::FromUtf8(description).substr(0, 256);
|
auto description_utf16 = StringHelpers::FromUtf8(description);
|
||||||
|
description_utf16.resize(std::min<size_t>(description_utf16.size(), 256));
|
||||||
if (description_utf16.size() != 0)
|
if (description_utf16.size() != 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < description_utf16.size(); i++)
|
for (int i = 0; i < description_utf16.size(); i++)
|
||||||
|
|
|
@ -51,15 +51,15 @@ class CafeWideString // fixed buffer size, null-terminated, PPC wchar_t (16bit b
|
||||||
|
|
||||||
bool assignFromUTF8(std::string_view sv)
|
bool assignFromUTF8(std::string_view sv)
|
||||||
{
|
{
|
||||||
std::basic_string<uint16be> beStr = StringHelpers::FromUtf8(sv);
|
std::vector<uint16be> beStr = StringHelpers::FromUtf8(sv);
|
||||||
if(beStr.length() > N-1)
|
if(beStr.size() > N-1)
|
||||||
{
|
{
|
||||||
memcpy(data, beStr.data(), (N-1)*sizeof(uint16be));
|
memcpy(data, beStr.data(), (N-1)*sizeof(uint16be));
|
||||||
data[N-1] = 0;
|
data[N-1] = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memcpy(data, beStr.data(), beStr.length()*sizeof(uint16be));
|
memcpy(data, beStr.data(), beStr.size()*sizeof(uint16be));
|
||||||
data[beStr.length()] = '\0';
|
data[beStr.size()] = '\0';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,9 +111,9 @@ namespace StringHelpers
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert utf8 string to Wii U big-endian wchar_t string
|
// convert utf8 string to Wii U big-endian wchar_t string
|
||||||
static std::basic_string<uint16be> FromUtf8(std::string_view str)
|
static std::vector<uint16be> FromUtf8(std::string_view str)
|
||||||
{
|
{
|
||||||
std::basic_string<uint16be> tmpStr;
|
std::vector<uint16be> tmpStr;
|
||||||
std::wstring w = boost::nowide::widen(str.data(), str.size());
|
std::wstring w = boost::nowide::widen(str.data(), str.size());
|
||||||
for (auto& c : w)
|
for (auto& c : w)
|
||||||
tmpStr.push_back((uint16)c);
|
tmpStr.push_back((uint16)c);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue