MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / Convert

Method Convert

src/core/stringutil.cpp:131–180  ·  view source on GitHub ↗

static*/

Source from the content-addressed store, hash-verified

129
130/*static*/
131std::string::const_iterator cStringUtil::Convert(std::string& nbs, const wc16_string& dbs)
132{
133#if IS_AROS
134 nbs.resize(dbs.length());
135 for (int x = 0; x < dbs.length(); ++x)
136 nbs[x] = (unsigned char)dbs[x];
137#else
138 cDebug d("cStringUtil::Convert( char, w16 )");
139
140 ASSERT((void*)nbs.c_str() != (void*)dbs.c_str());
141
142 if (dbs.empty())
143 nbs.erase();
144 else
145 {
146 if (tss_find_in_hash(dbs, nbs))
147 {
148 d.TraceNever(_T("found string in hash table\n"));
149 return nbs.begin();
150 }
151 else
152 {
153 d.TraceNever(_T("didn't find string in hash table\n"));
154 }
155
156 /*
157 d.TraceDebug( _T("converting: \n") );
158 for( int i = 0; i < dbs.size(); i++ )
159 d.TraceDebug( _T("0x%04X\n"), dbs[i] );
160 d.TraceDebug( _T("----\n") );
161 */
162
163 nbs.resize(dbs.size() * MB_CUR_MAX);
164
165 int nWrote = iCodeConverter::GetInstance()->Convert(
166 (char*)nbs.c_str(), nbs.size(), dbs.c_str(), dbs.size()); // c_str() because must be null terminated
167
168 d.TraceDetail(_T("iCodeConverter returned %d\n"), nWrote);
169
170 if (nWrote == -1)
171 throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
172
173 nbs.resize(nWrote);
174
175 tss_insert_in_hash(dbs, nbs);
176 }
177
178#endif
179 return nbs.begin();
180}
181
182/*static*/
183wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::string& nbs)

Callers 2

ConvertAndCompareStringFunction · 0.45
TestDbToMbFunction · 0.45

Calls 12

tss_find_in_hashFunction · 0.85
tss_insert_in_hashFunction · 0.85
wc16_stringClass · 0.85
c_strMethod · 0.80
emptyMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
TraceNeverMethod · 0.60
TraceDetailMethod · 0.60
resizeMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45

Tested by 1

TestDbToMbFunction · 0.36