39
39
*/
40
40
41
41
#include " base/string/cstring.h"
42
+ #include " base/basic_types.h"
43
+ #include < algorithm>
42
44
#include < cctype>
43
45
#include < cstdio>
44
- #include < sstream >
46
+ #include < cstdlib >
45
47
#include < cstring>
48
+ #include < sstream>
49
+ #include < string>
50
+
51
+ constexpr size_t NUMBER_TO_STRING_BUFFER_SIZE = 32 ;
52
+
53
+ // NOLINTBEGIN (*-c-arrays)
46
54
47
55
namespace MaxPlus {
48
56
@@ -81,8 +89,8 @@ MPString::MPString(const MPString &s) = default;
81
89
* Constructor.
82
90
*/
83
91
MPString::MPString (const int n) {
84
- char str[32 ];
85
- snprintf (&str[0 ], 32 , " %i" , n);
92
+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
93
+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %i" , n);
86
94
append (std::string (str));
87
95
}
88
96
@@ -91,8 +99,8 @@ MPString::MPString(const int n) {
91
99
* Constructor.
92
100
*/
93
101
MPString::MPString (const unsigned int n) {
94
- char str[32 ];
95
- snprintf (&str[0 ], 32 , " %u" , n);
102
+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
103
+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %u" , n);
96
104
append (std::string (str));
97
105
}
98
106
@@ -101,8 +109,8 @@ MPString::MPString(const unsigned int n) {
101
109
* Constructor.
102
110
*/
103
111
MPString::MPString (const long int n) {
104
- char str[32 ];
105
- snprintf (&str[0 ], 32 , " %ld" , n);
112
+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
113
+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %ld" , n);
106
114
append (std::string (str));
107
115
}
108
116
@@ -111,8 +119,8 @@ MPString::MPString(const long int n) {
111
119
* Constructor.
112
120
*/
113
121
MPString::MPString (const unsigned long int n) {
114
- char str[32 ];
115
- snprintf (&str[0 ], 32 , " %ld" , n);
122
+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
123
+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %ld" , n);
116
124
append (std::string (str));
117
125
}
118
126
@@ -121,8 +129,8 @@ MPString::MPString(const unsigned long int n) {
121
129
* Constructor.
122
130
*/
123
131
MPString::MPString (const long long int n) {
124
- char str[32 ];
125
- snprintf (&str[0 ], 32 , " %lld" , n);
132
+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
133
+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %lld" , n);
126
134
append (std::string (str));
127
135
}
128
136
@@ -131,8 +139,8 @@ MPString::MPString(const long long int n) {
131
139
* Constructor.
132
140
*/
133
141
MPString::MPString (const unsigned long long int n) {
134
- char str[32 ];
135
- snprintf (&str[0 ], 32 , " %lld" , n);
142
+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
143
+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %lld" , n);
136
144
append (std::string (str));
137
145
}
138
146
@@ -141,8 +149,8 @@ MPString::MPString(const unsigned long long int n) {
141
149
* Constructor.
142
150
*/
143
151
MPString::MPString (const CDouble n) {
144
- char str[32 ];
145
- snprintf (&str[0 ], 32 , " %g" , n);
152
+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
153
+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %g" , n);
146
154
append (std::string (str));
147
155
}
148
156
@@ -566,3 +574,5 @@ MPString MPString::regexReplaceMultiLine(const MPString ®ex, const MPString &
566
574
}
567
575
568
576
} // namespace MaxPlus
577
+
578
+ // NOLINTEND (*-c-arrays)
0 commit comments