//------------------------------------------------------------ static void checkTocLink( const char *toc_file_name, hashTable<CC_String,int> &linkTab, hashTable<CC_String,BTCollectable> &nodeTab ) { int flag = 0; char *ToCFileName = strdup ( toc_file_name ); hashTableIterator<CC_String,BTCollectable> nodeit( nodeTab ); while ( ++nodeit ) { CC_String *key = (CC_String *)nodeit.key(); BTCollectable *value = (BTCollectable *)nodeit.value(); if ( !linkTab.contains( key ) ) { flag = 1; const char *file_name = value->filename(); int line_num = value->linenum(); cerr << "(ERROR) Section ID = " << (const char *)*key << endl << " of file = " << file_name << endl << " at line = " << line_num << endl << " does not have a corresponding link with the value = " << (const char *)*key << endl << " from the ToC file = " << ToCFileName << "\n\n"; } } hashTableIterator<CC_String,int> linkit( linkTab ); while ( ++linkit ) { CC_String *link = linkit.key(); int *line_num = linkit.value(); if ( !nodeTab.contains( link ) ) { flag = 1; cerr << "(ERROR) IDREF = " << (const char *)*link << endl << " of ToC file = " << ToCFileName << endl << " at line = " << *line_num << endl << " is pointing to an unavailable node\n\n"; } } delete ToCFileName; if ( flag ) { throw(Unexpected("TOC validation failed\n")); } }
void spell_check(){ int newline, start_index, end_index, line_number = 1; string line, word; while (getline(infile, line)){ newline = line.find_last_not_of("\n"); if (newline != string::npos){ line.erase(newline+1); } start_index = line.find_first_of(valid_chars); while (start_index != string::npos){ end_index = line.find_first_not_of(valid_chars, start_index); word = toLowercase(line.substr(start_index, end_index-start_index)); start_index = line.find_first_of(valid_chars, end_index); if (word.find_first_of(digits) != string::npos){ continue; } else if (word.length() > 20){ outfile << "Long word at line " << line_number << ", starts: " << word.substr(0, 20) << endl; } else if (!dictionary.contains(word)){ outfile << "Unknown word at line " << line_number << ": " << word << endl; } if (end_index == string::npos){ break; } } line_number++; } }
void spellCheck() { string filenameIn, filenameOut, line, word; unsigned int startIndex, stopIndex; cout << "Enter name of input file: "; cin >> filenameIn; ifstream input(filenameIn.c_str()); if (!input) { cerr << "Error: could not open " << filenameIn << endl; exit(1); } cout << "Enter name of output file: "; cin >> filenameOut; ofstream output(filenameOut.c_str()); if (!output) { cerr << "Error: could not open " << filenameOut << endl; exit(1); } unsigned int lineNum = 1; while (getline(input, line)) { line = toLowerCaseSTD(line); int startIndex = line.find_first_of(validCharacters); int stopIndex = line.find_first_not_of(validCharacters, startIndex); while (startIndex != string::npos) { if (stopIndex == string::npos) { stopIndex = line.length(); } word = line.substr(startIndex, stopIndex - startIndex); if (word.length() > 20) { output << "Long word at line " << lineNum << ", starts: " << word.substr(0, 20) << endl; }else if (word.find_first_of(ignoreCharacters) != string::npos){ }else if (!dict.contains(word)){ output << "Unknown word at line " << lineNum << ": "<< word << endl; } if (stopIndex != line.length()) { line = line.substr(stopIndex + 1); } else { break; } startIndex = line.find_first_of(validCharacters); stopIndex = line.find_first_not_of(validCharacters, startIndex); } lineNum++; } input.close(); output.close(); }