Skip to content

Commit ea19c28

Browse files
committed
Migrate to std::string_view
This removes string_view lite as C++17 supports string views natively. For convenience (and to make the replacement simpler) ToString helper function is kept. Unfortunately C++17 has no starts/ends_with, helpers were added for this.
1 parent 34db541 commit ea19c28

28 files changed

Lines changed: 147 additions & 1828 deletions

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ set(LCF_HEADERS
290290
src/generated/lcf/rpg/trooppagecondition.h
291291
src/generated/lcf/rpg/variable.h
292292
src/lcf/third_party/span.h
293-
src/lcf/third_party/string_view.h
294293
)
295294

296295
set(LCF_SUPPORT_INI 0)

Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ lcfrpginclude_HEADERS = \
322322
src/generated/lcf/rpg/variable.h
323323

324324
lcfthirdpartyinclude_HEADERS = \
325-
src/lcf/third_party/span.h \
326-
src/lcf/third_party/string_view.h
325+
src/lcf/third_party/span.h
327326

328327
nodist_lcfinclude_HEADERS = src/lcf/config.h
329328

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ See the file [COPYING] for copying conditions.
117117
liblcf includes code of the following 3rd party software:
118118

119119
- [inih] under New BSD license.
120-
- [string-view-lite] and [span-lite] under Boost Software License, Version 1.0.
120+
- [span-lite] under Boost Software License, Version 1.0.
121121

122122
See the source code comment headers for license details.
123123

generator/csv/functions.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Structure,Method,Static,Headers
22
Actor,void Setup(bool is2k3),f,
33
Parameters,void Setup(int final_level),f,
4-
Terms,"std::string TermOrDefault(const DBString& db_term, StringView default_term)",t,
4+
Terms,"std::string TermOrDefault(const DBString& db_term, std::string_view default_term)",t,

