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

Method loadFromFile

src/common/WordFilter.cpp:717–792  ·  view source on GitHub ↗

loads a set of bad words from a specified file */

Source from the content-addressed store, hash-verified

715
716/** loads a set of bad words from a specified file */
717unsigned int WordFilter::loadFromFile(const std::string& fileName, bool verbose) {
718 char buffer[2048];
719 unsigned int totalAdded = 0;
720 std::ifstream filterStream(fileName.c_str());
721
722 if (!filterStream) {
723 if (verbose) {
724 std::cerr << "Warning: '" << fileName << "' bad word filter file not found" << std::endl;
725 }
726 return 0;
727 }
728
729 while (filterStream.good()) {
730 filterStream.getline(buffer, 2048);
731
732 std::string filterWord = buffer;
733
734 int position = filterWord.find_first_not_of("\r\n\t ");
735
736 // trim leading whitespace
737 if (position > 0) {
738 filterWord = filterWord.substr(position);
739 }
740
741 position = filterWord.find_first_of("#\r\n");
742
743 // trim trailing comments
744 if ((position >= 0) && (position < (int)filterWord.length())) {
745 filterWord = filterWord.substr(0, position);
746 }
747
748 position = filterWord.find_last_not_of(" \t\n\r");
749 // first whitespace is at next character position
750 position += 1;
751
752 // trim trailing whitespace
753 if ((position >= 0) && (position < (int)filterWord.length())) {
754 filterWord = filterWord.substr(0, position);
755 }
756
757 /* make sure the word isn't empty (e.g. comment lines) */
758 if (filterWord.length() == 0) {
759 continue;
760 }
761
762 /*
763 std::cout << "[[[" << filterWord << "]]]" << std::endl;
764 */
765
766 if (verbose) {
767 static int counter = 0;
768 if (counter-- <= 0) {
769 std::cout << ".";
770 std::cout.flush();
771 counter = 100;
772 }
773 }
774

Callers

nothing calls this directly

Calls 5

c_strMethod · 0.80
lengthMethod · 0.45
flushMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected