void NativeTextfieldWin::OnPaste() { if(textfield_->read_only() || !ViewDelegate::view_delegate) { return; } ui::Clipboard* clipboard = ViewDelegate::view_delegate->GetClipboard(); if(!clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), ui::Clipboard::BUFFER_STANDARD)) { return; } std::wstring clipboard_str; clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_str); if(!clipboard_str.empty()) { std::wstring collapsed(CollapseWhitespace(clipboard_str, false)); if(textfield_->style() & Textfield::STYLE_LOWERCASE) { collapsed = base::i18n::ToLower(collapsed); } // Force a Paste operation to trigger ContentsChanged, even if identical // contents are pasted into the text box. See http://crbug.com/79002 ReplaceSel(L"", false); textfield_->SyncText(); text_before_change_.clear(); ReplaceSel(collapsed.c_str(), true); } }
const char* StrPair::GetStr() { if ( _flags & NEEDS_FLUSH ) { *_end = 0; _flags ^= NEEDS_FLUSH; if ( _flags ) { char* p = _start; // the read pointer char* q = _start; // the write pointer while( p < _end ) { if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) { // CR-LF pair becomes LF // CR alone becomes LF // LF-CR becomes LF if ( *(p+1) == LF ) { p += 2; } else { ++p; } *q++ = LF; } else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) { if ( *(p+1) == CR ) { p += 2; } else { ++p; } *q++ = LF; } else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { // Entities handled by tinyXML2: // - special entities in the entity table [in/out] // - numeric character reference [in] // 中 or 中 if ( *(p+1) == '#' ) { char buf[10] = { 0 }; int len; p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) ); for( int i=0; i<len; ++i ) { *q++ = buf[i]; } TIXMLASSERT( q <= p ); } else { int i=0; for(; i<NUM_ENTITIES; ++i ) { if ( strncmp( p+1, entities[i].pattern, entities[i].length ) == 0 && *(p+entities[i].length+1) == ';' ) { // Found an entity convert; *q = entities[i].value; ++q; p += entities[i].length + 2; break; } } if ( i == NUM_ENTITIES ) { // fixme: treat as error? ++p; ++q; } } } else { *q = *p; ++p; ++q; } } *q = 0; } // The loop below has plenty going on, and this // is a less useful mode. Break it out. if ( _flags & COLLAPSE_WHITESPACE ) { CollapseWhitespace(); } _flags = (_flags & NEEDS_DELETE); } return _start; }
bool UniMarkdownFile::ReadString(String &line, String &eol, bool *lossy) { line.erase(); eol.erase(); int nlosses = m_txtstats.nlosses; int nDepth = 0; bool bDone = false; if (m_current < (const unsigned char *)m_pMarkdown->lower) { line = maketstring((const char *)m_current, m_pMarkdown->lower - (const char *)m_current); CollapseWhitespace(line); bDone = !line.empty(); m_current = (unsigned char *)m_pMarkdown->lower; } while (m_current < m_base + m_filesize && !bDone) { if (m_current < m_transparent) { // Leave whitespace alone when inside <? ?>, <!-- -->, or <![*[ ]]>. unsigned char * current = m_current; if (m_current == (const unsigned char *)m_pMarkdown->first) { nDepth = m_depth; } while (m_current < m_transparent && *m_current != '\r' && *m_current != '\n') { ++m_current; } line = maketstring((const char *)current, m_current - current); if (m_current < m_transparent) { unsigned char eol1 = *m_current++; if (m_current < m_transparent && *m_current == (eol1 ^ ('\r'^'\n'))) { ++m_current; ++m_txtstats.ncrlfs; } else { ++(eol1 == '\r' ? m_txtstats.ncrs : m_txtstats.nlfs); } } bDone = true; } else { while (m_current < m_base + m_filesize && isspace(*m_current)) { unsigned char eol1 = *m_current++; if (eol1 == '\r' || eol1 == '\n') { if (m_current < m_base + m_filesize && *m_current == (eol1 ^ ('\r'^'\n'))) { ++m_current; ++m_txtstats.ncrlfs; } else { ++(eol1 == '\r' ? m_txtstats.ncrs : m_txtstats.nlfs); } } } nDepth = m_depth; bool bPull = false; if (m_bMove && m_pMarkdown->Pull()) { ++m_depth; bPull = true; } Move(); bDone = m_bMove; if (!bDone) { --m_depth; bDone = m_pMarkdown->Push(); if (bPull && bDone) Move(); } if (bDone) { line = maketstring((const char *)m_current, m_pMarkdown->first - (const char *)m_current); CollapseWhitespace(line); m_current = (unsigned char *)m_pMarkdown->first; } else if (m_current < m_base + m_filesize) { bDone = true; line = maketstring((const char *)m_current, m_base + m_filesize - m_current); CollapseWhitespace(line); m_current = m_base + m_filesize; } bDone = !line.empty(); } } assert(line.find_first_of(_T("\r\n")) == String::npos); if (nDepth > 0) line.insert(0U, nDepth, _T('\t')); if (bDone) eol = _T("\n"); if (lossy) *lossy = nlosses != m_txtstats.nlosses; return bDone; }