MCPcopy Create free account
hub / github.com/ddnet/ddnet / FindString

Method FindString

src/game/localization.cpp:248–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246}
247
248const char *CLocalizationDatabase::FindString(unsigned Hash, unsigned ContextHash) const
249{
250 CString String;
251 String.m_Hash = Hash;
252 String.m_ContextHash = ContextHash;
253 String.m_pReplacement = nullptr;
254 auto Range1 = std::equal_range(m_vStrings.begin(), m_vStrings.end(), String);
255 if(std::distance(Range1.first, Range1.second) == 1)
256 return Range1.first->m_pReplacement;
257
258 const unsigned DefaultHash = str_quickhash("");
259 if(ContextHash != DefaultHash)
260 {
261 // Do another lookup with the default context hash
262 String.m_ContextHash = DefaultHash;
263 auto Range2 = std::equal_range(m_vStrings.begin(), m_vStrings.end(), String);
264 if(std::distance(Range2.first, Range2.second) == 1)
265 return Range2.first->m_pReplacement;
266 }
267
268 return nullptr;
269}
270
271CLocalizationDatabase g_Localization;

Callers 1

LocalizeFunction · 0.80

Calls 4

distanceFunction · 0.85
str_quickhashFunction · 0.85
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected