// classifyChar3A.cpp
//
// Classifies the characters in an
// entered string of 1 to 15 characters,
// using functions defined in textUtility.cpp
// and declared in header file textUtility.h.
// Outputs to the terminal window.

#include "textUtility.h"    // includes <iostream> and <string>

using namespace std;


/*
 * Displays, to the terminal window, a
 * table classifying the characters in
 * an entered string.
 *
 * The characters are classified as ASCII
 * letters, ASCII digits, ASCII space,
 * ASCII punctuation marks, ASCII control
 * characters, or non-ASCII characters.
 *
 * Global variables:
 *    cin - an istream object for interactive input.
 *           cin is an external variable, declared
 *           in library header file <iostream>.
 *    cout - an ostream object for output to the terminal.
 *           cout is an external variable, declared
 *           in library header file <iostream>.
 */
int main()
{
   cout << "Enter a string between 1 and 15 characters long:>";

   string text;            // to be entered by the user
   getline( cin, text );   // input entire line, including spaces
   cout << endl;

   // Check whether string length is within range:
   if ( text.length() == 0 || text.length() > 15 )  {
      cout << "You entered a string of length "
                 << text.length()
                 << ", should be between 1 and 15." << endl;
      return 1;
   }  // if

   // Print table headings:
   cout << "Position   Character   Classification" << endl;
   cout << "--------   ---------   --------------" << endl << endl;

   // Print table body:
   for ( int i = 0; i < text.length(); i++ )  {

      // Display character's position in string text:
      printRightJustified( i, 5, cout );

      // Display the character itself:
      char x = text[i];   // character at position i in string text
      cout << "          " << x << "        ";

      // Classify the character:
      if ( ! isAscii(x) )
         cout << "non-ASCII character" << endl;
      else if ( isSpace(x) )
         cout << "ASCII space" << endl;
      else if ( isAsciiDigit(x) )
         cout << "ASCII digit" << endl;
      else if ( isAsciiLetter(x) )
         cout << "ASCII letter" << endl;
      else if ( isAsciiControl(x) )
         cout << "ASCII control character" << endl;
      else
         cout << "ASCII punctuation mark" << endl;
   }  // for i

   return 0;
}  // function main