src/generated/lcf/rpg/terms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace rpg {
2828
// Sentinel name used to denote that the default hardcoded term should be used.
2929
static constexpr const char* kDefaultTerm = "default_term";
3030

31-
static std::string TermOrDefault(const DBString& db_term, StringView default_term);
31+
static std::string TermOrDefault(const DBString& db_term, std::string_view default_term);
3232
DBString encounter;
3333
DBString special_combat;
3434
DBString escape_success;

src/lcf/context.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace lcf {
1919
*/
2020
struct ContextNameBase {
2121
/** Constructor */
22-
constexpr ContextNameBase(StringView n, int i) : name(n), index(i) {}
22+
constexpr ContextNameBase(std::string_view n, int i) : name(n), index(i) {}
2323

2424
/** Name of the enumerated field */
25-
StringView name;
25+
std::string_view name;
2626

2727
/** Array index when the object is part of a list (-1 when not) */
2828
int index = -1;
@@ -38,7 +38,7 @@ struct ContextStructBase : ContextNameBase {
3838
using StructType_t = StructType;
3939

4040
/** Constructor */
41-
constexpr ContextStructBase(StringView n, int i, StructType_t* o)
41+
constexpr ContextStructBase(std::string_view n, int i, StructType_t* o)
4242
: ContextNameBase(n, i), obj(o) {}
4343

4444
/** Object instance (cast to appropriate RPG-type */
@@ -58,7 +58,7 @@ struct Context : ContextStructBase<StructType> {
5858
/** The type of the parent context */
5959
using ParentCtxType_t = ParentCtxType;
6060

61-
constexpr Context(StringView n, int i, StructType* o, const ParentCtxType_t* pctx)
61+
constexpr Context(std::string_view n, int i, StructType* o, const ParentCtxType_t* pctx)
6262
: ContextStructBase<StructType>{n, i, o}, parent(pctx) {}
6363

6464
/** Context of the parent (nullptr when no parent) */

src/lcf/dbstring.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
#include <iterator>
1515
#include <cstdint>
1616
#include <cstring>
17-
#include <limits>
1817
#include <algorithm>
1918
#include <ostream>
2019

21-
#include "lcf/string_view.h"
2220
#include "lcf/dbarrayalloc.h"
2321

2422
namespace lcf {
@@ -43,17 +41,17 @@ class DBString {
4341
static constexpr size_type npos = size_type(-1);
4442

4543
constexpr DBString() = default;
46-
explicit DBString(StringView s) : _storage(construct_sv(s.data(), s.size())) {}
44+
explicit DBString(std::string_view s) : _storage(construct_sv(s.data(), s.size())) {}
4745
explicit DBString(const std::string& s) : _storage(construct_z(s.c_str(), s.size())) {}
4846

4947
// Explicit construct for general const char*
50-
explicit DBString(const char* s) : DBString(StringView(s)) {}
48+
explicit DBString(const char* s) : DBString(std::string_view(s)) {}
5149
// Implicit constructor to capture string literals
5250
template <size_t N>
5351
DBString(const char(&literal)[N]) : _storage(construct_z(literal, N - 1)) {}
54-
DBString(const char* s, size_t len) : DBString(StringView(s, len)) {}
52+
DBString(const char* s, size_t len) : DBString(std::string_view(s, len)) {}
5553

56-
DBString(const DBString& o) : DBString(StringView(o)) {}
54+
DBString(const DBString& o) : DBString(std::string_view(o)) {}
5755
DBString(DBString&& o) noexcept { swap(o); }
5856

5957
DBString& operator=(const DBString&);
@@ -66,7 +64,7 @@ class DBString {
6664
~DBString() { destroy(); }
6765

6866
explicit operator std::string() const { return std::string(data(), size()); }
69-
operator StringView() const { return StringView(data(), size()); }
67+
operator std::string_view() const { return std::string_view(data(), size()); }
7068

7169
char& operator[](size_type i) { return data()[i]; }
7270
char operator[](size_type i) const { return data()[i]; }
@@ -123,21 +121,21 @@ inline std::string ToString(const DBString& s) {
123121
}
124122

125123
#define LCF_DBSTRING_MAKE_CMP_OPS(LTYPE, RTYPE) \
126-
inline bool operator==(LTYPE l, RTYPE r) { return StringView(l) == StringView(r); }\
127-
inline bool operator!=(LTYPE l, RTYPE r) { return StringView(l) != StringView(r); }\
128-
inline bool operator<(LTYPE l, RTYPE r) { return StringView(l) < StringView(r); }\
129-
inline bool operator>(LTYPE l, RTYPE r) { return StringView(l) > StringView(r); }\
130-
inline bool operator<=(LTYPE l, RTYPE r) { return StringView(l) <= StringView(r); }\
131-
inline bool operator>=(LTYPE l, RTYPE r) { return StringView(l) >= StringView(r); }\
124+
inline bool operator==(LTYPE l, RTYPE r) { return std::string_view(l) == std::string_view(r); }\
125+
inline bool operator!=(LTYPE l, RTYPE r) { return std::string_view(l) != std::string_view(r); }\
126+
inline bool operator<(LTYPE l, RTYPE r) { return std::string_view(l) < std::string_view(r); }\
127+
inline bool operator>(LTYPE l, RTYPE r) { return std::string_view(l) > std::string_view(r); }\
128+
inline bool operator<=(LTYPE l, RTYPE r) { return std::string_view(l) <= std::string_view(r); }\
129+
inline bool operator>=(LTYPE l, RTYPE r) { return std::string_view(l) >= std::string_view(r); }\
132130

133131
LCF_DBSTRING_MAKE_CMP_OPS(const DBString&, const DBString&);
134-
LCF_DBSTRING_MAKE_CMP_OPS(StringView, const DBString&);
135-
LCF_DBSTRING_MAKE_CMP_OPS(const DBString&, StringView);
132+
LCF_DBSTRING_MAKE_CMP_OPS(std::string_view, const DBString&);
133+
LCF_DBSTRING_MAKE_CMP_OPS(const DBString&, std::string_view);
136134
LCF_DBSTRING_MAKE_CMP_OPS(const char*, const DBString&);
137135
LCF_DBSTRING_MAKE_CMP_OPS(const DBString&, const char*);
138136

139137
inline std::ostream& operator<<(std::ostream& os, const DBString& s) {
140-
os << StringView(s);
138+
os << std::string_view(s);
141139
return os;
142140
}
143141

@@ -147,7 +145,7 @@ namespace std {
147145

148146
template <> struct hash<lcf::DBString> {
149147
size_t operator()(const lcf::DBString& s) const {
150-
return std::hash<lcf::StringView>()(lcf::StringView(s));
148+
return std::hash<std::string_view>()(std::string_view(s));
151149
}
152150
};
153151

src/lcf/ldb/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ namespace LDB_Reader {
3030
/**
3131
* Loads Database.
3232
*/
33-
std::unique_ptr<lcf::rpg::Database> Load(StringView filename, StringView encoding = "");
33+
std::unique_ptr<lcf::rpg::Database> Load(std::string_view filename, std::string_view encoding = "");
3434

3535
/**
3636
* Saves Database.
3737
*/
38-
bool Save(StringView filename, const lcf::rpg::Database& db, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
38+
bool Save(std::string_view filename, const lcf::rpg::Database& db, std::string_view encoding = "", SaveOpt opt = SaveOpt::eNone);
3939

4040
/**
4141
* Saves Database as XML.
4242
*/
43-
bool SaveXml(StringView filename, const lcf::rpg::Database& db);
43+
bool SaveXml(std::string_view filename, const lcf::rpg::Database& db);
4444

4545
/**
4646
* Load Database as XML.
4747
*/
48-
std::unique_ptr<lcf::rpg::Database> LoadXml(StringView filename);
48+
std::unique_ptr<lcf::rpg::Database> LoadXml(std::string_view filename);
4949

5050
/**
5151
* Loads Database.
5252
*/
53-
std::unique_ptr<lcf::rpg::Database> Load(std::istream& filestream, StringView encoding = "");
53+
std::unique_ptr<lcf::rpg::Database> Load(std::istream& filestream, std::string_view encoding = "");
5454

5555
/**
5656
* Saves Database.
5757
*/
58-
bool Save(std::ostream& filestream, const lcf::rpg::Database& db, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
58+
bool Save(std::ostream& filestream, const lcf::rpg::Database& db, std::string_view encoding = "", SaveOpt opt = SaveOpt::eNone);
5959

6060
/**
6161
* Saves Database as XML.

src/lcf/lmt/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ namespace LMT_Reader {
2525
/**
2626
* Loads Map Tree.
2727
*/
28-
std::unique_ptr<lcf::rpg::TreeMap> Load(StringView filename, StringView encoding = "");
28+
std::unique_ptr<lcf::rpg::TreeMap> Load(std::string_view filename, std::string_view encoding = "");
2929

3030
/**
3131
* Saves Map Tree.
3232
*/
33-
bool Save(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
33+
bool Save(std::string_view filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, std::string_view encoding = "", SaveOpt opt = SaveOpt::eNone);
3434

3535
/**
3636
* Saves Map Tree as XML.
3737
*/
38-
bool SaveXml(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine);
38+
bool SaveXml(std::string_view filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine);
3939

4040
/**
4141
* Loads Map Tree as XML.
4242
*/
43-
std::unique_ptr<lcf::rpg::TreeMap> LoadXml(StringView filename);
43+
std::unique_ptr<lcf::rpg::TreeMap> LoadXml(std::string_view filename);
4444

4545
/**
4646
* Loads Map Tree.
4747
*/
48-
std::unique_ptr<lcf::rpg::TreeMap> Load(std::istream& filestream, StringView encoding = "");
48+
std::unique_ptr<lcf::rpg::TreeMap> Load(std::istream& filestream, std::string_view encoding = "");
4949

5050
/**
5151
* Saves Map Tree.
5252
*/
53-
bool Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
53+
bool Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, std::string_view encoding = "", SaveOpt opt = SaveOpt::eNone);
5454

5555
/**
5656
* Saves Map Tree as XML.

src/lcf/lmu/reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ namespace LMU_Reader {
3030
/**
3131
* Loads map.
3232
*/
33-
std::unique_ptr<rpg::Map> Load(StringView filename, StringView encoding = "");
33+
std::unique_ptr<rpg::Map> Load(std::string_view filename, std::string_view encoding = "");
3434

3535
/**
3636
* Saves map.
3737
*/
38-
bool Save(StringView filename, const rpg::Map& map, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
38+
bool Save(std::string_view filename, const rpg::Map& map, EngineVersion engine, std::string_view encoding = "", SaveOpt opt = SaveOpt::eNone);
3939

4040
/**
4141
* Saves map as XML.
4242
*/
43-
bool SaveXml(StringView filename, const rpg::Map& map, EngineVersion engine);
43+
bool SaveXml(std::string_view filename, const rpg::Map& map, EngineVersion engine);
4444

4545
/**
4646
* Loads map as XML.
4747
*/
48-
std::unique_ptr<rpg::Map> LoadXml(StringView filename);
48+
std::unique_ptr<rpg::Map> LoadXml(std::string_view filename);
4949

5050
/**
5151
* Loads map.
5252
*/
53-
std::unique_ptr<rpg::Map> Load(std::istream& filestream, StringView encoding = "");
53+
std::unique_ptr<rpg::Map> Load(std::istream& filestream, std::string_view encoding = "");
5454

5555
/**
5656
* Saves map.
5757
*/
58-
bool Save(std::ostream& filestream, const rpg::Map& map, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);
58+
bool Save(std::ostream& filestream, const rpg::Map& map, EngineVersion engine, std::string_view encoding = "", SaveOpt opt = SaveOpt::eNone);
5959

6060
/**
6161
* Saves map as XML.

0 commit comments

Comments
 (0)