/* $Id: Character,v 1.2 2008/11/28 19:57:34 kiesling Exp $ -*-C-*-*/

/*
  This file is part of ctalk.
  Copyright  2005-2008  Robert Kiesling, ctalk@ctalklang.org.
  Permission is granted to copy this software provided that this copyright
  notice is included in all source code modules.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

/*
 *    Character class.
 */

/*
 *  If you change these definitions, make sure they match the
 *  definitions in the file, "ctalklib."
 */

#ifndef MAXMSG
#define MAXMSG 8192
#endif

#ifndef MAXLABEL
#define MAXLABEL 256
#endif

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE (!(FALSE))
#endif

Magnitude class Character;


#define TRIM_CHAR(c)    (substrcpy (c, c, 1, strlen (c) - 2))
#ifndef TRIM_CHAR_BUF
#define TRIM_CHAR_BUF(s) \
  { \
    while ((s[0] == '\'') && (s[1] != '\0')) \
      substrcpy (s, s, 1, strlen (s) - 2); \
  } \

#endif

/* Character instanceMethod asString (void) { */

/*   char valbuf[MAXLABEL]; */
/*   char *valbuf; */
/*   int val_length; */
/*   OBJECT *self_value, *result_object; */

/*   returnObjectClass String; */

/*   if ((self_value =  */
/*        __ctalkGetInstanceVariable (__ctalk_self_internal (),"value", 0))  */
/*       == NULL) { */
/*     self_value = __ctalk_self_internal (); */
/*   } */
/*   val_length = strlen (self_value -> __o_value); */
/*   valbuf = __xalloc (val_length + 1); */

/*   if ((self is Character) || */
/*       (self is Integer)) { */
/*     sprintf (valbuf, "%c", self value); */
/*   } else { */
/*     sprintf (valbuf, "%s", self value); */
/*   } */

/*   result_object = __ctalkCreateObjectInit ("result", */
/* 					   "String", "Character", */
/* 					   LOCAL_VAR, valbuf); */
/*   __xfree (valbuf); */
/*   return result_object; */
/*   methodReturnString(valbuf) */
/* } */

/*
 *    = (char value)
 *      Set the value of the receiver to the argument.
 *
 *      The asCharacter (class Magnitude) method performs
 *      radix conversions, but this function does that
 *      also, and makes sure the character is lexically
 *      correct.
 *
 *      Note that here the method must create the
 *      resultValue object as a C variable, because
 *      it can't call the set_value method from
 *      within itself.
 *
 *      For another way to make assignments, see
 *      Integer : set_value.
 */

Character instanceMethod = set_value (char __charArg) {

  self addInstanceVariable ("value", __charArg asCharacter value);
  return self;
}

/*
 *    isAlpha (void)
 *    Returns true if the receiver is a character A-Z, a-z.
 */

