Browse Source

Remove strncmp

pull/5015/head
Gleb Mazovetskiy 4 years ago
parent
commit
643c707c55
  1. 4
      Source/DiabloUI/diabloui.cpp
  2. 2
      Source/automap.cpp
  3. 4
      Source/effects.cpp
  4. 4
      Source/miniwin/miniwin.h
  5. 76
      Source/utils/language.cpp

4
Source/DiabloUI/diabloui.cpp

@ -185,13 +185,13 @@ void UiInitList_clear()
void UiPlayMoveSound()
{
if (gfnSoundFunction != nullptr)
gfnSoundFunction("sfx\\items\\titlemov.wav");
gfnSoundFunction("Sfx\\Items\\Titlemov.wav");
}
void UiPlaySelectSound()
{
if (gfnSoundFunction != nullptr)
gfnSoundFunction("sfx\\items\\titlslct.wav");
gfnSoundFunction("Sfx\\Items\\Titlslct.wav");
}
namespace {

2
Source/automap.cpp

@ -480,7 +480,7 @@ void DrawAutomapText(const Surface &out)
Point linePosition { 8, 8 };
if (gbIsMultiplayer) {
if (strcasecmp("0.0.0.0", szPlayerName) != 0) {
if (string_view("0.0.0.0") != szPlayerName) {
std::string description = std::string(_("Game: "));
description.append(szPlayerName);
DrawString(out, description, linePosition);

4
Source/effects.cpp

@ -1316,8 +1316,8 @@ void effects_play_sound(const char *sndFile)
return;
}
for (auto &sfx : sgSFX) {
if (strcasecmp(sfx.pszName, sndFile) == 0 && sfx.pSnd != nullptr) {
for (TSFX &sfx : sgSFX) {
if (sfx.pSnd != nullptr && string_view(sfx.pszName) == sndFile) {
if (!sfx.pSnd->isPlaying())
snd_play_snd(sfx.pSnd.get(), 0, 0);

4
Source/miniwin/miniwin.h

@ -6,8 +6,4 @@ namespace devilution {
#define MAX_PATH 260
#endif
#ifdef _MSC_VER
#define strcasecmp _stricmp
#endif
} // namespace devilution

76
Source/utils/language.cpp

@ -91,29 +91,6 @@ void SwapLE(MoEntry &entry)
entry.offset = SDL_SwapLE32(entry.offset);
}
char *StrTrimLeft(char *s)
{
while (*s != '\0' && isblank(*s) != 0) {
s++;
}
return s;
}
char *StrTrimRight(char *s)
{
size_t length = strlen(s);
while (length != 0) {
length--;
if (isblank(s[length]) != 0) {
s[length] = '\0';
} else {
break;
}
}
return s;
}
string_view TrimLeft(string_view str)
{
str.remove_prefix(std::min(str.find_first_not_of(" \t"), str.size()));
@ -220,19 +197,23 @@ void SetPluralForm(string_view expression)
/**
* Parse "nplurals=2;"
*/
void ParsePluralForms(const char *string)
void ParsePluralForms(string_view string)
{
const char *value = strstr(string, "nplurals");
if (value == nullptr)
const string_view pluralsKey = "nplurals";
const string_view::size_type pluralsPos = string.find(pluralsKey);
if (pluralsPos == string_view::npos)
return;
string.remove_prefix(pluralsPos + pluralsKey.size());
value = strstr(value, "=");
if (value == nullptr)
const string_view::size_type eqPos = string.find('=');
if (eqPos == string_view::npos)
return;
value += 1;
string_view value = string.substr(eqPos + 1);
if (value.empty() || value[0] < '0')
return;
const unsigned nplurals = SDL_atoi(value);
const unsigned nplurals = value[0] - '0';
if (nplurals == 0)
return;
@ -241,36 +222,25 @@ void ParsePluralForms(const char *string)
SetPluralForm(value);
}
void ParseMetadata(char *ptr)
void ParseMetadata(string_view metadata)
{
char *delim;
while ((ptr != nullptr) && ((delim = strstr(ptr, ":")) != nullptr)) {
char *key = StrTrimLeft(ptr);
char *val = StrTrimLeft(delim + 1);
// null-terminate key
*delim = '\0';
string_view::size_type delim;
// progress to next line (if any)
if ((ptr = strstr(val, "\n")) != nullptr) {
*ptr = '\0';
ptr++;
}
val = StrTrimRight(val);
while (!metadata.empty() && ((delim = metadata.find(':')) != string_view::npos)) {
const string_view key = TrimLeft(string_view(metadata.data(), delim));
string_view val = TrimLeft(string_view(metadata.data() + delim + 1, metadata.size() - delim - 1));
if ((strcmp("Content-Type", key) == 0) && ((delim = strstr(val, "=")) != nullptr)) {
if (strcasecmp(delim + 1, "utf-8") != 0) {
Log("Translation is now UTF-8 encoded!");
}
continue;
if ((delim = val.find('\n')) != string_view::npos) {
val = string_view(val.data(), delim);
metadata.remove_prefix(val.data() - metadata.data() + val.size() + 1);
} else {
metadata.remove_prefix(metadata.size());
}
// Match "Plural-Forms: nplurals=2; plural=(n != 1);"
if (strcmp("Plural-Forms", key) == 0) {
if (key == "Plural-Forms") {
ParsePluralForms(val);
continue;
break;
}
}
}

Loading…
Cancel
Save