MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / loadFromFile

Method loadFromFile

src/common/Language.cpp:47–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45/* public: */
46
47unsigned int Language::loadFromFile(std::string filename, bool verbose) {
48 unsigned int totalAdded = 0;
49 char buffer[2048];
50 std::istream* stream = FILEMGR.createDataInStream(filename);
51 if (stream == NULL) {
52 if (verbose) {
53 std::cerr << "Warning: '" << filename << "' language file not found" << std::endl;
54 }
55 return 0;
56 }
57 std::cout << "loading from " << filename << std::endl;
58 while (!stream->eof()) {
59 stream->getline(buffer, 2048);
60 std::string languageLine = buffer;
61
62 int position = languageLine.find_first_not_of("\r\n\t ");
63
64 // trim leading whitespace
65 if (position > 0) {
66 languageLine = languageLine.substr(position);
67 }
68
69 position = languageLine.find_first_of("#\r\n");
70
71 // trim trailing comments
72 if ((position >= 0) && (position < (int)languageLine.length())) {
73 languageLine = languageLine.substr(0, position);
74 }
75
76 position = languageLine.find_last_not_of("\r\n\t ");
77 position += 1;
78
79 // trim trailing whitespace
80 if ((position >= 0) && (position < (int)languageLine.length())) {
81 languageLine = languageLine.substr(0, position);
82 }
83
84 // make sure there is something left to add
85 if (languageLine.length() == 0) {
86 continue;
87 }
88
89 if (verbose) {
90 std::cout << ".";
91 }
92
93 // parse out the keywords
94 int num = -1;
95 std::string iso2 = "";
96 std::string iso3 = "";
97 std::string english = "";
98 std::string french = "";
99
100 // need at least the number and the iso2
101 if ((num == -1) || (iso2.length() == 0)) {
102 continue;
103 }
104

Callers 3

setupBadWordFilterFunction · 0.45
initClientFunction · 0.45
mainFunction · 0.45

Calls 3

LanguageClass · 0.85
createDataInStreamMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected