titlize.cpp 729 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <iostream>
  2. #include <iterator>
  3. #include <cctype>
  4. using namespace std;
  5. int main(int argc, char**)
  6. {
  7. if(argc > 1) // yaa, got bitten passing args instead of piping
  8. std::cerr << "warning: too many arguments for titlize" << '\n';
  9. cin >> noskipws;
  10. istream_iterator<unsigned char> in(cin);
  11. ostream_iterator<unsigned char> out(cout);
  12. *out++ = toupper(*in++);
  13. bool just_skipped_space = false;
  14. for(; in != istream_iterator<unsigned char>(); ++in, ++out)
  15. {
  16. if(*in == '.')
  17. break;
  18. if(*in == '_' || isspace(*in))
  19. {
  20. just_skipped_space = true;
  21. continue;
  22. }
  23. if(just_skipped_space)
  24. {
  25. *out++ = ' ';
  26. *out = toupper(*in);
  27. just_skipped_space = false;
  28. }
  29. else
  30. *out = *in;
  31. }
  32. return 0;
  33. }