MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / Lookup

Method Lookup

apps/tools/Tools/commands/StringtableCommand.cpp:391–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389}
390
391int StringtableCommand::Lookup(const std::string& inputPath, const std::string& language, const std::string& key)
392{
393 Table table;
394 if (!ParseCSV(inputPath, table))
395 return 1;
396 int langIdx = -1;
397 std::string langUpper = language;
398 for (auto& c : langUpper)
399 c = (char)toupper((unsigned char)c);
400
401 for (size_t i = 0; i < table.languages.size(); i++)
402 {
403 std::string colUpper = table.languages[i];
404 for (auto& c : colUpper)
405 c = (char)toupper((unsigned char)c);
406 if (colUpper == langUpper)
407 {
408 langIdx = static_cast<int>(i);
409 break;
410 }
411 }
412
413 if (langIdx < 0)
414 {
415 std::cerr << "Error: language '" << language << "' not found" << std::endl;
416 std::cerr << "Available: ";
417 for (size_t i = 0; i < table.languages.size(); i++)
418 {
419 if (i > 0)
420 std::cerr << ", ";
421 std::cerr << table.languages[i];
422 }
423 std::cerr << std::endl;
424 return 1;
425 }
426 std::string keyUpper = key;
427 for (auto& c : keyUpper)
428 c = (char)toupper((unsigned char)c);
429
430 bool fileIsUtf8 = HasUtf8CsvSuffix(inputPath);
431 Poseidon::Codepage cp =
432 fileIsUtf8 ? Poseidon::Codepage::Utf8 : Poseidon::CodepageForLanguage(table.languages[langIdx].c_str());
433
434 for (const auto& row : table.rows)
435 {
436 std::string rowKeyUpper = row.key;
437 for (auto& c : rowKeyUpper)
438 {
439 c = (char)toupper((unsigned char)c);
440 }
441 if (rowKeyUpper == keyUpper)
442 {
443 if (static_cast<size_t>(langIdx) < row.values.size())
444 {
445 // Transcode to UTF-8 so the output is consistent regardless of source encoding
446 std::cout << Poseidon::TranscodeToUtf8(row.values[langIdx], cp) << std::endl;
447 }
448 return 0;

Callers 3

test_terrain.cppFile · 0.45

Calls 4

CodepageForLanguageFunction · 0.85
TranscodeToUtf8Function · 0.85
sizeMethod · 0.80
HasUtf8CsvSuffixFunction · 0.70

Tested by

no test coverage detected