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;
}
}