[Scummvm-git-logs] scummvm master -> e31b6ea8a7f2b6ae6063ea6987d0192ea4cb5548
bluegr
noreply at scummvm.org
Thu Nov 28 23:16:58 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e31b6ea8a7 COMMON: Unified implementation of constructing strings with single characters
Commit: e31b6ea8a7f2b6ae6063ea6987d0192ea4cb5548
https://github.com/scummvm/scummvm/commit/e31b6ea8a7f2b6ae6063ea6987d0192ea4cb5548
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2024-11-29T01:16:55+02:00
Commit Message:
COMMON: Unified implementation of constructing strings with single characters
Changed paths:
common/dbcs-str.cpp
common/dbcs-str.h
common/str-base.h
common/str.cpp
common/str.h
common/ustr.cpp
common/ustr.h
diff --git a/common/dbcs-str.cpp b/common/dbcs-str.cpp
index 57782c43eb4..321e411f037 100644
--- a/common/dbcs-str.cpp
+++ b/common/dbcs-str.cpp
@@ -63,13 +63,6 @@ DBCSString::DBCSString(const String &str) : BaseString<uint16>() {
decodeDBCS(str.c_str(), str.size());
}
-DBCSString::DBCSString(uint16 c) : BaseString<uint16>() {
- _storage[0] = c;
- _storage[1] = 0;
-
- _size = (c == 0) ? 0 : 1;
-}
-
DBCSString &DBCSString::operator=(const DBCSString &str) {
assign(str);
return *this;
diff --git a/common/dbcs-str.h b/common/dbcs-str.h
index 8e185dc3095..ede861bf194 100644
--- a/common/dbcs-str.h
+++ b/common/dbcs-str.h
@@ -73,7 +73,7 @@ public:
explicit DBCSString(const String &str);
/** Construct a string consisting of the given character. */
- explicit DBCSString(value_type c);
+ explicit constexpr DBCSString(value_type c) : BaseString<uint16>(c) {}
/** Assign a given string to this string. */
DBCSString &operator=(const DBCSString &str);
diff --git a/common/str-base.h b/common/str-base.h
index de58d8c3dc6..986b6fb404e 100644
--- a/common/str-base.h
+++ b/common/str-base.h
@@ -83,6 +83,9 @@ public:
/** Construct a new empty string. */
constexpr BaseString() : _size(0), _str(_storage), _storage{0} {}
+ /** Construct a string consisting of the given character. */
+ explicit constexpr BaseString(value_type c) : _size((c == 0) ? 0 : 1), _str(_storage), _storage{c, 0} {}
+
/** Construct a copy of the given string. */
BaseString(const BaseString &str);
diff --git a/common/str.cpp b/common/str.cpp
index 56cfab4e414..140bad1673f 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -28,15 +28,6 @@
namespace Common {
-String::String(char c)
- : BaseString<char>() {
-
- _storage[0] = c;
- _storage[1] = 0;
-
- _size = (c == 0) ? 0 : 1;
-}
-
#ifndef SCUMMVM_UTIL
String::String(const U32String &str, Common::CodePage page)
: BaseString<char>() {
diff --git a/common/str.h b/common/str.h
index 0a507ad9a82..ac1f4607c9c 100644
--- a/common/str.h
+++ b/common/str.h
@@ -84,7 +84,7 @@ public:
String(String &&str) : BaseString<char>(static_cast<BaseString<char> &&>(str)) {}
/** Construct a string consisting of the given character. */
- explicit String(char c);
+ explicit constexpr String(value_type c) : BaseString<char>(c) {}
/** Construct a new string from the given u32 string. */
String(const U32String &str, CodePage page = kUtf8);
diff --git a/common/ustr.cpp b/common/ustr.cpp
index 4e83671fd6e..779cebfc0ae 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -48,13 +48,6 @@ U32String::U32String(const String &str, Common::CodePage page) : BaseString<u32c
decodeInternal(str.c_str(), str.size(), page);
}
-U32String::U32String(u32char_type_t c) : BaseString<u32char_type_t>() {
- _storage[0] = c;
- _storage[1] = 0;
-
- _size = (c == 0) ? 0 : 1;
-}
-
U32String &U32String::operator=(const U32String &str) {
assign(str);
return *this;
diff --git a/common/ustr.h b/common/ustr.h
index bb77251fb48..a8ae9e7bc10 100644
--- a/common/ustr.h
+++ b/common/ustr.h
@@ -96,7 +96,7 @@ public:
U32String(const String &str, CodePage page = kUtf8);
/** Construct a string consisting of the given character. */
- explicit U32String(value_type c);
+ explicit constexpr U32String(value_type c) : BaseString<u32char_type_t>(c) {}
/** Assign a given string to this string. */
U32String &operator=(const U32String &str);
More information about the Scummvm-git-logs
mailing list