23 #ifndef LOG4CPLUS_HELPERS_STRINGHELPER_HEADER_
24 #define LOG4CPLUS_HELPERS_STRINGHELPER_HEADER_
26 #include "dcmtk/oflog/config.h"
28 #include "dcmtk/ofstd/oflist.h"
63 template <
class StringType>
66 tokenize(
const StringType& s,
typename StringType::value_type c,
69 typedef typename StringType::size_type size_type;
70 size_type
const slen = s.length();
73 for (i=0; i < slen; ++i)
77 result.
push_back(StringType (s, first, i - first));
79 while (i+1 < slen && s[i+1] == c)
85 result.
push_back(StringType (s, first, i - first));
89 template <
typename intType>
94 step1 (tchar * & it, intType & value)
101 const OFBool isUnsigned = (OFstatic_cast(intType, -1) < 0) ? OFFalse : OFTrue;
104 const intType halfMaxSigned = OFstatic_cast(intType, 1) << (
sizeof(intType) * 8 - 2);
107 const intType maxSigned = halfMaxSigned - 1 + halfMaxSigned;
110 const intType minSigned = OFstatic_cast(intType, -1) - maxSigned;
113 const intType minVal = isUnsigned ? 0 : minSigned;
118 intType
const r = value / 10;
119 intType
const a = (0-r) * 10;
120 intType
const mod = 0-(a + value);
123 *(it - 1) = OFstatic_cast(tchar, LOG4CPLUS_TEXT(
'0') + mod);
132 template<
class intType>
135 convertIntegerToString (
tstring & str, intType value)
138 str = LOG4CPLUS_TEXT(
"0");
141 bool const negative = !(value > 0 || value == 0);
143 const size_t buffer_size = 30;
145 tchar buffer[buffer_size];
146 tchar * it = &buffer[buffer_size];
147 tchar
const *
const buf_end = it;
152 for (; value != 0; --it)
154 intType mod = value % 10;
156 *(it - 1) = OFstatic_cast(tchar, LOG4CPLUS_TEXT(
'0') + mod);
162 *it = LOG4CPLUS_TEXT(
'-');
165 str.
assign (OFstatic_cast(tchar
const *, it), buf_end - it);
169 template<
class intType>
172 convertIntegerToString (intType value)
175 convertIntegerToString (result, value);
183 #endif // LOG4CPLUS_HELPERS_STRINGHELPER_HEADER_