Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

October 19, 2005

Lowercase / Uppercase Conversion in C++

This short article discusses uppercase/lowercase character conversion in C++ paying special attention to Western and Eastern European characters, which are not converted correctly by the toupper and tolower C runtime library functions.

First, here are some code page charts for reference:
Windows-1250
Windows-1252
Iso-8859-1
Iso-8859-2

The toupper and tolower functions do not convert the characters w/diacritics in the range 0xC0-0xFF. You’ll notice that each lowercase character is equal to the uppercase character + 0×20.

Here is some sample code that converts correctly:

<font size=2 face=courier>
    unsigned char *buffer;
    …
    // Convert to uppercase
    int i = 0;
    while (buffer[i])
        {
	if (buffer[i] & 0×80)
	    {
	    unsigned char c = buffer[i];
	    if (c >= 224)
		{
		c -= 32;
		buffer[i] = (char)c;
		}
	    }
	else
	    {
	    buffer[i] = toupper(buffer[i]);
	    }
        i++;
        }
	
    // Convert to lowercase
    int i = 0;
    while (buffer[i])
        {
	if (buffer[i] & 0×80)
	    {
	    unsigned char c = buffer[i];
	    if (c >= 192 && c <= 223)
		{
		c += 32;
		buffer[i] = (char)c;
		}
	    }
	else
	    {
	    buffer[i] = tolower(buffer[i]);
	    }
        i++;
        }
</font>


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.