Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to std::string_view, liblcf #495 #3360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/async_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/async_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/async_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/audio_midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/audio_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/audio_secache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace {
}
}

std::unique_ptr<AudioSeCache> AudioSeCache::Create(Filesystem_Stream::InputStream stream, StringView name) {
std::unique_ptr<AudioSeCache> AudioSeCache::Create(Filesystem_Stream::InputStream stream, std::string_view name) {
auto se = std::make_unique<AudioSeCache>();
se->name = ToString(name);

Expand Down Expand Up @@ -107,7 +107,7 @@ void AudioSeCache::GetFormat(int& frequency, AudioDecoder::Format& format, int&
audio_decoder->GetFormat(frequency, format, channels);
}

std::unique_ptr<AudioSeCache> AudioSeCache::GetCachedSe(StringView name) {
std::unique_ptr<AudioSeCache> AudioSeCache::GetCachedSe(std::string_view name) {
auto se = std::make_unique<AudioSeCache>();
se->name = ToString(name);

Expand Down Expand Up @@ -192,7 +192,7 @@ void AudioSeCache::Clear() {
cache.clear();
}

StringView AudioSeCache::GetName() const {
std::string_view AudioSeCache::GetName() const {
return name;
}

Expand Down
6 changes: 3 additions & 3 deletions src/audio_secache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioSeCache> Create(Filesystem_Stream::InputStream stream, StringView name);
static std::unique_ptr<AudioSeCache> Create(Filesystem_Stream::InputStream stream, std::string_view name);

/**
* Retrieves the format of the internal audio decoder.
Expand All @@ -101,7 +101,7 @@ class AudioSeCache {
* @param name Cache entry name
* @return SE is already in cache, nullptr otherwise
*/
static std::unique_ptr<AudioSeCache> GetCachedSe(StringView name);
static std::unique_ptr<AudioSeCache> GetCachedSe(std::string_view name);

/**
* Retrieves the format of the cached file.
Expand Down Expand Up @@ -135,7 +135,7 @@ class AudioSeCache {
/**
* @return name of the cached SE
*/
StringView GetName() const;
std::string_view GetName() const;

static void Clear();
private:
Expand Down
2 changes: 1 addition & 1 deletion src/autobattle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ template <typename... Args>
static void DebugLog(const char*, Args&&...) {}
#endif

std::unique_ptr<AlgorithmBase> CreateAlgorithm(StringView name) {
std::unique_ptr<AlgorithmBase> CreateAlgorithm(std::string_view name) {
if (Utils::StrICmp(name, RpgRtImproved::name) == 0) {
return std::make_unique<RpgRtImproved>();
}
Expand Down
10 changes: 5 additions & 5 deletions src/autobattle.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AlgorithmBase;
* @param name of the algo.
* @return An auto battle algorithm to be used in battles.
*/
std::unique_ptr<AlgorithmBase> CreateAlgorithm(StringView name);
std::unique_ptr<AlgorithmBase> CreateAlgorithm(std::string_view name);

/**
* Base class for auto battle algorithm implementations.
Expand All @@ -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.
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/baseui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {};
Expand Down
2 changes: 1 addition & 1 deletion src/battle_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
58 changes: 29 additions & 29 deletions src/battle_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/battle_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Loading
Loading