1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 00:32:49 +00:00

Merge branch 'string_view' into 'master'

Move a couple of files from `const std::string&` to `std::string_view`

See merge request OpenMW/openmw!1901
This commit is contained in:
psi29a 2022-05-22 10:45:35 +00:00
commit 8dd3e53a30
6 changed files with 14 additions and 17 deletions

View File

@ -284,7 +284,7 @@ void loadCell(const Arguments& info, ESM::Cell &cell, ESM::ESMReader &esm, ESMDa
}
}
void printRawTes3(const std::string& path)
void printRawTes3(std::string_view path)
{
std::cout << "TES3 RAW file listing: " << path << '\n';
ESM::ESMReader esm;

View File

@ -84,7 +84,7 @@ void ESMReader::resolveParentFileIndices(const std::vector<ESMReader>& allPlugin
}
}
void ESMReader::openRaw(std::unique_ptr<std::istream>&& stream, const std::string& name)
void ESMReader::openRaw(std::unique_ptr<std::istream>&& stream, std::string_view name)
{
close();
mEsm = std::move(stream);
@ -94,9 +94,9 @@ void ESMReader::openRaw(std::unique_ptr<std::istream>&& stream, const std::strin
mEsm->seekg(0, mEsm->beg);
}
void ESMReader::openRaw(const std::string& filename)
void ESMReader::openRaw(std::string_view filename)
{
openRaw(Files::openBinaryInputFileStream(filename), filename);
openRaw(Files::openBinaryInputFileStream(std::string(filename)), filename);
}
void ESMReader::open(std::unique_ptr<std::istream>&& stream, const std::string &name)

View File

@ -61,7 +61,7 @@ public:
/// Raw opening. Opens the file and sets everything up but doesn't
/// parse the header.
void openRaw(std::unique_ptr<std::istream>&& stream, const std::string &name);
void openRaw(std::unique_ptr<std::istream>&& stream, std::string_view name);
/// Load ES file from a new stream, parses the header. Closes the
/// currently open file first, if any.
@ -69,7 +69,7 @@ public:
void open(const std::string &file);
void openRaw(const std::string &filename);
void openRaw(std::string_view filename);
/// Get the current position in the file. Make sure that the file has been opened!
size_t getFileOffset() const { return mEsm->tellg(); };

View File

@ -292,12 +292,9 @@ namespace Shader
}
const char* defaultTextures[] = { "diffuseMap", "normalMap", "emissiveMap", "darkMap", "detailMap", "envMap", "specularMap", "decalMap", "bumpMap", "glossMap" };
bool isTextureNameRecognized(const std::string& name)
bool isTextureNameRecognized(std::string_view name)
{
for (unsigned int i=0; i<sizeof(defaultTextures)/sizeof(defaultTextures[0]); ++i)
if (name == defaultTextures[i])
return true;
return false;
return std::find(std::begin(defaultTextures), std::end(defaultTextures), name) != std::end(defaultTextures);
}
void ShaderVisitor::applyStateSet(osg::ref_ptr<osg::StateSet> stateset, osg::Node& node)

View File

@ -348,7 +348,7 @@ std::string_view Utf8Encoder::getLegacyEnc(std::string_view input)
return mImpl.getLegacyEnc(input, BufferAllocationPolicy::UseGrowFactor, mBuffer);
}
ToUTF8::FromType ToUTF8::calculateEncoding(const std::string& encodingName)
ToUTF8::FromType ToUTF8::calculateEncoding(std::string_view encodingName)
{
if (encodingName == "win1250")
return ToUTF8::WINDOWS_1250;
@ -357,10 +357,10 @@ ToUTF8::FromType ToUTF8::calculateEncoding(const std::string& encodingName)
else if (encodingName == "win1252")
return ToUTF8::WINDOWS_1252;
else
throw std::runtime_error(std::string("Unknown encoding '") + encodingName + std::string("', see openmw --help for available options."));
throw std::runtime_error("Unknown encoding '" + std::string(encodingName) + "', see openmw --help for available options.");
}
std::string ToUTF8::encodingUsingMessage(const std::string& encodingName)
std::string ToUTF8::encodingUsingMessage(std::string_view encodingName)
{
if (encodingName == "win1250")
return "Using Central and Eastern European font encoding.";
@ -369,5 +369,5 @@ std::string ToUTF8::encodingUsingMessage(const std::string& encodingName)
else if (encodingName == "win1252")
return "Using default (English) font encoding.";
else
throw std::runtime_error(std::string("Unknown encoding '") + encodingName + std::string("', see openmw --help for available options."));
throw std::runtime_error("Unknown encoding '" + std::string(encodingName) + "', see openmw --help for available options.");
}

View File

@ -24,8 +24,8 @@ namespace ToUTF8
UseGrowFactor,
};
FromType calculateEncoding(const std::string& encodingName);
std::string encodingUsingMessage(const std::string& encodingName);
FromType calculateEncoding(std::string_view encodingName);
std::string encodingUsingMessage(std::string_view encodingName);
class StatelessUtf8Encoder
{