Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / String
diff options
context:
space:
mode:
2 files changed, 19 insertions, 2 deletions
-rw-r--r--src/Generic/String/String.cpp19
-rw-r--r--src/Generic/String/String.h2
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp
index d9cc235..ed096e8 100644
--- a/src/Generic/String/String.cpp
+++ b/src/Generic/String/String.cpp
@@ -62,6 +62,17 @@ String& String::operator+=(const char* str) {
/*!
* Converts the number to a C-style string and then uses += to append it.
*/
+String& String::operator+=(int number) {
+ if (number < 0) {
+ *this += "-";
+ number *= -1;
+ }
+ return *this += (unsigned)number;
+}
+
+/*!
+ * Converts the number to a C-style string and then uses += to append it.
+ */
String& String::operator+=(unsigned number) {
unsigned tempLen = 0;
for (unsigned tmp = number; tmp > 0 || tempLen == 0; tmp /= 10)
@@ -81,8 +92,12 @@ String& String::operator+=(unsigned number) {
* Converts the number to a C-style string and then uses += to append it.
*/
String& String::operator+=(double number) {
- if (number < 0) *this += "-";
- return ((*this += (unsigned)number) += ".") += (unsigned)((number - (unsigned)number) * DOUBLE_PRECISION);
+ if (number < 0) {
+ *this += "-";
+ number *= -1;
+ }
+ return ((*this += (unsigned)number) += ".")
+ += (unsigned)((number - (unsigned)number) * DOUBLE_PRECISION);
}
String::String() : String("") {}
diff --git a/src/Generic/String/String.h b/src/Generic/String/String.h
index f30151a..c520bc9 100644
--- a/src/Generic/String/String.h
+++ b/src/Generic/String/String.h
@@ -32,6 +32,8 @@ public:
//! Appends a C-style string
String& operator+=(const char* str);
//! Appends a number
+ String& operator+=(int number);
+ //! Appends a number
String& operator+=(unsigned number);
//! Appends a number
String& operator+=(double number);