Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / String / String.cpp
diff options
context:
space:
mode:
Commit1193df540e830db8039d86702825cd6beab76e12 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-09 08:55:50 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-09 08:55:50 +0300
Filesa3e263fd67d3b62e9a30137f0570696f1418a434 /src/Generic/String/String.cpp
FMI-OOP-P1_TicketSystem-1193df540e830db8039d86702825cd6beab76e12.tar
FMI-OOP-P1_TicketSystem-1193df540e830db8039d86702825cd6beab76e12.tar.gz
FMI-OOP-P1_TicketSystem-1193df540e830db8039d86702825cd6beab76e12.zip
Parent519235af82e58a8437e7c6185a0911721e021b42 (diff)
Added String tests and fixed operator+= with number
1 files changed, 4 insertions, 1 deletions
-rw-r--r--src/Generic/String/String.cpp5
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp
index 49c0b19..66e9ad4 100644
--- a/src/Generic/String/String.cpp
+++ b/src/Generic/String/String.cpp
@@ -63,7 +63,10 @@ String& String::operator+=(const char* str) {
* Converts the number to a C-style string and then uses += to append it.
*/
String& String::operator+=(unsigned number) {
- unsigned tempLen = number / 10 + 1;
+ unsigned tempLen = 0;
+ for (unsigned tmp = number; tmp > 0 || tempLen == 0; tmp /= 10)
+ tempLen++;
+
char* tmp = new char[tempLen + 1];
tmp[tempLen] = '\0';
for (unsigned i = tempLen - 1; i < tempLen; i--, number /= 10)