UInt32 TextInputMenu::FindLineEnd(UInt32 fromPos) const { if (fromPos >= GetMaxPos()) return GetInputLength(); UInt32 lBracPos = fromPos; while ( (lBracPos = m_inputText.find('<', lBracPos)) != std::string::npos ) { if (GetHTMLTagType(lBracPos) != kHTMLTag_Other) return lBracPos; lBracPos++; } return GetInputLength(); }
void CHostBrowser::OnDropped() { if ( m_nProtocol != PROTOCOL_ED2K && m_nProtocol != PROTOCOL_DC ) { if ( ! IsValid() ) return; if ( m_nState == hbsConnecting ) { theApp.Message( MSG_ERROR, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress ); if ( ! m_tPushed && SendPush( TRUE ) ) return; } else { if ( m_nLength == SIZE_UNKNOWN ) { m_nLength = GetInputLength(); ReadContent(); return; } theApp.Message( MSG_ERROR, IDS_BROWSE_DROPPED, (LPCTSTR)m_sAddress ); } } Stop(); }
UInt32 TextInputMenu::InsertText(UInt32 insertPos, const char* toInsert) { UInt32 insertLen = strlen(toInsert); if (GetInputLength() + insertLen >= m_maxLen) //not enough room for the text return insertPos; if (insertPos == m_inputText.length()) m_inputText.append(toInsert); else m_inputText.insert(insertPos, toInsert); return insertPos + insertLen; }
UInt32 TextInputMenu::InsertChar(UInt32 insertPos, char toInsert) { if (IsFull()) return insertPos; if (m_bIsHTML) // check for < > chars and disallow in book input { if (toInsert == '<' || toInsert == '>') return insertPos; } if (insertPos == GetInputLength()) m_inputText.append(1, toInsert); else m_inputText.insert(insertPos, 1, toInsert); return insertPos + 1; }
UInt32 TextInputMenu::FindWordBoundary(UInt32 startPos, bool bBackwards) const { UInt32 curPos = bBackwards ? startPos - 1 : startPos; SInt32 stepVal = bBackwards ? -1 : 1; UInt32 terminalPos = bBackwards ? m_minPos : GetInputLength(); char curChar = m_inputText[curPos]; if (curChar == '>') return FindHTMLMatchedBracket(curPos - 1, true); else if (curChar == '<') return FindHTMLMatchedBracket(curPos + 1, false) + 1; UInt32 nextPos = curPos + stepVal; bool bPatternStart = bBackwards ? true : false; //seek isgraph() first or !isgraph() first? bool bPrevIsGraph = isgraph(curChar) ? true : false; while (nextPos != terminalPos) { char nextChar = m_inputText[nextPos]; if (nextChar == '<' || nextChar == '>') return bBackwards ? curPos : nextPos; bool bNextIsGraph = isgraph(nextChar) ? true : false; if (bPrevIsGraph == bPatternStart && bNextIsGraph != bPatternStart) break; curPos = nextPos; nextPos += stepVal; bPrevIsGraph = bNextIsGraph; } if (nextPos == terminalPos) return terminalPos; return bBackwards ? nextPos + 1 : nextPos; }
BOOL CRemote::OnRead() { if ( ! CTransfer::OnRead() ) return FALSE; if ( m_sHandshake.IsEmpty() ) { if ( GetInputLength() > 4096 || ! Settings.Remote.Enable ) { Close(); return FALSE; } Read( m_sHandshake ); } if ( ! m_sHandshake.IsEmpty() ) { theApp.Message( MSG_DEBUG | MSG_FACILITY_INCOMING, L"%s >> REMOTE REQUEST: %s", (LPCTSTR)m_sAddress, (LPCTSTR)m_sHandshake ); return ReadHeaders(); } return TRUE; }
void TextInputMenu::Erase(UInt32 pos) { if (pos < GetInputLength()) m_inputText.erase(pos, 1); }