示例#1
0
	/// Appends another UTF8 string.
	REMutableString & REMutableString::append(const char * utf8String, 
											  const REUInt32 utf8StringLength)
	{
		const REUInt32 len = REStringUtilsPrivate::actualUTF8StringLength(utf8String, utf8StringLength);
		if (len)
		{
			const REUInt32 thisLen = this->length();
			const REUInt32 newLen = len + thisLen;
			REBuffer * newBuffer = new REBuffer();
			if (newBuffer)
			{
				if (newBuffer->resize(newLen + 1, false))
				{
					char * newData = (char *)newBuffer->buffer();
					if (thisLen > 0)
					{
						memcpy(newData, this->UTF8String(), thisLen);
					}
					memcpy(&newData[thisLen], utf8String, len);
					newData[newLen] = 0;
					_p = REPtr<REBuffer>(newBuffer);
					return (*this);
				}
				delete newBuffer;
			}
		}
		return (*this);
	}
示例#2
0
/// __RE_RECORE_CAN_INITIALIZE_FROM_URL_STRING__
REBOOL REData::initFromURLString(const REString & urlString)
{
	this->clear();
	
#ifdef __RE_RECORE_CAN_INITIALIZE_FROM_URL_STRING__
	REURL url(urlString);
	if (url.IsFileURL()) 
	{
		return this->InitFromPath(url.GetHierarchicalPart());
	}
	else
	{
		REURLRequestObject * request = REURLRequestObject::CreateWithURL(url);
		if (request) 
		{
			REBuffer downlBuff;
			const REBOOL isSended = REURLConnectionObject::SendRequest(request, &downlBuff, NULL);
			request->release();
			if (isSended)
			{
				if (downlBuff.GetSize()) 
				{
					return this->InitFromBuffer(downlBuff);
				}
				return true;
			}
		}
	}
#endif	
	return false;
}
示例#3
0
	void REMutableString::replaceWithLen(const char * charsStringValue, 
										 const char * withCharsStringValue, 
										 const REUInt32 firstLen, 
										 const REUInt32 secondLen)
	{
		if (firstLen) 
		{
			const REUInt32 length = this->length();
			REUInt32 ocurencesCount = 0;
			char * mainString = (char *)_p->buffer();
			while ( (mainString = strstr(mainString, charsStringValue)) ) 
			{
				ocurencesCount++;
				mainString += firstLen;
			}
			
			if (ocurencesCount) 
			{
				const REUInt32 resultLen = (length + (ocurencesCount * secondLen)) - (ocurencesCount * firstLen);
				REBuffer * newBuffer = new REBuffer();
				if (!newBuffer) return;
				if (!newBuffer->resize(resultLen + 1, false)) return;
				
				char * newData = (char *)newBuffer->buffer();
				mainString = (char *)_p->buffer();
				char * srcString = (char *)_p->buffer();
				char * dstString = newData;
				while ( (mainString = strstr(mainString, charsStringValue)) ) 
				{
					while (srcString != mainString) 
					{
						*dstString++ = *srcString++;
					}
					REUByte * addString = (REUByte *)withCharsStringValue;
					REUInt32 addLen = secondLen;
					while (addLen) 
					{
						*dstString++ = *addString++;
						addLen--;
					}
					mainString += firstLen;
					srcString += firstLen;
				}
				while (*srcString) 
				{
					*dstString++ = *srcString++;
				}
				newData[resultLen] = 0;
				_p = REPtr<REBuffer>(newBuffer);
			}
		}
	}
示例#4
0
REBufferNoCopy::REBufferNoCopy(const REBuffer & buffer) : REBuffer()
{
	_allocator = kREAllocatorNULL;

	const void * b = buffer.buffer();
	const RESizeT s = buffer.size();
	if (b && s)
	{
		_buff = const_cast<void *>(b);
		if (_buff)
		{
			_size = s;
		}
	}
}
示例#5
0
/// Constructs data from buffer.
/// buffer will be copyed.
REData::REData(const REBuffer & buffer) : 
	_fileOffset(0)
{
	const REUInt32 s = buffer.size();
	if (s > 0) 
	{
		REPtr<REBuffer> b(new REBuffer(buffer.buffer(), s));
		if (b.isNotEmpty()) 
		{
			if (b->size() == s) 
			{
				_buffer = b;
			}
		}
	}
}
示例#6
0
REBOOL REBufferObject::isEqual(REObject * anotherObject)
{
    if (anotherObject)
    {
        if (REObject::isEqual(anotherObject))
        {
            return true;
        }

        REBuffer * buff = dynamic_cast<REBuffer *>(anotherObject);
        if (buff)
        {
            if (buff->size() == this->size())
            {
                return (memcmp(buff->buffer(), this->buffer(), this->size()) == 0);
            }
        }
    }
    return false;
}