Leaked source code of windows server 2003
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
/*
* macunicode.cpp
* MSUAM
*
* Created by mconrad on Fri Nov 16 2001.
* Copyright (c) 2001 Microsoft Corp. All rights reserved.
*
*/
#include "macunicode.h"
// ---------------------------------------------------------------------------
// � MacSspCStringToUnicode()
// ---------------------------------------------------------------------------
// Convert a c-string (null terminated mbcs) into a unicode string.
//
OSStatus
MacSspCStringToUnicode(
IN PCSTR cString,
OUT UInt16* unicodeLen,
OUT UniCharArrayPtr* unicodeString
)
{
UnicodeMapping unicodeMapping;
TextToUnicodeInfo textInfo;
OSStatus Status = noErr;
ByteCount unicodeBufferSize = CALC_UNICODE_CSTRING_LENGTH(cString);
ByteCount unicodeActualLen = 0;
UniCharArrayPtr unicodeResult = NULL;
ByteCount actualCharsConverted = 0;
OptionBits controlFlags = 0;
//
//Just in case the caller didn't initialize the return
//parameters, we'll do it for them for safety.
//
*unicodeString = NULL;
*unicodeLen = 0;
//
//Create the test encoding that we'll use to convert Mac
//characters to unicode chars.
//
unicodeMapping.unicodeEncoding = CreateTextEncoding(
kTextEncodingUnicodeV2_0,
kUnicodeNoSubset,
kUnicode16BitFormat
);
//
//Call our homegrown routine that will set the proper encoding
//for the current script system.
//
Status = MacSspGetCurrentTextEncoding(&unicodeMapping.otherEncoding);
if (NT_SUCCESS(Status))
{
unicodeMapping.mappingVersion = kUnicodeUseLatestMapping;
Status = CreateTextToUnicodeInfo(&unicodeMapping, &textInfo);
if (NT_SUCCESS(Status))
{
//
//Allocate memory for the unicode string. Note that the buffer
//should be big enough to hold the new unicode string.
//
unicodeResult = (UniCharArrayPtr)NewPtrClear(unicodeBufferSize);
if (unicodeResult != nil)
{
//
//Set the control flags for this conversion.
//
//controlFlags = kUnicodeForceASCIIRangeMask;
Status = ConvertFromTextToUnicode(
textInfo,
strlen(cString),
cString,
controlFlags,
0,
NULL,
NULL,
NULL,
unicodeBufferSize,
&actualCharsConverted,
&unicodeActualLen,
unicodeResult
);
SspDebugPrint((DBUF, "ConvertFromTextToUnicode() returned = %d", Status));
if (NT_SUCCESS(Status))
{
SspDebugPrintHex(unicodeResult, unicodeActualLen);
*unicodeString = unicodeResult;
*unicodeLen = unicodeActualLen;
}
}
else
{
Status = memFullErr;
}
//
//Dispose of the opaque info structure used for the conversion.
//
DisposeTextToUnicodeInfo(&textInfo);
}
}
return(Status);
}
// ---------------------------------------------------------------------------
// � MacSspUnicodeToWindowsCString()
// ---------------------------------------------------------------------------
// Converts a unicode string to a single byte CString using the Windows ASCII
// mapping table.
//
OSStatus
MacSspUnicodeToWindowsCString(
IN UniCharArrayPtr unicodeString,
IN UInt32 unicodeLen,
IN UInt32 cStringBufferLen,
OUT PCHAR cString
)
{
OSStatus Status = noErr;
UnicodeMapping unicodeMapping;
UnicodeToTextInfo textInfo;
ByteCount inputRead = 0;
ByteCount outputLen = 0;
OptionBits options = 0;
unico
|