To uppercase & lowercase C/C++ functions for all ANSI characters
[Western European languages (codepage = 1252)]

/*
**	Copyright (c) Leigh Brasington 2013.  All rights reserved.
**	This code may be used and reproduced without written permission.
**
**	To uppercase and lowercase functions for ANSI - language agnostic
**
**	Keywords: unicode toupper tolower C/C++
*/

int
toupperANSI(int c)
{
	if (c < 0x8A)
		return toupper(c);
	if (c >= 0xe0 && c <= 0xfe && c != 0xf7)
		return (c - 0x20);	// between à && þ && not ÷
	switch(c)
	{
		case 0x9A:			// š
		case 0x9C:			// œ
		case 0x9E:			// ž
			return (c - 0x10);
		case 0xFF:			// ÿ
			return 0x9F;		// Ÿ
	}
	return c;
}

int
tolowerANSI(int c)
{
	if (c < 0x8A)
		return tolower(c);
	if (c >= 0xC0 && c <= 0xDE && c != 0xD7)
		return (c + 0x20);	// between À && Þ && not ×

	switch(c)
	{
		case 0x8A:			// Š
		case 0x8C:			// Œ
		case 0x8E:			// Ž
			return (c + 0x10);
		case 0x9F:			// Ÿ
			return 0xFF;		// ÿ
	}
	return c;
}

void
convertCase(char *p, int lgth, int type) // type: 0=lower, 1=upper, 2=title
{
	BOOL	bToUpper = type;

	if (!lgth)
		 lgth = strlen(p);
	p--;
	while (*++p && lgth--)
	{
		if (*p <= ' ')
		{
			if (type == 2)
				bToUpper = TRUE;
			continue;
		}
		*p = bToUpper ? toupperANSI(*p) : tolowerANSI(*p);
		if (type == 2)
			bToUpper = isspace(*p) ? TRUE : FALSE;
	}
}


Leigh Brasington's Freeware
Back to Leigh's Home Page Site Map                   Site Search 


Permalink http://leighb.com/toansiupper.htm [] Hosted by
Leigh Brasington / / Revised 24 May 13