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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 // Contains the source for the mbrtowc API implementation.
30 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
31 #include "libc_wsd_defs.h"
36 GET_STATIC_VAR_FROM_TLS(mbrtowc_mbs, mbstate_t)
37 #define mbs (*GET_WSD_VAR_NAME(mbrtowc_mbs, s)())
42 //-----------------------------------------------------------------------------
43 //Function Name : size_t mbrtowc(wchar_t *pwc, const char *s, size_t n,
45 //Description :inspects at most n bytes of the multibyte string starting
46 //at s, extracts the next complete multi-byte character, converts it to a wide
47 //character and stores it at *pwc.It updates the shift state *ps.
48 //Return Value : returns the number of bytes parsed from the multi-byte
49 //sequence starting at s, if a non-L'\0' wide character was recognized. It
50 //returns 0, if a Lâ\0â wide character was recognized. It returns (size_t)(-1)
51 //and sets errno to EILSEQ, if an invalid multibyte sequence was encountered.
52 //It returns (size_t)(-2) if it couldn't parse a complete multibyte character,
53 //meaning that n should be increased.
54 //-----------------------------------------------------------------------------
55 EXPORT_C size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
69 //number of chars to convert has a max of MB_CUR_MAX
70 TInt maxlen = (n > MB_CUR_MAX ? MB_CUR_MAX : n);
72 TPtrC8 src((const TUint8*)s, maxlen);
73 //length of 1 as we only want 1 wide character
74 TPtr16 awc((TUint16*)&wide, 1);
76 TInt ret = ConvertToUnicodeFromUtf8(awc, src, ps);
78 //return the number of chars converted which is the max number
79 //- the number not converted unless the character converted
80 //was the wide null character
83 //rval = (L'\0' != wide) ? maxlen - ret : 0;
95 //only assign the return if we have a target
104 return (size_t)(rval);