static*/
| 129 | |
| 130 | /*static*/ |
| 131 | std::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*/ |
| 183 | wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::string& nbs) |