Character instanceMethod isAlpha (void) {

  OBJECT *self_value, *result;
  char c;
  char buf[MAXMSG];

  returnObjectClass Integer;

  self_value = self;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if (((c >= 'A') && (c <= 'Z')) ||
      ((c >= 'a') && (c <= 'z'))) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *     isDigit (void)
 *     Return true if the receiver is a character 0-9.
 */

Character instanceMethod isDigit (void) {

  OBJECT *self_value, *result;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if ((c >= '0') && (c <= '9')) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *   isAlNum (void)
 *   Return true if the receiver is an alphanumeric character
 *   0-9, A-Z, a-z.
 */

Character instanceMethod isAlNum (void) {

  OBJECT *result, *self_value;

  returnObjectClass Integer;

  self_value = self;

   if ((self isAlpha) || (self isDigit)) {
     result = __ctalkCreateObjectInit ("result", "Integer",
 			 "Magnitude", self_value -> scope, "1");
   } else {
     result = __ctalkCreateObjectInit ("result", "Integer",
  		 "Magnitude", self_value -> scope, "0");
   }

  return result;
}

/*
 *   isASCII (void)
 *   Returns true if the receiver is an ASCII character in the
 *   range 0-127.  NOTE - With 8-bit characters this function
 *   should always return True.  A signed character always has a value
 *   between 0 and 127, according to GCC.
 */


Character instanceMethod isASCII (void) {
  OBJECT *result, *self_value;

  returnObjectClass Integer;

  self_value = self; 

  result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  return result;
}

/*
 *  isBlank (void)
 *  Returns true if the receiver is a space or horizontal 
 *  tab character.
 */

Character instanceMethod isBlank (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if ((c == 32) || (c == 9)) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

Character instanceMethod isCntrl (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if ((c >= 1) || (c <= 26)) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *   isGraph (void)
 *   Returns true if the receiver is any character except space.
 */

Character instanceMethod isGraph (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if (c != 32) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *   isLower (void)
 *   Returns true if the receiver is a lower case character.
 */

Character instanceMethod isLower (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self value;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if ((c >= 'a') && (c <= 'z')) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *   isPrint (void)
 *   Returns true if the receiver is a (barely) printable character.
 */

Character instanceMethod isPrint (void) {
  OBJECT *result, *self_value;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);

  if ((*buf >= ' ') && (*buf <= '' )) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *  isPunct (void)
 *  Returns true if the receiver is a printable ASCII character which is
 *  not alphanumeric.
 */

Character instanceMethod isPunct (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if (((c >= 32) && (c <= 47)) ||   /* ! ... . */
      ((c >= 58) && (c <= 64)) ||   /* : ... @ */
      ((c >= 91) && (c <= 96)) ||   /* [ ... ` */
      ((c >= 123) && (c <= 126))) { /* { ... ~ */
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *   isSpace (void)
 *   Returns true if the receiver is a space, horizontal tab, newline, 
 *   vertical tab, form feed, or carraige return character.
 */

Character instanceMethod isSpace (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self value;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if ((c == 32) ||    /* Space */
      (c == 9) ||     /* Horizontal Tab, \t */
      (c == 10) ||    /* Newline, \n */
      (c == 11) ||    /* Vertical Tab, \v */
      (c == 12) ||    /* Form Feed, \f */
      (c == 13)) {    /* Carraige Return, \r */
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *  isUpper (void)
 *  Returns true if the receiver is an upper case letter.
 */

Character instanceMethod isUpper (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self value;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if ((c >= 'A') && (c <= 'Z')) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *  isXDigit (void)
 *  Returns true if the receiver is a character 0-9, a-z, or A-Z.
 */

Character instanceMethod isXDigit (void) {
  OBJECT *result, *self_value;
  char c;
  char buf[MAXLABEL];

  returnObjectClass Integer;

  self_value = self value;

  strcpy (buf, self_value -> __o_value);
  TRIM_CHAR_BUF(buf);
  sscanf (buf, "%c", &c);

  if (((c >= '0') && (c <= '9')) ||
      ((c >= 'a') && (c <= 'f')) ||
      ((c >= 'A') && (c <= 'F'))) {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "1");
  } else {
    result = __ctalkCreateObjectInit ("result", "Integer",
		 "Magnitude", self_value -> scope, "0");
  }

  return result;
}

/*
 *   toUpper (void)
 *   If the receiver is a lower case letter, returns the upper
 *   case version.
 */

Character instanceMethod toUpper (void) {

  Character new result;

  if (self isAlpha && self isLower) {
    result = self asInteger value & 223;
  } else {
    result = self;
  }
  return result;
}

/*
 *   toLower (void)
 *   If the receiver is an upper case letter, returns the lower
 *   case version.
 */

Character instanceMethod toLower (void) {

  Character new result;

  if (self isAlpha && self isUpper) {
    result = self asInteger ^ 32;
  } else {
    result = self;
  }

  return result;

}

Character instanceMethod getChar (void) {
  OBJECT *result_object;
  char c;
  char buf[MAXMSG];
  c = (char) getchar ();
  if (feof(stdin)) c = EOF;
  sprintf (buf, "%c", c);
  result_object = 
    __ctalkCreateObjectInit ("result", self -> __o_classname,
				self -> __o_superclassname,
				self -> scope, buf);
  return result_object;
}

/*
 *    + (char c)
 *    Add the value of operand, "c," to the receiver.
 */

Character instanceMethod + add (char c) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  op1 = self value;
  op2 = c value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkCharRadixToChar (op2 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);
  TRIM_CHAR_BUF(operand_buf);

  math_result = *rcvr_buf + *operand_buf;

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character addition is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    - (char c)
 *    Subtract the value of operand, "c," to the receiver.
 */

Character instanceMethod - subtract (char c) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  op1 = self value;
  op2 = c value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkCharRadixToChar (op2 -> __o_value));

/*   while (*rcvr_buf == '\'') */
/*     TRIM_CHAR(rcvr_buf); */
/*   while (*operand_buf == '\'') */
/*     TRIM_CHAR(operand_buf); */
  TRIM_CHAR_BUF(rcvr_buf);
  TRIM_CHAR_BUF(operand_buf);

  math_result = *rcvr_buf - *operand_buf;

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character subtraction is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    * (char c)
 *    Multiply the value of operand, "c," to the receiver.
 */

Character instanceMethod * multiply (char c) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  op1 = self value;
  op2 = c value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkCharRadixToChar (op2 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);
  TRIM_CHAR_BUF(operand_buf);

  math_result = *rcvr_buf * *operand_buf;

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character multiplicaation is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    / (char c)
 *    Divide the value of operand, "c," to the receiver.
 */

Character instanceMethod / divide (char c) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  op1 = self value;
  op2 = c value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkCharRadixToChar (op2 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);
  TRIM_CHAR_BUF(operand_buf);

  math_result = *rcvr_buf / *operand_buf;

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character division is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    & (char c)
 *    Perform a bitwise and of operand, "c," to the receiver.
 */

Character instanceMethod & bitwise_and (char c) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  op1 = self value;
  op2 = c value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkCharRadixToChar (op2 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);
  TRIM_CHAR_BUF(operand_buf);

  math_result = *rcvr_buf & *operand_buf;

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character bitwise and is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    bitComp (char c)
 *    Perform a bit complement of the receiver.
 */

Character instanceMethod bitComp (char c) {

  char rcvr_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *result_object;

  op1 = self value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);

  math_result = ~(*rcvr_buf);

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character bit complement is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    | (char c)
 *    Perform a bitwise or of operand, "c," to the receiver.
 */

Character instanceMethod | bitwise_or (char c) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  op1 = self value;
  op2 = c value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkCharRadixToChar (op2 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);
  TRIM_CHAR_BUF(operand_buf);

  math_result = *rcvr_buf | *operand_buf;

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character bitwise or is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    | (char c)
 *    Perform a bitwise and of operand, "c," to the receiver.
 */

Character instanceMethod ^ bitwise_xor (char c) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  op1 = self value;
  op2 = c value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkCharRadixToChar (op2 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);
  TRIM_CHAR_BUF(operand_buf);

  math_result = *rcvr_buf ^ *operand_buf;

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character bitwise xor is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

Character instanceMethod << asl (int i) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  if (!i is Integer) {
    _warning ("Operand of << must be an Integer.\n");
    return NULL;
  }

  op1 = self value;
  op2 = i value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkIntRadixToDecimal (op2 -> __o_value));

/*   while (*rcvr_buf == '\'') */
/*     TRIM_CHAR(rcvr_buf); */
  TRIM_CHAR_BUF(rcvr_buf);

  math_result = *rcvr_buf << atoi (operand_buf);

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character << is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

Character instanceMethod >> asr (int i) {

  char rcvr_buf[MAXMSG], operand_buf[MAXMSG], buf[MAXMSG];
  int math_result;
  OBJECT *op1, *op2, *result_object;

  if (!i is Integer) {
    _warning ("Operand of << must be an Integer.\n");
    return NULL;
  }

  op1 = self value;
  op2 = i value;

  strcpy (rcvr_buf, __ctalkCharRadixToChar (op1 -> __o_value));
  strcpy (operand_buf, __ctalkIntRadixToDecimal (op2 -> __o_value));

  TRIM_CHAR_BUF(rcvr_buf);

  math_result = *rcvr_buf >> atoi (operand_buf);

  if ((math_result < 0) || (math_result > 127))
    _warning ("Result of character << is not an ASCII character.\n");

  sprintf (buf, "\'%c\'", math_result);
  result_object = 
    __ctalkCreateObjectInit ("result", op1 -> __o_classname,
				op1 -> __o_superclassname,
				op1 -> scope, buf);
  return result_object;
}

/*
 *    < (char c)
 *    Return TRUE if the receiver is less than the operand, FALSE
 *    otherwise.
 */

Character instanceMethod < lt (char c) {
  returnObjectClass Boolean;

  if (self asInteger < c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL

}

/*
 *    > (char c)
 *    Return TRUE if the receiver is greater than the operand, FALSE
 *    otherwise.
 */

Character instanceMethod > gt (char c) {

  returnObjectClass Boolean;

  if (self asInteger > c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL
}

/*
 *    <= (char c)
 *    Return TRUE if the receiver is less than or equal to the operand, 
 *    FALSE otherwise.
 */

Character instanceMethod <= le (char c) {
  returnObjectClass Boolean;

  if (self asInteger <= c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL
}

/*
 *    >= (char c)
 *    Return TRUE if the receiver is less than or equal to the operand, 
 *    FALSE otherwise.
 */

Character instanceMethod >= ge (char c) {
  returnObjectClass Boolean;

  if (self asInteger >= c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL
}

/*
 *    || (char c)
 *    Return TRUE if the receiver or the operand are TRUE,
 *    FALSE otherwise.
 */

Character instanceMethod || logicalOr (char c) {

  returnObjectClass Boolean;

  if (self asInteger || c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL
}

/*
 *    invert (char c)
 *    Return TRUE if the receiver evaluates to FALSE, FALSE if
 *    the receiver evaluates to TRUE.
 */

Character instanceMethod invert (char c) {

  returnObjectClass Boolean;

  if (self asInteger) {
    methodReturnFalse
  } else {
    methodReturnTrue
  }

  methodReturnNULL
}

/*
 *    && (char c)
 *    Return TRUE if the receiver and the operand are TRUE,
 *    FALSE otherwise.
 */

Character instanceMethod && logicalAnd (char c) {

  returnObjectClass Boolean;

  if (self asInteger && c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL
}

/*
 *    == (char c)
 *    Return True if the receiver and the argument are equal,
 *    false otherwise.
 */

Character instanceMethod == equality (char c) {
  returnObjectClass Boolean;

  if (self asInteger == c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL
} 

/*
 *    != (char c) 
 *
 *    Return True if the receiver is not equal
 *    to the argument, False otherwise.
 */

Character instanceMethod != inequality (char c) {
  returnObjectClass Boolean;

  if (self asInteger != c asInteger) {
    methodReturnTrue
  } else {
    methodReturnFalse
  }

  methodReturnNULL
} 


