/* @(#)chr.c 1.4 95/09/16 */

/*
 * Copyright (c) 1994, 1995 by Wayne C. Gramlich.  All rights reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * for any purpose is hereby granted without fee provided that the above
 * copyright notice and this permission are retained.  The author makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

/* LINTLIBRARY */

#include <ctype.h>

#include "chr_extern.h"

/*
 * chr_is_white_space(chr)
 *	This routine will return 1 if {chr} is a whitespace and 0 otherwise.
 */
int
chr_is_white_space(
    Chr chr)
{
    return isspace(chr) ? 1 : 0;
}

/*
 * chr_is_name(chr)
 *	This routine will return 1 if {chr} is an SGML name start character
 *	and 0 otherwise.
 */
int
chr_is_name(
    Chr chr)
{
    return (isalpha(chr) || isdigit(chr) || (chr == '.') ||
      (chr == '_') || (chr == '-')) ? 1 : 0;
}


/*
 * chr_is_name_start(chr)
 *	This routine will return 1 if {chr} is an SGML name start character
 *	and 0 otherwise.
 */
int
chr_is_name_start(
    Chr chr)
{
    return (isalnum(chr) || (chr == '.') || (chr == '_')) ? 1 : 0;
}

/*
 * chr_to_hex_digit(chr)
 *	This routine will return the hex digit corresponding to {chr}.
 */
unsigned
chr_to_hex_digit(
    Chr chr)
{
    switch (chr) {
	case '0':
	    return 0;
	case '1':
	    return 1;
	case '2':
	    return 2;
	case '3':
	    return 3;
	case '4':
	    return 4;
	case '5':
	    return 5;
	case '6':
	    return 6;
	case '7':
	    return 7;
	case '8':
	    return 8;
	case '9':
	    return 9;
	case 'a':
	case 'A':
	    return 10;
	case 'b':
	case 'B':
	    return 11;
	case 'c':
	case 'C':
	    return 12;
	case 'd':
	case 'D':
	    return 13;
	case 'e':
	case 'E':
	    return 14;
	case 'f':
	case 'F':
	    return 15;
    }
    return 0;
}

/*
 * chr_to_upper(chr)
 *	This routine will return an upper case version of {chr}.
 */
Chr
chr_to_upper(
    Chr chr)
{
    return toupper(chr);
}


