当前位置: 首页>>代码示例>>C++>>正文


C++ DString::length方法代码示例

本文整理汇总了C++中DString::length方法的典型用法代码示例。如果您正苦于以下问题:C++ DString::length方法的具体用法?C++ DString::length怎么用?C++ DString::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DString的用法示例。


在下文中一共展示了DString::length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: view

void TextConsoleViewer::view()
{
#ifdef _WIN32
    int topline, leftpos;
    leftpos = topline = 0;
    INPUT_RECORD ir;

    HANDLE hCon  = GetStdHandle(STD_OUTPUT_HANDLE);
    HANDLE hConI = CreateFile("CONIN$", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    if (hConI == INVALID_HANDLE_VALUE) return;
    SetConsoleMode(hConI, ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT);

    CONSOLE_SCREEN_BUFFER_INFO csbi;

    hCon = CreateConsoleScreenBuffer(GENERIC_WRITE|GENERIC_READ, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0);
    SetConsoleActiveScreenBuffer(hCon);
    GetConsoleScreenBufferInfo(hCon, &csbi);
    CONSOLE_CURSOR_INFO cci;
    cci.dwSize = 100;
    cci.bVisible = FALSE;
    SetConsoleCursorInfo(hCon, &cci);

    CHAR_INFO *buffer = new CHAR_INFO[csbi.dwSize.X * csbi.dwSize.Y];
    bool unc_fault = false;
    do {
        int lline = csbi.dwSize.Y;
        if (topline+lline > textLinesStore->getLineCount()) lline = textLinesStore->getLineCount()-topline;
        baseEditor->visibleTextEvent(topline, lline);

        for(int i = topline; i < topline + csbi.dwSize.Y; i++) {
            int Y = i-topline;

            int li;
            for(li = 0; li < csbi.dwSize.X; li++) {
                buffer[Y*csbi.dwSize.X + li].Char.UnicodeChar = ' ';
                buffer[Y*csbi.dwSize.X + li].Attributes = background;
            };

            if (i >= textLinesStore->getLineCount()) continue;
            DString iLine = textLinesStore->getLine(i);

            for(li = 0; li < csbi.dwSize.X; li++) {
                if (leftpos+li >= iLine.length()) break;
                buffer[Y*csbi.dwSize.X + li].Char.UnicodeChar = iLine[leftpos+li];
                if (unc_fault)
                    buffer[Y*csbi.dwSize.X + li].Char.AsciiChar = Encodings::toChar(encoding, iLine[leftpos+li]);
            };
            for(LineRegion *l1 = baseEditor->getLineRegions(i); l1 != null; l1 = l1->next) {
                if (l1->special || l1->rdef == null) continue;
                int end = l1->end;
                if (end == -1) end = iLine.length();
                int X = l1->start - leftpos;
                int len = end - l1->start;
                if (X < 0) {
                    len += X;
                    X = 0;
                };
                if (len < 0 || X >= csbi.dwSize.X) continue;
                if (len+X > csbi.dwSize.X) len = csbi.dwSize.X-X;
                WORD color = (WORD)(l1->styled()->fore + (l1->styled()->back<<4));
                if (!l1->styled()->bfore) color = (color&0xF0) + (background&0xF);
                if (!l1->styled()->bback) color = (color&0xF) + (background&0xF0);
                for(int li = 0; li < len; li++)
                    buffer[Y*csbi.dwSize.X + X + li].Attributes = color;
            };
        };
        COORD coor;
        coor.X = coor.Y = 0;
        SMALL_RECT sr;
        sr.Left = 0;
        sr.Right = csbi.dwSize.X-1;
        sr.Top = 0;
        sr.Bottom = csbi.dwSize.Y-1;
        if (!unc_fault && !WriteConsoleOutputW(hCon, buffer, csbi.dwSize, coor, &sr)) {
            unc_fault = true;
            continue;
        };
        if (unc_fault) WriteConsoleOutputA(hCon, buffer, csbi.dwSize, coor, &sr);

        // managing the keyboard
        do {
            DWORD tmp;
            ReadConsoleInput(hConI, &ir, 1, &tmp);
            if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) {
                GetConsoleScreenBufferInfo(hCon, &csbi);
                delete[] buffer;
                buffer = new CHAR_INFO[csbi.dwSize.X * csbi.dwSize.Y];
                break;
            };
            if (ir.EventType == MOUSE_EVENT && ir.Event.MouseEvent.dwEventFlags == 0x4) {
                switch(ir.Event.MouseEvent.dwButtonState) {
                case 0x780000:
                    topline-=csbi.dwSize.Y;
                    if (topline < 0) topline = 0;
                    break;
                case 0xFF880000:
                    topline += csbi.dwSize.Y;
                    if (topline > textLinesStore->getLineCount() - csbi.dwSize.Y) topline = textLinesStore->getLineCount() - csbi.dwSize.Y;
                    if (topline < 0) topline = 0;
                    break;
//.........这里部分代码省略.........
开发者ID:flaub,项目名称:Perfecto,代码行数:101,代码来源:TextConsoleViewer.cpp

示例2: sendPacket

int DServerSock::sendPacket ( int hSock, const DString & packet, bool checkSock )
{
	ssize_t numberChar;
	fd_set stFdSet;
	struct timeval stTime;
	DString buffer;
	long int timeout;

	if ( checkSock )
	{
		// check if socket is opened
		timeout = m_timeout;
		setTimeout ( 10 );
		m_status = readMessage ( hSock, buffer );
		setTimeout ( timeout );
	}

	if ( m_hSocket < 0 || m_status == NO_SOCKET )
	{
		m_status = NO_SOCKET;
		m_lastError = "No opened socket found";
		return m_status;
	}
	FD_ZERO ( &stFdSet );
	FD_SET ( hSock, &stFdSet );
	stTime.tv_sec = m_timeout;
	stTime.tv_usec = 0;

	if (m_debug)
	{
		printMessage(packet);
	}
	// Check if data can be sent without any blocking
	if ( ( select ( hSock+1, NULL, &stFdSet, NULL, &stTime ) != -1 ) &&
			  ( FD_ISSET ( hSock, &stFdSet ) ) )
	{
		numberChar = send ( hSock, packet.c_str(), packet.length(), 0 );
		if ( numberChar == static_cast<ssize_t> ( packet.length() ) )
		{
			m_lastError = "";
			m_status = SUCCESS;
		}
		else
		{
			m_lastError = "No data sent, ";
			m_lastError =  + strerror ( errno );
			m_status = NO_SEND;
		}
	}
	else
	{
		m_lastError = "No data sent, ";
		m_lastError =  + strerror ( errno );
		m_status = NO_SEND;
	}
	return m_status;
}
开发者ID:didier13150,项目名称:dlibs,代码行数:57,代码来源:dsocket.cpp

示例3: QueryParser

void CFindOptions::QueryParser( const DString& query )
{
	mPureQuery = query;

	mQuery.clear();

	// TODO Добавлять еще в начале и конце (.*) если нет кавычек в запросе

	UINT _length = query.length();

	for(UINT i=0;i<_length;i++)
	{
		if( (query[i] == Character::ASTERISK)
			|| (query[i] == Character::SPACE) )
		{
			mQuery += L"(.*)";
			continue;
		}

		if( (query[i] == Character::PLUS) // +
			||(query[i] == Character::QUESTION_MARK) // ?
			||(query[i] == Character::CARET_CURCUMFLEX) // ^
			||(query[i] == Character::DOLLAR_SIGN) // $
			||(query[i] == Character::EXCLAMATION_POINT) // !
			||(query[i] == Character::OPEN_BRACE) // {
			||(query[i] == Character::CLOSE_BRACE) // }
			||(query[i] == Character::BACKSLASH) // '\''
			||(query[i] == Character::GREATER_THAN_SIGN) // >
			||(query[i] == Character::LESS_THAN_SIGN) // <
			||(query[i] == Character::VERTICAL_BAR) // |
			||(query[i] == Character::OPEN_BRACKET) // (
			||(query[i] == Character::CLOSE_BRACKET) // )	
			||(query[i] == Character::EQUALS_SIGN) // =
			||(query[i] == Character::LEFT_SQUARE_BRACKET) // [
			||(query[i] == Character::RIGHT_SQUARE_BRACKET) // ]
			||(query[i] == Character::COLON) // :
			||(query[i] == Character::HYPHEN_MINUS) // -
			||(query[i] == Character::PERIOD) ) // .
		{
			mQuery += L'\\';
			// And continue...
		}

		mQuery += query[i];
	}
}
开发者ID:DarkKnight178,项目名称:Finder,代码行数:46,代码来源:CFindOptions.cpp

示例4: readMessage

int DServerSock::readMessage ( int hSock, DString &message )
{
	int numberChar;
	int availableNbChar = 0;
	char * bufchar;
	DString buffer;
	bool finished = false;

	// clear line
	message.clear();
	
	if ( hSock < 0 || m_status == NO_SOCKET )
	{
		m_status = NO_SOCKET;
		m_lastError = "No opened socket found";
		return m_status;
	}

	bufchar = new char[ m_buffSize + 1 ];

	while ( ! finished )
	{
		ioctl( hSock, FIONREAD, &availableNbChar );
		if ( availableNbChar )
		{
			memset ( bufchar, 0x0, m_buffSize + 1 );
			numberChar = recv ( hSock, bufchar, sizeof( bufchar ), 0 );
			if ( numberChar < 0 )
			{
				if ( ! message.length() )
				{
					m_lastError = "No data, ";
					m_lastError += strerror ( errno );
					m_status = RECV_NOTHING;
					//break;
				}
			}
			else if ( numberChar == 0 )
			{
				m_lastError = "Socket disconnected, ";
				m_lastError += strerror ( errno );
				m_status = NO_SOCKET;
				break;
			}
			else
			{
				buffer = bufchar;
				buffer.truncate ( numberChar );
				if ( buffer.length() > 0 )
				{
					if (m_debug)
					{
						printMessage(buffer);
					}
					if ( buffer.right(2) == "\r\n" )
					{
						finished = true;
					}
					message += buffer;
					m_status = SUCCESS;
					m_lastError = "";
				}
				else
				{
					if ( ! message.length() )
					{
						m_status = RECV_EMPTY;
						m_lastError = "Receive an empty message";
					}
					break;
				}
			}
		}
		else
		{
			finished = true;
		}
	}

	delete[]( bufchar );

	return m_status;
}
开发者ID:didier13150,项目名称:dlibs,代码行数:83,代码来源:dsocket.cpp


注:本文中的DString::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。