/* * Copyright (c) 2002 by Cliff Green. All rights reserved. Individual files * may be covered by other copyrights (as noted in the file itself). * * Redistribution and use in source and binary forms are permitted * provided that this entire copyright notice is duplicated in all such * copies. * * This software is provided "as is" and without any expressed or implied * warranties, including, without limitation, the implied warranties of * merchantibility and fitness for any particular purpose. */ //---------------------------------------------------------------------- // Source file: parse.cpp // Written by: Cliff Green, 2002 // Compiler: Metrowerks CodeWarrior Pro 6, g++ 3.0.4 // History: // Modified: Mar. 5, 2002 // By: Cliff Green // Comments: Parsing function implementation file. //---------------------------------------------------------------------- // This commentheader supports documentation tools such as Doc++ and // Doxygen: http://www.doxygen.org/ //---------------------------------------------------------------------- /// Parsing function implementation. See header for more comments. /** * Fill inputStr from input stream (input file stream handling will go to * first whitespace char, and the resulting string might contain non-alpha * characters), then create Word, add Word to vector unless the Word is * empty (e.g. if there's only non-alphas in the string). */ #include "parse.h" #include "word.h" #include #include #include WordVec parseFile (char const* fileName) { std::ifstream inFile(fileName); WordVec vec; if (!inFile) { // problem opening file, return empty vec return vec; } std::string inputStr; while (inFile >> inputStr) { // will be false for EOF or other file problem Word wd(inputStr.c_str()); if (wd.getLength() > 0) { vec.push_back(wd); // add to container } } return vec; }