Listing One


#include <set.h>
#include <mstring.h>
#include <algo.h>
#include <ctype.h>


// Return a copy of the string in "standard" form (lowercase, no punctuation)
string standardize( string s ) {
  string::iterator i = remove_if( s.begin(), s.end(), ispunct );
  s.erase( i, s.end() );
  transform( s.begin(), s.end(), s.begin(), tolower );
  return s;
}

// Filter a text file into an alphabetzied list of unique words contained 
// in that file, ignoring case and punctuation.
int main( int argc, char** ) {

  if ( argc != 1 ) throw("usage: lexicon\n");
  
  set< string, less< string > > words;

  transform( istream_iterator< string, ptrdiff_t >( cin ), 
         istream_iterator< string, ptrdiff_t >(),
         inserter( words, words.end() ),
         standardize );

  copy( words.begin(), words.end(), ostream_iterator< string >( cout, "\n" ) );

  return( 0 );
}