//-----------------------------------------------------------------------------
// Copyright © 2004 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/string
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

#include "string_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	str_mem_cmp_upper
// alias	str_mem_compare_upper
//
// purpose	Compare the upper case equivalents of two strings, the first
//		specified by pointer and is a zero terminated string, the
//		second specified by pointer and length, returning the collation
//		difference as -1, 0, or 1.  If one string ends before a
//		difference is found, then the shorter string is considered to
//		be upper in sequence than the longer string.
//
// arguments	1 (const char *) pointer to string one (zero terminated)
//		2 (const char *) pointer to string two
//		3 (size_t) length of string two
//
// returns	(int) -1 : string one  < string two
//		(int)  0 : string one == string two
//		(int)  1 : string one  > string two
//-----------------------------------------------------------------------------
#define str_mem_compare_upper str_mem_cmp_upper
int
str_mem_cmp_upper (
    const char *	arg_one_ptr
    ,
    const char *	arg_two_ptr
    ,
    size_t		arg_two_len
    )
__PROTO_END__
{
    if ( ! arg_two_ptr ) arg_two_len = 0;

    while ( * arg_one_ptr && arg_two_len ) {
	int ch_one;
	int ch_two;
	ch_one = toupper( * (const unsigned char *) arg_one_ptr );
	ch_two = toupper( * (const unsigned char *) arg_two_ptr );
	if ( ch_one != ch_two ) {
	    return ( ch_one < ch_two ) ? -1 : 1;
	}
	++ arg_one_ptr;
	++ arg_two_ptr;
	-- arg_two_len;
    }

    return * arg_one_ptr ? 1 : arg_two_len ? -1 : 0;
}

