MCPcopy Create free account
hub / github.com/catboost/catboost / EncodingHintByName

Function EncodingHintByName

library/cpp/charset/codepage.cpp:357–394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

355};
356
357ECharset EncodingHintByName(const char* encname) {
358 if (!encname)
359 return CODES_UNKNOWN; // safety check
360
361 // Common trouble: spurious "charset=" in the encoding name
362 if (!strnicmp(encname, "charset=", 8)) {
363 encname += 8;
364 }
365
366 // Strip everything up to the first alphanumeric, and after the last one
367 while (*encname && !isalnum(*encname))
368 ++encname;
369
370 if (!*encname)
371 return CODES_UNKNOWN;
372
373 const char* lastpos = encname + strlen(encname) - 1;
374 while (lastpos > encname && !isalnum(*lastpos))
375 --lastpos;
376
377 // Do some normalization
378 TString enc(encname, lastpos - encname + 1);
379 enc.to_lower();
380 for (char* p = enc.begin(); p != enc.end(); ++p) {
381 if (*p == ' ' || *p == '=' || *p == '_')
382 *p = '-';
383 }
384
385 NormalizeEncodingPrefixes(enc);
386
387 ECharset hint = CharsetByName(enc.c_str());
388 if (hint != CODES_UNKNOWN)
389 return hint;
390
391 if (Singleton<TEncodingNamesHashSet>()->Has(enc))
392 return CODES_UNSUPPORTED;
393 return CODES_UNKNOWN;
394}

Callers

nothing calls this directly

Calls 7

CharsetByNameFunction · 0.85
to_lowerMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45
HasMethod · 0.45

Tested by

no test coverage detected