Skip to content

Commit

Permalink
Remove utils/stdcompat/string_view.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Aug 14, 2023
1 parent 8ebe2e0 commit 8c1a847
Show file tree
Hide file tree
Showing 95 changed files with 806 additions and 823 deletions.
2 changes: 1 addition & 1 deletion Source/DiabloUI/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CreditsRenderer {
CreditsRenderer(char const *const *text, std::size_t textLines)
{
for (size_t i = 0; i < textLines; i++) {
string_view orgText = _(text[i]);
std::string_view orgText = _(text[i]);

uint16_t offset = 0;
size_t indexFirstNotTab = 0;
Expand Down
8 changes: 4 additions & 4 deletions Source/DiabloUI/diabloui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ void UiDestroy()
UnloadUiGFX();
}

bool UiValidPlayerName(string_view name)
bool UiValidPlayerName(std::string_view name)
{
if (name.empty())
return false;
Expand All @@ -655,7 +655,7 @@ bool UiValidPlayerName(string_view name)
if (!c_all_of(name, IsBasicLatin))
return false;

string_view bannedNames[] = {
std::string_view bannedNames[] = {
"gvdl",
"dvou",
"tiju",
Expand All @@ -670,8 +670,8 @@ bool UiValidPlayerName(string_view name)
for (char &character : buffer)
character++;

string_view tempName { buffer };
for (string_view bannedName : bannedNames) {
std::string_view tempName { buffer };
for (std::string_view bannedName : bannedNames) {
if (tempName.find(bannedName) != tempName.npos)
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DiabloUI/diabloui.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void UiDestroy();
void UiTitleDialog();
void UnloadUiGFX();
void UiInitialize();
bool UiValidPlayerName(string_view name); /* check */
bool UiValidPlayerName(std::string_view name); /* check */
void UiSelHeroMultDialog(bool (*fninfo)(bool (*fninfofunc)(_uiheroinfo *)), bool (*fncreate)(_uiheroinfo *), bool (*fnremove)(_uiheroinfo *), void (*fnstats)(unsigned int, _uidefaultstats *), _selhero_selections *dlgresult, uint32_t *saveNumber);
void UiSelHeroSingDialog(bool (*fninfo)(bool (*fninfofunc)(_uiheroinfo *)), bool (*fncreate)(_uiheroinfo *), bool (*fnremove)(_uiheroinfo *), void (*fnstats)(unsigned int, _uidefaultstats *), _selhero_selections *dlgresult, uint32_t *saveNumber, _difficulty *difficulty);
bool UiCreditsDialog();
Expand Down
12 changes: 6 additions & 6 deletions Source/DiabloUI/dialogs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "DiabloUI/dialogs.h"

#include <cstdint>
#include <string_view>
#include <utility>

#include "DiabloUI/button.h"
Expand All @@ -17,7 +18,6 @@
#include "utils/display.h"
#include "utils/language.h"
#include "utils/log.hpp"
#include "utils/stdcompat/string_view.hpp"

namespace devilution {

Expand Down Expand Up @@ -54,7 +54,7 @@ OptionalClxSprite LoadDialogSprite(bool hasCaption, bool isError)
return (*ownedDialogSprite)[0];
}

bool Init(string_view caption, string_view text, bool error, bool renderBehind)
bool Init(std::string_view caption, std::string_view text, bool error, bool renderBehind)
{
if (!renderBehind) {
if (!UiLoadBlackBackground()) {
Expand Down Expand Up @@ -137,7 +137,7 @@ void DialogLoop(const std::vector<std::unique_ptr<UiItemBase>> &items, const std
} while (!dialogEnd);
}

void UiOkDialog(string_view caption, string_view text, bool error, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind)
void UiOkDialog(std::string_view caption, std::string_view text, bool error, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind)
{
static bool inDialog = false;

Expand Down Expand Up @@ -183,17 +183,17 @@ void UiOkDialog(string_view caption, string_view text, bool error, const std::ve

} // namespace

void UiErrorOkDialog(string_view caption, string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind)
void UiErrorOkDialog(std::string_view caption, std::string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind)
{
UiOkDialog(caption, text, /*error=*/true, renderBehind);
}

void UiErrorOkDialog(string_view caption, string_view text, bool error)
void UiErrorOkDialog(std::string_view caption, std::string_view text, bool error)
{
UiOkDialog(caption, text, error, vecNULL);
}

void UiErrorOkDialog(string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind)
void UiErrorOkDialog(std::string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind)
{
UiErrorOkDialog({}, text, renderBehind);
}
Expand Down
6 changes: 3 additions & 3 deletions Source/DiabloUI/dialogs.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include <cstddef>
#include <string_view>

#include "DiabloUI/ui_item.h"
#include "utils/stdcompat/string_view.hpp"

namespace devilution {

void UiErrorOkDialog(string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind);
void UiErrorOkDialog(string_view caption, string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind);
void UiErrorOkDialog(std::string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind);
void UiErrorOkDialog(std::string_view caption, std::string_view text, const std::vector<std::unique_ptr<UiItemBase>> &renderBehind);

} // namespace devilution
6 changes: 3 additions & 3 deletions Source/DiabloUI/multi/selgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool IsGameCompatible(const GameData &data)
static std::string GetErrorMessageIncompatibility(const GameData &data)
{
if (data.programid != GAME_ID) {
string_view gameMode;
std::string_view gameMode;
switch (data.programid) {
case GameIdDiabloFull:
gameMode = _("Diablo");
Expand All @@ -103,7 +103,7 @@ static std::string GetErrorMessageIncompatibility(const GameData &data)
}
}

void UiInitGameSelectionList(string_view search)
void UiInitGameSelectionList(std::string_view search)
{
selgame_enteringGame = false;
selgame_selectedGame = 0;
Expand Down Expand Up @@ -228,7 +228,7 @@ void selgame_GameSelection_Focus(int value)
std::string infoString = std::string(_("Join the public game already in progress."));
infoString.append("\n\n");
if (IsGameCompatible(gameInfo.gameData)) {
string_view difficulty;
std::string_view difficulty;
switch (gameInfo.gameData.nDifficulty) {
case DIFF_NORMAL:
difficulty = _("Normal");
Expand Down
2 changes: 1 addition & 1 deletion Source/DiabloUI/settingsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void UiSettingsMenu()

optionDescription[0] = '\0';

string_view titleText;
std::string_view titleText;
switch (shownMenu) {
case ShownMenuType::Categories:
titleText = _("Settings");
Expand Down
30 changes: 15 additions & 15 deletions Source/DiabloUI/ui_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class UiArtText : public UiItemBase {
{
}

[[nodiscard]] string_view GetText() const
[[nodiscard]] std::string_view GetText() const
{
if (text_ != nullptr)
return text_;
Expand Down Expand Up @@ -227,7 +227,7 @@ class UiArtTextButton : public UiItemBase {
public:
using Callback = void (*)();

UiArtTextButton(string_view text, Callback action, SDL_Rect rect, UiFlags flags = UiFlags::None)
UiArtTextButton(std::string_view text, Callback action, SDL_Rect rect, UiFlags flags = UiFlags::None)
: UiItemBase(UiType::ArtTextButton, rect, flags)
, text_(text)
, action_(action)
Expand All @@ -239,7 +239,7 @@ class UiArtTextButton : public UiItemBase {
UiItemBase::SetFlags(flags);
}

[[nodiscard]] string_view GetText() const
[[nodiscard]] std::string_view GetText() const
{
return text_;
}
Expand All @@ -250,15 +250,15 @@ class UiArtTextButton : public UiItemBase {
}

private:
string_view text_;
std::string_view text_;
Callback action_;
};

//=============================================================================

class UiEdit : public UiItemBase {
public:
UiEdit(string_view hint, char *value, std::size_t maxLength, bool allowEmpty, SDL_Rect rect, UiFlags flags = UiFlags::None)
UiEdit(std::string_view hint, char *value, std::size_t maxLength, bool allowEmpty, SDL_Rect rect, UiFlags flags = UiFlags::None)
: UiItemBase(UiType::Edit, rect, flags)
, m_hint(hint)
, m_value(value)
Expand All @@ -268,7 +268,7 @@ class UiEdit : public UiItemBase {
}

// private:
string_view m_hint;
std::string_view m_hint;
char *m_value;
std::size_t m_max_length;
bool m_allowEmpty;
Expand All @@ -280,19 +280,19 @@ class UiEdit : public UiItemBase {

class UiText : public UiItemBase {
public:
UiText(string_view text, SDL_Rect rect, UiFlags flags = UiFlags::ColorDialogWhite)
UiText(std::string_view text, SDL_Rect rect, UiFlags flags = UiFlags::ColorDialogWhite)
: UiItemBase(UiType::Text, rect, flags)
, text_(text)
{
}

[[nodiscard]] string_view GetText() const
[[nodiscard]] std::string_view GetText() const
{
return text_;
}

private:
string_view text_;
std::string_view text_;
};

//=============================================================================
Expand All @@ -303,15 +303,15 @@ class UiButton : public UiItemBase {
public:
using Callback = void (*)();

UiButton(string_view text, Callback action, SDL_Rect rect, UiFlags flags = UiFlags::None)
UiButton(std::string_view text, Callback action, SDL_Rect rect, UiFlags flags = UiFlags::None)
: UiItemBase(UiType::Button, rect, flags)
, text_(text)
, action_(action)
, pressed_(false)
{
}

[[nodiscard]] string_view GetText() const
[[nodiscard]] std::string_view GetText() const
{
return text_;
}
Expand All @@ -337,7 +337,7 @@ class UiButton : public UiItemBase {
}

private:
string_view text_;
std::string_view text_;
Callback action_;

// State
Expand All @@ -348,14 +348,14 @@ class UiButton : public UiItemBase {

class UiListItem {
public:
UiListItem(string_view text = "", int value = 0, UiFlags uiFlags = UiFlags::None)
UiListItem(std::string_view text = "", int value = 0, UiFlags uiFlags = UiFlags::None)
: m_text(text)
, m_value(value)
, uiFlags(uiFlags)
{
}

UiListItem(string_view text, std::vector<DrawStringFormatArg> &args, int value = 0, UiFlags uiFlags = UiFlags::None)
UiListItem(std::string_view text, std::vector<DrawStringFormatArg> &args, int value = 0, UiFlags uiFlags = UiFlags::None)
: m_text(text)
, args(args)
, m_value(value)
Expand All @@ -364,7 +364,7 @@ class UiListItem {
}

// private:
string_view m_text;
std::string_view m_text;
std::vector<DrawStringFormatArg> args;
int m_value;
UiFlags uiFlags;
Expand Down
8 changes: 4 additions & 4 deletions Source/appfat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void FreeDlg()

} // namespace

void app_fatal(string_view str)
void app_fatal(std::string_view str)
{
FreeDlg();
UiErrorOkDialog(_("Error"), str);
Expand All @@ -60,7 +60,7 @@ void assert_fail(int nLineNo, const char *pszFile, const char *pszFail)
}
#endif

void ErrDlg(const char *title, string_view error, string_view logFilePath, int logLineNr)
void ErrDlg(const char *title, std::string_view error, std::string_view logFilePath, int logLineNr)
{
FreeDlg();

Expand All @@ -70,7 +70,7 @@ void ErrDlg(const char *title, string_view error, string_view logFilePath, int l
diablo_quit(1);
}

void InsertCDDlg(string_view archiveName)
void InsertCDDlg(std::string_view archiveName)
{
std::string text = fmt::format(
fmt::runtime(_("Unable to open main data archive ({:s}).\n"
Expand All @@ -82,7 +82,7 @@ void InsertCDDlg(string_view archiveName)
diablo_quit(1);
}

void DirErrorDlg(string_view error)
void DirErrorDlg(std::string_view error)
{
std::string text = fmt::format(fmt::runtime(_(/* TRANSLATORS: Error when Program is not allowed to write data */ "Unable to write to location:\n{:s}")), error);

Expand Down
11 changes: 6 additions & 5 deletions Source/appfat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
#pragma once

#include <string_view>

#include <SDL.h>

#include "utils/attributes.h"
#include "utils/stdcompat/string_view.hpp"

namespace devilution {

Expand All @@ -26,7 +27,7 @@ namespace devilution {
* @brief Terminates the game and displays an error message box.
* @param str Error message.
*/
[[noreturn]] void app_fatal(string_view str);
[[noreturn]] void app_fatal(std::string_view str);

#ifdef _DEBUG
/**
Expand All @@ -40,16 +41,16 @@ namespace devilution {
/**
* @brief Terminates the game and displays an error dialog box based on the given dialog_id.
*/
[[noreturn]] void ErrDlg(const char *title, string_view error, string_view logFilePath, int logLineNr);
[[noreturn]] void ErrDlg(const char *title, std::string_view error, std::string_view logFilePath, int logLineNr);

/**
* @brief Terminates the game with an insert CD error dialog.
*/
[[noreturn]] void InsertCDDlg(string_view archiveName);
[[noreturn]] void InsertCDDlg(std::string_view archiveName);

/**
* @brief Terminates the game with a read-only directory error dialog.
*/
[[noreturn]] void DirErrorDlg(string_view error);
[[noreturn]] void DirErrorDlg(std::string_view error);

} // namespace devilution
2 changes: 1 addition & 1 deletion Source/automap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ void DrawAutomapText(const Surface &out)

DrawString(out, description, linePosition);
linePosition.y += 15;
string_view difficulty;
std::string_view difficulty;
switch (sgGameInitInfo.nDifficulty) {
case DIFF_NORMAL:
difficulty = _("Normal");
Expand Down
Loading

0 comments on commit 8c1a847

Please sign in to comment.