diff --git a/src/async_handler.cpp b/src/async_handler.cpp index 46c0857d03..f79e398be4 100644 --- a/src/async_handler.cpp +++ b/src/async_handler.cpp @@ -200,7 +200,7 @@ void AsyncHandler::CreateRequestMapping(const std::string& file) { // Look for Meta.ini files and fetch them. They are required for detecting the translations. for (const auto& item: file_mapping) { - if (StringView(item.first).ends_with("meta.ini")) { + if (EndsWith(item.first, "meta.ini")) { auto* request = AsyncHandler::RequestFile(item.second); request->SetImportantFile(true); request->Start(); @@ -225,7 +225,7 @@ void AsyncHandler::ClearRequests() { async_requests.clear(); } -FileRequestAsync* AsyncHandler::RequestFile(StringView folder_name, StringView file_name) { +FileRequestAsync* AsyncHandler::RequestFile(std::string_view folder_name, std::string_view file_name) { auto path = FileFinder::MakePath(folder_name, file_name); auto* request = GetRequest(path); @@ -239,7 +239,7 @@ FileRequestAsync* AsyncHandler::RequestFile(StringView folder_name, StringView f return RegisterRequest(std::move(path), std::string(folder_name), std::string(file_name)); } -FileRequestAsync* AsyncHandler::RequestFile(StringView file_name) { +FileRequestAsync* AsyncHandler::RequestFile(std::string_view file_name) { return RequestFile(".", file_name); } diff --git a/src/async_handler.h b/src/async_handler.h index 22848eee9a..e96aa9a50c 100644 --- a/src/async_handler.h +++ b/src/async_handler.h @@ -55,7 +55,7 @@ namespace AsyncHandler { * @param file_name Name of the requested file requested. * @return The async request. */ - FileRequestAsync* RequestFile(StringView folder_name, StringView file_name); + FileRequestAsync* RequestFile(std::string_view folder_name, std::string_view file_name); /** * Creates a request to a file. @@ -67,7 +67,7 @@ namespace AsyncHandler { * @param file_name Name of the requested file requested. * @return The async request. */ - FileRequestAsync* RequestFile(StringView file_name); + FileRequestAsync* RequestFile(std::string_view file_name); /** * Checks if any file with important-flag hasn't finished downloading yet. diff --git a/src/async_op.h b/src/async_op.h index 3d5265e218..847bdf3106 100644 --- a/src/async_op.h +++ b/src/async_op.h @@ -172,7 +172,7 @@ class AsyncOp { * @return the new name of the event * @pre If GetType() is not eCloneMapEvent, the return value is undefined. */ - StringView GetEventName() const; + std::string_view GetEventName() const; private: Type _type = eNone; @@ -254,7 +254,7 @@ inline int AsyncOp::GetY() const { return _args[4]; } -inline StringView AsyncOp::GetEventName() const { +inline std::string_view AsyncOp::GetEventName() const { assert(GetType() == eCloneMapEvent); return _str_arg; } diff --git a/src/audio.cpp b/src/audio.cpp index b8c0e891f0..1ff8d87394 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -139,7 +139,7 @@ std::string AudioInterface::GetFluidsynthSoundfont() const { return cfg.soundfont.Get(); } -void AudioInterface::SetFluidsynthSoundfont(StringView sf) { +void AudioInterface::SetFluidsynthSoundfont(std::string_view sf) { cfg.soundfont.Set(ToString(sf)); MidiDecoder::ChangeFluidsynthSoundfont(sf); } diff --git a/src/audio.h b/src/audio.h index 7a90137997..d8a2d531c2 100644 --- a/src/audio.h +++ b/src/audio.h @@ -153,7 +153,7 @@ struct AudioInterface { void SetNativeMidiEnabled(bool enable); std::string GetFluidsynthSoundfont() const; - void SetFluidsynthSoundfont(StringView sf); + void SetFluidsynthSoundfont(std::string_view sf); protected: Game_ConfigAudio cfg; diff --git a/src/audio_midi.cpp b/src/audio_midi.cpp index 30b52ace25..44bb8b3b88 100644 --- a/src/audio_midi.cpp +++ b/src/audio_midi.cpp @@ -146,7 +146,7 @@ bool MidiDecoder::CheckFluidsynth(std::string& status_message) { return works.fluidsynth; } -void MidiDecoder::ChangeFluidsynthSoundfont(StringView sf_path) { +void MidiDecoder::ChangeFluidsynthSoundfont(std::string_view sf_path) { if (!works.fluidsynth || works.fluidsynth_status.empty()) { // Fluidsynth was not initialized yet or failed, will use the path from the config automatically works.fluidsynth = true; diff --git a/src/audio_midi.h b/src/audio_midi.h index 88a58a0c35..a6cafa074d 100644 --- a/src/audio_midi.h +++ b/src/audio_midi.h @@ -217,7 +217,7 @@ class MidiDecoder { */ static bool CheckFluidsynth(std::string& status_message); - static void ChangeFluidsynthSoundfont(StringView sf_path); + static void ChangeFluidsynthSoundfont(std::string_view sf_path); /** * Checks if WildMidi works. diff --git a/src/audio_secache.cpp b/src/audio_secache.cpp index 72882c39d9..57db3c75ff 100644 --- a/src/audio_secache.cpp +++ b/src/audio_secache.cpp @@ -68,7 +68,7 @@ namespace { } } -std::unique_ptr AudioSeCache::Create(Filesystem_Stream::InputStream stream, StringView name) { +std::unique_ptr AudioSeCache::Create(Filesystem_Stream::InputStream stream, std::string_view name) { auto se = std::make_unique(); se->name = ToString(name); @@ -107,7 +107,7 @@ void AudioSeCache::GetFormat(int& frequency, AudioDecoder::Format& format, int& audio_decoder->GetFormat(frequency, format, channels); } -std::unique_ptr AudioSeCache::GetCachedSe(StringView name) { +std::unique_ptr AudioSeCache::GetCachedSe(std::string_view name) { auto se = std::make_unique(); se->name = ToString(name); @@ -192,7 +192,7 @@ void AudioSeCache::Clear() { cache.clear(); } -StringView AudioSeCache::GetName() const { +std::string_view AudioSeCache::GetName() const { return name; } diff --git a/src/audio_secache.h b/src/audio_secache.h index f2b74f2ce8..0bc288bcf1 100644 --- a/src/audio_secache.h +++ b/src/audio_secache.h @@ -83,7 +83,7 @@ class AudioSeCache { * @param name Name for the cache entry * @return An AudioSeCache instance when the format was detected, otherwise null */ - static std::unique_ptr Create(Filesystem_Stream::InputStream stream, StringView name); + static std::unique_ptr Create(Filesystem_Stream::InputStream stream, std::string_view name); /** * Retrieves the format of the internal audio decoder. @@ -101,7 +101,7 @@ class AudioSeCache { * @param name Cache entry name * @return SE is already in cache, nullptr otherwise */ - static std::unique_ptr GetCachedSe(StringView name); + static std::unique_ptr GetCachedSe(std::string_view name); /** * Retrieves the format of the cached file. @@ -135,7 +135,7 @@ class AudioSeCache { /** * @return name of the cached SE */ - StringView GetName() const; + std::string_view GetName() const; static void Clear(); private: diff --git a/src/autobattle.cpp b/src/autobattle.cpp index 13cb92f03d..9077b464fd 100644 --- a/src/autobattle.cpp +++ b/src/autobattle.cpp @@ -40,7 +40,7 @@ template static void DebugLog(const char*, Args&&...) {} #endif -std::unique_ptr CreateAlgorithm(StringView name) { +std::unique_ptr CreateAlgorithm(std::string_view name) { if (Utils::StrICmp(name, RpgRtImproved::name) == 0) { return std::make_unique(); } diff --git a/src/autobattle.h b/src/autobattle.h index 5b39f32af3..e26f999e23 100644 --- a/src/autobattle.h +++ b/src/autobattle.h @@ -35,7 +35,7 @@ class AlgorithmBase; * @param name of the algo. * @return An auto battle algorithm to be used in battles. */ -std::unique_ptr CreateAlgorithm(StringView name); +std::unique_ptr CreateAlgorithm(std::string_view name); /** * Base class for auto battle algorithm implementations. @@ -48,7 +48,7 @@ class AlgorithmBase { virtual int GetId() const = 0; /** @return the name of this algorithm */ - virtual StringView GetName() const = 0; + virtual std::string_view GetName() const = 0; /** * Calculates the auto battle algorithm and sets the algorithm on source. @@ -74,7 +74,7 @@ class RpgRtCompat: public AlgorithmBase { int GetId() const override { return id; } - StringView GetName() const override { return name; } + std::string_view GetName() const override { return name; } private: void vSetAutoBattleAction(Game_Actor& source) override; }; @@ -90,7 +90,7 @@ class AttackOnly: public AlgorithmBase { int GetId() const override { return id; } - StringView GetName() const override { return name; } + std::string_view GetName() const override { return name; } private: void vSetAutoBattleAction(Game_Actor& source) override; }; @@ -106,7 +106,7 @@ class RpgRtImproved: public AlgorithmBase { int GetId() const override { return id; } - StringView GetName() const override { return name; } + std::string_view GetName() const override { return name; } private: void vSetAutoBattleAction(Game_Actor& source) override; }; diff --git a/src/baseui.h b/src/baseui.h index cb9eaeaf02..fcc8c0aeea 100644 --- a/src/baseui.h +++ b/src/baseui.h @@ -243,7 +243,7 @@ class BaseUi { * @param url URL to open * @return true when successful */ - virtual bool OpenURL(StringView path) { (void)path; return false; } + virtual bool OpenURL(std::string_view path) { (void)path; return false; } /** Toggles "stretch to screen width" on or off */ virtual void ToggleStretch() {}; diff --git a/src/battle_animation.cpp b/src/battle_animation.cpp index 3d854f9e5b..1d572870b9 100644 --- a/src/battle_animation.cpp +++ b/src/battle_animation.cpp @@ -44,7 +44,7 @@ BattleAnimation::BattleAnimation(const lcf::rpg::Animation& anim, bool only_soun SetZ(Priority_BattleAnimation); - StringView name = animation.animation_name; + std::string_view name = animation.animation_name; BitmapRef graphic; if (name.empty()) return; diff --git a/src/battle_message.cpp b/src/battle_message.cpp index 1b89b53f85..9ba4ad9d4e 100644 --- a/src/battle_message.cpp +++ b/src/battle_message.cpp @@ -26,7 +26,7 @@ namespace BattleMessage { -static std::string GetStateMessage(StringView target_name, StringView message) { +static std::string GetStateMessage(std::string_view target_name, std::string_view message) { if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( message, @@ -69,7 +69,7 @@ std::string GetDeathMessage(const Game_Battler& target) { return ""; } -static std::string GetActionFailureMessage(StringView source, StringView target, StringView message) { +static std::string GetActionFailureMessage(std::string_view source, std::string_view target, std::string_view message) { if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( message, @@ -87,7 +87,7 @@ std::string GetPhysicalFailureMessage(const Game_Battler& source, const Game_Bat } std::string GetSkillFailureMessage(const Game_Battler& source, const Game_Battler& target, const lcf::rpg::Skill& skill) { - StringView msg; + std::string_view msg; switch (skill.failure_message) { case 0: msg = lcf::Data::terms.skill_failure_a; @@ -108,10 +108,10 @@ std::string GetSkillFailureMessage(const Game_Battler& source, const Game_Battle } std::string GetUndamagedMessage(const Game_Battler& target) { - StringView name = target.GetName(); - StringView message = (target.GetType() == Game_Battler::Type_Ally) - ? StringView(lcf::Data::terms.actor_undamaged) - : StringView(lcf::Data::terms.enemy_undamaged); + std::string_view name = target.GetName(); + std::string_view message = (target.GetType() == Game_Battler::Type_Ally) + ? std::string_view(lcf::Data::terms.actor_undamaged) + : std::string_view(lcf::Data::terms.enemy_undamaged); if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( @@ -126,9 +126,9 @@ std::string GetUndamagedMessage(const Game_Battler& target) { } std::string GetCriticalHitMessage(const Game_Battler& source, const Game_Battler& target) { - StringView message = (target.GetType() == Game_Battler::Type_Ally) - ? StringView(lcf::Data::terms.actor_critical) - : StringView(lcf::Data::terms.enemy_critical); + std::string_view message = (target.GetType() == Game_Battler::Type_Ally) + ? std::string_view(lcf::Data::terms.actor_critical) + : std::string_view(lcf::Data::terms.enemy_critical); if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( @@ -142,7 +142,7 @@ std::string GetCriticalHitMessage(const Game_Battler& source, const Game_Battler } } -static std::string GetHpSpRecoveredMessage(const Game_Battler& target, int value, StringView points) { +static std::string GetHpSpRecoveredMessage(const Game_Battler& target, int value, std::string_view points) { if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( lcf::Data::terms.hp_recovery, @@ -175,11 +175,11 @@ std::string GetSpRecoveredMessage(const Game_Battler& target, int value) { return GetHpSpRecoveredMessage(target, value, lcf::Data::terms.spirit_points); } -std::string GetParameterAbsorbedMessage(const Game_Battler& source, const Game_Battler& target, int value, StringView points) { +std::string GetParameterAbsorbedMessage(const Game_Battler& source, const Game_Battler& target, int value, std::string_view points) { const auto target_is_ally = (target.GetType() == Game_Battler::Type_Ally); - StringView message = target_is_ally - ? StringView(lcf::Data::terms.actor_hp_absorbed) - : StringView(lcf::Data::terms.enemy_hp_absorbed); + std::string_view message = target_is_ally + ? std::string_view(lcf::Data::terms.actor_hp_absorbed) + : std::string_view(lcf::Data::terms.enemy_hp_absorbed); if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( @@ -232,9 +232,9 @@ std::string GetAgiAbsorbedMessage(const Game_Battler& source, const Game_Battler std::string GetDamagedMessage(const Game_Battler& target, int value) { bool target_is_ally = (target.GetType() == Game_Battler::Type_Ally); - StringView message = target_is_ally - ? StringView(lcf::Data::terms.actor_damaged) - : StringView(lcf::Data::terms.enemy_damaged); + std::string_view message = target_is_ally + ? std::string_view(lcf::Data::terms.actor_damaged) + : std::string_view(lcf::Data::terms.enemy_damaged); if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( @@ -257,16 +257,16 @@ std::string GetDamagedMessage(const Game_Battler& target, int value) { return ss.str(); } -std::string GetParameterChangeMessage(const Game_Battler& target, int value, StringView points) { +std::string GetParameterChangeMessage(const Game_Battler& target, int value, std::string_view points) { const bool is_positive = (value >= 0); value = std::abs(value); if (value == 0) { return ""; } - StringView message = is_positive - ? StringView(lcf::Data::terms.parameter_increase) - : StringView(lcf::Data::terms.parameter_decrease); + std::string_view message = is_positive + ? std::string_view(lcf::Data::terms.parameter_increase) + : std::string_view(lcf::Data::terms.parameter_decrease); if (Feature::HasPlaceholders()) { @@ -320,9 +320,9 @@ std::string GetAttributeShiftMessage(const Game_Battler& target, int value, cons if (value == 0) { return ""; } - StringView message = is_positive - ? StringView(lcf::Data::terms.resistance_increase) - : StringView(lcf::Data::terms.resistance_decrease); + std::string_view message = is_positive + ? std::string_view(lcf::Data::terms.resistance_increase) + : std::string_view(lcf::Data::terms.resistance_decrease); std::stringstream ss; if (Feature::HasPlaceholders()) { @@ -348,7 +348,7 @@ std::string GetAttributeShiftMessage(const Game_Battler& target, int value, cons return ss.str(); } -static std::string GetBasicStartMessage2k(const Game_Battler& source, StringView term) { +static std::string GetBasicStartMessage2k(const Game_Battler& source, std::string_view term) { if (Feature::HasPlaceholders()) { return Utils::ReplacePlaceholders( term, @@ -394,8 +394,8 @@ std::string GetTransformStartMessage(const Game_Battler& source, const lcf::rpg: return ToString(source.GetName()) + ToString(lcf::Data::terms.enemy_transform); } -static std::string GetSkillStartMessageGeneric(const Game_Battler& source, const Game_Battler* target, const lcf::rpg::Skill& skill, StringView usage, bool second_message = false) { - StringView target_name = "???"; +static std::string GetSkillStartMessageGeneric(const Game_Battler& source, const Game_Battler* target, const lcf::rpg::Skill& skill, std::string_view usage, bool second_message = false) { + std::string_view target_name = "???"; if (target && Algo::IsNormalOrSubskill(skill) && Algo::SkillTargetsOne(skill)) { target_name = target->GetName(); } @@ -457,7 +457,7 @@ std::string GetDoubleAttackStartMessage2k3(const Game_Battler& source) { } std::string GetSkillStartMessage2k3(const Game_Battler& source, const Game_Battler* target, const lcf::rpg::Skill& skill) { - StringView target_name = "???"; + std::string_view target_name = "???"; if (target && Algo::IsNormalOrSubskill(skill) && Algo::SkillTargetsOne(skill)) { target_name = target->GetName(); } diff --git a/src/battle_message.h b/src/battle_message.h index e17136d8f1..8631e39836 100644 --- a/src/battle_message.h +++ b/src/battle_message.h @@ -48,7 +48,7 @@ std::string GetHpRecoveredMessage(const Game_Battler& target, int value); std::string GetSpRecoveredMessage(const Game_Battler& target, int value); -std::string GetParameterAbsorbedMessage(const Game_Battler& source, const Game_Battler& target, int value, StringView points); +std::string GetParameterAbsorbedMessage(const Game_Battler& source, const Game_Battler& target, int value, std::string_view points); std::string GetHpAbsorbedMessage(const Game_Battler& source, const Game_Battler& target, int value); @@ -64,7 +64,7 @@ std::string GetAgiAbsorbedMessage(const Game_Battler& source, const Game_Battler std::string GetDamagedMessage(const Game_Battler& target, int value); -std::string GetParameterChangeMessage(const Game_Battler& target, int value, StringView points); +std::string GetParameterChangeMessage(const Game_Battler& target, int value, std::string_view points); std::string GetSpReduceMessage(const Game_Battler& target, int value); diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 9aa6b527ce..89bdf2db8c 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -338,7 +338,7 @@ void Bitmap::HueChangeBlit(int x, int y, Bitmap const& src, Rect const& src_rect Blit(dst_rect.x, dst_rect.y, bmp, bmp.GetRect(), Opacity::Opaque()); } -Point Bitmap::TextDraw(Rect const& rect, int color, StringView text, Text::Alignment align) { +Point Bitmap::TextDraw(Rect const& rect, int color, std::string_view text, Text::Alignment align) { switch (align) { case Text::AlignLeft: return TextDraw(rect.x, rect.y, color, text); @@ -363,13 +363,13 @@ Point Bitmap::TextDraw(Rect const& rect, int color, StringView text, Text::Align return {}; } -Point Bitmap::TextDraw(int x, int y, int color, StringView text, Text::Alignment align) { +Point Bitmap::TextDraw(int x, int y, int color, std::string_view text, Text::Alignment align) { auto f = font ? font : Font::Default(); auto system = Cache::SystemOrBlack(); return Text::Draw(*this, x, y, *f, *system, color, text, align); } -Point Bitmap::TextDraw(Rect const& rect, Color color, StringView text, Text::Alignment align) { +Point Bitmap::TextDraw(Rect const& rect, Color color, std::string_view text, Text::Alignment align) { switch (align) { case Text::AlignLeft: return TextDraw(rect.x, rect.y, color, text); @@ -394,7 +394,7 @@ Point Bitmap::TextDraw(Rect const& rect, Color color, StringView text, Text::Ali return {}; } -Point Bitmap::TextDraw(int x, int y, Color color, StringView text) { +Point Bitmap::TextDraw(int x, int y, Color color, std::string_view text) { auto f = font ? font : Font::Default(); return Text::Draw(*this, x, y, *f, color, text); } diff --git a/src/bitmap.h b/src/bitmap.h index 2e191916d7..c23992a3e3 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -223,7 +223,7 @@ class Bitmap { * * @return Bitmap identifier */ - StringView GetId() const; + std::string_view GetId() const; /** * Sets the identifier of the bitmap. @@ -259,7 +259,7 @@ class Bitmap { * @param align text alignment. * @return Where to draw the next glyph */ - Point TextDraw(int x, int y, int color, StringView text, Text::Alignment align = Text::AlignLeft); + Point TextDraw(int x, int y, int color, std::string_view text, Text::Alignment align = Text::AlignLeft); /** * Draws text to bitmap using the configured Font or the Font::Default() font. @@ -270,7 +270,7 @@ class Bitmap { * @param align text alignment inside bounding rectangle. * @return Where to draw the next glyph */ - Point TextDraw(Rect const& rect, int color, StringView text, Text::Alignment align = Text::AlignLeft); + Point TextDraw(Rect const& rect, int color, std::string_view text, Text::Alignment align = Text::AlignLeft); /** * Draws text to bitmap using the configured Font or the Font::Default() font. @@ -281,7 +281,7 @@ class Bitmap { * @param text text to draw. * @return Where to draw the next glyph */ - Point TextDraw(int x, int y, Color color, StringView text); + Point TextDraw(int x, int y, Color color, std::string_view text); /** * Draws text to bitmap using the configured Font or the Font::Default() font. @@ -291,7 +291,7 @@ class Bitmap { * @param text text to draw. * @param align text alignment inside bounding rectangle. */ - Point TextDraw(Rect const& rect, Color color, StringView, Text::Alignment align = Text::AlignLeft); + Point TextDraw(Rect const& rect, Color color, std::string_view, Text::Alignment align = Text::AlignLeft); /** * Blits source bitmap to this one. @@ -698,7 +698,7 @@ inline bool Bitmap::GetTransparent() const { return format.alpha_type != PF::NoAlpha; } -inline StringView Bitmap::GetId() const { +inline std::string_view Bitmap::GetId() const { return id; } diff --git a/src/cache.cpp b/src/cache.cpp index b9d36d5e4a..79e834f1e4 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -40,11 +40,11 @@ using namespace std::chrono_literals; namespace { - std::string MakeHashKey(StringView folder_name, StringView filename, bool transparent) { + std::string MakeHashKey(std::string_view folder_name, std::string_view filename, bool transparent) { return ToString(folder_name) + ":" + ToString(filename) + ":" + (transparent ? "T" : " "); } - std::string MakeTileHashKey(StringView chipset_name, int id) { + std::string MakeTileHashKey(std::string_view chipset_name, int id) { std::string key; key.reserve(chipset_name.size() + sizeof(int) + 2); key.append(reinterpret_cast(&id), sizeof(id)); @@ -54,7 +54,7 @@ namespace { return key; } - int IdFromTileHash(StringView key) { + int IdFromTileHash(std::string_view key) { int id = 0; if (key.size() > sizeof(id)) { std::memcpy(&id, key.data(), sizeof(id)); @@ -62,7 +62,7 @@ namespace { return id; } - const char* NameFromTileHash(StringView key) { + const char* NameFromTileHash(std::string_view key) { int offset = sizeof(int) + 1; if (static_cast(key.size()) < offset) { return ""; @@ -229,14 +229,14 @@ namespace { } template - BitmapRef LoadDummyBitmap(StringView, StringView, bool) { + BitmapRef LoadDummyBitmap(std::string_view, std::string_view, bool) { static_assert(Material::REND < T && T < Material::END, "Invalid material."); const Spec& s = spec[T]; return s.dummy_renderer(); } template - BitmapRef LoadBitmap(StringView filename, bool transparent) { + BitmapRef LoadBitmap(std::string_view filename, bool transparent) { static_assert(Material::REND < T && T < Material::END, "Invalid material."); const Spec& s = spec[T]; @@ -328,7 +328,7 @@ namespace { } template - BitmapRef LoadBitmap(StringView f) { + BitmapRef LoadBitmap(std::string_view f) { static_assert(Material::REND < T && T < Material::END, "Invalid material."); const Spec& s = spec[T]; return LoadBitmap(f, s.transparent); @@ -337,67 +337,67 @@ namespace { std::vector Cache::exfont_custom; -BitmapRef Cache::Backdrop(StringView file) { +BitmapRef Cache::Backdrop(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Battle(StringView file) { +BitmapRef Cache::Battle(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Battle2(StringView file) { +BitmapRef Cache::Battle2(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Battlecharset(StringView file) { +BitmapRef Cache::Battlecharset(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Battleweapon(StringView file) { +BitmapRef Cache::Battleweapon(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Charset(StringView file) { +BitmapRef Cache::Charset(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Chipset(StringView file) { +BitmapRef Cache::Chipset(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Faceset(StringView file) { +BitmapRef Cache::Faceset(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Frame(StringView file, bool transparent) { +BitmapRef Cache::Frame(std::string_view file, bool transparent) { return LoadBitmap(file, transparent); } -BitmapRef Cache::Gameover(StringView file) { +BitmapRef Cache::Gameover(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Monster(StringView file) { +BitmapRef Cache::Monster(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Panorama(StringView file) { +BitmapRef Cache::Panorama(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Picture(StringView file, bool transparent) { +BitmapRef Cache::Picture(std::string_view file, bool transparent) { return LoadBitmap(file, transparent); } -BitmapRef Cache::System2(StringView file) { +BitmapRef Cache::System2(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::Title(StringView file) { +BitmapRef Cache::Title(std::string_view file) { return LoadBitmap(file); } -BitmapRef Cache::System(StringView file) { +BitmapRef Cache::System(std::string_view file) { return LoadBitmap(file); } @@ -425,7 +425,7 @@ BitmapRef Cache::Exfont() { } } -BitmapRef Cache::Tile(StringView filename, int tile_id) { +BitmapRef Cache::Tile(std::string_view filename, int tile_id) { const auto key = MakeTileHashKey(filename, tile_id); auto it = cache_tiles.find(key); diff --git a/src/cache.h b/src/cache.h index 5ea53a5cf3..9bafd8dd6f 100644 --- a/src/cache.h +++ b/src/cache.h @@ -37,25 +37,25 @@ class Tone; * Cache namespace. */ namespace Cache { - BitmapRef Backdrop(StringView filename); - BitmapRef Battle(StringView filename); - BitmapRef Battle2(StringView filename); - BitmapRef Battlecharset(StringView filename); - BitmapRef Battleweapon(StringView filename); - BitmapRef Charset(StringView filename); + BitmapRef Backdrop(std::string_view filename); + BitmapRef Battle(std::string_view filename); + BitmapRef Battle2(std::string_view filename); + BitmapRef Battlecharset(std::string_view filename); + BitmapRef Battleweapon(std::string_view filename); + BitmapRef Charset(std::string_view filename); BitmapRef Exfont(); - BitmapRef Faceset(StringView filename); - BitmapRef Frame(StringView filename, bool transparent = true); - BitmapRef Gameover(StringView filename); - BitmapRef Monster(StringView filename); - BitmapRef Panorama(StringView filename); - BitmapRef Picture(StringView filename, bool transparent); - BitmapRef Chipset(StringView filename); - BitmapRef Title(StringView filename); - BitmapRef System(StringView filename); - BitmapRef System2(StringView filename); + BitmapRef Faceset(std::string_view filename); + BitmapRef Frame(std::string_view filename, bool transparent = true); + BitmapRef Gameover(std::string_view filename); + BitmapRef Monster(std::string_view filename); + BitmapRef Panorama(std::string_view filename); + BitmapRef Picture(std::string_view filename, bool transparent); + BitmapRef Chipset(std::string_view filename); + BitmapRef Title(std::string_view filename); + BitmapRef System(std::string_view filename); + BitmapRef System2(std::string_view filename); - BitmapRef Tile(StringView filename, int tile_id); + BitmapRef Tile(std::string_view filename, int tile_id); BitmapRef SpriteEffect(const BitmapRef& src_bitmap, const Rect& rect, bool flip_x, bool flip_y, const Tone& tone, const Color& blend); void Clear(); diff --git a/src/config_param.h b/src/config_param.h index 6b5e5e701c..ad803179a0 100644 --- a/src/config_param.h +++ b/src/config_param.h @@ -31,7 +31,7 @@ #include namespace { - inline std::string ParamValueToString(StringView s) { + inline std::string ParamValueToString(std::string_view s) { return ToString(s); } @@ -61,7 +61,7 @@ class ConfigParamBase { * @param description Description shown in the help window of the settings scene * @param value Initial value */ - ConfigParamBase(StringView name, StringView description, StringView config_section, StringView config_key, T value) : + ConfigParamBase(std::string_view name, std::string_view description, std::string_view config_section, std::string_view config_key, T value) : _name(name), _description(description), _config_section(config_section), _config_key(config_key), _value(value) {} /** @return current assigned value */ @@ -160,26 +160,26 @@ class ConfigParamBase { } /** @return name displayed in the settings scene */ - StringView GetName() const { + std::string_view GetName() const { return _name; } /** * @param name new name of the setting */ - void SetName(StringView name) { + void SetName(std::string_view name) { _name = name; } /** @return help text displayed in the settings scene */ - StringView GetDescription() const { + std::string_view GetDescription() const { return _description; } /** * @param description new description of the setting */ - void SetDescription(StringView description) { + void SetDescription(std::string_view description) { _description = description; } @@ -187,7 +187,7 @@ class ConfigParamBase { virtual std::string ValueToString() const = 0; virtual bool FromIni(const lcf::INIReader& ini) { - // FIXME: Migrate IniReader to StringView (or std::string_view with C++17) + // FIXME: Migrate IniReader to std::string_view (or std::string_view with C++17) if (ini.HasValue(ToString(_config_section), ToString(_config_key))) { if constexpr (std::is_same_v) { Set(ini.GetString(ToString(_config_section), ToString(_config_key), T())); @@ -213,10 +213,10 @@ class ConfigParamBase { protected: virtual bool vIsValid(const T& value) const = 0; - StringView _name; - StringView _description; - StringView _config_section; - StringView _config_key; + std::string_view _name; + std::string_view _description; + std::string_view _config_section; + std::string_view _config_key; T _value = {}; private: @@ -228,7 +228,7 @@ class ConfigParamBase { template class ConfigParam : public ConfigParamBase { public: - explicit ConfigParam(StringView name, StringView description, StringView config_section, StringView config_key, T value = {}) : + explicit ConfigParam(std::string_view name, std::string_view description, std::string_view config_section, std::string_view config_key, T value = {}) : ConfigParamBase(name, description, config_section, config_key, std::move(value)) {} bool vIsValid(const T&) const override { @@ -244,7 +244,7 @@ class ConfigParam : public ConfigParamBase { template class LockedConfigParam final : public ConfigParam { public: - explicit LockedConfigParam(StringView name, StringView description, T value = {}) : + explicit LockedConfigParam(std::string_view name, std::string_view description, T value = {}) : ConfigParam(name, description, "", "", value) { this->Lock(value); } @@ -257,11 +257,11 @@ template class RangeConfigParam : public ConfigParamBase { public: /** Construct with name and initial value */ - explicit RangeConfigParam(StringView name, StringView description, StringView config_section, StringView config_key, T value = {}) : + explicit RangeConfigParam(std::string_view name, std::string_view description, std::string_view config_section, std::string_view config_key, T value = {}) : ConfigParamBase(name, description, config_section, config_key, std::move(value)) {} /** Construct with name and initial value, min, and max */ - RangeConfigParam(StringView name, StringView description, StringView config_section, StringView config_key, T value, T minval, T maxval) : + RangeConfigParam(std::string_view name, std::string_view description, std::string_view config_section, std::string_view config_key, T value, T minval, T maxval) : ConfigParamBase(name, description, config_section, config_key, std::move(value)) { SetRange(minval, maxval); } /** @@ -324,7 +324,7 @@ class RangeConfigParam : public ConfigParamBase { /** A boolean configuration parameter */ class BoolConfigParam : public ConfigParamBase { public: - explicit BoolConfigParam(StringView name, StringView description, StringView config_section, StringView config_key, bool value) : + explicit BoolConfigParam(std::string_view name, std::string_view description, std::string_view config_section, std::string_view config_key, bool value) : ConfigParamBase(name, description, config_section, config_key, value) {} bool vIsValid(const bool&) const override { @@ -348,7 +348,7 @@ class BoolConfigParam : public ConfigParamBase { template class EnumConfigParam : public ConfigParamBase { public: - EnumConfigParam(StringView name, StringView description, StringView config_section, StringView config_key, E value, std::array values, std::array tags, std::array value_descriptions) : + EnumConfigParam(std::string_view name, std::string_view description, std::string_view config_section, std::string_view config_key, E value, std::array values, std::array tags, std::array value_descriptions) : ConfigParamBase(name, description, config_section, config_key, value), _values{ values }, _tags{ tags}, _value_descriptions{ value_descriptions } { for (size_t i = 0; i < S; ++i) { _valid[static_cast(i)] = true; @@ -381,15 +381,15 @@ class EnumConfigParam : public ConfigParamBase { return ToString(_values[static_cast(this->_value)]); } - std::array GetValues() const { + std::array GetValues() const { return _values; } - std::array GetDescriptions() const { + std::array GetDescriptions() const { return _value_descriptions; } - bool SetFromString(StringView value) { + bool SetFromString(std::string_view value) { for (size_t i = 0; i < _tags.size(); ++i) { if (value == _tags[i]) { this->Set(static_cast(i)); @@ -420,9 +420,9 @@ class EnumConfigParam : public ConfigParamBase { private: lcf::FlagSet _valid; - std::array _values; - std::array _tags; - std::array _value_descriptions; + std::array _values; + std::array _tags; + std::array _value_descriptions; bool _enabled = true; E GetFirstValid() const { @@ -438,7 +438,7 @@ class EnumConfigParam : public ConfigParamBase { class PathConfigParam : public StringConfigParam { public: - PathConfigParam(StringView name, StringView description, StringView config_section, StringView config_key, std::string value) : + PathConfigParam(std::string_view name, std::string_view description, std::string_view config_section, std::string_view config_key, std::string value) : StringConfigParam(name, description, config_section, config_key, value) {} std::string ValueToString() const override { diff --git a/src/decoder_fluidsynth.cpp b/src/decoder_fluidsynth.cpp index 40461ff230..de1220a868 100644 --- a/src/decoder_fluidsynth.cpp +++ b/src/decoder_fluidsynth.cpp @@ -288,7 +288,7 @@ void FluidSynthDecoder::ResetState() { pending_global_synth.reset(); } -bool FluidSynthDecoder::ChangeGlobalSoundfont(StringView sf_path, std::string& status_message) { +bool FluidSynthDecoder::ChangeGlobalSoundfont(std::string_view sf_path, std::string& status_message) { if (!global_synth) { return false; } diff --git a/src/decoder_fluidsynth.h b/src/decoder_fluidsynth.h index 42c28a9148..dc62c48955 100644 --- a/src/decoder_fluidsynth.h +++ b/src/decoder_fluidsynth.h @@ -46,7 +46,7 @@ class FluidSynthDecoder : public MidiDecoder { static bool Initialize(std::string& status_message); static void ResetState(); - static bool ChangeGlobalSoundfont(StringView sf_path, std::string& status_message); + static bool ChangeGlobalSoundfont(std::string_view sf_path, std::string& status_message); int FillBuffer(uint8_t* buffer, int length) override; diff --git a/src/directory_tree.cpp b/src/directory_tree.cpp index 3397f96fff..3e42bfd161 100644 --- a/src/directory_tree.cpp +++ b/src/directory_tree.cpp @@ -35,7 +35,7 @@ static void DebugLog(const char*, Args&&...) {} #endif namespace { - std::string make_key(StringView n) { + std::string make_key(std::string_view n) { return lcf::ReaderUtil::Normalize(n); }; } @@ -51,24 +51,24 @@ std::unique_ptr DirectoryTree::Create(Filesystem& fs) { return tree; } -bool DirectoryTree::WildcardMatch(const StringView& pattern, const StringView& text) { +bool DirectoryTree::WildcardMatch(const std::string_view& pattern, const std::string_view& text) { // Limitations: * and ? cannot be mixed, * only at beginning and end of string // Pattern and text are already normalized if (pattern.empty() && text.empty()) { return true; } - bool begin_wildcard = pattern.starts_with('*'); - bool end_wildcard = pattern.ends_with('*'); + bool begin_wildcard = StartsWith(pattern, '*'); + bool end_wildcard = EndsWith(pattern, '*'); if ((begin_wildcard || end_wildcard) && text.size() > 0) { // * handling bool found = false; if (begin_wildcard) { - found |= text.ends_with(pattern.substr(1)); + found |= EndsWith(text, pattern.substr(1)); } if (end_wildcard) { - found |= text.starts_with(pattern.substr(0, pattern.size() - 1)); + found |= StartsWith(text, pattern.substr(0, pattern.size() - 1)); } return found; } else { @@ -85,7 +85,7 @@ bool DirectoryTree::WildcardMatch(const StringView& pattern, const StringView& t } } -DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory(StringView path) const { +DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory(std::string_view path) const { std::vector entries; std::string fs_path = ToString(path); @@ -190,7 +190,7 @@ DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory(StringView path) return &Find(fs_cache, dir_key)->second; } -void DirectoryTree::ClearCache(StringView path) const { +void DirectoryTree::ClearCache(std::string_view path) const { DebugLog("ClearCache: {}", path); if (path.empty()) { @@ -210,15 +210,15 @@ void DirectoryTree::ClearCache(StringView path) const { dir_cache.erase(dir_it); } dir_missing_cache.erase(std::remove_if(dir_missing_cache.begin(), dir_missing_cache.end(), [&path] (const auto& dir) { - return StringView(dir).starts_with(path); + return StartsWith(dir, path); }), dir_missing_cache.end()); } -std::string DirectoryTree::FindFile(StringView filename, const Span exts) const { +std::string DirectoryTree::FindFile(std::string_view filename, const Span exts) const { return FindFile({ ToString(filename), exts }); } -std::string DirectoryTree::FindFile(StringView directory, StringView filename, const Span exts) const { +std::string DirectoryTree::FindFile(std::string_view directory, std::string_view filename, const Span exts) const { return FindFile({ FileFinder::MakePath(directory, filename), exts }); } diff --git a/src/directory_tree.h b/src/directory_tree.h index b5d7959846..1af84b9fd7 100644 --- a/src/directory_tree.h +++ b/src/directory_tree.h @@ -62,7 +62,7 @@ class DirectoryTree { /** File relative to the current tree to search */ std::string path; /** File extensions to append to the filename when searching */ - const Span exts; + const Span exts; /** * How often moving upwards when ".." is encountered in the path is * allowed (to prevent directory traversal) @@ -99,7 +99,7 @@ class DirectoryTree { * @param exts List of file extensions to probe * @return Path to file or empty string when not found */ - std::string FindFile(StringView filename, const Span exts = {}) const; + std::string FindFile(std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for the file in a specific @@ -110,7 +110,7 @@ class DirectoryTree { * @param exts List of file extensions to probe * @return Path to file or empty string when not found */ - std::string FindFile(StringView directory, StringView filename, const Span exts = {}) const; + std::string FindFile(std::string_view directory, std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for a file. @@ -128,9 +128,9 @@ class DirectoryTree { * @param path Path to enumerate, empty for root path * @return list of directory entries or nullptr on failure */ - DirectoryListType* ListDirectory(StringView path = "") const; + DirectoryListType* ListDirectory(std::string_view path = "") const; - void ClearCache(StringView path) const; + void ClearCache(std::string_view path) const; private: Filesystem* fs = nullptr; @@ -149,10 +149,10 @@ class DirectoryTree { /** lowered dir (full path from root) of missing directories */ mutable std::vector dir_missing_cache; - static bool WildcardMatch(const StringView& pattern, const StringView& text); + static bool WildcardMatch(const std::string_view& pattern, const std::string_view& text); template - auto Find(T& cache, StringView what, bool process_wildcards = false) const { + auto Find(T& cache, std::string_view what, bool process_wildcards = false) const { if (!process_wildcards) { // No wildcard - binary search auto it = std::lower_bound(cache.begin(), cache.end(), what, [](const auto& e, const auto& w) { diff --git a/src/dynrpg_easyrpg.cpp b/src/dynrpg_easyrpg.cpp index 1767be3507..276fef5225 100644 --- a/src/dynrpg_easyrpg.cpp +++ b/src/dynrpg_easyrpg.cpp @@ -88,7 +88,7 @@ static bool EasyAdd(dyn_arg_list args) { return true; } -bool DynRpg::EasyRpgPlugin::Invoke(StringView func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) { +bool DynRpg::EasyRpgPlugin::Invoke(std::string_view func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) { if (func == "call") { return EasyCall(args, do_yield, interpreter); } else if (func == "easyrpg_output") { diff --git a/src/dynrpg_easyrpg.h b/src/dynrpg_easyrpg.h index 6e2d9fe05b..6b8fc28335 100644 --- a/src/dynrpg_easyrpg.h +++ b/src/dynrpg_easyrpg.h @@ -31,7 +31,7 @@ namespace DynRpg { public: EasyRpgPlugin(Game_DynRpg& instance) : DynRpgPlugin("EasyRpgPlugin", instance) {} - bool Invoke(StringView func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) override; + bool Invoke(std::string_view func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) override; void Load(const std::vector& buffer) override; std::vector Save() override; diff --git a/src/dynrpg_textplugin.cpp b/src/dynrpg_textplugin.cpp index b041b0353a..772192f357 100644 --- a/src/dynrpg_textplugin.cpp +++ b/src/dynrpg_textplugin.cpp @@ -399,7 +399,7 @@ static bool RemoveAll(dyn_arg_list) { return true; } -bool DynRpg::TextPlugin::Invoke(StringView func, dyn_arg_list args, bool&, Game_Interpreter*) { +bool DynRpg::TextPlugin::Invoke(std::string_view func, dyn_arg_list args, bool&, Game_Interpreter*) { if (func == "write_text") { return WriteText(args); } else if (func == "append_line") { diff --git a/src/dynrpg_textplugin.h b/src/dynrpg_textplugin.h index 4a2f165c02..2b3f817ca0 100644 --- a/src/dynrpg_textplugin.h +++ b/src/dynrpg_textplugin.h @@ -26,7 +26,7 @@ namespace DynRpg { TextPlugin(Game_DynRpg& instance) : DynRpgPlugin("DynTextPlugin", instance) {} ~TextPlugin() override; - bool Invoke(StringView func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) override; + bool Invoke(std::string_view func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) override; void Update() override; void Load(const std::vector&) override; std::vector Save() override; diff --git a/src/enemyai.cpp b/src/enemyai.cpp index b99a3f4ce1..941be2be0f 100644 --- a/src/enemyai.cpp +++ b/src/enemyai.cpp @@ -50,7 +50,7 @@ static std::shared_ptr MakeAttackAllies(Gam } -std::unique_ptr CreateAlgorithm(StringView name) { +std::unique_ptr CreateAlgorithm(std::string_view name) { if (Utils::StrICmp(name, RpgRtImproved::name) == 0) { return std::make_unique(); } diff --git a/src/enemyai.h b/src/enemyai.h index a694618246..df0a438f18 100644 --- a/src/enemyai.h +++ b/src/enemyai.h @@ -35,7 +35,7 @@ class AlgorithmBase; * @param name of the algo. * @return An auto battle algorithm to be used in battles. */ -std::unique_ptr CreateAlgorithm(StringView name); +std::unique_ptr CreateAlgorithm(std::string_view name); /** * Base class for enemy ai algorithm implementations. @@ -48,7 +48,7 @@ class AlgorithmBase { virtual int GetId() const = 0; /** @return the name of this algorithm */ - virtual StringView GetName() const = 0; + virtual std::string_view GetName() const = 0; /** * Calculates the enemy ai algorithm and sets the algorithm on source. @@ -74,7 +74,7 @@ class RpgRtCompat: public AlgorithmBase { int GetId() const override { return id; } - StringView GetName() const override { return name; } + std::string_view GetName() const override { return name; } private: void vSetEnemyAiAction(Game_Enemy& source) override; }; @@ -90,7 +90,7 @@ class RpgRtImproved: public AlgorithmBase { int GetId() const override { return id; } - StringView GetName() const override { return name; } + std::string_view GetName() const override { return name; } private: void vSetEnemyAiAction(Game_Enemy& source) override; }; diff --git a/src/fileext_guesser.cpp b/src/fileext_guesser.cpp index b66fcc634b..756ea27412 100644 --- a/src/fileext_guesser.cpp +++ b/src/fileext_guesser.cpp @@ -42,7 +42,7 @@ FileExtGuesser::RPG2KNonStandardFilenameGuesser FileExtGuesser::GetRPG2kProjectW continue; } - if (item.first.length() == RtPrefix.length() + 3 && ToStringView(item.first).starts_with(RtPrefix)) { + if (item.first.length() == RtPrefix.length() + 3 && StartsWith(item.first, RtPrefix)) { std::string ext = item.first.substr(RtPrefix.length()); if (ext != "exe" && ext != "ini") { candidates.emplace_back(item.second.name, ext, fs.GetFilesize(fs.FindFile(item.second.name))); @@ -88,7 +88,7 @@ void FileExtGuesser::GuessAndAddLmuExtension(const FilesystemView& fs, Meta cons } if (item.first.length() == MapPrefixLength + 3 && - StringView(item.first).starts_with(MapPrefix)) { + StartsWith(item.first, MapPrefix)) { std::string ext = item.first.substr(MapPrefixLength); extCounts[ext] += 1; if (extCounts[ext] >= 5) { @@ -148,7 +148,7 @@ bool FileExtGuesser::RPG2KNonStandardFilenameGuesser::Empty() const { return rpgRTs.first.ext.empty() || rpgRTs.second.ext.empty(); } -std::string FileExtGuesser::RPG2KFileExtRemap::MakeFilename(StringView prefix, StringView suffix) +std::string FileExtGuesser::RPG2KFileExtRemap::MakeFilename(std::string_view prefix, std::string_view suffix) { std::stringstream res; res < extMap; }; diff --git a/src/filefinder.cpp b/src/filefinder.cpp index ccc2b841e5..ae22004eed 100644 --- a/src/filefinder.cpp +++ b/src/filefinder.cpp @@ -138,13 +138,13 @@ FilesystemView FileFinder::Root() { return root_fs->Subtree(""); } -std::string FileFinder::MakePath(StringView dir, StringView name) { +std::string FileFinder::MakePath(std::string_view dir, std::string_view name) { std::string str; if (dir.empty()) { str = ToString(name); } else if (name.empty()) { str = ToString(dir); - } else if (dir.ends_with("/")) { + } else if (EndsWith(dir, '/')) { str = ToString(dir) + ToString(name); } else { str = ToString(dir) + "/" + ToString(name); @@ -155,8 +155,8 @@ std::string FileFinder::MakePath(StringView dir, StringView name) { return str; } -std::string FileFinder::MakeCanonical(StringView path, int initial_deepness) { - StringView ns; +std::string FileFinder::MakeCanonical(std::string_view path, int initial_deepness) { + std::string_view ns; // Check if the path contains a namespace and prevent that the :// is replaced with :/ auto ns_pos = path.find("://"); if (ns_pos != std::string::npos) { @@ -187,7 +187,7 @@ std::string FileFinder::MakeCanonical(StringView path, int initial_deepness) { } std::string ret; - for (StringView s : path_can) { + for (std::string_view s : path_can) { ret = MakePath(ret, s); } @@ -201,7 +201,7 @@ std::string FileFinder::MakeCanonical(StringView path, int initial_deepness) { return ToString(ns) + root_slash + ret + drive_slash; } -std::vector FileFinder::SplitPath(StringView path) { +std::vector FileFinder::SplitPath(std::string_view path) { // Tokens are path delimiters ("/" and encoding aware "\") std::function f = [](char32_t t) { char32_t escape_char_back = '\0'; @@ -216,7 +216,7 @@ std::vector FileFinder::SplitPath(StringView path) { return Utils::Tokenize(path, f); } -std::pair FileFinder::GetPathAndFilename(StringView path) { +std::pair FileFinder::GetPathAndFilename(std::string_view path) { if (path.empty()) { return {"", ""}; } @@ -226,7 +226,7 @@ std::pair FileFinder::GetPathAndFilename(StringView pa const size_t last_slash_idx = path_copy.find_last_of('/'); if (last_slash_idx == std::string::npos) { - return {ToString(""), path_copy}; + return {"", path_copy}; } // Determine if the file is located at the filesystem root (e.g. / or drive:/) @@ -260,12 +260,12 @@ void FileFinder::ConvertPathDelimiters(std::string& path) { } } -std::string FileFinder::GetPathInsidePath(StringView path_to, StringView path_in) { - if (!path_in.starts_with(path_to)) { +std::string FileFinder::GetPathInsidePath(std::string_view path_to, std::string_view path_in) { + if (!StartsWith(path_in, path_to)) { return ToString(path_in); } - StringView path_out = path_in.substr(path_to.size()); + std::string_view path_out = path_in.substr(path_to.size()); if (!path_out.empty() && (path_out[0] == '/' || path_out[0] == '\\')) { path_out = path_out.substr(1); } @@ -273,21 +273,21 @@ std::string FileFinder::GetPathInsidePath(StringView path_to, StringView path_in return ToString(path_out); } -std::string FileFinder::GetPathInsideGamePath(StringView path_in) { +std::string FileFinder::GetPathInsideGamePath(std::string_view path_in) { return FileFinder::GetPathInsidePath(Game().GetFullPath(), path_in); } bool FileFinder::IsSupportedArchiveExtension(std::string path) { Utils::LowerCaseInPlace(path); - StringView pv = path; + std::string_view pv = path; #ifdef HAVE_LHASA - if (pv.ends_with(".lzh")) { + if (EndsWith(pv, ".lzh")) { return true; } #endif - return pv.ends_with(".zip") || pv.ends_with(".easyrpg"); + return EndsWith(pv, ".zip") || EndsWith(pv, ".easyrpg"); } void FileFinder::Quit() { @@ -368,7 +368,7 @@ bool FileFinder::OpenViewToEasyRpgFile(FilesystemView& fs) { std::string filename; for (auto& file : *files) { - if (StringView(file.second.name).ends_with(".easyrpg")) { + if (EndsWith(file.second.name, ".easyrpg")) { ++items; if (items == 2) { // Contains more than one game @@ -432,33 +432,33 @@ std::string find_generic_with_fallback(DirectoryTree::Args& args) { return found; } -std::string FileFinder::FindImage(StringView dir, StringView name) { +std::string FileFinder::FindImage(std::string_view dir, std::string_view name) { DirectoryTree::Args args = { MakePath(dir, name), IMG_TYPES, 1, false }; return find_generic(args); } -std::string FileFinder::FindMusic(StringView name) { +std::string FileFinder::FindMusic(std::string_view name) { DirectoryTree::Args args = { MakePath("Music", name), MUSIC_TYPES, 1, false }; return find_generic(args); } -std::string FileFinder::FindSound(StringView name) { +std::string FileFinder::FindSound(std::string_view name) { DirectoryTree::Args args = { MakePath("Sound", name), SOUND_TYPES, 1, false }; return find_generic(args); } -std::string FileFinder::FindFont(StringView name) { +std::string FileFinder::FindFont(std::string_view name) { DirectoryTree::Args args = { MakePath("Font", name), FONTS_TYPES, 1, true }; return find_generic(args); } -std::string FileFinder::FindText(StringView name) { +std::string FileFinder::FindText(std::string_view name) { DirectoryTree::Args args = { MakePath("Text", name), TEXT_TYPES, 1, true }; return find_generic_with_fallback(args); } -Filesystem_Stream::InputStream open_generic(StringView dir, StringView name, DirectoryTree::Args& args) { +Filesystem_Stream::InputStream open_generic(std::string_view dir, std::string_view name, DirectoryTree::Args& args) { if (!Tr::GetCurrentTranslationId().empty()) { auto tr_fs = Tr::GetCurrentTranslationFilesystem(); auto is = tr_fs.OpenFile(args); @@ -477,7 +477,7 @@ Filesystem_Stream::InputStream open_generic(StringView dir, StringView name, Dir return is; } -Filesystem_Stream::InputStream open_generic_with_fallback(StringView dir, StringView name, DirectoryTree::Args& args) { +Filesystem_Stream::InputStream open_generic_with_fallback(std::string_view dir, std::string_view name, DirectoryTree::Args& args) { auto is = FileFinder::Save().OpenFile(args); if (!is) { is = open_generic(dir, name, args); } if (!is) { @@ -487,27 +487,27 @@ Filesystem_Stream::InputStream open_generic_with_fallback(StringView dir, String return is; } -Filesystem_Stream::InputStream FileFinder::OpenImage(StringView dir, StringView name) { +Filesystem_Stream::InputStream FileFinder::OpenImage(std::string_view dir, std::string_view name) { DirectoryTree::Args args = { MakePath(dir, name), IMG_TYPES, 1, false }; return open_generic(dir, name, args); } -Filesystem_Stream::InputStream FileFinder::OpenMusic(StringView name) { +Filesystem_Stream::InputStream FileFinder::OpenMusic(std::string_view name) { DirectoryTree::Args args = { MakePath("Music", name), MUSIC_TYPES, 1, false }; return open_generic("Music", name, args); } -Filesystem_Stream::InputStream FileFinder::OpenSound(StringView name) { +Filesystem_Stream::InputStream FileFinder::OpenSound(std::string_view name) { DirectoryTree::Args args = { MakePath("Sound", name), SOUND_TYPES, 1, false }; return open_generic("Sound", name, args); } -Filesystem_Stream::InputStream FileFinder::OpenFont(StringView name) { +Filesystem_Stream::InputStream FileFinder::OpenFont(std::string_view name) { DirectoryTree::Args args = { MakePath("Font", name), FONTS_TYPES, 1, false }; return open_generic("Font", name, args); } -Filesystem_Stream::InputStream FileFinder::OpenText(StringView name) { +Filesystem_Stream::InputStream FileFinder::OpenText(std::string_view name) { DirectoryTree::Args args = { MakePath("Text", name), TEXT_TYPES, 1, false }; return open_generic_with_fallback("Text", name, args); } @@ -534,7 +534,7 @@ bool FileFinder::IsMajorUpdatedTree() { auto entries = fs.ListDirectory("music"); if (entries) { for (const auto& entry : *entries) { - if (entry.second.type == DirectoryTree::FileType::Regular && StringView(entry.first).ends_with(".mp3")) { + if (entry.second.type == DirectoryTree::FileType::Regular && EndsWith(entry.first, ".mp3")) { Output::Debug("MP3 file ({}) found", entry.second.name); return true; } diff --git a/src/filefinder.h b/src/filefinder.h index ec24d0f6a6..f9b371abca 100644 --- a/src/filefinder.h +++ b/src/filefinder.h @@ -136,7 +136,7 @@ namespace FileFinder { * @param name image file name to check. * @return path to file. */ - std::string FindImage(StringView dir, StringView name); + std::string FindImage(std::string_view dir, std::string_view name); /** * Finds a music file in the current RPG Maker game. @@ -144,7 +144,7 @@ namespace FileFinder { * @param name the music path and name. * @return path to file. */ - std::string FindMusic(StringView name); + std::string FindMusic(std::string_view name); /** * Finds a sound file in the current RPG Maker game. @@ -152,7 +152,7 @@ namespace FileFinder { * @param name the sound path and name. * @return path to file. */ - std::string FindSound(StringView name); + std::string FindSound(std::string_view name); /** * Finds a font file. @@ -161,7 +161,7 @@ namespace FileFinder { * @param name the font name. * @return path to file. */ - std::string FindFont(StringView name); + std::string FindFont(std::string_view name); /** * Finds a text file in the current RPG Maker game. @@ -169,7 +169,7 @@ namespace FileFinder { * @param name the text path and name. * @return path to file. */ - std::string FindText(StringView name); + std::string FindText(std::string_view name); /** * Finds an image file and opens a file handle to it. @@ -179,7 +179,7 @@ namespace FileFinder { * @param name image file name to check. * @return read handle on success or invalid handle if not found */ - Filesystem_Stream::InputStream OpenImage(StringView dir, StringView name); + Filesystem_Stream::InputStream OpenImage(std::string_view dir, std::string_view name); /** * Finds a music file and opens a file handle to it. @@ -189,7 +189,7 @@ namespace FileFinder { * @param name the music path and name. * @return read handle on success or invalid handle if not found */ - Filesystem_Stream::InputStream OpenMusic(StringView name); + Filesystem_Stream::InputStream OpenMusic(std::string_view name); /** * Finds a sound file and opens a file handle to it. @@ -199,7 +199,7 @@ namespace FileFinder { * @param name the sound path and name. * @return read handle on success or invalid handle if not found */ - Filesystem_Stream::InputStream OpenSound(StringView name); + Filesystem_Stream::InputStream OpenSound(std::string_view name); /** * Finds a font file and opens a file handle to it. @@ -208,7 +208,7 @@ namespace FileFinder { * @param name the font path and name. * @return read handle on success or invalid handle if not found */ - Filesystem_Stream::InputStream OpenFont(StringView name); + Filesystem_Stream::InputStream OpenFont(std::string_view name); /** * Finds a text file and opens a file handle to it. @@ -219,7 +219,7 @@ namespace FileFinder { * @param name the text path and name. * @return read handle on success or invalid handle if not found */ - Filesystem_Stream::InputStream OpenText(StringView name); + Filesystem_Stream::InputStream OpenText(std::string_view name); /** * Writes data to a txt file. @@ -228,7 +228,7 @@ namespace FileFinder { * @param name the text file path and name * @param data the content of the text file to be written */ - void WriteText(StringView name, StringView data); + void WriteText(std::string_view name, std::string_view data); /** * Appends name to directory. @@ -237,7 +237,7 @@ namespace FileFinder { * @param name file name to be appended to dir. * @return combined path */ - std::string MakePath(StringView dir, StringView name); + std::string MakePath(std::string_view dir, std::string_view name); /** * Creates a path out of multiple components @@ -255,7 +255,7 @@ namespace FileFinder { * @param initial_deepness How deep the passed path is relative to the game root * @return canonical path */ - std::string MakeCanonical(StringView path, int initial_deepness = -1); + std::string MakeCanonical(std::string_view path, int initial_deepness = -1); /** * Splits a path in it's components. @@ -263,7 +263,7 @@ namespace FileFinder { * @param path Path to split * @return Vector containing path components */ - std::vector SplitPath(StringView path); + std::vector SplitPath(std::string_view path); /** * Splits a path into path and filename. @@ -271,7 +271,7 @@ namespace FileFinder { * @param path Path to split * @return Pair containing dir and name */ - std::pair GetPathAndFilename(StringView path); + std::pair GetPathAndFilename(std::string_view path); /** * Converts all path delimiters to the platform delimiters. @@ -290,7 +290,7 @@ namespace FileFinder { * * @return The part of path_in that is inside path_to. path_in when the path is not in path_to */ - std::string GetPathInsidePath(StringView path_to, StringView path_in); + std::string GetPathInsidePath(std::string_view path_to, std::string_view path_in); /** * Return the part of "path_in" that is inside the current games directory. @@ -299,7 +299,7 @@ namespace FileFinder { * @param path_in An absolute path inside the game directory * @return The part of path_in that is inside the game directory, path_in when it's not in the directory */ - std::string GetPathInsideGamePath(StringView path_in); + std::string GetPathInsideGamePath(std::string_view path_in); /** * Checks whether a passed path ends with a supported extension for an archive, e.g. ".zip" diff --git a/src/filefinder_rtp.cpp b/src/filefinder_rtp.cpp index eb2b273e81..016127ac5a 100644 --- a/src/filefinder_rtp.cpp +++ b/src/filefinder_rtp.cpp @@ -164,7 +164,7 @@ FileFinder_RTP::FileFinder_RTP(bool no_rtp, bool no_rtp_warnings, std::string rt xdg_rtp = getenv("XDG_DATA_DIRS") ? std::string(getenv("XDG_DATA_DIRS")) : std::string("/usr/local/share/:/usr/share/"); std::vector tmp = Utils::Tokenize(xdg_rtp, f); - for (StringView p : tmp) { + for (std::string_view p : tmp) { xdg_rtp = ToString(p) + (p.back() == '/' ? "" : "/") + "rtp/" + version_str; if (FileFinder::Root().Exists(xdg_rtp)) { env_paths.push_back(xdg_rtp); @@ -173,12 +173,12 @@ FileFinder_RTP::FileFinder_RTP(bool no_rtp, bool no_rtp_warnings, std::string rt #endif // Add all found paths from the environment - for (StringView p : env_paths) { + for (std::string_view p : env_paths) { AddPath(p); } } -void FileFinder_RTP::AddPath(StringView p) { +void FileFinder_RTP::AddPath(std::string_view p) { using namespace FileFinder; auto fs = FileFinder::Root().Create(FileFinder::MakeCanonical(p)); if (fs) { @@ -213,7 +213,7 @@ void FileFinder_RTP::AddPath(StringView p) { } } -void FileFinder_RTP::ReadRegistry(StringView company, StringView product, StringView key) { +void FileFinder_RTP::ReadRegistry(std::string_view company, std::string_view product, std::string_view key) { #if defined(USE_WINE_REGISTRY) || defined(_WIN32) std::string rtp_path = Registry::ReadStrValue( HKEY_CURRENT_USER, "Software\\" + ToString(company) + "\\" + ToString(product), key, KEY32); @@ -233,7 +233,7 @@ void FileFinder_RTP::ReadRegistry(StringView company, StringView product, String #endif } -Filesystem_Stream::InputStream FileFinder_RTP::LookupInternal(StringView dir, StringView name, const Span exts, bool& is_rtp_asset) const { +Filesystem_Stream::InputStream FileFinder_RTP::LookupInternal(std::string_view dir, std::string_view name, const Span exts, bool& is_rtp_asset) const { int version = Player::EngineVersion(); auto normal_search = [&]() { @@ -306,7 +306,7 @@ Filesystem_Stream::InputStream FileFinder_RTP::LookupInternal(StringView dir, St return normal_search(); } -Filesystem_Stream::InputStream FileFinder_RTP::Lookup(StringView dir, StringView name, const Span exts) const { +Filesystem_Stream::InputStream FileFinder_RTP::Lookup(std::string_view dir, std::string_view name, const Span exts) const { if (!disable_rtp) { bool is_rtp_asset; auto is = LookupInternal(lcf::ReaderUtil::Normalize(dir), lcf::ReaderUtil::Normalize(name), exts, is_rtp_asset); diff --git a/src/filefinder_rtp.h b/src/filefinder_rtp.h index 745561292e..3a565a9d47 100644 --- a/src/filefinder_rtp.h +++ b/src/filefinder_rtp.h @@ -41,12 +41,12 @@ class FileFinder_RTP { * @param exts Extensions to probe * @return A handle to the file or an invalid handle if not found */ - Filesystem_Stream::InputStream Lookup(StringView dir, StringView name, const Span exts) const; + Filesystem_Stream::InputStream Lookup(std::string_view dir, std::string_view name, const Span exts) const; private: - void AddPath(StringView p); - void ReadRegistry(StringView company, StringView product, StringView key); - Filesystem_Stream::InputStream LookupInternal(StringView dir, StringView name, const Span exts, bool& is_rtp_asset) const; + void AddPath(std::string_view p); + void ReadRegistry(std::string_view company, std::string_view product, std::string_view key); + Filesystem_Stream::InputStream LookupInternal(std::string_view dir, std::string_view name, const Span exts, bool& is_rtp_asset) const; using search_path_list = std::vector; diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 132558f60c..8c82f27536 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -34,7 +34,7 @@ Filesystem::Filesystem(std::string base_path, FilesystemView parent_fs) : base_p tree = DirectoryTree::Create(*this); }; -Filesystem_Stream::InputStream Filesystem::OpenInputStream(StringView name, std::ios_base::openmode m) const { +Filesystem_Stream::InputStream Filesystem::OpenInputStream(std::string_view name, std::ios_base::openmode m) const { if (name.empty()) { return Filesystem_Stream::InputStream(); } @@ -49,7 +49,7 @@ Filesystem_Stream::InputStream Filesystem::OpenInputStream(StringView name, std: return is; } -Filesystem_Stream::InputStream Filesystem::OpenOrCreateInputStream(StringView name, std::ios_base::openmode m) const { +Filesystem_Stream::InputStream Filesystem::OpenOrCreateInputStream(std::string_view name, std::ios_base::openmode m) const { auto is = OpenInputStream(name, m); if (!is) { @@ -62,7 +62,7 @@ Filesystem_Stream::InputStream Filesystem::OpenOrCreateInputStream(StringView na return OpenInputStream(name, m); } -Filesystem_Stream::OutputStream Filesystem::OpenOutputStream(StringView name, std::ios_base::openmode m) const { +Filesystem_Stream::OutputStream Filesystem::OpenOutputStream(std::string_view name, std::ios_base::openmode m) const { if (name.empty()) { return Filesystem_Stream::OutputStream(); } @@ -80,11 +80,11 @@ Filesystem_Stream::OutputStream Filesystem::OpenOutputStream(StringView name, st return os; } -void Filesystem::ClearCache(StringView path) const { +void Filesystem::ClearCache(std::string_view path) const { tree->ClearCache(path); } -FilesystemView Filesystem::Create(StringView path) const { +FilesystemView Filesystem::Create(std::string_view path) const { // Determine the proper file system to use // When the path doesn't exist check if the path contains a file that can @@ -175,7 +175,7 @@ FilesystemView Filesystem::Subtree(std::string sub_path) const { return FilesystemView(shared_from_this(), sub_path); } -bool Filesystem::MakeDirectory(StringView, bool) const { +bool Filesystem::MakeDirectory(std::string_view, bool) const { return false; } @@ -184,11 +184,11 @@ bool Filesystem::IsValid() const { return Exists(""); } -std::string Filesystem::FindFile(StringView filename, const Span exts) const { +std::string Filesystem::FindFile(std::string_view filename, const Span exts) const { return tree->FindFile(filename, exts); } -std::string Filesystem::FindFile(StringView directory, StringView filename, const Span exts) const { +std::string Filesystem::FindFile(std::string_view directory, std::string_view filename, const Span exts) const { return tree->FindFile(directory, filename, exts); } @@ -196,11 +196,11 @@ std::string Filesystem::FindFile(const DirectoryTree::Args& args) const { return tree->FindFile(args); } -Filesystem_Stream::InputStream Filesystem::OpenFile(StringView filename, const Span exts) const { +Filesystem_Stream::InputStream Filesystem::OpenFile(std::string_view filename, const Span exts) const { return OpenInputStream(tree->FindFile(filename, exts)); } -Filesystem_Stream::InputStream Filesystem::OpenFile(StringView directory, StringView filename, const Span exts) const { +Filesystem_Stream::InputStream Filesystem::OpenFile(std::string_view directory, std::string_view filename, const Span exts) const { return OpenInputStream(tree->FindFile(directory, filename, exts)); } @@ -238,22 +238,22 @@ void FilesystemView::ClearCache() const { fs->ClearCache(GetSubPath()); } -std::string FilesystemView::FindFile(StringView name, const Span exts) const { +std::string FilesystemView::FindFile(std::string_view name, const Span exts) const { assert(fs); std::string found = fs->FindFile(MakePath(name), exts); if (!found.empty() && !sub_path.empty()) { - assert(StringView(found).starts_with(sub_path)); + assert(StartsWith(found, sub_path)); // substr calculation must consider if the subpath is / or drive:/ return found.substr(sub_path.size() + (sub_path.back() == '/' ? 0 : 1)); } return found; } -std::string FilesystemView::FindFile(StringView dir, StringView name, const Span exts) const { +std::string FilesystemView::FindFile(std::string_view dir, std::string_view name, const Span exts) const { assert(fs); std::string found = fs->FindFile(MakePath(dir), name, exts); if (!found.empty() && !sub_path.empty()) { - assert(StringView(found).starts_with(sub_path)); + assert(StartsWith(found, sub_path)); // substr calculation must consider if the subpath is / or drive:/ return found.substr(sub_path.size() + (sub_path.back() == '/' ? 0 : 1)); } @@ -267,19 +267,19 @@ std::string FilesystemView::FindFile(const DirectoryTree::Args& args) const { args_cp.path = path; std::string found = fs->FindFile(args_cp); if (!found.empty() && !sub_path.empty()) { - assert(StringView(found).starts_with(sub_path)); + assert(StartsWith(found, sub_path)); // substr calculation must consider if the subpath is / or drive:/ return found.substr(sub_path.size() + (sub_path.back() == '/' ? 0 : 1)); } return found; } -Filesystem_Stream::InputStream FilesystemView::OpenFile(StringView name, const Span exts) const { +Filesystem_Stream::InputStream FilesystemView::OpenFile(std::string_view name, const Span exts) const { assert(fs); return fs->OpenFile(MakePath(name), exts); } -Filesystem_Stream::InputStream FilesystemView::OpenFile(StringView dir, StringView name, const Span exts) const { +Filesystem_Stream::InputStream FilesystemView::OpenFile(std::string_view dir, std::string_view name, const Span exts) const { assert(fs); return fs->OpenFile(MakePath(dir), name, exts); } @@ -292,37 +292,37 @@ Filesystem_Stream::InputStream FilesystemView::OpenFile(const DirectoryTree::Arg return fs->OpenFile(args_cp); } -std::string FilesystemView::MakePath(StringView subdir) const { +std::string FilesystemView::MakePath(std::string_view subdir) const { assert(fs); return FileFinder::MakePath(sub_path, subdir); } -bool FilesystemView::IsFile(StringView path) const { +bool FilesystemView::IsFile(std::string_view path) const { assert(fs); return fs->IsFile(MakePath(path)); } -bool FilesystemView::IsDirectory(StringView path, bool follow_symlinks) const { +bool FilesystemView::IsDirectory(std::string_view path, bool follow_symlinks) const { assert(fs); return fs->IsDirectory(MakePath(path), follow_symlinks); } -bool FilesystemView::Exists(StringView path) const { +bool FilesystemView::Exists(std::string_view path) const { assert(fs); return fs->Exists(MakePath(path)); } -int64_t FilesystemView::GetFilesize(StringView path) const { +int64_t FilesystemView::GetFilesize(std::string_view path) const { assert(fs); return fs->GetFilesize(MakePath(path)); } -DirectoryTree::DirectoryListType* FilesystemView::ListDirectory(StringView path) const { +DirectoryTree::DirectoryListType* FilesystemView::ListDirectory(std::string_view path) const { assert(fs); return fs->ListDirectory(MakePath(path)); } -Filesystem_Stream::InputStream FilesystemView::OpenInputStream(StringView name, std::ios_base::openmode m) const { +Filesystem_Stream::InputStream FilesystemView::OpenInputStream(std::string_view name, std::ios_base::openmode m) const { assert(fs); if (name.empty()) { @@ -332,7 +332,7 @@ Filesystem_Stream::InputStream FilesystemView::OpenInputStream(StringView name, return fs->OpenInputStream(MakePath(name), m); } -Filesystem_Stream::InputStream FilesystemView::OpenOrCreateInputStream(StringView name, std::ios_base::openmode m) const { +Filesystem_Stream::InputStream FilesystemView::OpenOrCreateInputStream(std::string_view name, std::ios_base::openmode m) const { assert(fs); if (name.empty()) { @@ -342,7 +342,7 @@ Filesystem_Stream::InputStream FilesystemView::OpenOrCreateInputStream(StringVie return fs->OpenOrCreateInputStream(MakePath(name), m); } -Filesystem_Stream::OutputStream FilesystemView::OpenOutputStream(StringView name, std::ios_base::openmode m) const { +Filesystem_Stream::OutputStream FilesystemView::OpenOutputStream(std::string_view name, std::ios_base::openmode m) const { assert(fs); if (name.empty()) { @@ -352,22 +352,22 @@ Filesystem_Stream::OutputStream FilesystemView::OpenOutputStream(StringView name return fs->OpenOutputStream(MakePath(name), m); } -std::streambuf* FilesystemView::CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* FilesystemView::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { assert(fs); return fs->CreateInputStreambuffer(MakePath(path), mode); } -std::streambuf* FilesystemView::CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* FilesystemView::CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { assert(fs); return fs->CreateOutputStreambuffer(MakePath(path), mode); } -FilesystemView FilesystemView::Create(StringView p) const { +FilesystemView FilesystemView::Create(std::string_view p) const { assert(fs); return fs->Create(MakePath(p)); } -bool FilesystemView::MakeDirectory(StringView dir, bool follow_symlinks) const { +bool FilesystemView::MakeDirectory(std::string_view dir, bool follow_symlinks) const { assert(fs); return fs->MakeDirectory(MakePath(dir), follow_symlinks); } @@ -377,7 +377,7 @@ bool FilesystemView::IsFeatureSupported(Filesystem::Feature f) const { return fs->IsFeatureSupported(f); } -FilesystemView FilesystemView::Subtree(StringView sub_path) const { +FilesystemView FilesystemView::Subtree(std::string_view sub_path) const { assert(fs); return FilesystemView(fs, MakePath(sub_path)); } diff --git a/src/filesystem.h b/src/filesystem.h index 02936dcdee..eb4bc3ac1e 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -86,7 +86,7 @@ class Filesystem : public std::enable_shared_from_this { * @param m stream mode. Default is binary. * @return A Stream. The stream is invalid when the open failed. */ - Filesystem_Stream::InputStream OpenInputStream(StringView name, + Filesystem_Stream::InputStream OpenInputStream(std::string_view name, std::ios_base::openmode m = std::ios_base::in | std::ios_base::binary) const; /** @@ -97,7 +97,7 @@ class Filesystem : public std::enable_shared_from_this { * @param m stream mode. Default is binary. * @return A Stream. The stream is invalid when the open failed. */ - Filesystem_Stream::InputStream OpenOrCreateInputStream(StringView name, + Filesystem_Stream::InputStream OpenOrCreateInputStream(std::string_view name, std::ios_base::openmode m = std::ios_base::in | std::ios_base::binary) const; /** @@ -107,7 +107,7 @@ class Filesystem : public std::enable_shared_from_this { * @param m stream mode. Default is binary. * @return A Stream. The stream is invalid when the open failed or write is not supported. */ - Filesystem_Stream::OutputStream OpenOutputStream(StringView name, + Filesystem_Stream::OutputStream OpenOutputStream(std::string_view name, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary) const; /** @@ -116,7 +116,7 @@ class Filesystem : public std::enable_shared_from_this { * @param path a path relative to the filesystems root * @return List of directory entries */ - DirectoryTree::DirectoryListType* ListDirectory(StringView path) const; + DirectoryTree::DirectoryListType* ListDirectory(std::string_view path) const; /** * Clears the filesystem cache. Changes in the filesystem become visible @@ -125,7 +125,7 @@ class Filesystem : public std::enable_shared_from_this { * * @param path Path to flush */ - void ClearCache(StringView path) const; + void ClearCache(std::string_view path) const; /** * Creates a new appropriate filesystem from the specified path. @@ -134,7 +134,7 @@ class Filesystem : public std::enable_shared_from_this { * @param p Virtual path to use * @return Valid Filesystem when the parsing was successful, otherwise invalid */ - virtual FilesystemView Create(StringView p) const; + virtual FilesystemView Create(std::string_view p) const; /** * Creates a subview into the filesystem tree. @@ -154,7 +154,7 @@ class Filesystem : public std::enable_shared_from_this { * @param exts List of file extensions to probe * @return Path to file or empty string when not found */ - std::string FindFile(StringView filename, const Span exts = {}) const; + std::string FindFile(std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for the file in a specific @@ -165,7 +165,7 @@ class Filesystem : public std::enable_shared_from_this { * @param exts List of file extensions to probe * @return Path to file or empty string when not found */ - std::string FindFile(StringView directory, StringView filename, const Span exts = {}) const; + std::string FindFile(std::string_view directory, std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for a file. @@ -185,7 +185,7 @@ class Filesystem : public std::enable_shared_from_this { * @param exts List of file extensions to probe * @return Handle to the file if found, otherwise an invalid handle */ - Filesystem_Stream::InputStream OpenFile(StringView filename, const Span exts = {}) const; + Filesystem_Stream::InputStream OpenFile(std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for the file in a specific directory @@ -196,7 +196,7 @@ class Filesystem : public std::enable_shared_from_this { * @param exts List of file extensions to probe * @return Handle to the file if found, otherwise an invalid handle */ - Filesystem_Stream::InputStream OpenFile(StringView directory, StringView filename, const Span exts = {}) const; + Filesystem_Stream::InputStream OpenFile(std::string_view directory, std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for the file and opens a read handle. @@ -215,11 +215,11 @@ class Filesystem : public std::enable_shared_from_this { * Abstract methods to be implemented by filesystems. */ /** @{ */ - virtual bool IsFile(StringView path) const = 0; - virtual bool IsDirectory(StringView path, bool follow_symlinks) const = 0; - virtual bool Exists(StringView path) const = 0; - virtual int64_t GetFilesize(StringView path) const = 0; - virtual bool MakeDirectory(StringView dir, bool follow_symlinks) const; + virtual bool IsFile(std::string_view path) const = 0; + virtual bool IsDirectory(std::string_view path, bool follow_symlinks) const = 0; + virtual bool Exists(std::string_view path) const = 0; + virtual int64_t GetFilesize(std::string_view path) const = 0; + virtual bool MakeDirectory(std::string_view dir, bool follow_symlinks) const; virtual bool IsFeatureSupported(Feature f) const; virtual std::string Describe() const = 0; /** @} */ @@ -229,9 +229,9 @@ class Filesystem : public std::enable_shared_from_this { * Abstract methods to be implemented by filesystems. */ /** @{ */ - virtual bool GetDirectoryContent(StringView path, std::vector& entries) const = 0; - virtual std::streambuf* CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const = 0; - virtual std::streambuf* CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const; + virtual bool GetDirectoryContent(std::string_view path, std::vector& entries) const = 0; + virtual std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const = 0; + virtual std::streambuf* CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const; /** @} */ /** @@ -295,7 +295,7 @@ class FilesystemView { * @param exts List of file extensions to probe * @return Path to file or empty string when not found */ - std::string FindFile(StringView filename, const Span exts = {}) const; + std::string FindFile(std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for the file in a specific @@ -306,7 +306,7 @@ class FilesystemView { * @param exts List of file extensions to probe * @return Path to file or empty string when not found */ - std::string FindFile(StringView directory, StringView filename, const Span exts = {}) const; + std::string FindFile(std::string_view directory, std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for a file. @@ -326,7 +326,7 @@ class FilesystemView { * @param exts List of file extensions to probe * @return Handle to the file if found, otherwise an invalid handle */ - Filesystem_Stream::InputStream OpenFile(StringView filename, const Span exts = {}) const; + Filesystem_Stream::InputStream OpenFile(std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for the file in a specific directory @@ -337,7 +337,7 @@ class FilesystemView { * @param exts List of file extensions to probe * @return Handle to the file if found, otherwise an invalid handle */ - Filesystem_Stream::InputStream OpenFile(StringView directory, StringView filename, const Span exts = {}) const; + Filesystem_Stream::InputStream OpenFile(std::string_view directory, std::string_view filename, const Span exts = {}) const; /** * Does a case insensitive search for the file and opens a read handle. @@ -354,32 +354,32 @@ class FilesystemView { * @param subpath Path to append to the subtree root * @return Combined path */ - std::string MakePath(StringView subdir) const; + std::string MakePath(std::string_view subdir) const; /** * @param path Path to check * @return True when path is a regular file */ - bool IsFile(StringView path) const; + bool IsFile(std::string_view path) const; /** * @param path Path to check * @param follow_symlinks Whether to follow symlinks (if supported by this filesystem) * @return True when path is a directory */ - bool IsDirectory(StringView path, bool follow_symlinks) const; + bool IsDirectory(std::string_view path, bool follow_symlinks) const; /** * @param path Path to check * @return True when a file exists at the path */ - bool Exists(StringView path) const; + bool Exists(std::string_view path) const; /** * @param path Path to check * @return A filesize or -1 on error. */ - int64_t GetFilesize(StringView path) const; + int64_t GetFilesize(std::string_view path) const; /** * Enumerates a directory. @@ -387,7 +387,7 @@ class FilesystemView { * @param path Path to enumerate, empty for subtree root path * @return list of directory entries or nullptr on failure */ - DirectoryTree::DirectoryListType* ListDirectory(StringView path = "") const; + DirectoryTree::DirectoryListType* ListDirectory(std::string_view path = "") const; /** * Creates stream from filename for reading. @@ -396,7 +396,7 @@ class FilesystemView { * @param m stream mode. Default is binary. * @return A Stream. The stream is invalid when the open failed. */ - Filesystem_Stream::InputStream OpenInputStream(StringView name, + Filesystem_Stream::InputStream OpenInputStream(std::string_view name, std::ios_base::openmode m = std::ios_base::in | std::ios_base::binary) const; /** @@ -407,7 +407,7 @@ class FilesystemView { * @param m stream mode. Default is binary. * @return A Stream. The stream is invalid when the open failed. */ - Filesystem_Stream::InputStream OpenOrCreateInputStream(StringView name, + Filesystem_Stream::InputStream OpenOrCreateInputStream(std::string_view name, std::ios_base::openmode m = std::ios_base::in | std::ios_base::binary) const; /** @@ -417,7 +417,7 @@ class FilesystemView { * @param m stream mode. Default is binary. * @return A Stream. The stream is invalid when the open failed or write is not supported. */ - Filesystem_Stream::OutputStream OpenOutputStream(StringView name, + Filesystem_Stream::OutputStream OpenOutputStream(std::string_view name, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary) const; /** @@ -429,7 +429,7 @@ class FilesystemView { * @param mode stream mode. * @return A Stream. The stream is invalid when the open failed. */ - std::streambuf* CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const; /** * Creates stream from filename for writing. @@ -440,7 +440,7 @@ class FilesystemView { * @param mode stream mode. * @return A Stream. The stream is invalid when the open failed or write is not supported. */ - std::streambuf* CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const; + std::streambuf* CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const; /** * Creates a new appropriate filesystem from the specified path. @@ -449,7 +449,7 @@ class FilesystemView { * @param p Virtual path to use * @return Valid Filesystem when the parsing was successful, otherwise invalid */ - FilesystemView Create(StringView p) const; + FilesystemView Create(std::string_view p) const; /** * Recursively creates a new directory. @@ -459,7 +459,7 @@ class FilesystemView { * @param follow_symlinks Whether to follow symlinks (if supported by this filesystem) * @return true when the path was created */ - bool MakeDirectory(StringView dir, bool follow_symlinks) const; + bool MakeDirectory(std::string_view dir, bool follow_symlinks) const; /** * @param f Filesystem feature to check @@ -473,7 +473,7 @@ class FilesystemView { * @param sub_path root of the subtree * @return subtree rooted at sub_path */ - FilesystemView Subtree(StringView sub_path) const; + FilesystemView Subtree(std::string_view sub_path) const; /** @return human readable representation of this filesystem for debug purposes */ std::string Describe() const; @@ -505,12 +505,12 @@ inline bool Filesystem::IsFeatureSupported(Filesystem::Feature) const { return false; } -inline std::streambuf* Filesystem::CreateOutputStreambuffer(StringView, std::ios_base::openmode) const { +inline std::streambuf* Filesystem::CreateOutputStreambuffer(std::string_view, std::ios_base::openmode) const { assert(!IsFeatureSupported(Feature::Write) && "Write supported but CreateOutputStreambuffer not implemented"); return nullptr; } -inline DirectoryTree::DirectoryListType* Filesystem::ListDirectory(StringView path) const { +inline DirectoryTree::DirectoryListType* Filesystem::ListDirectory(std::string_view path) const { return tree->ListDirectory(path); } diff --git a/src/filesystem_hook.cpp b/src/filesystem_hook.cpp index 90dd5639c0..fe9be95299 100644 --- a/src/filesystem_hook.cpp +++ b/src/filesystem_hook.cpp @@ -86,23 +86,23 @@ FilesystemView HookFilesystem::Detect(FilesystemView fs) { return fs; } -bool HookFilesystem::IsFile(StringView path) const { +bool HookFilesystem::IsFile(std::string_view path) const { return GetParent().IsFile(path); } -bool HookFilesystem::IsDirectory(StringView path, bool follow_symlinks) const { +bool HookFilesystem::IsDirectory(std::string_view path, bool follow_symlinks) const { return GetParent().IsDirectory(path, follow_symlinks); } -bool HookFilesystem::Exists(StringView path) const { +bool HookFilesystem::Exists(std::string_view path) const { return GetParent().Exists(path); } -int64_t HookFilesystem::GetFilesize(StringView path) const { +int64_t HookFilesystem::GetFilesize(std::string_view path) const { return GetParent().GetFilesize(path); } -bool HookFilesystem::MakeDirectory(StringView dir, bool follow_symlinks) const { +bool HookFilesystem::MakeDirectory(std::string_view dir, bool follow_symlinks) const { return GetParent().MakeDirectory(dir, follow_symlinks); } @@ -110,7 +110,7 @@ bool HookFilesystem::IsFeatureSupported(Feature f) const { return GetParent().IsFeatureSupported(f); } -std::streambuf* HookFilesystem::CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* HookFilesystem::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { auto parent_sb = GetParent().CreateInputStreambuffer(path, mode); if (active_hook == Hook::SacredTears) { @@ -122,11 +122,11 @@ std::streambuf* HookFilesystem::CreateInputStreambuffer(StringView path, std::io return parent_sb; } -std::streambuf* HookFilesystem::CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* HookFilesystem::CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { return GetParent().CreateOutputStreambuffer(path, mode); } -bool HookFilesystem::GetDirectoryContent(StringView path, std::vector& tree) const { +bool HookFilesystem::GetDirectoryContent(std::string_view path, std::vector& tree) const { auto dir_tree = GetParent().ListDirectory(path); if (!dir_tree) { diff --git a/src/filesystem_hook.h b/src/filesystem_hook.h index 260116ae2f..8557198e82 100644 --- a/src/filesystem_hook.h +++ b/src/filesystem_hook.h @@ -39,19 +39,19 @@ class HookFilesystem : public Filesystem { * Implementation of abstract methods */ /** @{ */ - bool IsFile(StringView path) const override; - bool IsDirectory(StringView path, bool follow_symlinks) const override; - bool Exists(StringView path) const override; - int64_t GetFilesize(StringView path) const override; - bool MakeDirectory(StringView dir, bool follow_symlinks) const override; + bool IsFile(std::string_view path) const override; + bool IsDirectory(std::string_view path, bool follow_symlinks) const override; + bool Exists(std::string_view path) const override; + int64_t GetFilesize(std::string_view path) const override; + bool MakeDirectory(std::string_view dir, bool follow_symlinks) const override; bool IsFeatureSupported(Feature f) const override; std::string Describe() const override; /** @} */ protected: /** @{ */ - bool GetDirectoryContent(StringView path, std::vector& entries) const override; - std::streambuf* CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const override; - std::streambuf* CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const override; + bool GetDirectoryContent(std::string_view path, std::vector& entries) const override; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + std::streambuf* CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; /** @} */ Hook active_hook; diff --git a/src/filesystem_lzh.cpp b/src/filesystem_lzh.cpp index f4925c4106..4cfbb63221 100644 --- a/src/filesystem_lzh.cpp +++ b/src/filesystem_lzh.cpp @@ -34,7 +34,7 @@ #include "lhasa.h" -static std::string normalize_path(StringView path) { +static std::string normalize_path(std::string_view path) { if (path == "." || path == "/" || path.empty()) { return ""; }; @@ -74,7 +74,7 @@ static LHAInputStreamType vio = { nullptr // close not supported by istream interface }; -LzhFilesystem::LzhFilesystem(std::string base_path, FilesystemView parent_fs, StringView enc) : +LzhFilesystem::LzhFilesystem(std::string base_path, FilesystemView parent_fs, std::string_view enc) : Filesystem(base_path, parent_fs) { is = parent_fs.OpenInputStream(GetPath()); if (!is) { @@ -242,7 +242,7 @@ LzhFilesystem::LzhFilesystem(std::string base_path, FilesystemView parent_fs, St lzh_entries.erase(lzh_entries.begin(), entries_del_it.base()); } -bool LzhFilesystem::IsFile(StringView path) const { +bool LzhFilesystem::IsFile(std::string_view path) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); if (entry) { @@ -251,7 +251,7 @@ bool LzhFilesystem::IsFile(StringView path) const { return false; } -bool LzhFilesystem::IsDirectory(StringView path, bool) const { +bool LzhFilesystem::IsDirectory(std::string_view path, bool) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); if (entry) { @@ -260,13 +260,13 @@ bool LzhFilesystem::IsDirectory(StringView path, bool) const { return false; } -bool LzhFilesystem::Exists(StringView path) const { +bool LzhFilesystem::Exists(std::string_view path) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); return entry != nullptr; } -int64_t LzhFilesystem::GetFilesize(StringView path) const { +int64_t LzhFilesystem::GetFilesize(std::string_view path) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); if (entry) { @@ -275,7 +275,7 @@ int64_t LzhFilesystem::GetFilesize(StringView path) const { return 0; } -std::streambuf* LzhFilesystem::CreateInputStreambuffer(StringView path, std::ios_base::openmode) const { +std::streambuf* LzhFilesystem::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); if (entry && !entry->is_directory) { @@ -310,7 +310,7 @@ std::streambuf* LzhFilesystem::CreateInputStreambuffer(StringView path, std::ios return nullptr; } -bool LzhFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const { +bool LzhFilesystem::GetDirectoryContent(std::string_view path, std::vector& entries) const { if (!IsDirectory(path, false)) { return false; } @@ -321,7 +321,7 @@ bool LzhFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const override; + bool IsFile(std::string_view path) const override; + bool IsDirectory(std::string_view path, bool follow_symlinks) const override; + bool Exists(std::string_view path) const override; + int64_t GetFilesize(std::string_view path) const override; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + bool GetDirectoryContent(std::string_view path, std::vector& entries) const override; std::string Describe() const override; /** @} */ @@ -68,7 +68,7 @@ class LzhFilesystem : public Filesystem { bool is_directory; }; - const LzhEntry* Find(StringView what) const; + const LzhEntry* Find(std::string_view what) const; std::vector> lzh_entries; std::string encoding; diff --git a/src/filesystem_native.cpp b/src/filesystem_native.cpp index fad9cd9097..758f7b6c10 100644 --- a/src/filesystem_native.cpp +++ b/src/filesystem_native.cpp @@ -38,23 +38,23 @@ NativeFilesystem::NativeFilesystem(std::string base_path, FilesystemView parent_fs) : Filesystem(std::move(base_path), parent_fs) { } -bool NativeFilesystem::IsFile(StringView path) const { +bool NativeFilesystem::IsFile(std::string_view path) const { return Platform::File(ToString(path)).IsFile(false); } -bool NativeFilesystem::IsDirectory(StringView dir, bool follow_symlinks) const { +bool NativeFilesystem::IsDirectory(std::string_view dir, bool follow_symlinks) const { return Platform::File(ToString(dir)).IsDirectory(follow_symlinks); } -bool NativeFilesystem::Exists(StringView filename) const { +bool NativeFilesystem::Exists(std::string_view filename) const { return Platform::File(ToString(filename)).Exists(); } -int64_t NativeFilesystem::GetFilesize(StringView path) const { +int64_t NativeFilesystem::GetFilesize(std::string_view path) const { return Platform::File(ToString(path)).GetSize(); } -std::streambuf* NativeFilesystem::CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* NativeFilesystem::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { #ifdef USE_CUSTOM_FILEBUF (void)mode; int fd = open(ToString(path).c_str(), O_RDONLY); @@ -83,7 +83,7 @@ std::streambuf* NativeFilesystem::CreateInputStreambuffer(StringView path, std:: #endif } -std::streambuf* NativeFilesystem::CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* NativeFilesystem::CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { #ifdef USE_CUSTOM_FILEBUF int flags = O_TRUNC; @@ -116,7 +116,7 @@ std::streambuf* NativeFilesystem::CreateOutputStreambuffer(StringView path, std: #endif } -bool NativeFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const { +bool NativeFilesystem::GetDirectoryContent(std::string_view path, std::vector& entries) const { std::string p = ToString(path); Platform::Directory dir(p); @@ -148,7 +148,7 @@ bool NativeFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const override; - bool MakeDirectory(StringView path, bool follow_symlinks) const override; + bool IsFile(std::string_view path) const override; + bool IsDirectory(std::string_view path, bool follow_symlinks) const override; + bool Exists(std::string_view path) const override; + int64_t GetFilesize(std::string_view path) const override; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + std::streambuf* CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + bool GetDirectoryContent(std::string_view path, std::vector& entries) const override; + bool MakeDirectory(std::string_view path, bool follow_symlinks) const override; bool IsFeatureSupported(Feature f) const override; std::string Describe() const override; /** @} */ diff --git a/src/filesystem_root.cpp b/src/filesystem_root.cpp index 270c6efa7f..4cb334590c 100644 --- a/src/filesystem_root.cpp +++ b/src/filesystem_root.cpp @@ -23,7 +23,7 @@ # include "platform/android/filesystem_saf.h" #endif -constexpr const StringView root_ns = "root://"; +constexpr const std::string_view root_ns = "root://"; RootFilesystem::RootFilesystem() : Filesystem("", FilesystemView()) { // Add platform specific namespaces here @@ -38,8 +38,8 @@ RootFilesystem::RootFilesystem() : Filesystem("", FilesystemView()) { assert(fs_list.back().first == "file" && "File namespace must be last!"); } -FilesystemView RootFilesystem::Create(StringView path) const { - if (path.starts_with(root_ns)) { +FilesystemView RootFilesystem::Create(std::string_view path) const { + if (StartsWith(path, root_ns)) { // Debug feature: root:// is a pseudo namespace // Shows a list of all namespaces in the Game Browser if (path.size() > root_ns.size()) { @@ -57,32 +57,32 @@ FilesystemView RootFilesystem::Create(StringView path) const { return fs.Create(path); } -bool RootFilesystem::IsFile(StringView path) const { +bool RootFilesystem::IsFile(std::string_view path) const { return FilesystemForPath(path).IsFile(path); } -bool RootFilesystem::IsDirectory(StringView path, bool follow_symlinks) const { +bool RootFilesystem::IsDirectory(std::string_view path, bool follow_symlinks) const { return FilesystemForPath(path).IsDirectory(path, follow_symlinks); } -bool RootFilesystem::Exists(StringView path) const { +bool RootFilesystem::Exists(std::string_view path) const { return FilesystemForPath(path).Exists(path); } -int64_t RootFilesystem::GetFilesize(StringView path) const { +int64_t RootFilesystem::GetFilesize(std::string_view path) const { return FilesystemForPath(path).GetFilesize(path); } -std::streambuf* RootFilesystem::CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* RootFilesystem::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { return FilesystemForPath(path).CreateInputStreambuffer(path, mode); } -std::streambuf* RootFilesystem::CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* RootFilesystem::CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { return FilesystemForPath(path).CreateOutputStreambuffer(path, mode); } -bool RootFilesystem::GetDirectoryContent(StringView path, std::vector& tree) const { +bool RootFilesystem::GetDirectoryContent(std::string_view path, std::vector& tree) const { if (path.empty()) { // Debug feature: Return all available namespaces as a directory list for (const auto& p : fs_list) { @@ -94,7 +94,7 @@ bool RootFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const override; - bool MakeDirectory(StringView path, bool follow_symlinks) const override; + bool IsFile(std::string_view path) const override; + bool IsDirectory(std::string_view path, bool follow_symlinks) const override; + bool Exists(std::string_view path) const override; + int64_t GetFilesize(std::string_view path) const override; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + std::streambuf* CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + bool GetDirectoryContent(std::string_view path, std::vector& entries) const override; + bool MakeDirectory(std::string_view path, bool follow_symlinks) const override; std::string Describe() const override; /** @} */ @@ -77,7 +77,7 @@ class RootFilesystem : public Filesystem { * @param path Path to resolve. * @return Filesystem that supports this path */ - const Filesystem& FilesystemForPath(StringView path) const; + const Filesystem& FilesystemForPath(std::string_view path) const; // ns -> fs, NativeFilesystem is always last using FsList = std::vector>>; diff --git a/src/filesystem_stream.cpp b/src/filesystem_stream.cpp index 180a098958..3aaf5a32c7 100644 --- a/src/filesystem_stream.cpp +++ b/src/filesystem_stream.cpp @@ -45,7 +45,7 @@ Filesystem_Stream::InputStream& Filesystem_Stream::InputStream::operator=(InputS return *this; } -StringView Filesystem_Stream::InputStream::GetName() const { +std::string_view Filesystem_Stream::InputStream::GetName() const { return name; } @@ -89,7 +89,7 @@ Filesystem_Stream::OutputStream& Filesystem_Stream::OutputStream::operator=(Outp return *this; } -StringView Filesystem_Stream::OutputStream::GetName() const { +std::string_view Filesystem_Stream::OutputStream::GetName() const { return name; } diff --git a/src/filesystem_stream.h b/src/filesystem_stream.h index 24a1f8b81f..fe1c2465d8 100644 --- a/src/filesystem_stream.h +++ b/src/filesystem_stream.h @@ -37,7 +37,7 @@ namespace Filesystem_Stream { InputStream(InputStream&& is) noexcept; InputStream& operator=(InputStream&& is) noexcept; - StringView GetName() const; + std::string_view GetName() const; std::streampos GetSize() const; void Close(); @@ -63,7 +63,7 @@ namespace Filesystem_Stream { OutputStream(OutputStream&& os) noexcept; OutputStream& operator=(OutputStream&& os) noexcept; - StringView GetName() const; + std::string_view GetName() const; void Close(); private: diff --git a/src/filesystem_zip.cpp b/src/filesystem_zip.cpp index e3301ea48d..94cc1b36ad 100644 --- a/src/filesystem_zip.cpp +++ b/src/filesystem_zip.cpp @@ -37,7 +37,7 @@ constexpr uint32_t central_directory_entry = 0x02014b50; constexpr uint32_t local_header = 0x04034b50; constexpr uint32_t local_header_size = 30; -static std::string normalize_path(StringView path) { +static std::string normalize_path(std::string_view path) { if (path == "." || path == "/" || path.empty()) { return ""; }; @@ -52,7 +52,7 @@ static std::string normalize_path(StringView path) { return inner_path; } -ZipFilesystem::ZipFilesystem(std::string base_path, FilesystemView parent_fs, StringView enc) : +ZipFilesystem::ZipFilesystem(std::string base_path, FilesystemView parent_fs, std::string_view enc) : Filesystem(base_path, parent_fs) { zip_is = parent_fs.OpenInputStream(GetPath()); if (!zip_is) { @@ -329,7 +329,7 @@ bool ZipFilesystem::ReadLocalHeader(std::istream& zipfile, StorageMethod& method return true; } -bool ZipFilesystem::IsFile(StringView path) const { +bool ZipFilesystem::IsFile(std::string_view path) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); if (entry) { @@ -338,7 +338,7 @@ bool ZipFilesystem::IsFile(StringView path) const { return false; } -bool ZipFilesystem::IsDirectory(StringView path, bool) const { +bool ZipFilesystem::IsDirectory(std::string_view path, bool) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); if (entry) { @@ -347,13 +347,13 @@ bool ZipFilesystem::IsDirectory(StringView path, bool) const { return false; } -bool ZipFilesystem::Exists(StringView path) const { +bool ZipFilesystem::Exists(std::string_view path) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); return entry != nullptr; } -int64_t ZipFilesystem::GetFilesize(StringView path) const { +int64_t ZipFilesystem::GetFilesize(std::string_view path) const { std::string path_normalized = normalize_path(path); auto entry = Find(path); if (entry) { @@ -362,7 +362,7 @@ int64_t ZipFilesystem::GetFilesize(StringView path) const { return 0; } -std::streambuf* ZipFilesystem::CreateInputStreambuffer(StringView path, std::ios_base::openmode) const { +std::streambuf* ZipFilesystem::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode) const { std::string path_normalized = normalize_path(path); auto central_entry = Find(path); if (central_entry && !central_entry->is_directory) { @@ -433,7 +433,7 @@ std::streambuf* ZipFilesystem::CreateInputStreambuffer(StringView path, std::ios return nullptr; } -bool ZipFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const { +bool ZipFilesystem::GetDirectoryContent(std::string_view path, std::vector& entries) const { if (!IsDirectory(path, false)) { return false; } @@ -444,7 +444,7 @@ bool ZipFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const override; + bool IsFile(std::string_view path) const override; + bool IsDirectory(std::string_view path, bool follow_symlinks) const override; + bool Exists(std::string_view path) const override; + int64_t GetFilesize(std::string_view path) const override; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + bool GetDirectoryContent(std::string_view path, std::vector& entries) const override; std::string Describe() const override; /** @} */ @@ -65,7 +65,7 @@ class ZipFilesystem : public Filesystem { bool FindCentralDirectory(std::istream& stream, uint32_t& offset, uint32_t& size, uint16_t& num_entries) const; bool ReadCentralDirectoryEntry(std::istream& zipfile, std::string& filepath, ZipEntry& entry, bool& is_utf8) const; bool ReadLocalHeader(std::istream& zipfile, StorageMethod& method, ZipEntry& entry) const; - const ZipEntry* Find(StringView what) const; + const ZipEntry* Find(std::string_view what) const; std::vector> zip_entries; std::vector> zip_entries_cp437; diff --git a/src/font.cpp b/src/font.cpp index 29ee2e220f..41fa03761c 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -119,7 +119,7 @@ namespace { using function_type = BitmapFontGlyph const*(*)(char32_t); - BitmapFont(StringView name, function_type func); + BitmapFont(std::string_view name, function_type func); Rect vGetSize(char32_t glyph) const override; GlyphRet vRender(char32_t glyph) const override; @@ -142,7 +142,7 @@ namespace { GlyphRet vRenderShaped(char32_t glyph) const override; bool vCanShape() const override; #ifdef HAVE_HARFBUZZ - std::vector vShape(U32StringView txt) const override; + std::vector vShape(std::u32string_view txt) const override; #endif void vApplyStyle(const Style& style) override; @@ -237,7 +237,7 @@ namespace { } } // anonymous namespace -BitmapFont::BitmapFont(StringView name, function_type func) +BitmapFont::BitmapFont(std::string_view name, function_type func) : Font(name, HEIGHT, false, false), func(func) {} @@ -491,7 +491,7 @@ bool FTFont::vCanShape() const { } #ifdef HAVE_HARFBUZZ -std::vector FTFont::vShape(U32StringView txt) const { +std::vector FTFont::vShape(std::u32string_view txt) const { hb_buffer_clear_contents(hb_buffer); hb_buffer_add_utf32(hb_buffer, reinterpret_cast(txt.data()), txt.size(), 0, txt.size()); @@ -691,7 +691,7 @@ void Font::Dispose() { } // Constructor. -Font::Font(StringView name, int size, bool bold, bool italic) +Font::Font(std::string_view name, int size, bool bold, bool italic) : name(ToString(name)) { original_style.size = size; @@ -700,7 +700,7 @@ Font::Font(StringView name, int size, bool bold, bool italic) current_style = original_style; } -StringView Font::GetName() const { +std::string_view Font::GetName() const { return name; } @@ -884,7 +884,7 @@ bool Font::CanShape() const { return vCanShape(); } -std::vector Font::Shape(U32StringView text) const { +std::vector Font::Shape(std::u32string_view text) const { assert(vCanShape()); return vShape(text); diff --git a/src/font.h b/src/font.h index e3daaf1fad..85a0d81264 100644 --- a/src/font.h +++ b/src/font.h @@ -101,7 +101,7 @@ class Font { /** * @return Name of the font */ - StringView GetName() const; + std::string_view GetName() const; /** * Determines the size of a bitmap required to render a single character. @@ -185,7 +185,7 @@ class Font { * @param text Text to shape * @return Shaping information. See Font::ShapeRet */ - std::vector Shape(U32StringView text) const; + std::vector Shape(std::u32string_view text) const; /** * Defines a fallback font that shall be used when a glyph is not found in the current font. @@ -251,11 +251,11 @@ class Font { virtual GlyphRet vRender(char32_t glyph) const = 0; virtual GlyphRet vRenderShaped(char32_t glyph) const { return vRender(glyph); }; virtual bool vCanShape() const { return false; } - virtual std::vector vShape(U32StringView) const { return {}; } + virtual std::vector vShape(std::u32string_view) const { return {}; } virtual void vApplyStyle(const Style& style) { (void)style; }; protected: - Font(StringView name, int size, bool bold, bool italic); + Font(std::string_view name, int size, bool bold, bool italic); std::string name; bool style_applied = false; diff --git a/src/game_actor.cpp b/src/game_actor.cpp index 4543a181c9..8a41a3925b 100644 --- a/src/game_actor.cpp +++ b/src/game_actor.cpp @@ -906,8 +906,8 @@ Point Game_Actor::GetOriginalPosition() const { return { dbActor->battle_x, dbActor->battle_y }; } -StringView Game_Actor::GetSkillName() const { - return dbActor->rename_skill ? StringView(dbActor->skill_name) : StringView(lcf::Data::terms.command_skill); +std::string_view Game_Actor::GetSkillName() const { + return dbActor->rename_skill ? std::string_view(dbActor->skill_name) : std::string_view(lcf::Data::terms.command_skill); } void Game_Actor::SetSprite(const std::string &file, int index, bool transparent) { @@ -1144,7 +1144,7 @@ void Game_Actor::ChangeClass(int new_class_id, } } -StringView Game_Actor::GetClassName() const { +std::string_view Game_Actor::GetClassName() const { if (!GetClass()) { return {}; } diff --git a/src/game_actor.h b/src/game_actor.h index c3b34e63d6..bad19e1cda 100644 --- a/src/game_actor.h +++ b/src/game_actor.h @@ -241,28 +241,28 @@ class Game_Actor final : public Game_Battler { * * @return name. */ - StringView GetName() const override; + std::string_view GetName() const override; /** * Gets actor name from the database. * * @return name. */ - StringView GetOriginalName() const; + std::string_view GetOriginalName() const; /** * Gets actor character sprite filename. * * @return character sprite filename. */ - StringView GetSpriteName() const override; + std::string_view GetSpriteName() const override; /** * Gets actor character sprite filename from the database. * * @return character sprite filename. */ - StringView GetOriginalSpriteName() const; + std::string_view GetOriginalSpriteName() const; /** * Gets actor character sprite index. @@ -293,14 +293,14 @@ class Game_Actor final : public Game_Battler { * * @return face graphic filename. */ - StringView GetFaceName() const; + std::string_view GetFaceName() const; /** * Gets actor face graphic filename from the database. * * @return face graphic filename. */ - StringView GetOriginalFaceName() const; + std::string_view GetOriginalFaceName() const; /** * Gets actor face graphic index. @@ -321,14 +321,14 @@ class Game_Actor final : public Game_Battler { * * @return title. */ - StringView GetTitle() const; + std::string_view GetTitle() const; /** * Gets actor title from the database. * * @return title. */ - StringView GetOriginalTitle() const; + std::string_view GetOriginalTitle() const; /** * Gets actor equipped weapon ID. @@ -758,7 +758,7 @@ class Game_Actor final : public Game_Battler { * * @return name of skill menu item */ - StringView GetSkillName() const; + std::string_view GetSkillName() const; /** * Sets new actor name. @@ -841,7 +841,7 @@ class Game_Actor final : public Game_Battler { * * @return Rpg2k3 hero class name */ - StringView GetClassName() const; + std::string_view GetClassName() const; /** * Gets battle commands. @@ -1001,13 +1001,13 @@ inline void Game_Actor::SetName(const std::string &new_name) { : lcf::rpg::SaveActor::kEmptyName; } -inline StringView Game_Actor::GetName() const { +inline std::string_view Game_Actor::GetName() const { return data.name != lcf::rpg::SaveActor::kEmptyName - ? StringView(data.name) - : StringView(dbActor->name); + ? std::string_view(data.name) + : std::string_view(dbActor->name); } -inline StringView Game_Actor::GetOriginalName() const { +inline std::string_view Game_Actor::GetOriginalName() const { return dbActor->name; } @@ -1017,23 +1017,23 @@ inline void Game_Actor::SetTitle(const std::string &new_title) { : lcf::rpg::SaveActor::kEmptyName; } -inline StringView Game_Actor::GetTitle() const { +inline std::string_view Game_Actor::GetTitle() const { return data.title != lcf::rpg::SaveActor::kEmptyName - ? StringView(data.title) - : StringView(dbActor->title); + ? std::string_view(data.title) + : std::string_view(dbActor->title); } -inline StringView Game_Actor::GetOriginalTitle() const { +inline std::string_view Game_Actor::GetOriginalTitle() const { return dbActor->title; } -inline StringView Game_Actor::GetSpriteName() const { +inline std::string_view Game_Actor::GetSpriteName() const { return (!data.sprite_name.empty()) - ? StringView(data.sprite_name) - : StringView(dbActor->character_name); + ? std::string_view(data.sprite_name) + : std::string_view(dbActor->character_name); } -inline StringView Game_Actor::GetOriginalSpriteName() const { +inline std::string_view Game_Actor::GetOriginalSpriteName() const { return dbActor->character_name; } @@ -1057,13 +1057,13 @@ inline int Game_Actor::GetOriginalSpriteTransparency() const { return dbActor->transparent ? 3 : 0; } -inline StringView Game_Actor::GetFaceName() const { +inline std::string_view Game_Actor::GetFaceName() const { return (!data.face_name.empty()) - ? StringView(data.face_name) - : StringView(dbActor->face_name); + ? std::string_view(data.face_name) + : std::string_view(dbActor->face_name); } -inline StringView Game_Actor::GetOriginalFaceName() const { +inline std::string_view Game_Actor::GetOriginalFaceName() const { return dbActor->face_name; } diff --git a/src/game_battler.h b/src/game_battler.h index 79b4acad7c..1666bd3780 100644 --- a/src/game_battler.h +++ b/src/game_battler.h @@ -234,14 +234,14 @@ class Game_Battler { * * @return Character name */ - virtual StringView GetName() const = 0; + virtual std::string_view GetName() const = 0; /** * Gets the filename of the character sprite * * @return Filename of character sprite */ - virtual StringView GetSpriteName() const = 0; + virtual std::string_view GetSpriteName() const = 0; /** * Gets battler HP. @@ -771,7 +771,7 @@ class Game_Battler { /** * Convenience function to access the battlers party member index. - * + * * @return Index of this member in their party. */ int GetPartyIndex(); diff --git a/src/game_character.cpp b/src/game_character.cpp index 5f6338ec2b..becbab1348 100644 --- a/src/game_character.cpp +++ b/src/game_character.cpp @@ -40,11 +40,11 @@ Game_Character::Game_Character(Type type, lcf::rpg::SaveMapEventBase* d) : { } -void Game_Character::SanitizeData(StringView name) { +void Game_Character::SanitizeData(std::string_view name) { SanitizeMoveRoute(name, data()->move_route, data()->move_route_index, "move_route_index"); } -void Game_Character::SanitizeMoveRoute(StringView name, const lcf::rpg::MoveRoute& mr, int32_t& idx, StringView chunk_name) { +void Game_Character::SanitizeMoveRoute(std::string_view name, const lcf::rpg::MoveRoute& mr, int32_t& idx, std::string_view chunk_name) { const auto n = static_cast(mr.move_commands.size()); if (idx < 0 || idx > n) { idx = n; diff --git a/src/game_character.h b/src/game_character.h index fc5cca9f82..8f19274d7a 100644 --- a/src/game_character.h +++ b/src/game_character.h @@ -43,7 +43,7 @@ class Game_Character { Vehicle }; - static StringView TypeToStr(Type t); + static std::string_view TypeToStr(Type t); virtual ~Game_Character() = default; Game_Character(Game_Character&&) = default; @@ -912,9 +912,9 @@ class Game_Character { protected: explicit Game_Character(Type type, lcf::rpg::SaveMapEventBase* d); /** Check for and fix incorrect data after loading save game */ - void SanitizeData(StringView name); + void SanitizeData(std::string_view name); /** Check for and fix incorrect move route data after loading save game */ - void SanitizeMoveRoute(StringView name, const lcf::rpg::MoveRoute& mr, int32_t& idx, StringView chunk_name); + void SanitizeMoveRoute(std::string_view name, const lcf::rpg::MoveRoute& mr, int32_t& idx, std::string_view chunk_name); void Update(); virtual void UpdateAnimation(); virtual void UpdateNextMovementAction() = 0; @@ -1403,7 +1403,7 @@ inline bool Game_Character::IsDirectionDiagonal(int d) { return d >= UpRight; } -inline StringView Game_Character::TypeToStr(Game_Character::Type type) { +inline std::string_view Game_Character::TypeToStr(Game_Character::Type type) { switch (type) { case Player: return "Player"; case Vehicle: return "Vehicle"; diff --git a/src/game_commonevent.cpp b/src/game_commonevent.cpp index 1f74ffe7d1..d15ab4dc59 100644 --- a/src/game_commonevent.cpp +++ b/src/game_commonevent.cpp @@ -73,7 +73,7 @@ int Game_CommonEvent::GetIndex() const { // Game_Map ensures validity of Common Events -StringView Game_CommonEvent::GetName() const { +std::string_view Game_CommonEvent::GetName() const { return lcf::ReaderUtil::GetElement(lcf::Data::commonevents, common_event_id)->name; } diff --git a/src/game_commonevent.h b/src/game_commonevent.h index f8069a3a0d..ae70179b0b 100644 --- a/src/game_commonevent.h +++ b/src/game_commonevent.h @@ -73,7 +73,7 @@ class Game_CommonEvent { * * @return event name. */ - StringView GetName() const; + std::string_view GetName() const; /** * Gets trigger condition. diff --git a/src/game_config.cpp b/src/game_config.cpp index e559244d43..3e44bd85f3 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -49,9 +49,9 @@ namespace { #if USE_SDL == 1 // For SDL1 hardcode a different config file because it uses a completely different mapping for gamepads - StringView config_name = "config_sdl1.ini"; + std::string_view config_name = "config_sdl1.ini"; #else - StringView config_name = EASYRPG_CONFIG_NAME; + std::string_view config_name = EASYRPG_CONFIG_NAME; #endif } diff --git a/src/game_dynrpg.cpp b/src/game_dynrpg.cpp index 6610808401..bb4a6263f6 100644 --- a/src/game_dynrpg.cpp +++ b/src/game_dynrpg.cpp @@ -40,7 +40,7 @@ enum DynRpg_ParseMode { }; // Var arg referenced by $n -std::string DynRpg::ParseVarArg(StringView func_name, dyn_arg_list args, int index, bool& parse_okay) { +std::string DynRpg::ParseVarArg(std::string_view func_name, dyn_arg_list args, int index, bool& parse_okay) { parse_okay = true; if (index >= static_cast(args.size())) { parse_okay = false; @@ -93,7 +93,7 @@ std::string DynRpg::ParseVarArg(StringView func_name, dyn_arg_list args, int ind } -static std::string ParseToken(std::string token, StringView function_name) { +static std::string ParseToken(std::string token, std::string_view function_name) { std::string::iterator text_index, end; text_index = token.begin(); end = token.end(); @@ -367,7 +367,7 @@ std::string DynRpg::ParseCommand(std::string command, std::vector& return function_name; } -bool Game_DynRpg::Invoke(StringView command, Game_Interpreter* interpreter) { +bool Game_DynRpg::Invoke(std::string_view command, Game_Interpreter* interpreter) { InitPlugins(); std::vector args; @@ -380,7 +380,7 @@ bool Game_DynRpg::Invoke(StringView command, Game_Interpreter* interpreter) { return Invoke(function_name, args, interpreter); } -bool Game_DynRpg::Invoke(StringView func, dyn_arg_list args, Game_Interpreter* interpreter) { +bool Game_DynRpg::Invoke(std::string_view func, dyn_arg_list args, Game_Interpreter* interpreter) { InitPlugins(); bool yield = false; diff --git a/src/game_dynrpg.h b/src/game_dynrpg.h index 591cf58e9c..edfd22967d 100644 --- a/src/game_dynrpg.h +++ b/src/game_dynrpg.h @@ -43,12 +43,12 @@ using dynfunc = bool(*)(dyn_arg_list); namespace DynRpg { class EasyRpgPlugin; - std::string ParseVarArg(StringView func_name, dyn_arg_list args, int index, bool& parse_okay); + std::string ParseVarArg(std::string_view func_name, dyn_arg_list args, int index, bool& parse_okay); std::string ParseCommand(std::string command, std::vector& params); namespace detail { template - inline bool parse_arg(StringView, dyn_arg_list, const int, T&, bool&) { + inline bool parse_arg(std::string_view, dyn_arg_list, const int, T&, bool&) { static_assert(sizeof(T) == -1, "Only parsing int, float and std::string supported"); return false; } @@ -56,7 +56,7 @@ namespace DynRpg { // FIXME: Extracting floats that are followed by chars behaviour varies depending on the C++ library // see https://bugs.llvm.org/show_bug.cgi?id=17782 template <> - inline bool parse_arg(StringView func_name, dyn_arg_list args, const int i, float& value, bool& parse_okay) { + inline bool parse_arg(std::string_view func_name, dyn_arg_list args, const int i, float& value, bool& parse_okay) { if (!parse_okay) return false; value = 0.0; if (args[i].empty()) { @@ -75,7 +75,7 @@ namespace DynRpg { } template <> - inline bool parse_arg(StringView func_name, dyn_arg_list args, const int i, int& value, bool& parse_okay) { + inline bool parse_arg(std::string_view func_name, dyn_arg_list args, const int i, int& value, bool& parse_okay) { if (!parse_okay) return false; value = 0; if (args[i].empty()) { @@ -93,7 +93,7 @@ namespace DynRpg { } template <> - inline bool parse_arg(StringView, dyn_arg_list args, const int i, std::string& value, bool& parse_okay) { + inline bool parse_arg(std::string_view, dyn_arg_list args, const int i, std::string& value, bool& parse_okay) { if (!parse_okay) return false; value = args[i]; parse_okay = true; @@ -101,14 +101,14 @@ namespace DynRpg { } template - inline void parse_args(StringView func_name, dyn_arg_list in, Tuple& value, bool& parse_okay, std::index_sequence) { + inline void parse_args(std::string_view func_name, dyn_arg_list in, Tuple& value, bool& parse_okay, std::index_sequence) { (void)std::initializer_list{parse_arg(func_name, in, I, std::get(value), parse_okay)...}; } } template - std::tuple ParseArgs(StringView func_name, dyn_arg_list args, bool* parse_okay = nullptr) { + std::tuple ParseArgs(std::string_view func_name, dyn_arg_list args, bool* parse_okay = nullptr) { std::tuple t; if (args.size() < sizeof...(Targs)) { if (parse_okay) @@ -129,7 +129,7 @@ namespace DynRpg { */ class Game_DynRpg { public: - bool Invoke(StringView command, Game_Interpreter* interpreter = nullptr); + bool Invoke(std::string_view command, Game_Interpreter* interpreter = nullptr); void Update(); void Load(int slot); void Save(int slot); @@ -137,7 +137,7 @@ class Game_DynRpg { private: friend DynRpg::EasyRpgPlugin; - bool Invoke(StringView func, dyn_arg_list args, Game_Interpreter* interpreter = nullptr); + bool Invoke(std::string_view func, dyn_arg_list args, Game_Interpreter* interpreter = nullptr); void InitPlugins(); using dyn_rpg_func = std::unordered_map; @@ -158,8 +158,8 @@ class DynRpgPlugin { DynRpgPlugin() = delete; virtual ~DynRpgPlugin() = default; - StringView GetIdentifier() const { return identifier; } - virtual bool Invoke(StringView func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) = 0; + std::string_view GetIdentifier() const { return identifier; } + virtual bool Invoke(std::string_view func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) = 0; virtual void Update() {} virtual void Load(const std::vector&) {} virtual std::vector Save() { return {}; } diff --git a/src/game_enemy.h b/src/game_enemy.h index 0821c2fed9..416cecc008 100644 --- a/src/game_enemy.h +++ b/src/game_enemy.h @@ -59,7 +59,7 @@ class Game_Enemy final : public Game_Battler /** * Gets the base attribute rate when actor is damaged. - * + * * @param attribute_id Attribute to query * @return Attribute rate */ @@ -84,7 +84,7 @@ class Game_Enemy final : public Game_Battler * * @return Character name */ - StringView GetName() const override; + std::string_view GetName() const override; /** @return The troop member id in the battle lineup */ int GetTroopMemberId() const; @@ -94,7 +94,7 @@ class Game_Enemy final : public Game_Battler * * @return Filename of enemy sprite */ - StringView GetSpriteName() const override; + std::string_view GetSpriteName() const override; /** * Gets the maximum HP for the current level. @@ -366,11 +366,11 @@ inline std::vector& Game_Enemy::GetStates() { return states; } -inline StringView Game_Enemy::GetName() const { +inline std::string_view Game_Enemy::GetName() const { return enemy->name; } -inline StringView Game_Enemy::GetSpriteName() const { +inline std::string_view Game_Enemy::GetSpriteName() const { return enemy->battler_name; } diff --git a/src/game_event.cpp b/src/game_event.cpp index 62c78757a3..a409e6aece 100644 --- a/src/game_event.cpp +++ b/src/game_event.cpp @@ -48,7 +48,7 @@ Game_Event::Game_Event(int map_id, const lcf::rpg::Event* event) : } void Game_Event::SanitizeData() { - StringView name = event->name; + std::string_view name = event->name; Game_Character::SanitizeData(name); if (page != nullptr) { SanitizeMoveRoute(name, page->move_route, data()->original_move_route_index, "original_move_route_index"); @@ -297,7 +297,7 @@ int Game_Event::GetId() const { return data()->ID; } -StringView Game_Event::GetName() const { +std::string_view Game_Event::GetName() const { return event->name; } diff --git a/src/game_event.h b/src/game_event.h index 94139a7a91..225cc4e4a4 100644 --- a/src/game_event.h +++ b/src/game_event.h @@ -77,7 +77,7 @@ class Game_Event : public Game_EventBase { * * @return event name. */ - StringView GetName() const; + std::string_view GetName() const; /** Clears waiting_execution flag */ void ClearWaitingForegroundExecution(); diff --git a/src/game_ineluki.cpp b/src/game_ineluki.cpp index 8e5a6d1982..d8d7ab20dd 100644 --- a/src/game_ineluki.cpp +++ b/src/game_ineluki.cpp @@ -73,7 +73,7 @@ bool Game_Ineluki::Execute(const lcf::rpg::Sound& se) { return false; } -bool Game_Ineluki::Execute(StringView ini_file) { +bool Game_Ineluki::Execute(std::string_view ini_file) { auto ini_file_s = ToString(ini_file); if (functions.find(ini_file_s) == functions.end()) { @@ -89,10 +89,10 @@ bool Game_Ineluki::Execute(StringView ini_file) { Output::InfoStr(cmd.arg); } else if (cmd.name == "execprogram") { // Fake execute some known programs - if (StringView(cmd.arg).starts_with("exitgame") || - StringView(cmd.arg).starts_with("taskkill")) { + if (StartsWith(cmd.arg, "exitgame") || + StartsWith(cmd.arg, "taskkill")) { Player::exit_flag = true; - } else if (StringView(cmd.arg).starts_with("SaveCount.dat")) { + } else if (StartsWith(cmd.arg, "SaveCount.dat")) { // no-op, detected through saves.script access } else { Output::Warning("Ineluki ExecProgram {}: Not supported", cmd.arg); @@ -179,7 +179,7 @@ bool Game_Ineluki::Execute(StringView ini_file) { return true; } -bool Game_Ineluki::ExecuteScriptList(StringView list_file) { +bool Game_Ineluki::ExecuteScriptList(std::string_view list_file) { auto is = FileFinder::Game().OpenInputStream(ToString(list_file)); assert(async_scripts.empty()); @@ -208,7 +208,7 @@ bool Game_Ineluki::ExecuteScriptList(StringView list_file) { return true; } -bool Game_Ineluki::Parse(StringView ini_file) { +bool Game_Ineluki::Parse(std::string_view ini_file) { auto ini_file_s = ToString(ini_file); auto is = FileFinder::Game().OpenInputStream(ini_file_s); diff --git a/src/game_ineluki.h b/src/game_ineluki.h index 72f33c1de4..ba8588da7a 100644 --- a/src/game_ineluki.h +++ b/src/game_ineluki.h @@ -52,7 +52,7 @@ class Game_Ineluki { * @param ini_file INI file to execute * @return Whether the file is a valid script */ - bool Execute(StringView ini_file); + bool Execute(std::string_view ini_file); /** * Executes a file containing a list of script files. @@ -63,7 +63,7 @@ class Game_Ineluki { * @param list_file File to process * @return Whether the file was found */ - bool ExecuteScriptList(StringView list_file); + bool ExecuteScriptList(std::string_view list_file); /** * Returns the normal midi ticks or an element from the output list depending @@ -85,7 +85,7 @@ class Game_Ineluki { * @param ini_file Script to parse * @return Whether the file is a valid script */ - bool Parse(StringView ini_file); + bool Parse(std::string_view ini_file); struct InelukiCommand { std::string name; diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 2ff69b7a5b..39a19d825b 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -1504,7 +1504,7 @@ std::vector Game_Interpreter::GetActors(int mode, int id) { return actors; } -Game_Character* Game_Interpreter::GetCharacter(int event_id, StringView origin) const { +Game_Character* Game_Interpreter::GetCharacter(int event_id, std::string_view origin) const { if (event_id == Game_Character::CharThisEvent) { event_id = GetThisEventId(); // Is a common event @@ -2015,7 +2015,7 @@ bool Game_Interpreter::CommandComment(const lcf::rpg::EventCommand &com) { if (!Player::IsPatchDynRpg() && Player::HasEasyRpgExtensions()) { // Only accept commands starting with @easyrpg_ - if (!StringView(com.string).starts_with("@easyrpg_")) { + if (!StartsWith(com.string, "@easyrpg_")) { return true; } } @@ -3647,8 +3647,8 @@ bool Game_Interpreter::CommandConditionalBranch(lcf::rpg::EventCommand const& co int ignoreCase = com.parameters[4] >> 8 & 1; std::string str_param = ToString(com.string); - StringView str_l = Main_Data::game_strings->GetWithMode(str_param, modes[0]+1, com.parameters[2], *Main_Data::game_variables); - StringView str_r = Main_Data::game_strings->GetWithMode(str_param, modes[1], com.parameters[3], *Main_Data::game_variables); + std::string_view str_l = Main_Data::game_strings->GetWithMode(str_param, modes[0]+1, com.parameters[2], *Main_Data::game_variables); + std::string_view str_r = Main_Data::game_strings->GetWithMode(str_param, modes[1], com.parameters[3], *Main_Data::game_variables); result = ManiacPatch::CheckString(str_l, str_r, op, ignoreCase); } break; @@ -4174,7 +4174,7 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co Main_Data::game_variables->Set(com.parameters[3], 0); break; } - Main_Data::game_strings->Asg(var, StringView(character->GetSpriteName())); + Main_Data::game_strings->Asg(var, std::string_view(character->GetSpriteName())); Main_Data::game_variables->Set(com.parameters[3], character->GetSpriteIndex()); break; } else { @@ -4182,19 +4182,19 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co switch (event_id) { case Game_Character::CharPlayer: // Return dynamic player sprite - Main_Data::game_strings->Asg(var, StringView(character->GetSpriteName())); + Main_Data::game_strings->Asg(var, std::string_view(character->GetSpriteName())); Main_Data::game_variables->Set(com.parameters[3], character->GetSpriteIndex()); break; case Game_Character::CharBoat: - Main_Data::game_strings->Asg(var, StringView(lcf::Data::system.boat_name)); + Main_Data::game_strings->Asg(var, std::string_view(lcf::Data::system.boat_name)); Main_Data::game_variables->Set(com.parameters[3], lcf::Data::system.boat_index); break; case Game_Character::CharShip: - Main_Data::game_strings->Asg(var, StringView(lcf::Data::system.ship_name)); + Main_Data::game_strings->Asg(var, std::string_view(lcf::Data::system.ship_name)); Main_Data::game_variables->Set(com.parameters[3], lcf::Data::system.ship_index); break; case Game_Character::CharAirship: - Main_Data::game_strings->Asg(var, StringView(lcf::Data::system.airship_name)); + Main_Data::game_strings->Asg(var, std::string_view(lcf::Data::system.airship_name)); Main_Data::game_variables->Set(com.parameters[3], lcf::Data::system.airship_index); break; default: { @@ -4205,7 +4205,7 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co Main_Data::game_strings->Asg(var, ""); Main_Data::game_variables->Set(com.parameters[3], 0); } else { - Main_Data::game_strings->Asg(var, StringView(page->character_name)); + Main_Data::game_strings->Asg(var, std::string_view(page->character_name)); Main_Data::game_variables->Set(com.parameters[3], page->character_index); } } @@ -5128,7 +5128,7 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& case 12: //File (file) { // maniacs does not like a file extension - StringView filename = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); + std::string_view filename = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); // args[1] is the encoding... 0 for ansi, 1 for utf8 bool do_yield; result = Game_Strings::FromFile(filename, args[1], do_yield); @@ -5188,7 +5188,7 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& break; case 4: //inStr FIXME: takes hex? { - StringView search = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); + std::string_view search = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); args[1] = ValueOrVariable(modes[1], args[1]); // not sure this is necessary but better safe args[2] = ValueOrVariable(modes[2], args[2]); @@ -5198,7 +5198,7 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& } case 5: //split takes hex { - StringView delimiter = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); + std::string_view delimiter = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); args[1] = ValueOrVariable(modes[1], args[1]); args[2] = ValueOrVariable(modes[2], args[2]); @@ -5208,7 +5208,7 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& } case 7: //toFile takes hex { - StringView filename = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); + std::string_view filename = Main_Data::game_strings->GetWithMode(str_param, modes[0], args[0], *Main_Data::game_variables); args[1] = ValueOrVariable(modes[1], args[1]); Main_Data::game_strings->ToFile(str_params, ToString(filename), args[1]); diff --git a/src/game_interpreter.h b/src/game_interpreter.h index 04bf3afda3..8f5b40af34 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -95,7 +95,7 @@ class Game_Interpreter : public Game_BaseInterpreterContext lcf::rpg::SaveEventExecState GetSaveState(); /** @return Game_Character of the passed event_id */ - Game_Character* GetCharacter(int event_id, StringView origin) const override; + Game_Character* GetCharacter(int event_id, std::string_view origin) const override; /** @return the event_id of the current frame */ int GetCurrentEventId() const; diff --git a/src/game_interpreter_map.cpp b/src/game_interpreter_map.cpp index 6a25531866..915eddd541 100644 --- a/src/game_interpreter_map.cpp +++ b/src/game_interpreter_map.cpp @@ -468,7 +468,7 @@ bool Game_Interpreter_Map::CommandShowInn(lcf::rpg::EventCommand const& com) { / PendingMessage pm(Game_Message::CommandCodeInserter); pm.SetFromForegroundInterpreter(main_flag); - StringView greeting_1, greeting_2, greeting_3, accept, cancel; + std::string_view greeting_1, greeting_2, greeting_3, accept, cancel; switch (inn_type) { case 0: diff --git a/src/game_interpreter_shared.cpp b/src/game_interpreter_shared.cpp index d4bebfa733..ee923ada5b 100644 --- a/src/game_interpreter_shared.cpp +++ b/src/game_interpreter_shared.cpp @@ -158,7 +158,7 @@ int Game_Interpreter_Shared::ValueOrVariableBitfield(lcf::rpg::EventCommand cons return com.parameters[val_idx]; } -StringView Game_Interpreter_Shared::CommandStringOrVariable(lcf::rpg::EventCommand const& com, int mode_idx, int val_idx) { +std::string_view Game_Interpreter_Shared::CommandStringOrVariable(lcf::rpg::EventCommand const& com, int mode_idx, int val_idx) { if (!Player::IsPatchManiac()) { return com.string; } @@ -172,7 +172,7 @@ StringView Game_Interpreter_Shared::CommandStringOrVariable(lcf::rpg::EventComma return com.string; } -StringView Game_Interpreter_Shared::CommandStringOrVariableBitfield(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx) { +std::string_view Game_Interpreter_Shared::CommandStringOrVariableBitfield(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx) { if (!Player::IsPatchManiac()) { return com.string; } diff --git a/src/game_interpreter_shared.h b/src/game_interpreter_shared.h index 99e3cb3d59..6cea473a31 100644 --- a/src/game_interpreter_shared.h +++ b/src/game_interpreter_shared.h @@ -93,8 +93,8 @@ namespace Game_Interpreter_Shared { template int ValueOrVariableBitfield(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx, Game_BaseInterpreterContext const& interpreter); - StringView CommandStringOrVariable(lcf::rpg::EventCommand const& com, int mode_idx, int val_idx); - StringView CommandStringOrVariableBitfield(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx); + std::string_view CommandStringOrVariable(lcf::rpg::EventCommand const& com, int mode_idx, int val_idx); + std::string_view CommandStringOrVariableBitfield(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx); bool CheckOperator(int val, int val2, int op); @@ -146,7 +146,7 @@ class Game_BaseInterpreterContext { virtual ~Game_BaseInterpreterContext() {} virtual int GetThisEventId() const = 0; - virtual Game_Character* GetCharacter(int event_id, StringView origin) const = 0; + virtual Game_Character* GetCharacter(int event_id, std::string_view origin) const = 0; virtual const lcf::rpg::SaveEventExecFrame& GetFrame() const = 0; protected: diff --git a/src/game_map.cpp b/src/game_map.cpp index 5180fdd437..553e887b00 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -399,7 +399,7 @@ void Game_Map::Caching::MapCache::Clear() { } } -bool Game_Map::CloneMapEvent(int src_map_id, int src_event_id, int target_x, int target_y, int target_event_id, StringView target_name) { +bool Game_Map::CloneMapEvent(int src_map_id, int src_event_id, int target_x, int target_y, int target_event_id, std::string_view target_name) { std::unique_ptr source_map_storage; const lcf::rpg::Map* source_map; @@ -1631,10 +1631,10 @@ int Game_Map::GetChipset() { return chipset != nullptr ? chipset->ID : 0; } -StringView Game_Map::GetChipsetName() { +std::string_view Game_Map::GetChipsetName() { return chipset != nullptr - ? StringView(chipset->chipset_name) - : StringView(""); + ? std::string_view(chipset->chipset_name) + : std::string_view(""); } int Game_Map::GetPositionX() { @@ -1762,7 +1762,7 @@ std::vector& Game_Map::GetCommonEvents() { return common_events; } -StringView Game_Map::GetMapName(int id) { +std::string_view Game_Map::GetMapName(int id) { for (unsigned int i = 0; i < lcf::Data::treemap.maps.size(); ++i) { if (lcf::Data::treemap.maps[i].ID == id) { return lcf::Data::treemap.maps[i].name; diff --git a/src/game_map.h b/src/game_map.h index a5f37b7b8b..b1d2fd9eba 100644 --- a/src/game_map.h +++ b/src/game_map.h @@ -107,7 +107,7 @@ namespace Game_Map { * @param target_name New name of the event. When empty the original name is used. * @return Whether the cloning was successful. It will fail when source map or the src/target event do not exist. */ - bool CloneMapEvent(int src_map_id, int src_event_id, int target_x, int target_y, int target_event_id, StringView target_name); + bool CloneMapEvent(int src_map_id, int src_event_id, int target_x, int target_y, int target_event_id, std::string_view target_name); /** * Deletes a map event. @@ -485,7 +485,7 @@ namespace Game_Map { int GetChipset(); /** @return chipset filename. */ - StringView GetChipsetName(); + std::string_view GetChipsetName(); /** * Gets the offset of the screen from the left edge @@ -625,7 +625,7 @@ namespace Game_Map { * @param id map ID. * @return map name from MapInfo vector. */ - StringView GetMapName(int id); + std::string_view GetMapName(int id); /** * Sets the chipset. diff --git a/src/game_message.cpp b/src/game_message.cpp index cfb9edd653..2ae087c106 100644 --- a/src/game_message.cpp +++ b/src/game_message.cpp @@ -81,11 +81,11 @@ int Game_Message::GetRealPosition() { } } -int Game_Message::WordWrap(StringView line, const int limit, const WordWrapCallback& callback) { +int Game_Message::WordWrap(std::string_view line, const int limit, const WordWrapCallback& callback) { return WordWrap(line, limit, callback, *Font::Default()); } -int Game_Message::WordWrap(StringView line, const int limit, const WordWrapCallback& callback, const Font& font) { +int Game_Message::WordWrap(std::string_view line, const int limit, const WordWrapCallback& callback, const Font& font) { int start = 0; int line_count = 0; diff --git a/src/game_message.h b/src/game_message.h index 555c2bdd21..59959e826c 100644 --- a/src/game_message.h +++ b/src/game_message.h @@ -60,7 +60,7 @@ namespace Game_Message { void SetPendingMessage(PendingMessage&& pm); /** Callback type for WordWrap function */ - using WordWrapCallback = const std::function; + using WordWrapCallback = const std::function; /** * Breaks the line into lines, each of which is equal @@ -80,8 +80,8 @@ namespace Game_Message { * @param[in] limit maximum size of each line after word-breaking. * @param callback a function to be called for each word-wrapped line */ - int WordWrap(StringView line, int limit, const WordWrapCallback& callback); - int WordWrap(StringView line, int limit, const WordWrapCallback& callback, const Font& font); + int WordWrap(std::string_view line, int limit, const WordWrapCallback& callback); + int WordWrap(std::string_view line, int limit, const WordWrapCallback& callback, const Font& font); /** * Return if it's legal to show a new message box. diff --git a/src/game_strings.cpp b/src/game_strings.cpp index 3a6e2ab13c..79a318f959 100644 --- a/src/game_strings.cpp +++ b/src/game_strings.cpp @@ -56,12 +56,12 @@ nlohmann::json* Game_Strings::ParseJson(int id) { } #endif -StringView Game_Strings::Asg(Str_Params params, StringView string) { +std::string_view Game_Strings::Asg(Str_Params params, std::string_view string) { Set(params, string); return Get(params.string_id); } -StringView Game_Strings::Cat(Str_Params params, StringView string) { +std::string_view Game_Strings::Cat(Str_Params params, std::string_view string) { if (params.string_id <= 0) { return {}; } @@ -189,7 +189,7 @@ int Game_Strings::Split(Str_Params params, const std::string& delimiter, int str return components; } -std::string Game_Strings::FromFile(StringView filename, int encoding, bool& do_yield) { +std::string Game_Strings::FromFile(std::string_view filename, int encoding, bool& do_yield) { do_yield = false; Filesystem_Stream::InputStream is = FileFinder::OpenText(filename); @@ -219,7 +219,7 @@ std::string Game_Strings::FromFile(StringView filename, int encoding, bool& do_y return file_content; } -StringView Game_Strings::ToFile(Str_Params params, std::string filename, int encoding) { +std::string_view Game_Strings::ToFile(Str_Params params, std::string filename, int encoding) { std::string str = ToString(Get(params.string_id)); if (params.extract) { @@ -265,14 +265,14 @@ StringView Game_Strings::ToFile(Str_Params params, std::string filename, int enc return str; } -StringView Game_Strings::PopLine(Str_Params params, int offset, int string_out_id) { +std::string_view Game_Strings::PopLine(Str_Params params, int offset, int string_out_id) { // FIXME: consideration needed around encoding -- what mode are files read in? if (params.string_id <= 0) { return {}; } std::string result; - StringView str = Get(params.string_id); + std::string_view str = Get(params.string_id); std::stringstream ss(ToString(str)); @@ -291,7 +291,7 @@ StringView Game_Strings::PopLine(Str_Params params, int offset, int string_out_i return Get(params.string_id); } -StringView Game_Strings::ExMatch(Str_Params params, std::string expr, int var_id, int begin, int string_out_id, Game_Variables& variables) { +std::string_view Game_Strings::ExMatch(Str_Params params, std::string expr, int var_id, int begin, int string_out_id, Game_Variables& variables) { // std::regex only works with char and wchar, not char32 // For full Unicode support requires the w-API, even on non-Windows systems int var_result; @@ -358,7 +358,7 @@ const Game_Strings::Strings_t& Game_Strings::RangeOp(Str_Params params, int stri return GetData(); } -std::string Game_Strings::PrependMin(StringView string, int min_size, char c) { +std::string Game_Strings::PrependMin(std::string_view string, int min_size, char c) { int len = Utils::UTF8Length(string); if (min_size < 0) { @@ -376,7 +376,7 @@ std::string Game_Strings::PrependMin(StringView string, int min_size, char c) { return ToString(string); } -std::string Game_Strings::Extract(StringView string, bool as_hex) { +std::string Game_Strings::Extract(std::string_view string, bool as_hex) { PendingMessage::CommandInserter cmd_fn; if (as_hex) { @@ -388,7 +388,7 @@ std::string Game_Strings::Extract(StringView string, bool as_hex) { return PendingMessage::ApplyTextInsertingCommands(ToString(string), Player::escape_char, cmd_fn); } -std::string Game_Strings::Substring(StringView source, int begin, int length) { +std::string Game_Strings::Substring(std::string_view source, int begin, int length) { const char* iter = source.data(); const auto end = source.data() + source.size(); @@ -411,7 +411,7 @@ std::string Game_Strings::Substring(StringView source, int begin, int length) { } } -std::string Game_Strings::Insert(StringView source, StringView what, int where) { +std::string Game_Strings::Insert(std::string_view source, std::string_view what, int where) { const char* iter = source.data(); const auto end = source.data() + source.size(); @@ -423,7 +423,7 @@ std::string Game_Strings::Insert(StringView source, StringView what, int where) return std::string(source.data(), ret.next) + ToString(what) + std::string(ret.next, end); } -std::string Game_Strings::Erase(StringView source, int begin, int length) { +std::string Game_Strings::Erase(std::string_view source, int begin, int length) { const char* iter = source.data(); const auto end = source.data() + source.size(); @@ -451,7 +451,7 @@ std::string Game_Strings::Erase(StringView source, int begin, int length) { return ret; } -std::string Game_Strings::RegExReplace(StringView str, StringView search, StringView replace, std::regex_constants::match_flag_type flags) { +std::string Game_Strings::RegExReplace(std::string_view str, std::string_view search, std::string_view replace, std::regex_constants::match_flag_type flags) { // std::regex only works with char and wchar, not char32 // For full Unicode support requires the w-API, even on non-Windows systems auto wstr = Utils::ToWideString(str); @@ -465,7 +465,7 @@ std::string Game_Strings::RegExReplace(StringView str, StringView search, String return Utils::FromWideString(result); } -int Game_Strings::AdjustIndex(StringView str, int index) { +int Game_Strings::AdjustIndex(std::string_view str, int index) { if (index >= 0) { return index; } diff --git a/src/game_strings.h b/src/game_strings.h index 739b8f77c8..b2b74ae504 100644 --- a/src/game_strings.h +++ b/src/game_strings.h @@ -72,41 +72,41 @@ class Game_Strings { const Strings_t& GetData() const; std::vector GetLcfData() const; - StringView Get(int id) const; - StringView GetIndirect(int id, const Game_Variables& variables) const; - StringView GetWithMode(StringView str_data, int mode, int arg, const Game_Variables& variables) const; - std::string GetWithModeAndPos(StringView str_data, int mode, int arg, int& pos, const Game_Variables& variables); + std::string_view Get(int id) const; + std::string_view GetIndirect(int id, const Game_Variables& variables) const; + std::string_view GetWithMode(std::string_view str_data, int mode, int arg, const Game_Variables& variables) const; + std::string GetWithModeAndPos(std::string_view str_data, int mode, int arg, int& pos, const Game_Variables& variables); #ifdef HAVE_NLOHMANN_JSON nlohmann::json* ParseJson(int id); #endif - StringView Asg(Str_Params params, StringView string); - StringView Cat(Str_Params params, StringView string); + std::string_view Asg(Str_Params params, std::string_view string); + std::string_view Cat(Str_Params params, std::string_view string); int ToNum(Str_Params params, int var_id, Game_Variables& variables); int GetLen(Str_Params params, int var_id, Game_Variables& variables) const; int InStr(Str_Params params, std::string search, int var_id, int begin, Game_Variables& variables) const; int Split(Str_Params params, const std::string& delimiter, int string_out_id, int var_id, Game_Variables& variables); - static std::string FromFile(StringView filename, int encoding, bool& do_yield); - StringView ToFile(Str_Params params, std::string filename, int encoding); - StringView PopLine(Str_Params params, int offset, int string_out_id); - StringView ExMatch(Str_Params params, std::string expr, int var_id, int begin, int string_out_id, Game_Variables& variables); + static std::string FromFile(std::string_view filename, int encoding, bool& do_yield); + std::string_view ToFile(Str_Params params, std::string filename, int encoding); + std::string_view PopLine(Str_Params params, int offset, int string_out_id); + std::string_view ExMatch(Str_Params params, std::string expr, int var_id, int begin, int string_out_id, Game_Variables& variables); const Strings_t& RangeOp(Str_Params params, int string_id_1, std::string string, int op, int args[], Game_Variables& variables); - static std::string PrependMin(StringView string, int min_size, char c); - static std::string Extract(StringView string, bool as_hex); - static std::string Substring(StringView source, int begin, int length); - static std::string Insert(StringView source, StringView what, int where); - static std::string Erase(StringView source, int begin, int length); - static std::string RegExReplace(StringView str, StringView search, StringView replace, std::regex_constants::match_flag_type flags = std::regex_constants::match_default); - static int AdjustIndex(StringView str, int index); + static std::string PrependMin(std::string_view string, int min_size, char c); + static std::string Extract(std::string_view string, bool as_hex); + static std::string Substring(std::string_view source, int begin, int length); + static std::string Insert(std::string_view source, std::string_view what, int where); + static std::string Erase(std::string_view source, int begin, int length); + static std::string RegExReplace(std::string_view str, std::string_view search, std::string_view replace, std::regex_constants::match_flag_type flags = std::regex_constants::match_default); + static int AdjustIndex(std::string_view str, int index); static std::optional ManiacsCommandInserter(char ch, const char** iter, const char* end, uint32_t escape_char); static std::optional ManiacsCommandInserterHex(char ch, const char** iter, const char* end, uint32_t escape_char); private: - void Set(Str_Params params, StringView string); + void Set(Str_Params params, std::string_view string); bool ShouldWarn(int id) const; void WarnGet(int id) const; @@ -118,7 +118,7 @@ class Game_Strings { #endif }; -inline void Game_Strings::Set(Str_Params params, StringView string) { +inline void Game_Strings::Set(Str_Params params, std::string_view string) { if (params.string_id <= 0) { return; } @@ -188,7 +188,7 @@ inline bool Game_Strings::ShouldWarn(int id) const { return id <= 0 && _warnings > 0; } -inline StringView Game_Strings::Get(int id) const { +inline std::string_view Game_Strings::Get(int id) const { if (EP_UNLIKELY(ShouldWarn(id))) { WarnGet(id); } @@ -199,12 +199,12 @@ inline StringView Game_Strings::Get(int id) const { return it->second; } -inline StringView Game_Strings::GetIndirect(int id, const Game_Variables& variables) const { +inline std::string_view Game_Strings::GetIndirect(int id, const Game_Variables& variables) const { auto val_indirect = variables.Get(id); return Get(static_cast(val_indirect)); } -inline StringView Game_Strings::GetWithMode(StringView str_data, int mode, int arg, const Game_Variables& variables) const { +inline std::string_view Game_Strings::GetWithMode(std::string_view str_data, int mode, int arg, const Game_Variables& variables) const { switch (mode) { case StringEvalMode::eStringEval_Direct: return Get(arg); @@ -215,7 +215,7 @@ inline StringView Game_Strings::GetWithMode(StringView str_data, int mode, int a } } -inline std::string Game_Strings::GetWithModeAndPos(StringView str_data, int mode, int arg, int& pos, const Game_Variables& variables) { +inline std::string Game_Strings::GetWithModeAndPos(std::string_view str_data, int mode, int arg, int& pos, const Game_Variables& variables) { std::string ret; switch (mode) { case StringEvalMode::eStringEval_Text: { diff --git a/src/game_switches.cpp b/src/game_switches.cpp index 0057fc2872..74b864f786 100644 --- a/src/game_switches.cpp +++ b/src/game_switches.cpp @@ -86,7 +86,7 @@ void Game_Switches::FlipRange(int first_id, int last_id) { } } -StringView Game_Switches::GetName(int _id) const { +std::string_view Game_Switches::GetName(int _id) const { const auto* sw = lcf::ReaderUtil::GetElement(lcf::Data::switches, _id); if (!sw) { diff --git a/src/game_switches.h b/src/game_switches.h index 4ddfa67c24..62b8e4f3f4 100644 --- a/src/game_switches.h +++ b/src/game_switches.h @@ -49,7 +49,7 @@ class Game_Switches { bool Flip(int switch_id); void FlipRange(int first_id, int last_id); - StringView GetName(int switch_id) const; + std::string_view GetName(int switch_id) const; bool IsValid(int switch_id) const; diff --git a/src/game_system.cpp b/src/game_system.cpp index 130b6a5553..a4f0556ad0 100644 --- a/src/game_system.cpp +++ b/src/game_system.cpp @@ -50,7 +50,7 @@ const lcf::rpg::SaveSystem& Game_System::GetSaveData() const { return data; } -bool Game_System::IsStopFilename(StringView name, Filesystem_Stream::InputStream (*find_func) (StringView), Filesystem_Stream::InputStream& found_stream) { +bool Game_System::IsStopFilename(std::string_view name, Filesystem_Stream::InputStream (*find_func) (std::string_view), Filesystem_Stream::InputStream& found_stream) { if (name.empty() || name == "(OFF)") { found_stream = Filesystem_Stream::InputStream(); return true; @@ -58,14 +58,14 @@ bool Game_System::IsStopFilename(StringView name, Filesystem_Stream::InputStream found_stream = find_func(name); - return !found_stream && (name.starts_with('(') && name.ends_with(')')); + return !found_stream && (StartsWith(name, '(') && EndsWith(name, ')')); } -bool Game_System::IsStopMusicFilename(StringView name, Filesystem_Stream::InputStream& found_stream) { +bool Game_System::IsStopMusicFilename(std::string_view name, Filesystem_Stream::InputStream& found_stream) { return IsStopFilename(name, FileFinder::OpenMusic, found_stream); } -bool Game_System::IsStopSoundFilename(StringView name, Filesystem_Stream::InputStream& found_stream) { +bool Game_System::IsStopSoundFilename(std::string_view name, Filesystem_Stream::InputStream& found_stream) { return IsStopFilename(name, FileFinder::OpenSound, found_stream); } @@ -182,7 +182,7 @@ void Game_System::SePlay(const lcf::rpg::Sound& se, bool stop_sounds) { se_adj.volume = volume; se_adj.tempo = tempo; se_request_ids[se.name] = request->Bind(&Game_System::OnSeReady, this, se_adj, stop_sounds); - if (StringView(se.name).ends_with(".script")) { + if (EndsWith(se.name, ".script")) { // Is a Ineluki Script File request->SetImportantFile(true); } @@ -199,9 +199,9 @@ void Game_System::SePlay(const lcf::rpg::Animation &animation) { } } -StringView Game_System::GetSystemName() { +std::string_view Game_System::GetSystemName() { return !data.graphics_name.empty() ? - StringView(data.graphics_name) : StringView(lcf::Data::system.system_name); + std::string_view(data.graphics_name) : std::string_view(lcf::Data::system.system_name); } void Game_System::OnChangeSystemGraphicReady(FileRequestResult* result) { @@ -536,7 +536,7 @@ void Game_System::OnBgmReady(FileRequestResult* result) { return; } - if (Player::IsPatchKeyPatch() && StringView(result->file).ends_with(".link") && stream.GetSize() < 500) { + if (Player::IsPatchKeyPatch() && EndsWith(result->file, ".link") && stream.GetSize() < 500) { // Handle Ineluki's MP3 patch std::string line = InelukiReadLink(stream); @@ -562,7 +562,7 @@ void Game_System::OnSeReady(FileRequestResult* result, lcf::rpg::Sound se, bool se_request_ids.erase(item); } - if (Player::IsPatchKeyPatch() && StringView(result->file).ends_with(".script")) { + if (Player::IsPatchKeyPatch() && EndsWith(result->file, ".script")) { // Is a Ineluki Script File Main_Data::game_ineluki->Execute(se); return; @@ -581,7 +581,7 @@ void Game_System::OnSeReady(FileRequestResult* result, lcf::rpg::Sound se, bool return; } - if (Player::IsPatchKeyPatch() && StringView(result->file).ends_with(".link") && stream.GetSize() < 500) { + if (Player::IsPatchKeyPatch() && EndsWith(result->file, ".link") && stream.GetSize() < 500) { // Handle Ineluki's MP3 patch std::string line = InelukiReadLink(stream); diff --git a/src/game_system.h b/src/game_system.h index 4feee2ce17..ac3d34fb38 100644 --- a/src/game_system.h +++ b/src/game_system.h @@ -136,7 +136,7 @@ class Game_System { void SePlay(const lcf::rpg::Animation& animation); /** @return system graphic filename. */ - StringView GetSystemName(); + std::string_view GetSystemName(); /** @return message stretch style */ lcf::rpg::System::Stretch GetMessageStretch(); @@ -159,7 +159,7 @@ class Game_System { void ResetSystemGraphic(); /** @return the system2 graphic name */ - StringView GetSystem2Name(); + std::string_view GetSystem2Name(); /** @return true if the game has a configured system graphic */ bool HasSystemGraphic(); @@ -248,12 +248,12 @@ class Game_System { * @return true when the file is supposed to Stop playback. * false otherwise and a handle to the file is returned in found_stream */ - static bool IsStopFilename(StringView name, Filesystem_Stream::InputStream (*find_func) (StringView), Filesystem_Stream::InputStream& found_stream); + static bool IsStopFilename(std::string_view name, Filesystem_Stream::InputStream (*find_func) (std::string_view), Filesystem_Stream::InputStream& found_stream); - static bool IsStopMusicFilename(StringView name, Filesystem_Stream::InputStream& found_stream); - static bool IsStopMusicFilename(StringView name); - static bool IsStopSoundFilename(StringView name, Filesystem_Stream::InputStream& found_stream); - static bool IsStopSoundFilename(StringView name); + static bool IsStopMusicFilename(std::string_view name, Filesystem_Stream::InputStream& found_stream); + static bool IsStopMusicFilename(std::string_view name); + static bool IsStopSoundFilename(std::string_view name, Filesystem_Stream::InputStream& found_stream); + static bool IsStopSoundFilename(std::string_view name); /** @return current atb mode */ AtbMode GetAtbMode(); @@ -313,7 +313,7 @@ class Game_System { void ClearMessageFace(); /** @return name of file that contains the face. */ - StringView GetMessageFaceName(); + std::string_view GetMessageFaceName(); /** * Set FaceSet graphic file containing the face. @@ -463,12 +463,12 @@ inline bool Game_System::HasSystem2Graphic() { return !GetSystem2Name().empty(); } -inline bool Game_System::IsStopMusicFilename(StringView name) { +inline bool Game_System::IsStopMusicFilename(std::string_view name) { Filesystem_Stream::InputStream s; return IsStopMusicFilename(name, s); } -inline bool Game_System::IsStopSoundFilename(StringView name) { +inline bool Game_System::IsStopSoundFilename(std::string_view name) { Filesystem_Stream::InputStream s; return IsStopSoundFilename(name, s); } @@ -478,7 +478,7 @@ inline void Game_System::ClearMessageFace() { SetMessageFaceIndex(0); } -inline StringView Game_System::GetMessageFaceName() { +inline std::string_view Game_System::GetMessageFaceName() { return data.face_name; } @@ -614,7 +614,7 @@ inline void Game_System::IncSaveCount() { ++data.save_count; } -inline StringView Game_System::GetSystem2Name() { +inline std::string_view Game_System::GetSystem2Name() { return dbsys->system2_name; } diff --git a/src/game_variables.cpp b/src/game_variables.cpp index d255ace021..07f36e8f4f 100644 --- a/src/game_variables.cpp +++ b/src/game_variables.cpp @@ -596,7 +596,7 @@ void Game_Variables::SwapArray(int first_id_a, int last_id_a, int first_id_b) { } } -StringView Game_Variables::GetName(int _id) const { +std::string_view Game_Variables::GetName(int _id) const { const auto* var = lcf::ReaderUtil::GetElement(lcf::Data::variables, _id); if (!var) { diff --git a/src/game_variables.h b/src/game_variables.h index 0d6e9382e2..bef6b6efbf 100644 --- a/src/game_variables.h +++ b/src/game_variables.h @@ -127,7 +127,7 @@ class Game_Variables { void BitShiftRightArray(int first_id_a, int last_id_a, int first_id_b); void SwapArray(int first_id_a, int last_id_a, int first_id_b); - StringView GetName(int _id) const; + std::string_view GetName(int _id) const; int GetSize() const; int GetSizeWithLimit() const; diff --git a/src/game_vehicle.cpp b/src/game_vehicle.cpp index 50688c8ebb..187e271ce4 100644 --- a/src/game_vehicle.cpp +++ b/src/game_vehicle.cpp @@ -203,7 +203,7 @@ void Game_Vehicle::Update() { Game_Character::Update(); } -StringView Game_Vehicle::GetOrigSpriteName() const { +std::string_view Game_Vehicle::GetOrigSpriteName() const { if (!data()->orig_sprite_name.empty()) { return data()->orig_sprite_name; } diff --git a/src/game_vehicle.h b/src/game_vehicle.h index eb78c8a71b..f5b85c1602 100644 --- a/src/game_vehicle.h +++ b/src/game_vehicle.h @@ -88,7 +88,7 @@ class Game_Vehicle : public Game_VehicleBase { void SetOrigSpriteGraphic(std::string sprite_name, int index); /** Gets the original sprite graphic name */ - StringView GetOrigSpriteName() const; + std::string_view GetOrigSpriteName() const; /** Gets the original sprite graphic index */ int GetOrigSpriteIndex() const; diff --git a/src/input.cpp b/src/input.cpp index 629c41fece..dd40a92848 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -378,7 +378,7 @@ Point Input::GetMousePosition() { return source->GetMousePosition(); } -void Input::AddRecordingData(Input::RecordingData type, StringView data) { +void Input::AddRecordingData(Input::RecordingData type, std::string_view data) { assert(source); source->AddRecordingData(type, data); } diff --git a/src/input.h b/src/input.h index 4dd980b8b1..c6cc76a9ae 100644 --- a/src/input.h +++ b/src/input.h @@ -291,7 +291,7 @@ namespace Input { * @param type type of data sent * @param data Sent data */ - void AddRecordingData(RecordingData type, StringView data); + void AddRecordingData(RecordingData type, std::string_view data); /** @return If the input is recorded */ bool IsRecording(); diff --git a/src/input_source.cpp b/src/input_source.cpp index c05b31e3b6..63969f18c0 100644 --- a/src/input_source.cpp +++ b/src/input_source.cpp @@ -92,10 +92,10 @@ Input::LogSource::LogSource(const char* log_path, const Game_ConfigInput& cfg, D std::string header; Utils::ReadLine(log_file, header); - if (StringView(header).starts_with("H EasyRPG")) { + if (StartsWith(header, "H EasyRPG")) { std::string ver; Utils::ReadLine(log_file, ver); - if (StringView(ver).starts_with("V 2")) { + if (StartsWith(ver, "V 2")) { version = 2; } else { Output::Error("Unsupported logfile version {}", ver); @@ -115,7 +115,7 @@ void Input::LogSource::Update() { pressed_buttons.reset(); std::string line; - while (Utils::ReadLine(log_file, line) && !StringView(line).starts_with("F ")) { + while (Utils::ReadLine(log_file, line) && !StartsWith(line, "F ")) { // no-op } if (!line.empty()) { @@ -324,7 +324,7 @@ void Input::Source::UpdateTouch() { #endif } -void Input::Source::AddRecordingData(Input::RecordingData type, StringView data) { +void Input::Source::AddRecordingData(Input::RecordingData type, std::string_view data) { if (record_log) { *record_log << static_cast(type) << " " << data << "\n"; } diff --git a/src/input_source.h b/src/input_source.h index c3b91f0dc4..b8a13fc706 100644 --- a/src/input_source.h +++ b/src/input_source.h @@ -97,7 +97,7 @@ namespace Input { * @param type type of data sent * @param data Sent data */ - void AddRecordingData(RecordingData type, StringView data); + void AddRecordingData(RecordingData type, std::string_view data); /** @return If the input is recorded */ bool IsRecording() const { diff --git a/src/maniac_patch.cpp b/src/maniac_patch.cpp index 0926849e3c..dcc00b6edf 100644 --- a/src/maniac_patch.cpp +++ b/src/maniac_patch.cpp @@ -784,7 +784,7 @@ bool ManiacPatch::GetKeyState(uint32_t key_id) { } -bool ManiacPatch::CheckString(StringView str_l, StringView str_r, int op, bool ignore_case) { +bool ManiacPatch::CheckString(std::string_view str_l, std::string_view str_r, int op, bool ignore_case) { auto check = [op](const auto& l, const auto& r) { switch (op) { case 0: // eq @@ -809,8 +809,8 @@ bool ManiacPatch::CheckString(StringView str_l, StringView str_r, int op, bool i return check(str_l, str_r); } -StringView ManiacPatch::GetLcfName(int data_type, int id, bool is_dynamic) { - auto get_name = [&id](StringView type, const auto& vec) -> StringView { +std::string_view ManiacPatch::GetLcfName(int data_type, int id, bool is_dynamic) { + auto get_name = [&id](std::string_view type, const auto& vec) -> std::string_view { auto* data = lcf::ReaderUtil::GetElement(vec, id); if (!data) { Output::Warning("Unable to read {} name: {}", type, id); @@ -883,8 +883,8 @@ StringView ManiacPatch::GetLcfName(int data_type, int id, bool is_dynamic) { return {}; } -StringView ManiacPatch::GetLcfDescription(int data_type, int id, bool is_dynamic) { - auto get_desc = [id](StringView type, const auto& vec) -> StringView { +std::string_view ManiacPatch::GetLcfDescription(int data_type, int id, bool is_dynamic) { + auto get_desc = [id](std::string_view type, const auto& vec) -> std::string_view { auto* data = lcf::ReaderUtil::GetElement(vec, id); if (!data) { Output::Warning("Unable to read {} description: {}", type, id); diff --git a/src/maniac_patch.h b/src/maniac_patch.h index 2b5c2c4edd..34d26bc16c 100644 --- a/src/maniac_patch.h +++ b/src/maniac_patch.h @@ -37,10 +37,10 @@ namespace ManiacPatch { bool GetKeyState(uint32_t key_id); - bool CheckString(StringView str_l, StringView str_r, int op, bool ignore_case); + bool CheckString(std::string_view str_l, std::string_view str_r, int op, bool ignore_case); - StringView GetLcfName(int data_type, int id, bool is_dynamic); - StringView GetLcfDescription(int data_type, int id, bool is_dynamic); + std::string_view GetLcfName(int data_type, int id, bool is_dynamic); + std::string_view GetLcfDescription(int data_type, int id, bool is_dynamic); } #endif diff --git a/src/message_overlay.cpp b/src/message_overlay.cpp index 9a8b3c2413..e5f8c5b38d 100644 --- a/src/message_overlay.cpp +++ b/src/message_overlay.cpp @@ -81,7 +81,7 @@ void MessageOverlay::AddMessage(const std::string& message, Color color) { Game_Message::WordWrap( message, Player::screen_width - 6, // hardcoded to screen width because the bitmap is not initialized early enough - [&](StringView line) { + [&](std::string_view line) { messages.emplace_back(std::string(line), color); }, *Font::DefaultBitmapFont() ); diff --git a/src/meta.cpp b/src/meta.cpp index bc51999476..e3bf2c635a 100644 --- a/src/meta.cpp +++ b/src/meta.cpp @@ -68,7 +68,7 @@ std::string crc32file(std::string file_name) { } -Meta::Meta(StringView meta_file) { +Meta::Meta(std::string_view meta_file) { ini = std::make_unique(ToString(meta_file)); // Cache per-game lookups @@ -84,7 +84,7 @@ Meta::Meta(StringView meta_file) { } -void Meta::ReInitForNonStandardExtensions(StringView file1, StringView file2) { +void Meta::ReInitForNonStandardExtensions(std::string_view file1, std::string_view file2) { if (!Empty()) { if (canon_ini_lookup.empty()) { IdentifyCanonName(file1, file2); @@ -130,7 +130,7 @@ std::vector Meta::GetImportChildPaths(const FilesystemView& parent_ return res; } -std::vector Meta::SearchImportPaths(const FilesystemView& parent_fs, StringView child_path) const { +std::vector Meta::SearchImportPaths(const FilesystemView& parent_fs, std::string_view child_path) const { if (!Empty()) { int pivotMapId = GetPivotMap(); auto parent = GetParentGame(); @@ -141,7 +141,7 @@ std::vector Meta::SearchImportPaths(const FilesystemView& parent } -std::vector Meta::BuildImportCandidateList(const FilesystemView& parent_fs, StringView child_path, StringView parent_game_name, int pivot_map_id) const { +std::vector Meta::BuildImportCandidateList(const FilesystemView& parent_fs, std::string_view child_path, std::string_view parent_game_name, int pivot_map_id) const { // Scan each folder, looking for an ini file // For now, this only works with "standard" folder layouts, since we need Game files + Save files std::vector res; @@ -248,7 +248,7 @@ std::string Meta::GetExVocabTranslateTitleText() const { return GetExVocab(MTINI_EXVOCAB_TRANSLATE_TITLE_KEY, MTINI_EXVOCAB_TRANSLATE_TITLE_VALUE); } -std::string Meta::GetExVocab(StringView term, StringView def_value) const { +std::string Meta::GetExVocab(std::string_view term, std::string_view def_value) const { if (!Empty()) { return ini->GetString(canon_ini_lookup, ToString(term), ToString(def_value)); } @@ -256,7 +256,7 @@ std::string Meta::GetExVocab(StringView term, StringView def_value) const { return ToString(def_value); } -void Meta::IdentifyCanonName(StringView lmtFile, StringView ldbFile) { +void Meta::IdentifyCanonName(std::string_view lmtFile, std::string_view ldbFile) { // Calculate the lookup based on the LMT/LDB hashes, preferring to use LMT only if possible. // This requires a mandatory field, for which we will use "Name". if (!Empty()) { diff --git a/src/meta.h b/src/meta.h index 42e85e91ff..7ff2161087 100644 --- a/src/meta.h +++ b/src/meta.h @@ -40,7 +40,7 @@ class Meta { * Construct a Meta object by parsing a file * @param meta_file The path to the ini file to load */ - Meta(StringView meta_file); + Meta(std::string_view meta_file); /** * When dealing with non-standard extensions, Meta will need @@ -50,7 +50,7 @@ class Meta { * @file1 The first of two identical files (either LMT/LDB, but with no way of knowing at the time) * @file2 The second of two identical files (either LMT/LDB, but with no way of knowing at the time) */ - void ReInitForNonStandardExtensions(StringView file1, StringView file2); + void ReInitForNonStandardExtensions(std::string_view file1, std::string_view file2); /** * Retrieves the map used for pivoting between multi-game save files @@ -86,7 +86,7 @@ class Meta { * @param child_path the path of the child relative to parent_tree * @return vector of FileItems; one for each valid save file on this child_path */ - std::vector SearchImportPaths(const FilesystemView& parent_fs, StringView child_path) const; + std::vector SearchImportPaths(const FilesystemView& parent_fs, std::string_view child_path) const; /** * Retrieve the LDB extension's replacement in non-standard projects. @@ -139,7 +139,7 @@ class Meta { * @param def_value The default value to return if the ini contains no override. * @return the INI-defined value, or the defualt value for this vocabulary term */ - std::string GetExVocab(StringView term, StringView def_value) const; + std::string GetExVocab(std::string_view term, std::string_view def_value) const; /** * Heuristically tries to guess the canonical name of this game, @@ -148,7 +148,7 @@ class Meta { * @param lmtFile The path to the file we expect to be RPG_RT.lmt * @param ldbFile The path to the file we expect to be RPG_RT.ldb */ - void IdentifyCanonName(StringView lmtFile, StringView ldbFile); + void IdentifyCanonName(std::string_view lmtFile, std::string_view ldbFile); /** * Internal function called by SearchImportPaths @@ -158,7 +158,7 @@ class Meta { * @param pivot_map_id the id of the map used to pivot between the prequel and the current game * @return vector of FileItems; one for each valid save file on this child_path */ - std::vector BuildImportCandidateList(const FilesystemView& parent_fs, StringView child_path, StringView parent_game_name, int pivot_map_id) const; + std::vector BuildImportCandidateList(const FilesystemView& parent_fs, std::string_view child_path, std::string_view parent_game_name, int pivot_map_id) const; /** * Was the INI file passed to the constructor invalid or empty? diff --git a/src/output.cpp b/src/output.cpp index e4f7fd2139..294b1e86c5 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -206,7 +206,7 @@ bool Output::TakeScreenshot() { #endif } -bool Output::TakeScreenshot(StringView file) { +bool Output::TakeScreenshot(std::string_view file) { auto ret = FileFinder::Save().OpenOutputStream(file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc); if (ret) { diff --git a/src/output.h b/src/output.h index cc05a3de43..4186072b1f 100644 --- a/src/output.h +++ b/src/output.h @@ -74,7 +74,7 @@ namespace Output { * @param file file to save. * @return true if success, otherwise false. */ - bool TakeScreenshot(StringView file); + bool TakeScreenshot(std::string_view file); /** * Takes screenshot and save it to specified stream. diff --git a/src/platform.cpp b/src/platform.cpp index 0106502673..c29241984a 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -136,7 +136,7 @@ bool Platform::File::MakeDirectory(bool follow_symlinks) const { auto components = FileFinder::SplitPath(path); std::string cur_path; - if (StringView(path).starts_with("/")) { + if (StartsWith(path, "/")) { cur_path += "/"; } diff --git a/src/platform/3ds/audio.cpp b/src/platform/3ds/audio.cpp index 1b3d5efd7b..b6dc074c0e 100644 --- a/src/platform/3ds/audio.cpp +++ b/src/platform/3ds/audio.cpp @@ -100,7 +100,7 @@ void CtrAudio::BGM_Play(Filesystem_Stream::InputStream filestream, int volume, i if (!dsp_inited) return; - StringView name = filestream.GetName(); + std::string_view name = filestream.GetName(); if (!filestream) { Output::Warning("Couldn't play BGM {}: File not readable", name); return; diff --git a/src/platform/android/filesystem_apk.cpp b/src/platform/android/filesystem_apk.cpp index 9f13dbb358..f4032c55c2 100644 --- a/src/platform/android/filesystem_apk.cpp +++ b/src/platform/android/filesystem_apk.cpp @@ -31,7 +31,7 @@ ApkFilesystem::ApkFilesystem() : Filesystem("", FilesystemView()) { mgr = AAssetManager_fromJava(env, asset_manager); } -bool ApkFilesystem::IsFile(StringView path) const { +bool ApkFilesystem::IsFile(std::string_view path) const { AAsset* asset = AAssetManager_open(mgr, ToString(path).c_str(), AASSET_MODE_STREAMING); if (!asset) { return false; @@ -40,7 +40,7 @@ bool ApkFilesystem::IsFile(StringView path) const { return true; } -bool ApkFilesystem::IsDirectory(StringView dir, bool) const { +bool ApkFilesystem::IsDirectory(std::string_view dir, bool) const { // The openDir has no way to indicate failure // This will also report false for empty directories... AAssetDir* asset = AAssetManager_openDir(mgr, ToString(dir).c_str()); @@ -52,11 +52,11 @@ bool ApkFilesystem::IsDirectory(StringView dir, bool) const { return name != nullptr; } -bool ApkFilesystem::Exists(StringView filename) const { +bool ApkFilesystem::Exists(std::string_view filename) const { return IsFile(filename) || IsDirectory(filename, false); } -int64_t ApkFilesystem::GetFilesize(StringView path) const { +int64_t ApkFilesystem::GetFilesize(std::string_view path) const { AAsset* asset = AAssetManager_open(mgr, ToString(path).c_str(), AASSET_MODE_STREAMING); if (!asset) { return -1; @@ -82,7 +82,7 @@ class AassetStreamBuf : public Filesystem_Stream::InputMemoryStreamBufView { AAsset* asset; }; -std::streambuf* ApkFilesystem::CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* ApkFilesystem::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { AAsset* asset = AAssetManager_open(mgr, ToString(path).c_str(), AASSET_MODE_STREAMING); if (!asset) { return nullptr; @@ -99,11 +99,11 @@ std::streambuf* ApkFilesystem::CreateInputStreambuffer(StringView path, std::ios return new AassetStreamBuf(asset, Span(buffer, len)); } -std::streambuf* ApkFilesystem::CreateOutputStreambuffer(StringView, std::ios_base::openmode) const { +std::streambuf* ApkFilesystem::CreateOutputStreambuffer(std::string_view, std::ios_base::openmode) const { return nullptr; } -bool ApkFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const { +bool ApkFilesystem::GetDirectoryContent(std::string_view path, std::vector& entries) const { // WARNING: API Limitation // According to Android source code some implementations will skip directories here! // The function is good enough to boot a zip in standalone mode. diff --git a/src/platform/android/filesystem_apk.h b/src/platform/android/filesystem_apk.h index f01a2ca4eb..b15d86bc57 100644 --- a/src/platform/android/filesystem_apk.h +++ b/src/platform/android/filesystem_apk.h @@ -39,13 +39,13 @@ class ApkFilesystem : public Filesystem { * Implementation of abstract methods */ /** @{ */ - bool IsFile(StringView path) const override; - bool IsDirectory(StringView path, bool follow_symlinks) const override; - bool Exists(StringView path) const override; - int64_t GetFilesize(StringView path) const override; - std::streambuf* CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const override; - std::streambuf* CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const override; - bool GetDirectoryContent(StringView path, std::vector& entries) const override; + bool IsFile(std::string_view path) const override; + bool IsDirectory(std::string_view path, bool follow_symlinks) const override; + bool Exists(std::string_view path) const override; + int64_t GetFilesize(std::string_view path) const override; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + std::streambuf* CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + bool GetDirectoryContent(std::string_view path, std::vector& entries) const override; std::string Describe() const override; /** @} */ diff --git a/src/platform/android/filesystem_saf.cpp b/src/platform/android/filesystem_saf.cpp index 63403e459c..173639a9e2 100644 --- a/src/platform/android/filesystem_saf.cpp +++ b/src/platform/android/filesystem_saf.cpp @@ -23,7 +23,7 @@ #include #include -static jobject get_jni_handle(const SafFilesystem* fs, StringView path) { +static jobject get_jni_handle(const SafFilesystem* fs, std::string_view path) { std::string combined_path = FileFinder::MakePath(fs->GetPath(), path); JNIEnv* env = EpAndroid::env; @@ -39,7 +39,7 @@ SafFilesystem::SafFilesystem(std::string base_path, FilesystemView parent_fs) : // no-op } -bool SafFilesystem::IsFile(StringView path) const { +bool SafFilesystem::IsFile(std::string_view path) const { auto obj = get_jni_handle(this, path); if (!obj) { return false; @@ -53,7 +53,7 @@ bool SafFilesystem::IsFile(StringView path) const { return res > 0; } -bool SafFilesystem::IsDirectory(StringView dir, bool) const { +bool SafFilesystem::IsDirectory(std::string_view dir, bool) const { auto obj = get_jni_handle(this, dir); if (!obj) { return false; @@ -67,7 +67,7 @@ bool SafFilesystem::IsDirectory(StringView dir, bool) const { return res > 0; } -bool SafFilesystem::Exists(StringView filename) const { +bool SafFilesystem::Exists(std::string_view filename) const { auto obj = get_jni_handle(this, filename); if (!obj) { return false; @@ -81,7 +81,7 @@ bool SafFilesystem::Exists(StringView filename) const { return res > 0; } -int64_t SafFilesystem::GetFilesize(StringView path) const { +int64_t SafFilesystem::GetFilesize(std::string_view path) const { auto obj = get_jni_handle(this, path); if (!obj) { return -1; @@ -137,7 +137,7 @@ class FdStreamBufIn : public std::streambuf { char* buffer_end = &buffer.back(); }; -std::streambuf* SafFilesystem::CreateInputStreambuffer(StringView path, std::ios_base::openmode) const { +std::streambuf* SafFilesystem::CreateInputStreambuffer(std::string_view path, std::ios_base::openmode) const { auto obj = get_jni_handle(this, path); if (!obj) { return nullptr; @@ -213,7 +213,7 @@ class FdStreamBufOut : public std::streambuf { char* buffer_end = &buffer.back(); }; -std::streambuf* SafFilesystem::CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const { +std::streambuf* SafFilesystem::CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const { auto obj = get_jni_handle(this, path); if (!obj) { return nullptr; @@ -232,7 +232,7 @@ std::streambuf* SafFilesystem::CreateOutputStreambuffer(StringView path, std::io return new FdStreamBufOut(fd); } -bool SafFilesystem::GetDirectoryContent(StringView path, std::vector& entries) const { +bool SafFilesystem::GetDirectoryContent(std::string_view path, std::vector& entries) const { auto obj = get_jni_handle(this, path); if (!obj) { return false; diff --git a/src/platform/android/filesystem_saf.h b/src/platform/android/filesystem_saf.h index 2d939a9bd8..85bc00e255 100644 --- a/src/platform/android/filesystem_saf.h +++ b/src/platform/android/filesystem_saf.h @@ -37,13 +37,13 @@ class SafFilesystem : public Filesystem { * Implementation of abstract methods */ /** @{ */ - bool IsFile(StringView path) const override; - bool IsDirectory(StringView path, bool follow_symlinks) const override; - bool Exists(StringView path) const override; - int64_t GetFilesize(StringView path) const override; - std::streambuf* CreateInputStreambuffer(StringView path, std::ios_base::openmode mode) const override; - std::streambuf* CreateOutputStreambuffer(StringView path, std::ios_base::openmode mode) const override; - bool GetDirectoryContent(StringView path, std::vector& entries) const override; + bool IsFile(std::string_view path) const override; + bool IsDirectory(std::string_view path, bool follow_symlinks) const override; + bool Exists(std::string_view path) const override; + int64_t GetFilesize(std::string_view path) const override; + std::streambuf* CreateInputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + std::streambuf* CreateOutputStreambuffer(std::string_view path, std::ios_base::openmode mode) const override; + bool GetDirectoryContent(std::string_view path, std::vector& entries) const override; bool IsFeatureSupported(Feature f) const override; std::string Describe() const override; /** @} */ diff --git a/src/platform/emscripten/interface.cpp b/src/platform/emscripten/interface.cpp index ccbd7b42a7..458fe4c3ad 100644 --- a/src/platform/emscripten/interface.cpp +++ b/src/platform/emscripten/interface.cpp @@ -116,7 +116,7 @@ bool Emscripten_Interface_Private::UploadSoundfontStep2(std::string filename, in std::string name = std::get<1>(FileFinder::GetPathAndFilename(filename)); // TODO: No good way to sanitize this, would require launching an entire, second fluidsynth session - if (!StringView(name).ends_with(".sf2")) { + if (!EndsWith(name, ".sf2")) { Output::Warning("Selected file is not a valid soundfont"); return false; } diff --git a/src/platform/linux/midiout_device_alsa.cpp b/src/platform/linux/midiout_device_alsa.cpp index d17bae9da1..beb4d1e665 100644 --- a/src/platform/linux/midiout_device_alsa.cpp +++ b/src/platform/linux/midiout_device_alsa.cpp @@ -42,7 +42,7 @@ AlsaMidiOutDevice::AlsaMidiOutDevice(std::string& status_message) { snd_seq_client_info_set_client(client_info, -1); while (snd_seq_query_next_client(midi_out, client_info) == 0) { const char* client_name = snd_seq_client_info_get_name(client_info); - if (StringView(client_name) == "Midi Through") { + if (std::string_view(client_name) == "Midi Through") { continue; } @@ -65,7 +65,7 @@ AlsaMidiOutDevice::AlsaMidiOutDevice(std::string& status_message) { candidate_found = true; // FIXME: Hardcoded, no config scene yet - if (StringView(client_name).starts_with("FLUID") || StringView(client_name).starts_with("TiMidity")) { + if (StartsWith(client_name, "FLUID") || StartsWith(client_name, "TiMidity")) { // Perfect candidate found, stop searching goto done; } diff --git a/src/platform/sdl/sdl2_ui.cpp b/src/platform/sdl/sdl2_ui.cpp index 6af0764835..ac384c5445 100644 --- a/src/platform/sdl/sdl2_ui.cpp +++ b/src/platform/sdl/sdl2_ui.cpp @@ -1334,7 +1334,7 @@ Rect Sdl2Ui::GetWindowMetrics() const { } } -bool Sdl2Ui::OpenURL(StringView url) { +bool Sdl2Ui::OpenURL(std::string_view url) { #if SDL_VERSION_ATLEAST(2, 0, 14) if (IsFullscreen()) { ToggleFullscreen(); diff --git a/src/platform/sdl/sdl2_ui.h b/src/platform/sdl/sdl2_ui.h index cef74fe1fd..f8a1707994 100644 --- a/src/platform/sdl/sdl2_ui.h +++ b/src/platform/sdl/sdl2_ui.h @@ -70,7 +70,7 @@ class Sdl2Ui final : public BaseUi { void ToggleStretch() override; void ToggleVsync() override; void vGetConfig(Game_ConfigVideo& cfg) const override; - bool OpenURL(StringView url) override; + bool OpenURL(std::string_view url) override; Rect GetWindowMetrics() const override; bool HandleErrorOutput(const std::string &message) override; diff --git a/src/platform/sdl/sdl3_ui.cpp b/src/platform/sdl/sdl3_ui.cpp index 3beb25758a..e0e810c199 100644 --- a/src/platform/sdl/sdl3_ui.cpp +++ b/src/platform/sdl/sdl3_ui.cpp @@ -1252,7 +1252,7 @@ Rect Sdl3Ui::GetWindowMetrics() const { } } -bool Sdl3Ui::OpenURL(StringView url) { +bool Sdl3Ui::OpenURL(std::string_view url) { if (IsFullscreen()) { ToggleFullscreen(); } diff --git a/src/platform/sdl/sdl3_ui.h b/src/platform/sdl/sdl3_ui.h index 69fe2295af..badae3c773 100644 --- a/src/platform/sdl/sdl3_ui.h +++ b/src/platform/sdl/sdl3_ui.h @@ -70,7 +70,7 @@ class Sdl3Ui final : public BaseUi { void ToggleStretch() override; void ToggleVsync() override; void vGetConfig(Game_ConfigVideo& cfg) const override; - bool OpenURL(StringView url) override; + bool OpenURL(std::string_view url) override; Rect GetWindowMetrics() const override; bool HandleErrorOutput(const std::string &message) override; diff --git a/src/player.cpp b/src/player.cpp index 048ad62e65..0dc3a962b8 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -152,7 +152,7 @@ namespace { } void Player::Init(std::vector args) { - lcf::LogHandler::SetHandler([](lcf::LogHandler::Level level, StringView message, lcf::LogHandler::UserData) { + lcf::LogHandler::SetHandler([](lcf::LogHandler::Level level, std::string_view message, lcf::LogHandler::UserData) { Output::Debug("lcf ({}): {}", lcf::LogHandler::kLevelTags.tag(level), message); }); diff --git a/src/registry.cpp b/src/registry.cpp index 6ad81dfc46..9e4fcce5fd 100644 --- a/src/registry.cpp +++ b/src/registry.cpp @@ -39,7 +39,7 @@ #endif #endif -std::string Registry::ReadStrValue(HKEY hkey, StringView key, StringView val, REGVIEW view) { +std::string Registry::ReadStrValue(HKEY hkey, std::string_view key, std::string_view val, REGVIEW view) { char value[1024]; DWORD size = 1024; DWORD type = REG_SZ; @@ -80,7 +80,7 @@ std::string Registry::ReadStrValue(HKEY hkey, StringView key, StringView val, RE return string_value; } -int Registry::ReadBinValue(HKEY hkey, StringView key, StringView val, unsigned char* bin, REGVIEW view) { +int Registry::ReadBinValue(HKEY hkey, std::string_view key, std::string_view val, unsigned char* bin, REGVIEW view) { DWORD size = 1024; DWORD type = REG_BINARY; HKEY key_handle; diff --git a/src/registry.h b/src/registry.h index 32f86cd361..3928b37b0a 100644 --- a/src/registry.h +++ b/src/registry.h @@ -42,12 +42,12 @@ namespace Registry { /** * Reads string value. */ - std::string ReadStrValue(HKEY hkey, StringView key, StringView val, REGVIEW view = NATIVE); + std::string ReadStrValue(HKEY hkey, std::string_view key, std::string_view val, REGVIEW view = NATIVE); /** * Reads binary value. */ - int ReadBinValue(HKEY hkey, StringView, StringView val, unsigned char* bin, REGVIEW view = NATIVE); + int ReadBinValue(HKEY hkey, std::string_view, std::string_view val, unsigned char* bin, REGVIEW view = NATIVE); } #endif diff --git a/src/registry_wine.cpp b/src/registry_wine.cpp index 3e4fcb1bfe..8b9d3f9182 100644 --- a/src/registry_wine.cpp +++ b/src/registry_wine.cpp @@ -35,7 +35,7 @@ Wine registry file example: "RuntimePackagePath"="C:\\Program Files (x86)\\ASCII\\RPG2000\\RTP" */ -std::string Registry::ReadStrValue(HKEY hkey, StringView key, StringView val, REGVIEW view) { +std::string Registry::ReadStrValue(HKEY hkey, std::string_view key, std::string_view val, REGVIEW view) { std::string prefix = getenv("WINEPREFIX")? getenv("WINEPREFIX"): getenv("HOME")? std::string(getenv("HOME")).append("/.wine"): @@ -100,7 +100,7 @@ std::string Registry::ReadStrValue(HKEY hkey, StringView key, StringView val, RE if (!in_section) { if (line.empty() || line[0] != '[') { continue; - } else if (ToStringView(Utils::LowerCaseInPlace(line)).starts_with(formatted_key_search)) { + } else if (StartsWith(Utils::LowerCaseInPlace(line), formatted_key_search)) { // Found the section in_section = true; } @@ -110,7 +110,7 @@ std::string Registry::ReadStrValue(HKEY hkey, StringView key, StringView val, RE break; } - if (ToStringView(Utils::LowerCase(line)).starts_with(formatted_val)) { + if (StartsWith(Utils::LowerCase(line), formatted_val)) { // value found string_value = line.substr(formatted_val.length()); break; @@ -153,7 +153,7 @@ std::string Registry::ReadStrValue(HKEY hkey, StringView key, StringView val, RE return path; } -int Registry::ReadBinValue(HKEY, StringView, StringView, unsigned char*, REGVIEW) { +int Registry::ReadBinValue(HKEY, std::string_view, std::string_view, unsigned char*, REGVIEW) { return 0; // not really used yet } diff --git a/src/rtp.cpp b/src/rtp.cpp index bd1c778063..c60868a06e 100644 --- a/src/rtp.cpp +++ b/src/rtp.cpp @@ -21,11 +21,11 @@ #include #include "rtp.h" -static std::pair get_table_idx(const char* const lookup_table[16], const int lookup_table_idx[16], StringView category) { +static std::pair get_table_idx(const char* const lookup_table[16], const int lookup_table_idx[16], std::string_view category) { int i; for (i = 0; lookup_table[i] != nullptr; ++i) { - if (StringView(lookup_table[i]) == category) { + if (std::string_view(lookup_table[i]) == category) { return {lookup_table_idx[i], lookup_table_idx[i+1]}; } } @@ -36,7 +36,7 @@ static std::pair get_table_idx(const char* const lookup_table[16], con template static void detect_helper(const FilesystemView& fs, std::vector& hit_list, - T rtp_table, int num_rtps, int offset, const std::pair& range, Span ext_list, int miss_limit) { + T rtp_table, int num_rtps, int offset, const std::pair& range, Span ext_list, int miss_limit) { std::string ret; for (int j = 1; j <= num_rtps; ++j) { int cur_miss = 0; @@ -128,13 +128,13 @@ std::vector RTP::Detect(const FilesystemView& fs, int version, template static std::vector lookup_any_to_rtp_helper(T rtp_table, const std::pair& range, - StringView src_name, int num_rtps, int offset) { + std::string_view src_name, int num_rtps, int offset) { std::vector type_hits; for (int i = range.first; i < range.second; ++i) { for (int j = 1; j <= num_rtps; ++j) { const char* name = rtp_table[i][j]; - if (name != nullptr && src_name == StringView(name)) { + if (name != nullptr && src_name == std::string_view(name)) { type_hits.push_back((RTP::Type)(j - 1 + offset)); } } @@ -143,7 +143,7 @@ static std::vector lookup_any_to_rtp_helper(T rtp_table, const std::p return type_hits; } -std::vector RTP::LookupAnyToRtp(StringView src_category, StringView src_name, int version) { +std::vector RTP::LookupAnyToRtp(std::string_view src_category, std::string_view src_name, int version) { if (version == 2000) { auto tbl_idx = get_table_idx(rtp_table_2k_categories, rtp_table_2k_categories_idx, src_category); return lookup_any_to_rtp_helper(rtp_table_2k, tbl_idx, src_name, num_2k_rtps, 0); @@ -155,11 +155,11 @@ std::vector RTP::LookupAnyToRtp(StringView src_category, StringView s template static std::string lookup_rtp_to_rtp_helper(T rtp_table, const std::pair& range, - StringView src_name, int src_index, int dst_index, bool* is_rtp_asset) { + std::string_view src_name, int src_index, int dst_index, bool* is_rtp_asset) { for (int i = range.first; i < range.second; ++i) { const char* name = rtp_table[i][src_index + 1]; - if (name != nullptr && src_name == StringView(name)) { + if (name != nullptr && src_name == std::string_view(name)) { const char* dst_name = rtp_table[i][dst_index + 1]; if (is_rtp_asset) { @@ -177,7 +177,7 @@ static std::string lookup_rtp_to_rtp_helper(T rtp_table, const std::pair LookupAnyToRtp(StringView src_category, StringView src_name, int version); + std::vector LookupAnyToRtp(std::string_view src_category, std::string_view src_name, int version); /** * Takes a source and a destination RTP. Maps source name to destination name and returns it. @@ -107,7 +107,7 @@ namespace RTP { * @param is_rtp_asset When not null indicates if src_name is a known entry in the src_rtp but only when src_rtp != target_rtp * @return The translated asset name or empty string when the mapping is unavailable */ - std::string LookupRtpToRtp(StringView src_category, StringView src_name, + std::string LookupRtpToRtp(std::string_view src_category, std::string_view src_name, RTP::Type src_rtp, RTP::Type target_rtp, bool* is_rtp_asset = nullptr); } diff --git a/src/scene_battle_rpg2k.cpp b/src/scene_battle_rpg2k.cpp index 3568bc05d6..4d59103987 100644 --- a/src/scene_battle_rpg2k.cpp +++ b/src/scene_battle_rpg2k.cpp @@ -1077,7 +1077,7 @@ Scene_Battle_Rpg2k::BattleActionReturn Scene_Battle_Rpg2k::ProcessBattleActionBe } if (pri_state != nullptr) { - StringView msg = pri_was_healed + std::string_view msg = pri_was_healed ? pri_state->message_recovery : pri_state->message_affected; @@ -1988,7 +1988,7 @@ void Scene_Battle_Rpg2k::PushItemRecievedMessages(PendingMessage& pm, std::vecto for (std::vector::iterator it = drops.begin(); it != drops.end(); ++it) { const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, *it); // No Output::Warning needed here, reported later when the item is added - StringView item_name = item ? StringView(item->name) : StringView("??? BAD ITEM ???"); + std::string_view item_name = item ? std::string_view(item->name) : std::string_view("??? BAD ITEM ???"); if (Feature::HasPlaceholders()) { pm.PushLine( diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index 0c51d4a9a2..4d1b60662b 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -499,8 +499,8 @@ void Scene_Battle_Rpg2k3::UpdateAnimations() { } } -void Scene_Battle_Rpg2k3::DrawFloatText(int x, int y, int color, StringView text, Game_Battler* battler, FloatTextType type) { - std::stringstream ss(text.to_string()); +void Scene_Battle_Rpg2k3::DrawFloatText(int x, int y, int color, std::string_view text, Game_Battler* battler, FloatTextType type) { + std::stringstream ss(ToString(text)); int value = 0; ss >> value; bool should_override = Game_Battle::ManiacBattleHook( @@ -1065,7 +1065,7 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneAction() static int last_substate = -1; if (state != last_state || scene_action_substate != last_substate) { int actor_id = active_actor ? active_actor->GetId() : 0; - StringView actor_name = active_actor ? StringView(active_actor->GetName()) : "Null"; + std::string_view actor_name = active_actor ? std::string_view(active_actor->GetName()) : "Null"; Output::Debug("Battle2k3 ProcessSceneAction({}, {}) actor={}({}) frames={} auto_battle={}", state, scene_action_substate, actor_name, actor_id, Main_Data::game_system->GetFrameCounter(), auto_battle); last_state = state; last_substate = scene_action_substate; @@ -1870,7 +1870,7 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionVi for (auto& item_id: drops) { const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id); // No Output::Warning needed here, reported later when the item is added - StringView item_name = item ? StringView(item->name) : StringView("??? BAD ITEM ???"); + std::string_view item_name = item ? std::string_view(item->name) : std::string_view("??? BAD ITEM ???"); ss.str(""); ss << item_name << space << lcf::Data::terms.item_recieved; diff --git a/src/scene_battle_rpg2k3.h b/src/scene_battle_rpg2k3.h index 045d3ce6ac..8bd1391633 100644 --- a/src/scene_battle_rpg2k3.h +++ b/src/scene_battle_rpg2k3.h @@ -128,7 +128,7 @@ class Scene_Battle_Rpg2k3 : public Scene_Battle { Heal = 1, Miss = 2, }; - void DrawFloatText(int x, int y, int color, StringView text, Game_Battler* battler, FloatTextType type); + void DrawFloatText(int x, int y, int color, std::string_view text, Game_Battler* battler, FloatTextType type); bool IsTransparent() const; diff --git a/src/sprite_actor.cpp b/src/sprite_actor.cpp index 7d002c85b2..2ade5dfbf3 100644 --- a/src/sprite_actor.cpp +++ b/src/sprite_actor.cpp @@ -165,7 +165,7 @@ void Sprite_Actor::SetAnimationState(int state, LoopState loop, int animation_id return; } - StringView sprite_file = ext->battler_name; + std::string_view sprite_file = ext->battler_name; if (ext->animation_type == lcf::rpg::BattlerAnimationPose::AnimType_battle) { do_not_draw = false; diff --git a/src/sprite_character.cpp b/src/sprite_character.cpp index c4ac096334..8685a31619 100644 --- a/src/sprite_character.cpp +++ b/src/sprite_character.cpp @@ -128,7 +128,7 @@ void Sprite_Character::ChipsetUpdated() { refresh_bitmap = true; } -Rect Sprite_Character::GetCharacterRect(StringView name, int index, const Rect bitmap_rect) { +Rect Sprite_Character::GetCharacterRect(std::string_view name, int index, const Rect bitmap_rect) { Rect rect; rect.width = 24 * (TILE_SIZE / 16) * 3; rect.height = 32 * (TILE_SIZE / 16) * 4; diff --git a/src/sprite_character.h b/src/sprite_character.h index 09ad7a98a6..f6c571aae8 100644 --- a/src/sprite_character.h +++ b/src/sprite_character.h @@ -71,7 +71,7 @@ class Sprite_Character : public Sprite { * * @return Rect describing image sub region containing character frames. */ - static Rect GetCharacterRect(StringView name, int index, Rect bitmap_rect); + static Rect GetCharacterRect(std::string_view name, int index, Rect bitmap_rect); /** * Called when the map chipset is changed by an event diff --git a/src/sprite_weapon.cpp b/src/sprite_weapon.cpp index e29fb5f72e..83ac0d45f7 100644 --- a/src/sprite_weapon.cpp +++ b/src/sprite_weapon.cpp @@ -99,7 +99,7 @@ void Sprite_Weapon::StartAttack(bool secondary_weapon) { return; } - StringView sprite_file = battler_animation_weapon->weapon_name; + std::string_view sprite_file = battler_animation_weapon->weapon_name; if (!sprite_file.empty()) { FileRequestAsync* request = AsyncHandler::RequestFile("BattleWeapon", sprite_file); diff --git a/src/string_view.cpp b/src/string_view.cpp index 13a526504d..5d09806fe4 100644 --- a/src/string_view.cpp +++ b/src/string_view.cpp @@ -26,9 +26,4 @@ auto fmt::formatter::format(const lcf::DBString& s, format_contex return formatter::format(sv, ctx); } -auto fmt::formatter::format(const lcf::StringView& s, format_context& ctx) const -> decltype(ctx.out()) { - string_view sv(s.data(), s.size()); - return formatter::format(sv, ctx); -} - #endif diff --git a/src/string_view.h b/src/string_view.h index bb5fcbb3fa..e49d22c083 100644 --- a/src/string_view.h +++ b/src/string_view.h @@ -21,42 +21,29 @@ #include #include #include + #if FMT_VERSION < 60000 // Remove after 0.8.1 in 2024: allow building with fmt 5 # include #endif -using StringView = lcf::StringView; -using U32StringView = lcf::U32StringView; - using lcf::ToString; -using lcf::ToStringView; +using lcf::StartsWith; +using lcf::EndsWith; // Version required to use the new formatting API #define EP_FMT_MODERN_VERSION 80000 -// FIXME: liblcf doesn't depend on fmt, so we need to add this here to enable fmtlib support for our StringView. +// FIXME: liblcf doesn't depend on fmt, so we need to add this here to enable fmtlib support for our std::string_view. #if FMT_VERSION >= EP_FMT_MODERN_VERSION -template<> -struct fmt::formatter : formatter { - auto format(const lcf::StringView& s, format_context& ctx) const -> decltype(ctx.out()); -}; - template<> struct fmt::formatter : formatter { auto format(const lcf::DBString& s, format_context& ctx) const -> decltype(ctx.out()); }; #else -namespace nonstd { namespace sv_lite { -template -inline fmt::basic_string_view to_string_view(basic_string_view s) { - return fmt::basic_string_view(s.data(), s.size()); -} -} } - namespace lcf { inline fmt::basic_string_view to_string_view(const lcf::DBString& s) { - return to_string_view(StringView(s)); + return to_string_view(std::string_view(s)); } } #endif diff --git a/src/text.cpp b/src/text.cpp index e8050f6de0..4fdc5d441b 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -56,7 +56,7 @@ Point Text::Draw(Bitmap& dest, int x, int y, const Font& font, Color color, char } } -Point Text::Draw(Bitmap& dest, const int x, const int y, const Font& font, const Bitmap& system, const int color, StringView text, const Text::Alignment align) { +Point Text::Draw(Bitmap& dest, const int x, const int y, const Font& font, const Bitmap& system, const int color, std::string_view text, const Text::Alignment align) { if (text.length() == 0) return { 0, 0 }; Rect dst_rect = Text::GetSize(font, text); @@ -141,7 +141,7 @@ Point Text::Draw(Bitmap& dest, const int x, const int y, const Font& font, const return { next_glyph_pos, ih }; } -Point Text::Draw(Bitmap& dest, const int x, const int y, const Font& font, const Color color, StringView text) { +Point Text::Draw(Bitmap& dest, const int x, const int y, const Font& font, const Color color, std::string_view text) { if (text.length() == 0) return { 0, 0 }; int dx = x; @@ -182,7 +182,7 @@ Point Text::Draw(Bitmap& dest, const int x, const int y, const Font& font, const return { mx - x , dy - y }; } -Rect Text::GetSize(const Font& font, StringView text) { +Rect Text::GetSize(const Font& font, std::string_view text) { Rect rect; Rect rect_tmp; diff --git a/src/text.h b/src/text.h index e453d33822..176a7f2d53 100644 --- a/src/text.h +++ b/src/text.h @@ -54,7 +54,7 @@ namespace Text { * * @return Where to draw the next glyph when continuing drawing. See Font::GlyphRet.advance */ - Point Draw(Bitmap& dest, int x, int y, const Font& font, const Bitmap& system, int color, StringView text, Text::Alignment align = Text::AlignLeft); + Point Draw(Bitmap& dest, int x, int y, const Font& font, const Bitmap& system, int color, std::string_view text, Text::Alignment align = Text::AlignLeft); /** * Draws the text onto dest bitmap with given parameters. Does not draw a shadow. @@ -68,7 +68,7 @@ namespace Text { * * @return Where to draw the next glyph when continuing drawing. See Font::GlyphRet.advance */ - Point Draw(Bitmap& dest, int x, int y, const Font& font, Color color, StringView text); + Point Draw(Bitmap& dest, int x, int y, const Font& font, Color color, std::string_view text); /** * Draws the character onto dest bitmap with given parameters. @@ -112,7 +112,7 @@ namespace Text { * * @return Rect describing the rendered string boundary */ - Rect GetSize(const Font& font, StringView text); + Rect GetSize(const Font& font, std::string_view text); /** * Determines the size of a bitmap required to render a single character. diff --git a/src/translation.cpp b/src/translation.cpp index 2c101b6f55..cd1d016e58 100644 --- a/src/translation.cpp +++ b/src/translation.cpp @@ -156,7 +156,7 @@ const std::vector& Translation::GetLanguages() const } -void Translation::SelectLanguage(StringView lang_id) +void Translation::SelectLanguage(std::string_view lang_id) { // Try to read in our language files. Output::Debug("Changing language to: '{}'", (!lang_id.empty() ? lang_id : "")); @@ -190,7 +190,7 @@ void Translation::SelectLanguage(StringView lang_id) } } -void Translation::SelectLanguageAsync(FileRequestResult*, StringView lang_id) { +void Translation::SelectLanguageAsync(FileRequestResult*, std::string_view lang_id) { --request_counter; if (request_counter == 0) { requests.clear(); @@ -256,7 +256,7 @@ void Translation::RequestAndAddMap(int map_id) { request->Start(); } -bool Translation::ParseLanguageFiles(StringView lang_id) +bool Translation::ParseLanguageFiles(std::string_view lang_id) { FilesystemView language_tree; @@ -308,7 +308,7 @@ bool Translation::ParseLanguageFiles(StringView lang_id) if (is) { ParsePoFile(std::move(is), *mapnames); } - } else if (StringView(tr_name.first).ends_with(".po")) { + } else if (EndsWith(tr_name.first, ".po")) { // This will fail in the web player but is intentional // The fetching happens on map load instead // Still parsing all files locally to get syntax errors early @@ -552,7 +552,7 @@ namespace { } /** Change the string value of the EventCommand at position "idx" to "newStr" */ - void ReWriteString(size_t idx, StringView newStr) { + void ReWriteString(size_t idx, std::string_view newStr) { if (idx < commands.size()) { commands[idx].string = lcf::DBString(newStr); } @@ -563,7 +563,7 @@ namespace { * Sets the string value to "line". Note that ShowMessage_2 is chosen if baseMsgBox is false. * This also updates the index if relevant, but it does not update external index caches. */ - void PutShowMessageBeforeIndex(StringView line, size_t idx, bool baseMsgBox) { + void PutShowMessageBeforeIndex(std::string_view line, size_t idx, bool baseMsgBox) { // We need a reference index for the indent. size_t refIndent = 0; if (idx < commands.size()) { @@ -776,7 +776,7 @@ void Translation::RewriteEventCommandMessage(const Dictionary& dict, std::vector } } -void Translation::RewriteMapMessages(StringView map_name, lcf::rpg::Map& map) { +void Translation::RewriteMapMessages(std::string_view map_name, lcf::rpg::Map& map) { // Retrieve lookup for this map. auto mapIt = maps.find(ToString(map_name)); if (mapIt==maps.end()) { return; } @@ -822,7 +822,7 @@ void Dictionary::addEntry(const Entry& entry) // Returns success void Dictionary::FromPo(Dictionary& res, Filesystem_Stream::InputStream& in) { std::string line; - lcf::StringView line_view; + std::string_view line_view; bool found_header = false; bool parse_item = false; int line_number = 0; @@ -891,7 +891,7 @@ void Dictionary::FromPo(Dictionary& res, Filesystem_Stream::InputStream& in) { while (Utils::ReadLine(in, line)) { line_view = Utils::TrimWhitespace(line); ++line_number; - if (line_view.empty() || line_view.starts_with("#")) { + if (line_view.empty() || StartsWith(line_view, "#")) { break; } e.translation += extract_string(0); @@ -909,7 +909,7 @@ void Dictionary::FromPo(Dictionary& res, Filesystem_Stream::InputStream& in) { while (Utils::ReadLine(in, line)) { line_view = Utils::TrimWhitespace(line); ++line_number; - if (line_view.empty() || line_view.starts_with("msgstr")) { + if (line_view.empty() || StartsWith(line_view, "msgstr")) { read_msgstr(); return; } @@ -921,25 +921,25 @@ void Dictionary::FromPo(Dictionary& res, Filesystem_Stream::InputStream& in) { line_view = Utils::TrimWhitespace(line); ++line_number; if (!found_header) { - if (line_view.starts_with("msgstr")) { + if (StartsWith(line_view, "msgstr")) { found_header = true; } continue; } if (!parse_item) { - if (line_view.starts_with("msgctxt")) { + if (StartsWith(line_view, "msgctxt")) { e.context = extract_string(7); parse_item = true; - } else if (line_view.starts_with("msgid")) { + } else if (StartsWith(line_view, "msgid")) { parse_item = true; read_msgid(); } } else { - if (line_view.starts_with("msgid")) { + if (StartsWith(line_view, "msgid")) { read_msgid(); - } else if (line_view.starts_with("msgstr")) { + } else if (StartsWith(line_view, "msgstr")) { read_msgstr(); } } diff --git a/src/translation.h b/src/translation.h index 70b88ba9d1..5a9cfdd77c 100644 --- a/src/translation.h +++ b/src/translation.h @@ -109,7 +109,7 @@ class Dictionary { * @return True if the original string was replaced; false otherwise. */ template - bool TranslateString(StringView context, StringType& original) const; + bool TranslateString(std::string_view context, StringType& original) const; private: /** @@ -126,7 +126,7 @@ class Dictionary { // Template implementation template -bool Dictionary::TranslateString(StringView context, StringType& original) const +bool Dictionary::TranslateString(std::string_view context, StringType& original) const { std::stringstream key; key << original; @@ -191,7 +191,7 @@ class Translation { * * @param lang_id The language ID (or "" for "Default") */ - void SelectLanguage(StringView lang_id); + void SelectLanguage(std::string_view lang_id); /** * Does a async fetch of a map po file. @@ -207,7 +207,7 @@ class Translation { * @param map_name The name of the map with formatting similar to the .po file; e.g., "map0104.po" * @param map The map object itself (for modifying). */ - void RewriteMapMessages(StringView map_name, lcf::rpg::Map& map); + void RewriteMapMessages(std::string_view map_name, lcf::rpg::Map& map); /** * Retrieve the current language. @@ -226,7 +226,7 @@ class Translation { private: - void SelectLanguageAsync(FileRequestResult* result, StringView lang_id); + void SelectLanguageAsync(FileRequestResult* result, std::string_view lang_id); /** * Reset all saved language data and revert to "no translation". @@ -295,7 +295,7 @@ class Translation { * @param lang_id The ID of the language to parse, or "" for Default (no parsing is done) * @return True if the language directory was found; false otherwise */ - bool ParseLanguageFiles(StringView lang_id); + bool ParseLanguageFiles(std::string_view lang_id); // Our translations are broken apart into multiple files; we store a lookup for each one. std::unique_ptr sys; // RPG_RT.ldb.po diff --git a/src/utils.cpp b/src/utils.cpp index 9fb443b3eb..39fc77dc07 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -47,7 +47,7 @@ namespace { } -std::string Utils::LowerCase(StringView str) { +std::string Utils::LowerCase(std::string_view str) { auto result = std::string(str); LowerCaseInPlace(result); return result; @@ -58,7 +58,7 @@ std::string& Utils::LowerCaseInPlace(std::string& str) { return str; } -std::string Utils::UpperCase(StringView str) { +std::string Utils::UpperCase(std::string_view str) { auto result = std::string(str); UpperCaseInPlace(result); return result; @@ -83,7 +83,7 @@ int Utils::StrICmp(const char* l, const char* r) { return *l - *r; } -int Utils::StrICmp(StringView l, StringView r) { +int Utils::StrICmp(std::string_view l, std::string_view r) { for (size_t i = 0; i < std::min(l.size(), r.size()); ++i) { auto d = Lower(l[i]) - Lower(r[i]); if (d != 0) { @@ -93,7 +93,7 @@ int Utils::StrICmp(StringView l, StringView r) { return l.size() - r.size(); } -std::u16string Utils::DecodeUTF16(StringView str) { +std::u16string Utils::DecodeUTF16(std::string_view str) { std::u16string result; for (auto it = str.begin(), str_end = str.end(); it < str_end; ++it) { uint8_t c1 = static_cast(*it); @@ -168,7 +168,7 @@ std::u16string Utils::DecodeUTF16(StringView str) { return result; } -std::u32string Utils::DecodeUTF32(StringView str) { +std::u32string Utils::DecodeUTF32(std::string_view str) { std::u32string result; for (auto it = str.begin(), str_end = str.end(); it < str_end; ++it) { uint8_t c1 = static_cast(*it); @@ -393,7 +393,7 @@ Utils::UtfNextResult Utils::UTF8Skip(const char* iter, const char* end, int skip return ret; } -int Utils::UTF8Length(StringView str) { +int Utils::UTF8Length(std::string_view str) { size_t len = 0; const char* iter = str.data(); @@ -456,22 +456,22 @@ Utils::TextRet Utils::TextNext(const char* iter, const char* end, char32_t escap // Please report an issue when you get a compile error here because your toolchain is broken and lacks wchar_t template -static std::wstring ToWideStringImpl(StringView); +static std::wstring ToWideStringImpl(std::string_view); #if __SIZEOF_WCHAR_T__ == 4 || __WCHAR_MAX__ > 0x10000 template<> // utf32 -std::wstring ToWideStringImpl<4>(StringView str) { +std::wstring ToWideStringImpl<4>(std::string_view str) { const auto tmp = Utils::DecodeUTF32(str); return std::wstring(tmp.begin(), tmp.end()); } #else template<> // utf16 -std::wstring ToWideStringImpl<2>(StringView str) { +std::wstring ToWideStringImpl<2>(std::string_view str) { const auto tmp = Utils::DecodeUTF16(str); return std::wstring(tmp.begin(), tmp.end()); } #endif -std::wstring Utils::ToWideString(StringView str) { +std::wstring Utils::ToWideString(std::string_view str) { return ToWideStringImpl(str); } @@ -564,7 +564,7 @@ bool Utils::ReadLine(std::istream& is, std::string& line_out) { } } -std::vector Utils::Tokenize(StringView str_to_tokenize, const std::function predicate) { +std::vector Utils::Tokenize(std::string_view str_to_tokenize, const std::function predicate) { std::u32string text = DecodeUTF32(str_to_tokenize); std::vector tokens; std::u32string cur_token; @@ -622,7 +622,7 @@ std::string Utils::ReplaceAll(std::string str, const std::string& search, const return str; } -std::string Utils::ReplacePlaceholders(StringView text_template, Span types, Span values) { +std::string Utils::ReplacePlaceholders(std::string_view text_template, Span types, Span values) { auto str = std::string(text_template); size_t index = str.find("%"); while (index != std::string::npos) { @@ -648,7 +648,7 @@ std::string Utils::ReplacePlaceholders(StringView text_template, Span(c))) { @@ -672,7 +672,7 @@ StringView Utils::TrimWhitespace(StringView s) { return s; } -std::string Utils::FormatDate(const std::tm *tm, StringView format) { +std::string Utils::FormatDate(const std::tm *tm, std::string_view format) { constexpr int buf_size = 128; char buffer[buf_size]; diff --git a/src/utils.h b/src/utils.h index ce5cb925b5..b219da6467 100644 --- a/src/utils.h +++ b/src/utils.h @@ -29,8 +29,8 @@ #include "span.h" namespace Utils { - constexpr StringView DateFormat_YYMMDD = "%y%m%d"; - constexpr StringView DateFormat_HHMMSS = "%H%M%S"; + constexpr std::string_view DateFormat_YYMMDD = "%y%m%d"; + constexpr std::string_view DateFormat_HHMMSS = "%H%M%S"; /** * Converts a string to lower case (ASCII only) @@ -38,7 +38,7 @@ namespace Utils { * @param str string to convert. * @return the converted string. */ - std::string LowerCase(StringView str); + std::string LowerCase(std::string_view str); /** * Converts a string to lower case in-place (ASCII only, faster) @@ -54,7 +54,7 @@ namespace Utils { * @param str string to convert. * @return the converted string. */ - std::string UpperCase(StringView str); + std::string UpperCase(std::string_view str); /** * Converts a string to upper case in-place. (ASCII only, faster) @@ -82,7 +82,7 @@ namespace Utils { * * @return < 0 if l is before r, 0 if equal, > 0 l is after r */ - int StrICmp(StringView l, StringView r); + int StrICmp(std::string_view l, std::string_view r); /** * Converts Utf8 to UTF-16. @@ -90,7 +90,7 @@ namespace Utils { * @param str string to convert. * @return the converted string. */ - std::u16string DecodeUTF16(StringView str); + std::u16string DecodeUTF16(std::string_view str); /** * Converts UTF-8 to UTF-32. @@ -98,7 +98,7 @@ namespace Utils { * @param str string to convert. * @return the converted string. */ - std::u32string DecodeUTF32(StringView str); + std::u32string DecodeUTF32(std::string_view str); /** * Converts UTF-16 to UTF-8. @@ -147,7 +147,7 @@ namespace Utils { * @param str unicode string * @return amount of codepoints */ - int UTF8Length(StringView str); + int UTF8Length(std::string_view str); // Please report an issue when you get a compile error here because your toolchain is broken and lacks wchar_t /** @@ -156,7 +156,7 @@ namespace Utils { * @param str string to convert. * @return the converted string. */ - std::wstring ToWideString(StringView str); + std::wstring ToWideString(std::string_view str); /** * Converts std::wstring to UTF-8 string. @@ -270,7 +270,7 @@ namespace Utils { * @param predicate Predicate function, must return true when the character is used for splitting. * @return vector containing the elements between the tokens */ - std::vector Tokenize(StringView str_to_tokenize, const std::function predicate); + std::vector Tokenize(std::string_view str_to_tokenize, const std::function predicate); /* * Searches for newlines and calls f(const std::string&) for each line. @@ -279,7 +279,7 @@ namespace Utils { * @param f function of type void(const std::string&) */ template - void ForEachLine(StringView line, F&& f); + void ForEachLine(std::string_view line, F&& f); /** * Reads a stream until EOF and returns the read bytes. @@ -317,7 +317,7 @@ namespace Utils { * should match types in number of elements and order. * @return A new string with placeholders replaced. */ - std::string ReplacePlaceholders(StringView text_template, Span types, Span values); + std::string ReplacePlaceholders(std::string_view text_template, Span types, Span values); /** * @return value clamped between min and max @@ -338,7 +338,7 @@ namespace Utils { * @param s * @return true when s contains only ASCII */ - bool StringIsAscii(StringView s); + bool StringIsAscii(std::string_view s); /** * Trims whitespace from the start and the end of a string @@ -346,7 +346,7 @@ namespace Utils { * @param s String to trim * @return View on the trimmed string */ - StringView TrimWhitespace(StringView s); + std::string_view TrimWhitespace(std::string_view s); /** * Formats a date. @@ -355,7 +355,7 @@ namespace Utils { * @param format Format string (See strftime) * @return formatted date */ - std::string FormatDate(const std::tm* tm, StringView format); + std::string FormatDate(const std::tm* tm, std::string_view format); /** * RPG_RT / Delphi compatible rounding of floating point. @@ -384,11 +384,11 @@ namespace Utils { } /** - * Create a std::array from the given parameters, automatically deducing the size. + * Create a std::array from the given parameters, automatically deducing the size. */ template constexpr auto MakeSvArray(Types&& ... t) { - return MakeArray(std::forward(t)...); + return MakeArray(std::forward(t)...); } /** @@ -400,11 +400,11 @@ namespace Utils { } /** - * Create a std::vector from the given parameters. + * Create a std::vector from the given parameters. */ template constexpr auto MakeSvVector(Types&& ... t) { - return MakeVector(std::forward(t)...); + return MakeVector(std::forward(t)...); } } // namespace Utils @@ -415,7 +415,7 @@ constexpr T Utils::Clamp(T value, const T& minv, const T& maxv) { } template -inline void Utils::ForEachLine(StringView line, F&& f) { +inline void Utils::ForEachLine(std::string_view line, F&& f) { size_t next = 0; do { auto idx = line.find('\n', next); @@ -437,7 +437,7 @@ inline bool Utils::IsControlCharacter(T ch) { return (ch >= 0x0 && ch <= 0x1F) || ch == 0x7F; } -inline bool Utils::StringIsAscii(StringView s) { +inline bool Utils::StringIsAscii(std::string_view s) { return std::all_of(s.begin(), s.end(), [](char c) { return isascii(static_cast(c)); }); diff --git a/src/window_base.cpp b/src/window_base.cpp index 63c45bb98e..dec0bf16fe 100644 --- a/src/window_base.cpp +++ b/src/window_base.cpp @@ -102,7 +102,7 @@ void Window_Base::OnFaceReady(FileRequestResult* result, int face_index, int cx, // All these functions assume that the input is valid -void Window_Base::DrawFace(StringView face_name, int face_index, int cx, int cy, bool flip) { +void Window_Base::DrawFace(std::string_view face_name, int face_index, int cx, int cy, bool flip) { if (face_name.empty()) { return; } FileRequestAsync* request = AsyncHandler::RequestFile("FaceSet", face_name); @@ -213,7 +213,7 @@ void Window_Base::DrawActorSp(const Game_Battler& actor, int cx, int cy, int dig } void Window_Base::DrawActorParameter(const Game_Battler& actor, int cx, int cy, int type) const { - StringView name; + std::string_view name; int value; switch (type) { @@ -245,7 +245,7 @@ void Window_Base::DrawActorParameter(const Game_Battler& actor, int cx, int cy, } void Window_Base::DrawEquipmentType(const Game_Actor& actor, int cx, int cy, int type) const { - StringView name; + std::string_view name; switch (type) { case 0: diff --git a/src/window_base.h b/src/window_base.h index 482a666861..68afdd94bc 100644 --- a/src/window_base.h +++ b/src/window_base.h @@ -52,7 +52,7 @@ class Window_Base : public Window { * Draw helpers. */ /** @{ */ - void DrawFace(StringView face_name, int face_index, int cx, int cy, bool flip = false); + void DrawFace(std::string_view face_name, int face_index, int cx, int cy, bool flip = false); void DrawActorFace(const Game_Actor& actor, int cx, int cy); void DrawActorName(const Game_Battler& actor, int cx, int cy) const; void DrawActorTitle(const Game_Actor& actor, int cx, int cy) const; diff --git a/src/window_battlemessage.cpp b/src/window_battlemessage.cpp index 6ca1d16ace..a2e268cdfc 100644 --- a/src/window_battlemessage.cpp +++ b/src/window_battlemessage.cpp @@ -36,20 +36,20 @@ Window_BattleMessage::Window_BattleMessage(int ix, int iy, int iwidth, int iheig SetZ(Priority_Window + 50); } -void Window_BattleMessage::Push(StringView message) { +void Window_BattleMessage::Push(std::string_view message) { #ifdef EP_DEBUG_BATTLE2K_MESSAGE Output::Debug("Battle2k Message Push \"{}\"", message); #endif - Utils::ForEachLine(message, [this](StringView line) + Utils::ForEachLine(message, [this](std::string_view line) { PushLine(line); }); } -void Window_BattleMessage::PushLine(StringView line) { +void Window_BattleMessage::PushLine(std::string_view line) { if (Feature::HasPlaceholders()) { Game_Message::WordWrap( line, GetWidth() - 20, - [this](StringView wrap_line) { + [this](std::string_view wrap_line) { lines.push_back(std::string(wrap_line)); } ); @@ -61,7 +61,7 @@ void Window_BattleMessage::PushLine(StringView line) { needs_refresh = true; } -void Window_BattleMessage::PushWithSubject(StringView message, StringView subject) { +void Window_BattleMessage::PushWithSubject(std::string_view message, std::string_view subject) { if (Feature::HasPlaceholders()) { Push(Utils::ReplacePlaceholders( message, diff --git a/src/window_battlemessage.h b/src/window_battlemessage.h index 4275cf1422..37b2e6527d 100644 --- a/src/window_battlemessage.h +++ b/src/window_battlemessage.h @@ -40,7 +40,7 @@ class Window_BattleMessage : public Window_Base { * * @param message The text to be displayed. */ - void Push(StringView message); + void Push(std::string_view message); /** * Pushes a message, either prepending the subject to it, @@ -50,7 +50,7 @@ class Window_BattleMessage : public Window_Base { * @param message Message to be displayed. * @param subject Subject that will be displayed in the message. */ - void PushWithSubject(StringView message, StringView subject); + void PushWithSubject(std::string_view message, std::string_view subject); void Pop(); @@ -95,7 +95,7 @@ class Window_BattleMessage : public Window_Base { static const int linesPerPage = 4; protected: - void PushLine(StringView line); + void PushLine(std::string_view line); private: std::vector lines; diff --git a/src/window_command.cpp b/src/window_command.cpp index 3d83944463..ea15af4f97 100644 --- a/src/window_command.cpp +++ b/src/window_command.cpp @@ -72,7 +72,7 @@ bool Window_Command::IsItemEnabled(int index) { return commands_enabled[index]; } -void Window_Command::SetItemText(unsigned index, StringView text) { +void Window_Command::SetItemText(unsigned index, std::string_view text) { if (index < commands.size()) { commands[index] = ToString(text); DrawItem(index, IsItemEnabled(index) ? Font::ColorDefault : Font::ColorDisabled); diff --git a/src/window_command.h b/src/window_command.h index e3ab59cd4e..0d04cf439f 100644 --- a/src/window_command.h +++ b/src/window_command.h @@ -81,7 +81,7 @@ class Window_Command: public Window_Selectable { * @param index command index. * @param text new item text. */ - void SetItemText(unsigned index, StringView text); + void SetItemText(unsigned index, std::string_view text); /** * Replace all commands with a new command set. diff --git a/src/window_equipstatus.cpp b/src/window_equipstatus.cpp index 719fced295..4af4cb3ae9 100644 --- a/src/window_equipstatus.cpp +++ b/src/window_equipstatus.cpp @@ -84,7 +84,7 @@ int Window_EquipStatus::GetNewParameterColor(int old_value, int new_value) { } void Window_EquipStatus::DrawParameter(int cx, int cy, int type) { - StringView name; + std::string_view name; int value; int new_value; diff --git a/src/window_gamelist.cpp b/src/window_gamelist.cpp index 237974a203..7b3257b61a 100644 --- a/src/window_gamelist.cpp +++ b/src/window_gamelist.cpp @@ -60,7 +60,7 @@ bool Window_GameList::Refresh(FilesystemView filesystem_base, bool show_dotdot) } #endif - if (StringView(dir.second.name).ends_with(".save")) { + if (EndsWith(dir.second.name, ".save")) { continue; } if (dir.second.type == DirectoryTree::FileType::Regular) { diff --git a/src/window_help.cpp b/src/window_help.cpp index b080537c1b..4b5e7289d2 100644 --- a/src/window_help.cpp +++ b/src/window_help.cpp @@ -58,7 +58,7 @@ void Window_Help::AddText(std::string text, int color, Text::Alignment align, bo std::string::size_type nextpos = 0; while (nextpos != std::string::npos) { nextpos = text.find(' ', pos); - auto segment = ToStringView(text).substr(pos, nextpos - pos); + auto segment = std::string_view(text).substr(pos, nextpos - pos); auto offset = contents->TextDraw(text_x_offset, 2, color, segment, align); text_x_offset += offset.x; diff --git a/src/window_message.cpp b/src/window_message.cpp index 9c46aff0be..dbde321640 100644 --- a/src/window_message.cpp +++ b/src/window_message.cpp @@ -168,7 +168,7 @@ void Window_Message::StartMessageProcessing(PendingMessage pm) { Game_Message::WordWrap( line, width - 24, - [&](StringView wrapped_line) { + [&](std::string_view wrapped_line) { append(std::string(wrapped_line)); } ); diff --git a/src/window_name.cpp b/src/window_name.cpp index 71ce4da4ae..587de0b41f 100644 --- a/src/window_name.cpp +++ b/src/window_name.cpp @@ -43,7 +43,7 @@ void Window_Name::Set(std::string text) { Refresh(); } -void Window_Name::Append(StringView text) { +void Window_Name::Append(std::string_view text) { // Avoid string copies by reusing the buffer in name name.append(text.begin(), text.end()); if (Text::GetSize(*Font::Default(), name).width <= (12 * 6)) { diff --git a/src/window_name.h b/src/window_name.h index 5fefb88589..3a9ee261f0 100644 --- a/src/window_name.h +++ b/src/window_name.h @@ -39,7 +39,7 @@ class Window_Name : public Window_Base { void Refresh(); void Set(std::string text); - void Append(StringView text); + void Append(std::string_view text); void Erase(); const std::string& Get() const; diff --git a/src/window_paramstatus.cpp b/src/window_paramstatus.cpp index 87d75bcd76..d9e9754925 100644 --- a/src/window_paramstatus.cpp +++ b/src/window_paramstatus.cpp @@ -36,7 +36,7 @@ Window_ParamStatus::Window_ParamStatus(int ix, int iy, int iwidth, int iheight, void Window_ParamStatus::Refresh() { contents->Clear(); - auto draw = [this](int y, StringView name, int value) { + auto draw = [this](int y, std::string_view name, int value) { // Draw Term contents->TextDraw(0, y, 1, name); diff --git a/src/window_settings.cpp b/src/window_settings.cpp index f692438a28..49811dc052 100644 --- a/src/window_settings.cpp +++ b/src/window_settings.cpp @@ -39,10 +39,10 @@ # include "platform/emscripten/interface.h" #endif -class MenuItem final : public ConfigParam { +class MenuItem final : public ConfigParam { public: - explicit MenuItem(StringView name, StringView description, StringView value) : - ConfigParam(name, description, "", "", value) { + explicit MenuItem(std::string_view name, std::string_view description, std::string_view value) : + ConfigParam(name, description, "", "", value) { } }; @@ -367,8 +367,8 @@ void Window_Settings::RefreshAudioSoundfont() { std::string sf_lower = Utils::LowerCase(Audio().GetFluidsynthSoundfont()); for (const auto& item: *list) { - if (item.second.type == DirectoryTree::FileType::Regular && (StringView(item.first).ends_with(".sf2") || StringView(item.first).ends_with(".soundfont"))) { - AddOption(MenuItem(item.second.name, "Use this custom soundfont", StringView(sf_lower).ends_with(item.first) ? "[x]" : ""), [this, fs, item]() { + if (item.second.type == DirectoryTree::FileType::Regular && (EndsWith(item.first, ".sf2") || EndsWith(item.first, ".soundfont"))) { + AddOption(MenuItem(item.second.name, "Use this custom soundfont", EndsWith(sf_lower, item.first) ? "[x]" : ""), [this, fs, item]() { Audio().SetFluidsynthSoundfont(FileFinder::MakePath(fs.GetFullPath(), item.second.name)); Pop(); }); @@ -464,11 +464,11 @@ void Window_Settings::RefreshEngineFont(bool mincho) { assert(list); for (const auto& item: *list) { bool is_font = std::any_of(FileFinder::FONTS_TYPES.begin(), FileFinder::FONTS_TYPES.end(), [&item](const auto& ext) { - return StringView(item.first).ends_with(ext); + return EndsWith(item.first, ext); }); if (item.second.type == DirectoryTree::FileType::Regular && is_font) { - AddOption(MenuItem(item.second.name, "Use this font", StringView(font_lower).ends_with(item.first) ? "[x]" : ""), [=, &cfg, &setting]() mutable { + AddOption(MenuItem(item.second.name, "Use this font", EndsWith(font_lower, item.first) ? "[x]" : ""), [=, &cfg, &setting]() mutable { if (Input::IsTriggered(Input::LEFT) || Input::IsRepeated(Input::LEFT)) { if (font_size.Get() == font_size.GetMin()) { font_size.Set(font_size.GetMax()); diff --git a/src/window_shop.h b/src/window_shop.h index 742f05786e..011c1e8efb 100644 --- a/src/window_shop.h +++ b/src/window_shop.h @@ -56,17 +56,17 @@ class Window_Shop : public Window_Base { protected: void UpdateCursorRect(); - StringView greeting; - StringView regreeting; - StringView buy_msg; - StringView sell_msg; - StringView leave_msg; - StringView buy_select; - StringView buy_number; - StringView purchased; - StringView sell_select; - StringView sell_number; - StringView sold_msg; + std::string_view greeting; + std::string_view regreeting; + std::string_view buy_msg; + std::string_view sell_msg; + std::string_view leave_msg; + std::string_view buy_select; + std::string_view buy_number; + std::string_view purchased; + std::string_view sell_select; + std::string_view sell_number; + std::string_view sold_msg; int index; int mode; int buy_index; diff --git a/src/window_shopparty.cpp b/src/window_shopparty.cpp index d2b98e8ed2..b2ba968310 100644 --- a/src/window_shopparty.cpp +++ b/src/window_shopparty.cpp @@ -195,7 +195,7 @@ void Window_ShopParty::Update() { void Window_ShopParty::OnCharsetSpriteReady(FileRequestResult* /* result */, int party_index) { Game_Actor *actor = Main_Data::game_party->GetActors()[party_index]; - StringView sprite_name = actor->GetSpriteName(); + std::string_view sprite_name = actor->GetSpriteName(); int sprite_id = actor->GetSpriteIndex(); BitmapRef bm = Cache::Charset(sprite_name); auto rect = Sprite_Character::GetCharacterRect(sprite_name, sprite_id, bm->GetRect()); diff --git a/src/window_stringview.cpp b/src/window_stringview.cpp index d683241a6f..c92e3241a1 100644 --- a/src/window_stringview.cpp +++ b/src/window_stringview.cpp @@ -33,7 +33,7 @@ Window_StringView::~Window_StringView() { } -void Window_StringView::SetDisplayData(StringView data) { +void Window_StringView::SetDisplayData(std::string_view data) { display_data_raw = ToString(data); } @@ -77,7 +77,7 @@ void Window_StringView::Refresh() { line_numbers.push_back(++c); if (auto_linebreak) { bool skipFirstNo = true; - Game_Message::WordWrap(new_line, limit, [&](StringView line) { + Game_Message::WordWrap(new_line, limit, [&](std::string_view line) { if (!skipFirstNo) line_numbers.push_back(0); skipFirstNo = false; diff --git a/src/window_stringview.h b/src/window_stringview.h index ead59bc3ef..1d383cbd2a 100644 --- a/src/window_stringview.h +++ b/src/window_stringview.h @@ -28,7 +28,7 @@ class Window_StringView : public Window_Selectable { void Update() override; - void SetDisplayData(StringView data); + void SetDisplayData(std::string_view data); std::string GetDisplayData(bool eval_cmds); void Refresh(); diff --git a/tests/utils.cpp b/tests/utils.cpp index cf3ac1c1ef..f5d3e08b2e 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -47,7 +47,7 @@ TEST_CASE("StrICmp") { } SUBCASE("sv") { - testStrICmp(); + testStrICmp(); } } diff --git a/tests/wordwrap.cpp b/tests/wordwrap.cpp index a39d104d4d..65441402e0 100644 --- a/tests/wordwrap.cpp +++ b/tests/wordwrap.cpp @@ -7,9 +7,9 @@ TEST_SUITE_BEGIN("Word Wrap"); constexpr int limit_2k = SCREEN_TARGET_WIDTH - 20; -static std::vector WordWrap(StringView line, int limit = limit_2k) { +static std::vector WordWrap(std::string_view line, int limit = limit_2k) { std::vector lines; - Game_Message::WordWrap(line, limit, [&](StringView l) { lines.push_back(std::string(l)); }); + Game_Message::WordWrap(line, limit, [&](std::string_view l) { lines.push_back(std::string(l)); }); return lines; }