Skip to content

Commit

Permalink
fix(string): fix some bugs
Browse files Browse the repository at this point in the history
please refer to the file change history for details
  • Loading branch information
CLimber-Rong committed Aug 21, 2024
1 parent dd4521c commit cbbed4e
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions include/stdc_implemented/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ class String {
String toString(int value) {
StrFree();
str = (char_type*)StrCalloc(256);
if(sprintf(str, "%d", value) < 0) {
//如果出错就为-1
*this = String("-1");
}
snprintf(str, 256, "%d", value);
str = (char_type*)realloc(str, strlen(str)+1);
return String(str);
}
Expand All @@ -122,21 +119,15 @@ class String {
String toString(float value) {
StrFree();
str = (char_type*)StrCalloc(256);
if(sprintf(str, "%f", value) < 0) {
//如果出错就为-1
*this = String("-1");
}
snprintf(str, 256, "%f", value);
str = (char_type*)realloc(str, strlen(str)+1);
return String(str);
}

String toString(double value) {
StrFree();
str = (char_type*)StrCalloc(256);
if(sprintf(str, "%lf", value) < 0) {
//如果出错就为-1
*this = String("-1");
}
snprintf(str, 256, "%lf", value);
str = (char_type*)realloc(str, strlen(str)+1);
return String(str);
}
Expand Down

0 comments on commit cbbed4e

Please sign in to comment.