コード例 #1
0
ファイル: NUnicodeParser.cpp プロジェクト: refnum/nano
//============================================================================
//		NUnicodeParser::RemoveBOM : Remove a BOM prefix.
//----------------------------------------------------------------------------
void NUnicodeParser::RemoveBOM(NData &theData, NStringEncoding theEncoding) const
{   NStringEncoding		bomEncoding;
    NRange				theBOM;



    // Validate our parameters
    NN_ASSERT(NStringEncoder::IsEncodingUTF(theEncoding));
    NN_UNUSED(theEncoding);



    // Get the state we need
    bomEncoding = GetBOM(theData, theBOM);
    if (!theBOM.IsEmpty())
        theData.RemoveData(theBOM);



    // Validate the encoding
    //
    // Endian-specific BOMs should match the format we expected.
    switch (bomEncoding) {
    case kNStringEncodingInvalid:
        // No BOM
        break;

    case kNStringEncodingUTF8:
        NN_ASSERT(theEncoding == kNStringEncodingUTF8);
        break;

    case kNStringEncodingUTF16BE:
        NN_ASSERT(theEncoding == kNStringEncodingUTF16 || theEncoding == kNStringEncodingUTF16BE);
        break;

    case kNStringEncodingUTF16LE:
        NN_ASSERT(theEncoding == kNStringEncodingUTF16 || theEncoding == kNStringEncodingUTF16LE);
        break;

    case kNStringEncodingUTF32BE:
        NN_ASSERT(theEncoding == kNStringEncodingUTF32 || theEncoding == kNStringEncodingUTF32BE);
        break;

    case kNStringEncodingUTF32LE:
        NN_ASSERT(theEncoding == kNStringEncodingUTF32 || theEncoding == kNStringEncodingUTF32LE);
        break;

    default:
        NN_LOG("Invalid encoding: %d", theEncoding);
        break;
    }
}
コード例 #2
0
ファイル: NMessageServer.cpp プロジェクト: x414e54/nano
//============================================================================
//		NMessageServer::SocketHasConnection : The socket has a connection.
//----------------------------------------------------------------------------
NSocketConnectionFunctor NMessageServer::SocketHasConnection(NSocket *theSocket, NSocket *newSocket)
{	StLock							acquireLock(mLock);
	NSocketConnectionFunctor		theFunctor;



	// Validate our parameters and state
	NN_ASSERT(theSocket == &mSocket);
	
	NN_UNUSED(theSocket);



	// Get the functor
	if (mStatus == kNServerStarted)
		theFunctor = BindSelf(NMessageServer::ServerThread, newSocket);
	
	return(theFunctor);
}