示例#1
0
void
nImO::Array::printToStringBuffer
    (nImO::StringBuffer &   outBuffer,
     const bool             squished)
    const
{
    ODL_OBJENTER(); //####
    ODL_P1("outBuffer = ", &outBuffer); //####
    ODL_B1("squished = ", squished); //####
    bool    first = true;

    outBuffer.addChar(kStartArrayChar);
    for (const_iterator walker(inherited2::begin()); inherited2::end() != walker; ++walker)
    {
        SpValue aValue(*walker);

        if (nullptr != aValue)
        {
            if ((! squished) || (! first))
            {
                outBuffer.addChar(' ');
            }
            aValue->printToStringBuffer(outBuffer, squished);
            first = false;
        }
    }
    if (! squished)
    {
        outBuffer.addChar(' ');
    }
    outBuffer.addChar(kEndArrayChar);
    ODL_OBJEXIT(); //####
} // nImO::Array::printToStringBuffer
示例#2
0
文件: domnode.cpp 项目: z4y4/njord
JSBool setAttribute(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	JS_BeginRequest(cx);
	nsCOMPtr<nsIDOMNode> mNode = (nsIDOMNode*)JS_GetPrivate(cx, obj);
	nsCOMPtr<nsIDOMElement> mElement = do_QueryInterface(mNode);
	if(mElement == NULL)
	{
		*rval = JSVAL_FALSE;
		JS_EndRequest(cx);
		return JS_TRUE;
	}
	LPWSTR name, value;
	if(!JS_ConvertArguments(cx, argc, argv, "W W", &name, &value))
	{
		JS_ReportError(cx, "Error parsing arguments in set attribute");
		JS_EndRequest(cx);
		return JS_FALSE;
	}
	JS_EndRequest(cx);

	nsDependentString aName(name), aValue(value);
	EnterCriticalSection(&domStateLock);
	domState = 1;
	mElement->SetAttribute(aName, aValue);
	LeaveCriticalSection(&domStateLock);
	return JS_TRUE;
}
示例#3
0
bool
nImO::Array::equalTo
    (const nImO::Value &    other,
     bool &                 validComparison)
    const
{
    ODL_OBJENTER(); //####
    ODL_P2("other = ", &other, "validComparison = ", &validComparison); //####
    bool    result = (inherited2::begin() != inherited2::end());

    validComparison = result;
    ODL_B1("validComparison <- ", validComparison); //####
    // Note that all the values must be validated.
    for (const_iterator walker(inherited2::begin()); validComparison && (inherited2::end() != walker); ++walker)
    {
        SpValue aValue(*walker);

        if (aValue)
        {
            result &= aValue->equalTo(other, validComparison);
        }
    }
    ODL_OBJEXIT_I(result); //####
    return result;
} // nImO::Array::equalTo
示例#4
0
// static
nsresult
KeyPath::Parse(JSContext* aCx, const JS::Value& aValue_, KeyPath* aKeyPath)
{
    JS::Rooted<JS::Value> aValue(aCx, aValue_);
    KeyPath keyPath(0);

    aKeyPath->SetType(NONEXISTENT);

    // See if this is a JS array.
    if (JS_IsArrayObject(aCx, aValue)) {

        JS::Rooted<JSObject*> obj(aCx, aValue.toObjectOrNull());

        uint32_t length;
        if (!JS_GetArrayLength(aCx, obj, &length)) {
            return NS_ERROR_FAILURE;
        }

        if (!length) {
            return NS_ERROR_FAILURE;
        }

        keyPath.SetType(ARRAY);

        for (uint32_t index = 0; index < length; index++) {
            JS::Rooted<JS::Value> val(aCx);
            JSString* jsstr;
            nsAutoJSString str;
            if (!JS_GetElement(aCx, obj, index, &val) ||
                    !(jsstr = JS::ToString(aCx, val)) ||
                    !str.init(aCx, jsstr)) {
                return NS_ERROR_FAILURE;
            }

            if (!keyPath.AppendStringWithValidation(aCx, str)) {
                return NS_ERROR_FAILURE;
            }
        }
    }
    // Otherwise convert it to a string.
    else if (!aValue.isNull() && !aValue.isUndefined()) {
        JSString* jsstr;
        nsAutoJSString str;
        if (!(jsstr = JS::ToString(aCx, aValue)) ||
                !str.init(aCx, jsstr)) {
            return NS_ERROR_FAILURE;
        }

        keyPath.SetType(STRING);

        if (!keyPath.AppendStringWithValidation(aCx, str)) {
            return NS_ERROR_FAILURE;
        }
    }

    *aKeyPath = keyPath;
    return NS_OK;
}
DWORD CRegKey::QueryValue(LPCWSTR lpszValueName,LPWSTR lpStr,DWORD cbData) const
{
	if (IsUnicodeSystem())
	{
		cbData*=2;
		DWORD dwType;
		DWORD dwDataLen=cbData;
		if (::RegQueryValueExW(m_hKey,(LPWSTR)lpszValueName,NULL,&dwType,(LPBYTE)lpStr,&dwDataLen)!=ERROR_SUCCESS)
			return 0;
		if (dwType==REG_MULTI_SZ)
		{
			if (dwDataLen+sizeof(WCHAR)<=cbData)
			{
				lpStr[dwDataLen/2]='\0';
				return dwDataLen/2;
			}
			return dwDataLen/2-1;			
		}
		if (dwType!=REG_SZ && dwType!=REG_EXPAND_SZ && REG_MULTI_SZ)
			return 0;
		return dwDataLen/2-1;
	}
	else
	{
		W2A aValue(lpszValueName);

		DWORD dwType,dwDataLen;
		if (::RegQueryValueExA(m_hKey,aValue,NULL,&dwType,NULL,&dwDataLen)!=ERROR_SUCCESS)
			return 0;
		
		if (lpStr==NULL)
			return dwDataLen;

		switch (dwType)
		{
		case REG_SZ:
		case REG_EXPAND_SZ:
			{
				char* pDataA=new char[dwDataLen+1];
				
				if (::RegQueryValueExA(m_hKey,aValue,NULL,NULL,(LPBYTE)pDataA,&dwDataLen)!=ERROR_SUCCESS)
				{
					delete[] pDataA;
					return 0;
				}
					
				MultiByteToWideChar(CP_ACP,0,pDataA,dwDataLen,lpStr,cbData);
				if (cbData<dwDataLen)
					lpStr[cbData-1]=L'\0';
				delete[] pDataA;
				return min(cbData,dwDataLen);
			}
		case REG_MULTI_SZ:
			{
				char* pDataA=new char[dwDataLen+1];
				LONG lRet=::RegQueryValueExA(m_hKey,aValue,NULL,NULL,(LPBYTE)pDataA,&dwDataLen);
				if (lRet!=ERROR_SUCCESS)
				{
					delete[] pDataA;
					return lRet;
				}

				if (!MultiByteToWideChar(CP_ACP,0,pDataA,dwDataLen,lpStr,cbData))
					return 0;

				delete[] pDataA;
				if (dwDataLen+1<=cbData)
				{
					lpStr[dwDataLen]='\0';
					return dwDataLen;
				}
				return dwDataLen-1;				
			}
		default:
			return FALSE;
		}
	}
}
示例#6
0
void
nImO::Array::writeToMessage
    (nImO::Message &    outMessage)
    const
{
    ODL_ENTER(); //####
    ODL_P1("outMessage = ", &outMessage); //####
    if (0 < inherited2::size())
    {
        ODL_LOG("(0 < inherited2::size())"); //####
        DataKind           startArray = (DataKind::Other | DataKind::OtherContainerStart |
                                         DataKind::OtherContainerTypeArray |
                                         DataKind::OtherContainerNonEmptyValue);
        DataKind           endArray = (DataKind::Other | DataKind::OtherContainerEnd |
                                       DataKind::OtherContainerTypeArray |
                                       DataKind::OtherContainerNonEmptyValue);
        std::queue<double> doublesSeen;

        outMessage.appendBytes(&startArray, sizeof(startArray));
        writeInt64ToMessage(outMessage, static_cast<int>(inherited2::size()) + DataKindIntegerShortValueMinValue - 1);
        for (const_iterator walker(inherited2::begin()); inherited2::end() != walker; ++walker)
        {
            SpValue aValue(*walker);

            if (aValue)
            {
                // Check for sequences of Double values
                const Double *  doubleValue = aValue->asDouble();

                if (nullptr == doubleValue)
                {
                    Double::writeValuesToMessage(doublesSeen, outMessage);
                    aValue->writeToMessage(outMessage);
                }
                else
                {
                    doublesSeen.push(doubleValue->getDoubleValue());
                }
            }
        }
        // Write out any held Double values
        Double::writeValuesToMessage(doublesSeen, outMessage);
        outMessage.appendBytes(&endArray, sizeof(endArray));
    }
    else
    {
        ODL_LOG("! (0 < inherited2::size())"); //####
        static const DataKind   stuff[] =
        {
            (DataKind::Other | DataKind::OtherContainerStart |
             DataKind::OtherContainerTypeArray |
             DataKind::OtherContainerEmptyValue),
            (DataKind::Other | DataKind::OtherContainerEnd |
             DataKind::OtherContainerTypeArray |
             DataKind::OtherContainerEmptyValue)
        };

        outMessage.appendBytes(stuff, sizeof(stuff));
    }
    ODL_EXIT(); //####
} // nImO::Array::writeToMessage
示例#7
0
nImO::SpValue
nImO::Array::extractValue
    (const nImO::Message &  theMessage,
     const int              leadByte,
     size_t &               position,
     nImO::SpArray          parentValue)
{
    ODL_ENTER(); //####
    ODL_P3("theMessage = ", &theMessage, "position = ", &position, "parentValue = ", //####
           parentValue.get()); //####
    ODL_X1("leadByte = ", leadByte); //####
    SpValue result;
    bool    atEnd;
    bool    isEmpty = (DataKind::OtherContainerEmptyValue == (DataKind::OtherContainerEmptyMask & leadByte));
    int     aByte;

    ++position; // We will always accept the lead byte
    ODL_I1("position <- ", position); //####
    if (isEmpty)
    {
        ODL_LOG("(isEmpty)"); //####
        aByte = theMessage.getByte(position, atEnd);
        ODL_X1("aByte <- ", aByte); //####
        ODL_B1("atEnd <- ", atEnd); //####
        if (! atEnd)
        {
            ODL_LOG("(! atEnd)"); //####
            static const DataKind   endMarker = (DataKind::Other | DataKind::OtherContainerEnd |
                                                 DataKind::OtherContainerTypeArray | DataKind::OtherContainerEmptyValue);

            if (toUType(endMarker) == aByte)
            {
                ODL_LOG("(endMarker == aByte)"); //####
                result.reset(new Array);
                ++position;
                ODL_I1("position <- ", position); //####
            }
            else
            {
                ODL_LOG("! (endMarker == aByte)"); //####
                result.reset(new Invalid("Empty Array with incorrect end tag @", position));
            }
        }
    }
    else
    {
        ODL_LOG("! (isEmpty)"); //####
        aByte = theMessage.getByte(position, atEnd);
        ODL_X1("aByte <- ", aByte); //####
        ODL_B1("atEnd <- ", atEnd); //####
        if (! atEnd)
        {
            ODL_LOG("(! atEnd)"); //####
            IntStatus numStatus;
            int64_t   elementCount = extractInt64FromMessage(theMessage, aByte, position, numStatus);

            if (IntStatus::Successful == numStatus)
            {
                ODL_LOG("(IntStatus::Successful == status)"); //####
                elementCount -= DataKindIntegerShortValueMinValue - 1;
                ODL_I1("elementCount <- ", elementCount); //####
                if (0 >= elementCount)
                {
                    ODL_LOG("(0 >= elementCount)"); //####
                    result.reset(new Invalid("Array with zero or negative count @", position));
                }
                else
                {
                    auto    anArray = std::make_shared<Array>();

                    result = anArray;
                    if (nullptr == result)
                    {
                        ODL_LOG("(nullptr == result)"); //####
                        result.reset(new Invalid("Could not allocate an Array"));
                    }
                    else
                    {
                        bool    okSoFar = true;

                        for ( ; okSoFar && (elementCount > static_cast<int64_t>(anArray->size())); )
                        {
                            aByte = theMessage.getByte(position, atEnd);
                            ODL_X1("aByte <- ", aByte); //####
                            ODL_B1("atEnd <- ", atEnd); //####
                            if (atEnd)
                            {
                                ODL_LOG("(atEnd)"); //####
                                result.reset();
                                okSoFar = false;
                            }
                            else
                            {
                                SpValue aValue(getValueFromMessage(theMessage, position, aByte, anArray));

                                // Note that it is the responsibility of the extractor to add to
                                // this Array, so it's not correct for this loop to perform an
                                // append operation.
                                if (nullptr == aValue)
                                {
                                    ODL_LOG("(nullptr == aValue)"); //####
                                    result.reset(new Invalid("Null Value read @", position));
                                    okSoFar = false;
                                }
                                else if (aValue->asFlaw())
                                {
                                    ODL_LOG("(aValue->asFlaw())"); //####
                                    result = aValue;
                                    okSoFar = false;
                                }
                            }
                        }
                        if (okSoFar)
                        {
                            aByte = theMessage.getByte(position, atEnd);
                            ODL_X1("aByte <- ", aByte); //####
                            ODL_B1("atEnd <- ", atEnd); //####
                            if (atEnd)
                            {
                                ODL_LOG("(atEnd)"); //####
                                result.reset();
                                okSoFar = false;
                            }
                            else
                            {
                                ODL_LOG("! (atEnd)"); //####
                                static const DataKind endMarker = (DataKind::Other | DataKind::OtherContainerEnd |
                                                                   DataKind::OtherContainerTypeArray |
                                                                   DataKind::OtherContainerNonEmptyValue);

                                if (toUType(endMarker) == aByte)
                                {
                                    ODL_LOG("(toUType(endMarker) == aByte)"); //####
                                    ++position;
                                    ODL_I1("position <- ", position); //####
                                }
                                else
                                {
                                    ODL_LOG("! (toUType(endMarker) == aByte)"); //####
                                    result.reset(new Invalid("Non-empty Array with incorrect end "
                                                             "tag @", position));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                ODL_LOG("! (IntStatus::Successful == numStatus)"); //####
            }
        }
    }
    if ((nullptr != parentValue) && (nullptr != result) && (! result->asFlaw()))
    {
        ODL_LOG("((nullptr != parentValue) && (nullptr != result) && (! result->asFlaw()))"); //####
        parentValue->addValue(result);
    }
    ODL_EXIT_P(result.get()); //####
    return result;
} // nImO::Array::extractValue