示例#1
0
void FString::StripLeft (const char *charset)
{
	size_t max = Len(), i, j;
	if (max == 0) return;
	for (i = 0; i < max; ++i)
	{
		if (!strchr (charset, Chars[i]))
			break;
	}
	if (i == 0)
	{ // Nothing to strip.
		return;
	}
	if (Data()->RefCount <= 1)
	{
		for (j = 0; i <= max; ++j, ++i)
		{
			Chars[j] = Chars[i];
		}
		ReallocBuffer (j-1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (max - i);
		StrCopy (Chars, old->Chars() + i, max - i);
		old->Release();
	}
}
示例#2
0
FString &FString::AppendCStrPart (const char *tail, size_t tailLen)
{
	size_t len1 = Len();
	ReallocBuffer (len1 + tailLen);
	StrCopy (Chars + len1, tail, tailLen);
	return *this;
}
示例#3
0
void FString::StripRight (const char *charset)
{
	size_t max = Len(), i;
	if (max == 0) return;
	for (i = --max; i > 0; i--)
	{
		if (!strchr (charset, Chars[i]))
			break;
	}
	if (i == max)
	{ // Nothing to strip.
		return;
	}
	if (Data()->RefCount <= 1)
	{
		Chars[i+1] = '\0';
		ReallocBuffer (i+1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (i+1);
		StrCopy (Chars, old->Chars(), i+1);
		old->Release();
	}
}
示例#4
0
void FString::StripLeftRight ()
{
	size_t max = Len(), i, j, k;
	if (max == 0) return;
	for (i = 0; i < max; ++i)
	{
		if (!isspace((unsigned char)Chars[i]))
			break;
	}
	for (j = max - 1; j >= i; --j)
	{
		if (!isspace((unsigned char)Chars[j]))
			break;
	}
	if (i == 0 && j == max - 1)
	{ // Nothing to strip.
		return;
	}
	if (Data()->RefCount <= 1)
	{
		for (k = 0; i <= j; ++i, ++k)
		{
			Chars[k] = Chars[i];
		}
		Chars[k] = '\0';
		ReallocBuffer (k);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer(j - i + 1);
		StrCopy(Chars, old->Chars(), j - i + 1);
		old->Release();
	}
}
示例#5
0
void FString::StripLeftRight (const char *charset)
{
	size_t max = Len(), i, j, k;
	if (max == 0) return;
	for (i = 0; i < max; ++i)
	{
		if (!strchr (charset, Chars[i]))
			break;
	}
	for (j = max - 1; j >= i; --j)
	{
		if (!strchr (charset, Chars[j]))
			break;
	}
	if (Data()->RefCount <= 1)
	{
		for (k = 0; i <= j; ++i, ++k)
		{
			Chars[k] = Chars[i];
		}
		Chars[k] = '\0';
		ReallocBuffer (k);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (j - i);
		StrCopy (Chars, old->Chars(), j - i);
		old->Release();
	}
}
void OutputMemoryBitStream::WriteBits( uint8_t inData,
									  uint32_t inBitCount )
{
	uint32_t nextBitHead = mBitHead + static_cast< uint32_t >( inBitCount );
	
	if( nextBitHead > mBitCapacity )
	{
		ReallocBuffer( std::max( mBitCapacity * 2, nextBitHead ) );
	}
	
	//calculate the byteOffset into our buffer
	//by dividing the head by 8
	//and the bitOffset by taking the last 3 bits
	uint32_t byteOffset = mBitHead >> 3;
	uint32_t bitOffset = mBitHead & 0x7;
	
	uint8_t currentMask = ~( 0xff << bitOffset );
	mBuffer[ byteOffset ] = ( mBuffer[ byteOffset ] & currentMask ) | ( inData << bitOffset );
	
	//calculate how many bits were not yet used in
	//our target byte in the buffer
	uint32_t bitsFreeThisByte = 8 - bitOffset;
	
	//if we needed more than that, carry to the next byte
	if( bitsFreeThisByte < inBitCount )
	{
		//we need another byte
		mBuffer[ byteOffset + 1 ] = inData >> bitsFreeThisByte;
	}
示例#7
0
void FString::Insert (size_t index, const char *instr, size_t instrlen)
{
	if (instrlen > 0)
	{
		size_t mylen = Len();
		if (index >= mylen)
		{
			AppendCStrPart(instr, instrlen);
		}
		else if (Data()->RefCount <= 1)
		{
			ReallocBuffer(mylen + instrlen);
			memmove(Chars + index + instrlen, Chars + index, (mylen - index + 1) * sizeof(char));
			memcpy(Chars + index, instr, instrlen * sizeof(char));
		}
		else
		{
			FStringData *old = Data();
			AllocBuffer(mylen + instrlen);
			StrCopy(Chars, old->Chars(), index);
			StrCopy(Chars + index, instr, instrlen);
			StrCopy(Chars + index + instrlen, old->Chars() + index, mylen - index);
			old->Release();
		}
	}
}
示例#8
0
void FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen)
{
	LockBuffer();
	for (size_t checkpt = 0; checkpt < Len(); )
	{
		char *match = strstr (Chars + checkpt, oldstr);
		size_t len = Len();
		if (match != NULL)
		{
			size_t matchpt = match - Chars;
			if (oldstrlen != newstrlen)
			{
				ReallocBuffer (len + newstrlen - oldstrlen);
				memmove (Chars + matchpt + newstrlen, Chars + matchpt + oldstrlen, (len + 1 - matchpt - oldstrlen)*sizeof(char));
			}
			memcpy (Chars + matchpt, newstr, newstrlen);
			checkpt = matchpt + newstrlen;
		}
		else
		{
			break;
		}
	}
	UnlockBuffer();
}
// 从缓存区的前面添加字符串
void SuperMapFilterStringBuffer::PrependString(const char *Str)
{
  size_t slen = strlen( Str ); 
  ReallocBuffer( slen + 1, false );
  m_FirstBuffIndex -= slen;
  strncpy(&m_pFilterText[m_FirstBuffIndex], Str, slen );    
}
// 从缓存区的末尾添加字符串
void SuperMapFilterStringBuffer::AppendString(const char *Str)
{
  size_t slen = strlen( Str ); 
  ReallocBuffer( slen + 1, true );
  strcpy( &m_pFilterText[m_NextBuffIndex], Str );
  m_NextBuffIndex += slen;
}
示例#11
0
void FString::Truncate(long newlen)
{
	if (newlen >= 0 && newlen < (long)Len())
	{
		ReallocBuffer (newlen);
		Chars[newlen] = '\0';
	}
}
示例#12
0
void CVersionInfoBuffer::Write(LPVOID lpData, DWORD dwSize)
{
	if (dwSize+m_dwPosition > m_dwBufSize)
		ReallocBuffer(dwSize+m_dwPosition);

	memcpy(m_lpData + m_dwPosition, lpData, dwSize);
	m_dwPosition += dwSize;
}
示例#13
0
FString &FString::operator += (const char *tail)
{
	size_t len1 = Len();
	size_t len2 = strlen(tail);
	ReallocBuffer (len1 + len2);
	StrCopy (Chars + len1, tail, len2);
	return *this;
}
示例#14
0
FString &FString::operator += (char tail)
{
	size_t len1 = Len();
	ReallocBuffer (len1 + 1);
	Chars[len1] = tail;
	Chars[len1+1] = '\0';
	return *this;
}
示例#15
0
void FString::Truncate(long newlen)
{
	if (newlen <= 0)
	{
		Data()->Release();
		NullString.RefCount++;
		Chars = &NullString.Nothing[0];
	}
	else if (newlen < (long)Len())
	{
		ReallocBuffer (newlen);
		Chars[newlen] = '\0';
	}
}
示例#16
0
FString &FString::CopyCStrPart(const char *tail, size_t tailLen)
{
	if (tailLen > 0)
	{
		ReallocBuffer(tailLen);
		StrCopy(Chars, tail, tailLen);
	}
	else
	{
		Data()->Release();
		NullString.RefCount++;
		Chars = &NullString.Nothing[0];
	}
	return *this;
}
示例#17
0
//
// Set
//
BOOL DoubleBuffer::Set(MIDIHDR * pDest, MIDIHDR * pSrc) const
{
    ASSERT(pDest != NULL);
    ASSERT(pSrc != NULL);

    // Do we need to reallocate the buffer
    while (pSrc->dwBufferLength > max(pDest->dwBufferLength, CHUNKSIZE)) {
        if (!ReallocBuffer(pDest))
            return FALSE;
    }

    memcpy(pDest->lpData, pSrc->lpData, pSrc->dwBufferLength);
    pDest->dwBufferLength = pDest->dwBytesRecorded = pSrc->dwBufferLength;

    return TRUE;
}
示例#18
0
void FString::StripChars (char killchar)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; ++read)
	{
		if (Chars[read] != killchar)
		{
			Chars[write++] = Chars[read];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
示例#19
0
void FString::StripChars (const char *killchars)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; ++read)
	{
		if (strchr (killchars, Chars[read]) == NULL)
		{
			Chars[write++] = Chars[read];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
示例#20
0
XnStatus XnSensorAudioStream::SetNumberOfChannels(XnUInt32 nNumberOfChannels)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	nRetVal = m_Helper.BeforeSettingFirmwareParam(NumberOfChannelsProperty(), nNumberOfChannels);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = XnAudioStream::SetNumberOfChannels(nNumberOfChannels);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = ReallocBuffer();
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_Helper.AfterSettingFirmwareParam(NumberOfChannelsProperty());
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
示例#21
0
void FString::StripRight ()
{
	size_t max = Len(), i;
	for (i = max - 1; i-- > 0; )
	{
		if (!isspace(Chars[i]))
			break;
	}
	if (Data()->RefCount <= 1)
	{
		Chars[i+1] = '\0';
		ReallocBuffer (i+1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (i+1);
		StrCopy (Chars, old->Chars(), i+1);
		old->Release();
	}
}
示例#22
0
void FString::StripRight (const char *charset)
{
	size_t max = Len(), i;
	for (i = max; i-- > 0; )
	{
		if (!strchr (charset, Chars[i]))
			break;
	}
	if (Data()->RefCount <= 1)
	{
		Chars[i+1] = '\0';
		ReallocBuffer (i+1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (i+1);
		StrCopy (Chars, old->Chars(), i+1);
		old->Release();
	}
}
示例#23
0
XnStatus XnSensorAudioStream::Init()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// init base
	nRetVal = XnAudioStream::Init();
	XN_IS_STATUS_OK(nRetVal);

	// init helper
	nRetVal = m_Helper.Init(this, this);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnOSCreateCriticalSection(&m_buffer.hLock);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = SetReadChunkSize(XN_AUDIO_STREAM_DEFAULT_CHUNK_SIZE);
	XN_IS_STATUS_OK(nRetVal);

	// add properties
	XN_VALIDATE_ADD_PROPERTIES(this, &m_LeftChannelVolume, &m_RightChannelVolume, &m_ActualRead);

	// check what's the firmware audio packet size
	if (m_Helper.GetPrivateData()->SensorHandle.MiscConnection.bIsISO)
		m_nOrigAudioPacketSize = XN_SENSOR_PROTOCOL_AUDIO_PACKET_SIZE_ISO;
	else
		m_nOrigAudioPacketSize = XN_SENSOR_PROTOCOL_AUDIO_PACKET_SIZE_BULK;

	// alloc buffer
	nRetVal = ReallocBuffer();
	XN_IS_STATUS_OK(nRetVal);

	m_buffer.pAudioCallback = NewDataCallback;
	m_buffer.pAudioCallbackCookie = this;

	// data processor
	nRetVal = m_Helper.RegisterDataProcessorProperty(NumberOfChannelsProperty());
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
示例#24
0
void FString::MergeChars (const char *charset, char newchar)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; )
	{
		if (strchr (charset, Chars[read]) != NULL)
		{
			while (strchr (charset, Chars[++read]) != NULL)
			{
			}
			Chars[write++] = newchar;
		}
		else
		{
			Chars[write++] = Chars[read++];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
示例#25
0
void FString::MergeChars (char merger, char newchar)
{
	size_t read, write, mylen;

	LockBuffer();
	for (read = write = 0, mylen = Len(); read < mylen; )
	{
		if (Chars[read] == merger)
		{
			while (Chars[++read] == merger)
			{
			}
			Chars[write++] = newchar;
		}
		else
		{
			Chars[write++] = Chars[read++];
		}
	}
	Chars[write] = '\0';
	ReallocBuffer (write);
	UnlockBuffer();
}
示例#26
0
void FString::StripLeft ()
{
	size_t max = Len(), i, j;
	for (i = 0; i < max; ++i)
	{
		if (!isspace(Chars[i]))
			break;
	}
	if (Data()->RefCount <= 1)
	{
		for (j = 0; i <= max; ++j, ++i)
		{
			Chars[j] = Chars[i];
		}
		ReallocBuffer (j-1);
	}
	else
	{
		FStringData *old = Data();
		AllocBuffer (max - i);
		StrCopy (Chars, old->Chars() + i, max - i);
		old->Release();
	}
}
示例#27
0
static void ResampleFloat( filter_t *p_filter,
                           block_t **pp_out_buf,  size_t *pi_out,
                           float **pp_in,
                           int i_in, int i_in_end,
                           double d_factor, bool b_factor_old,
                           int i_nb_channels, int i_bytes_per_frame )
{
    filter_sys_t *p_sys = p_filter->p_sys;

    float *p_in = *pp_in;
    size_t i_out = *pi_out;
    float *p_out = (float*)(*pp_out_buf)->p_buffer + i_out * i_nb_channels;

    for( ; i_in < i_in_end; i_in++ )
    {
        if( b_factor_old && d_factor == 1 )
        {
            if( ReallocBuffer( pp_out_buf, &p_out,
                               i_out, i_nb_channels, i_bytes_per_frame ) )
                return;
            /* Just copy the samples */
            memcpy( p_out, p_in, i_bytes_per_frame );
            p_in += i_nb_channels;
            p_out += i_nb_channels;
            i_out++;
            continue;
        }

        while( p_sys->i_remainder < p_filter->fmt_out.audio.i_rate )
        {
            if( ReallocBuffer( pp_out_buf, &p_out,
                               i_out, i_nb_channels, i_bytes_per_frame ) )
                return;

            if( d_factor >= 1 )
            {
                /* FilterFloatUP() is faster if we can use it */

                /* Perform left-wing inner product */
                FilterFloatUP( SMALL_FILTER_FLOAT_IMP, SMALL_FILTER_FLOAT_IMPD,
                               SMALL_FILTER_NWING, p_in, p_out,
                               p_sys->i_remainder,
                               p_filter->fmt_out.audio.i_rate,
                               -1, i_nb_channels );
                /* Perform right-wing inner product */
                FilterFloatUP( SMALL_FILTER_FLOAT_IMP, SMALL_FILTER_FLOAT_IMPD,
                               SMALL_FILTER_NWING, p_in + i_nb_channels, p_out,
                               p_filter->fmt_out.audio.i_rate -
                               p_sys->i_remainder,
                               p_filter->fmt_out.audio.i_rate,
                               1, i_nb_channels );

#if 0
                /* Normalize for unity filter gain */
                for( i = 0; i < i_nb_channels; i++ )
                {
                    *(p_out+i) *= d_old_scale_factor;
                }
#endif
            }
            else
            {
                /* Perform left-wing inner product */
                FilterFloatUD( SMALL_FILTER_FLOAT_IMP, SMALL_FILTER_FLOAT_IMPD,
                               SMALL_FILTER_NWING, p_in, p_out,
                               p_sys->i_remainder,
                               p_filter->fmt_out.audio.i_rate, p_filter->fmt_in.audio.i_rate,
                               -1, i_nb_channels );
                /* Perform right-wing inner product */
                FilterFloatUD( SMALL_FILTER_FLOAT_IMP, SMALL_FILTER_FLOAT_IMPD,
                               SMALL_FILTER_NWING, p_in + i_nb_channels, p_out,
                               p_filter->fmt_out.audio.i_rate -
                               p_sys->i_remainder,
                               p_filter->fmt_out.audio.i_rate, p_filter->fmt_in.audio.i_rate,
                               1, i_nb_channels );
            }

            p_out += i_nb_channels;
            i_out++;

            p_sys->i_remainder += p_filter->fmt_in.audio.i_rate;
        }

        p_in += i_nb_channels;
        p_sys->i_remainder -= p_filter->fmt_out.audio.i_rate;
    }

    *pp_in  = p_in;
    *pi_out = i_out;
}
示例#28
0
//
//	Creates key store report.
//
WINERROR KeyStoreReport(
	PWCHAR*	ppReport,	// receives key report
	PULONG	pLength,	// size of the report in chars
	BOOL	bDelete
	)
{
	WINERROR Status = ERROR_NOT_ENOUGH_MEMORY;
	PKEY_CONTEXT Ctx, NextCtx;
	ULONG	bLen, TotalLen = 1, Index = 0, Length, InitialSize;
	ULONG   LengthClipbrd = 0;
	PWCHAR	Buffer, NewBuffer;
	SYSTEMTIME	DateTime;
	FILETIME	LocalTime;
	PLIST_ENTRY ListEntry;
#if _DEBUG
	HANDLE	PrevKey = 0;
#endif

	InitialSize = MAX_REPORT_BUFFER_SIZE;

	if (Buffer = AppAlloc(InitialSize))
	{
		bLen = MAX_REPORT_BUFFER_SIZE / sizeof(WCHAR);
		Buffer[0] = 0xfeff;	// Unicode file magic
		Buffer[1] = 0;

		bLen -= 1;

		NextCtx = EnumContext(NULL);

		while(Ctx = NextCtx)
		{
#if _DEBUG
			PHANDLE_RECORD pHRec = CONTAINING_RECORD(Ctx, HANDLE_RECORD, Context);
			ASSERT(pHRec->RefCount == 2);
			ASSERT(PrevKey != pHRec->Key);
			PrevKey = pHRec->Key;
#endif
			if (Ctx->bActive)
			{
				FileTimeToLocalFileTime(&Ctx->Time, &LocalTime);
				FileTimeToSystemTime(&LocalTime, &DateTime);

				// Calculating new message length
				Length = cstrlenW(wczReportFormat) + lstrlenW(Ctx->ProcessPath) + lstrlenW(Ctx->WindowText) + Ctx->Count + 1;

				// Checking if there's enough free space within the buffer to fit the message
				if ((bLen >= Length) ||
					// Trying to reallocate the buffer
					((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) &&
					(Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen)))
				{
					Length = wnsprintfW(
						Buffer + TotalLen,
						bLen,
						wczReportFormat,
						DateTime.wDay,
						DateTime.wMonth,
						DateTime.wYear,
						DateTime.wHour,
						DateTime.wMinute,
						DateTime.wSecond,
						(LPWSTR)&Ctx->ProcessPath,
						(LPWSTR)&Ctx->WindowText,
						(LPWSTR)&Ctx->KeyBuffer
						);
					bLen -= Length;
					TotalLen += Length;
				}
			}	// if (Ctx->bActive)

			if (!IsListEmpty(&Ctx->ClipboardChain))
			{
				for ( ListEntry = Ctx->ClipboardChain.Flink;
					ListEntry != &Ctx->ClipboardChain;
					ListEntry = ListEntry->Flink)
				{
					PCLIPBOARD_ENTRY CEntry = CONTAINING_RECORD(ListEntry,CLIPBOARD_ENTRY,qLink);
					Length = cstrlenW(wczFormatClipbrd) + lstrlenA(CEntry->Buffer);

					// Checking if there's enough free space within the buffer to fit the message
					if ((bLen >= Length) ||
						// Trying to reallocate the buffer
						((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) &&
						(Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen)))
					{
						FileTimeToLocalFileTime(&CEntry->Time, &LocalTime);
						FileTimeToSystemTime(&LocalTime, &DateTime);

						Length = wnsprintfW(
							Buffer + TotalLen, 
							bLen,
							wczFormatClipbrd,
							DateTime.wDay,
							DateTime.wMonth,
							DateTime.wYear,
							DateTime.wHour,
							DateTime.wMinute,
							DateTime.wSecond,
							(LPWSTR)CEntry->Buffer
							);
						bLen -= Length;
						TotalLen += Length;
					}
				}
			}	// if (!IsListEmpty(&Ctx->ClipboardChain))

			NextCtx = EnumContext(Ctx);

			if (bDelete)
				ReleaseContext(Ctx);
			else
				Index += 1;

			ReleaseContext(Ctx);
		}	// while(Ctx = NextCtx)

		if (TotalLen > 1)
		{
			*ppReport = Buffer;
			*pLength = TotalLen;
			Status = NO_ERROR;
		}
		else
		{
			AppFree(Buffer);
			Status = ERROR_NO_MORE_FILES;
		}
	}	// if (Buffer = AppAlloc(DEFAULT_REPORT_BUFFER_SIZE))

	return(Status);
}
示例#29
0
FString &FString::CopyCStrPart(const char *tail, size_t tailLen)
{
	ReallocBuffer(tailLen);
	StrCopy(Chars, tail, tailLen);
	return *this;
}