os/ossrv/genericopenlibs/cstdlib/LCHAR/CASECMP.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Implement case-insensitive comparison using the full folded comparison
sl@0
    15
// functions of E32
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <string.h>
sl@0
    21
sl@0
    22
/**
sl@0
    23
Compares the null-terminated strings left and right and returns an integer 
sl@0
    24
greater than,equal to, or less than zero (0), accordingly as left 
sl@0
    25
is lexicographically greater than,equal to, or less than right after
sl@0
    26
translation of each corresponding character to lowercase.
sl@0
    27
@return an integer greater than, equal to, or less than zero (0),
sl@0
    28
accordingly as the string left is greater than, equal to,
sl@0
    29
or less than the string right.
sl@0
    30
@param left The first string to compare.
sl@0
    31
@param right The second string to compare.
sl@0
    32
*/
sl@0
    33
extern "C" EXPORT_C int strcasecmp (const char *left, const char *right)
sl@0
    34
	{
sl@0
    35
	TPtrC8 Left((const TText8*)left);
sl@0
    36
	TPtrC8 Right((const TText8*)right);
sl@0
    37
	return Left.CompareF(Right);
sl@0
    38
	}
sl@0
    39
sl@0
    40
extern "C" EXPORT_C int strncasecmp (const char *left, const char *right, size_t length)
sl@0
    41
	{
sl@0
    42
	TUint leftlength=strlen(left);
sl@0
    43
	TUint rightlength=strlen(right);
sl@0
    44
	// The length parameter is the maximum amount of the string to be searched,
sl@0
    45
	// so truncate the descriptors appropriately
sl@0
    46
	if (leftlength>length)
sl@0
    47
		leftlength=length;
sl@0
    48
	if (rightlength>length)
sl@0
    49
		rightlength=length;
sl@0
    50
	TPtrC8 Left((const TText8*)left,leftlength);
sl@0
    51
	TPtrC8 Right((const TText8*)right,rightlength);
sl@0
    52
	return Left.CompareF(Right);
sl@0
    53
	}