os/ossrv/genericopenlibs/openenvcore/libc/src/wcwidth.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Name        : wcwidth.cpp
    15 // Part of     : MRT LIBC
    16 // Contains the source for wcwidth API implementation.
    17 // Version     :
    18 //
    19 
    20 
    21  
    22 #include <e32std.h>
    23 #include <wchar.h>
    24 #include <wctype.h>
    25 
    26 #ifdef __cplusplus
    27 extern "C" {
    28 #endif
    29 
    30 EXPORT_C int
    31 wcwidth(wchar_t wc)
    32 {
    33 	int rVal,result = 0;
    34 	TChar::TCjkWidth rWid;
    35 		
    36 	//check for end of string
    37 	if(wc == L'\0')
    38 	{
    39 		return (result);
    40 	}
    41 	
    42 	//check if the character is printable
    43 	rVal = iswprint((wint_t)wc);
    44 
    45 	//if printable
    46 	if(rVal)
    47 	{
    48 		rWid = (TChar::TCjkWidth)TChar((TUint)wc).GetCjkWidth();
    49 		if(rWid == TChar::ENarrow)
    50 		{
    51 			result = TChar::EHalfWidth;
    52 		}
    53 		if(rWid == TChar::EWide)
    54 		{
    55 			result = TChar::EFullWidth;
    56 		}
    57 	}
    58 	else
    59 	{
    60 		result = -1;//if the character is not printable
    61 	}
    62 	
    63 	return (result);
    64 }
    65 
    66 #ifdef __cplusplus
    67 }
    68 #endif
    69