Exemple #1
0
String& String::insert(size_t pos, char c, size_t rep)
{
    KEEPOLD;

    //
    // preconditions
    //

    if(pos > length())
        strError("String::insert", "OutOfRange");
    //
    // operations
    //

    if(rep == 1)
        doReplace(pos, 0, &c, 1);
    else if(rep > 0)
        insert(pos, String(c, rep));

    //
    // post conditions
    //

    assert(length() == (rep + OLD.length()));
#ifndef NDEBUG
    for(int i = 0; i < rep; i++)
        assert(getAt(i + pos) == c);
#endif /* NDEBUG */

    return *this;
}
Exemple #2
0
void ChangeSet::apply_helper()
{
    // convert all ops to replace
    QList<EditOp> replaceList;
    {
        while (!m_operationList.isEmpty()) {
            const EditOp cmd(m_operationList.first());
            m_operationList.removeFirst();
            convertToReplace(cmd, &replaceList);
        }
    }

    // execute replaces
    if (m_cursor)
        m_cursor->beginEditBlock();

    while (!replaceList.isEmpty()) {
        const EditOp cmd(replaceList.first());
        replaceList.removeFirst();
        doReplace(cmd, &replaceList);
    }

    if (m_cursor)
        m_cursor->endEditBlock();
}
Exemple #3
0
String& String::getRemove(char& c, size_t pos)
{
    KEEPOLD;

    //
    // preconditions
    //

    if(pos >= length())
        strError("String::getRemove", "OutOfRange");

    //
    // operations
    //

    c = getAtRaw(pos);

    doReplace(pos, 1,  "", 0);

    //
    // post conditions
    //

    assert(length() == (OLD.length() - 1));
    assert(OLD.getAt(pos) == c);

    return *this;
}
Exemple #4
0
void Window::initializeDialogs()
{
	// Create our dialog objects.

	preferencesDialog = new PreferencesDialog(this);

	findDialog = new FindDialog(this);

	replaceDialog = new ReplaceDialog(this);

	goToDialog = new GoToDialog(this);

	aboutDialog = new AboutDialog(this);

	// Connect our dialog actions.

	QObject::connect(findDialog, SIGNAL(accepted()), this,
	                 SLOT(doFindNext()));
	QObject::connect(replaceDialog, SIGNAL(replaceClicked()), this,
	                 SLOT(doReplace()));
	QObject::connect(replaceDialog, SIGNAL(findClicked()), this,
	                 SLOT(doReplaceFind()));
	QObject::connect(replaceDialog, SIGNAL(replaceSelectionClicked()), this,
	                 SLOT(doReplaceSelection()));
	QObject::connect(replaceDialog, SIGNAL(replaceAllClicked()), this,
	                 SLOT(doReplaceAll()));
	QObject::connect(goToDialog, SIGNAL(accepted()), this,
	                 SLOT(doGoToAccepted()));
}
Exemple #5
0
String& String::replace(size_t pos, size_t len, const  String& s)
{
    KEEPOLD;
    size_t thisLen = length();

    //
    // preconditions
    //

    if(pos > thisLen)
        strError("String::replace", "OutOfRange");

    //
    // operations
    //

    if(this == &s) {                         // if argument string is target
        return replace(pos, len, String(s)); // get a copy and call it
                                             // recursively
    }

    if((pos + len) > thisLen)
        len = thisLen - pos;

    doReplace(pos, len, s.getStr(), s.length());

    //
    // post conditions
    //

    assert(length() == (OLD.length() - len + s.length()));

    return *this;
}
Exemple #6
0
String& String::remove(size_t pos, size_t n)
{
    KEEPOLD;
    size_t thisLen = length();

    //
    // preconditions
    //

    if(pos > length())
        strError("String::remove", "OutOfRange");

    //
    // operations
    //

    if(n == NPOS || (pos + n) > thisLen)
        n = thisLen - pos;

    if(n > 0)
        doReplace(pos, n,  "", 0);

    //
    // post conditions
    //

    assert(length() == (OLD.length() - n));

    return *this;
}
Exemple #7
0
String& String::getRemove(String& s, size_t pos, size_t n)
{
    KEEPOLD;
    size_t thisLen = length();

    //
    // preconditions
    //

    if(pos > thisLen)
        strError("String::getRemove", "OutOfRange");

    //
    // operations
    //

    if(n == NPOS || (pos + n) > thisLen)
        n = thisLen - pos;

    s = substr(pos, n);
    doReplace(pos, n,  "", 0);

    //
    // post conditions
    //

    assert(length() == (OLD.length() - s.length()));
    assert(s == OLD.substr(pos, n));

    return *this;
}
Exemple #8
0
String& String::replace(size_t pos, size_t n, const char *cb, size_t len)
{
    KEEPOLD;
    size_t thisLen = length();

    //
    // preconditions
    //

    if(pos > thisLen)
        strError("String::replace", "OutOfRange");
    if(cb == 0)
        strError("String::replace", "InvalidArgument");

    //
    // operations
    //

    if(len == NPOS)
        len = strlen(cb);

    if((pos + n) > thisLen)
        n = thisLen - pos;

    if(n > 0 || len > 0)
        doReplace(pos, n, cb, len);

    //
    // post conditions
    //

    assert(length() == (OLD.length() - n + len));

    return *this;
}
Exemple #9
0
//
// insert
//
String& String::insert(size_t pos, const String& s)
{
    KEEPOLD;

    //
    // preconditions
    //

    if(pos > length())
        strError("String::insert", "OutOfRange");

    //
    // operations
    //

    if(this == &s)
        return insert(pos, String(s));          // insert into itself
    if(s.srep)
        doReplace(pos, 0, s.srep->str, s.srep->getLen());

    //
    // post conditions
    //

    assert(length() == (s.length() + OLD.length()));
    assert(memcmp(cStr() + pos, s.cStr(), s.length()) == 0);

    return *this;
}
Exemple #10
0
String& String::append(char c, size_t rep)
{
    KEEPOLD;

    //
    // preconditions
    //

    if(rep == NPOS)
        strError("String::append", "OutOfRange");

    //
    // operations
    //

    if(rep == 1)
        doReplace(length(), 0, &c, 1);
    else if(rep > 0)
        operator+=(String(c, rep));

    //
    // post conditions
    //

    assert((OLD.length() + rep) == length());
#ifndef NDEBUG
    for(int i = 0; i < rep; i++) {
        int j = i + OLD.length();
        assert(getAt(j) == c);
    }
#endif /* NDEBUG */

    return *this;
}
Exemple #11
0
String& String::append(const char* cb, size_t n)
{
    KEEPOLD;

    //
    // preconditions
    //

    if(cb == 0)
        strError("String::append", "InvalidArgument");

    //
    // operations
    //

    if(n == NPOS)
        n = strlen(cb);

    if(n > 0)
        doReplace(length(), 0, cb, n);

    //
    // post conditions
    //

    assert((OLD.length() + n) == length());
    assert(memcmp(cStr() + OLD.length(), cb, n) == 0);

    return *this;
}
ReplaceDialog::ReplaceDialog(QWidget* parent,  const char* name, Qt::WFlags fl )
    : QDialog( parent, fl )
{
setWindowTitle(name);
setModal(true);
ui.setupUi(this);
connect( ui.findButton, SIGNAL( clicked() ), this, SLOT( doReplace() ) );
connect( ui.replaceallButton, SIGNAL( clicked() ), this, SLOT( doReplaceAll() ) );
connect( ui.closeButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
ui.findButton->setShortcut(Qt::Key_Return);
}
Exemple #13
0
String& String::insert(size_t pos, const char* cb, size_t n)
{
    KEEPOLD;

#ifndef NDEBUG
    char *pOLD = 0;
    if(cb != 0) {
        if(n == NPOS)
            n = strlen(cb);
        pOLD = new char[n];
        assert(pOLD != 0);
        memcpy(pOLD, cb, n);
    }
#endif

    //
    // preconditions
    //

    if(pos > length())
        strError("String::insert", "OutOfRange");
    if(cb == 0)
        strError("String::insert", "InvalidArgument");

    //
    // operations
    //

    if(n == NPOS)
        n = strlen(cb);

    if(n > 0)
        doReplace(pos, 0, cb, n);

    //
    // post conditions
    //

    assert(length() == (n + OLD.length()));

#ifndef NDEBUG
    //
    // this asertion is so complicated
    // because of hacks like: s.insert(1, s.cStr() + 2)
    //
    assert(memcmp(cStr() + pos, pOLD, n) == 0);
    delete [] pOLD;
#endif

    return *this;
}
Exemple #14
0
String& String::operator+=(char c)
{
    KEEPOLD;

    //
    // operations
    //

    doReplace(length(), 0, &c, 1);

    //
    // post conditions
    //

    assert((OLD.length() + 1) == length());
    assert(getAt(OLD.length()) == c);

    return *this;
}
Exemple #15
0
String& String::operator+=(const char *cs)
{
    KEEPOLD;
#ifndef NDEBUG
    char *pOLD = 0;
    if(cs != 0) {
        pOLD = new char[strlen(cs) + 1];
        assert(pOLD != 0);
        strcpy(pOLD, cs);
    }
#endif

    //
    // preconditions
    //

    if(cs == 0)
        strError("String::operator+=", "InvalidArgument");

    //
    // operations
    //

    doReplace(length(), 0, cs, strlen(cs));

    //
    // post conditions
    //

#ifndef NDEBUG
    //
    // this asertion is so complicated
    // because of hacks like: s += s.cStr();
    //
    assert((OLD.length() + strlen(pOLD)) == length());
    assert(memcmp(cStr() + OLD.length(), pOLD, strlen(pOLD)) == 0);
    delete [] pOLD;
#endif

    return *this;
}
Exemple #16
0
ReplaceWidget::ReplaceWidget(QWidget* parent)
    : QWidget( parent)
{
ui.setupUi(this);
connect( ui.findButton, SIGNAL( clicked() ), this, SLOT( doReplace() ) );
connect( ui.replaceallButton, SIGNAL( clicked() ), this, SLOT( doReplaceAll() ) );
connect( ui.closeButton, SIGNAL( clicked() ), this, SLOT( doHide() ) );
//ui.findButton->setShortcut(Qt::Key_Return);
ui.findButton->setToolTip("Return");
ui.closeButton->setShortcut(Qt::Key_Escape);
ui.closeButton->setToolTip("Escape");
ui.moreButton->setCheckable(true);
ui.moreButton->setAutoDefault(false);
connect(ui.moreButton, SIGNAL(toggled(bool)), this, SLOT(expand(bool)));
ui.checkRegExp->setChecked( false );
ui.checkSelection->setChecked( false );
connect(ui.checkSelection, SIGNAL(toggled(bool)), this, SLOT(updateSelection(bool)));
connect(ui.checkRegExp, SIGNAL(toggled(bool)), this, SLOT(updateReg(bool)));
ui.extension->hide();
updateGeometry();
}
Exemple #17
0
//
//  appending operators
//
String& String::operator+=(const String& s)
{
    size_t sLen;
    KEEPOLD;

    //
    // operations
    //

    if(this == &s)              // append to self
        return operator+=(String(s));
    sLen = s.length();
    if(sLen > 0)
        doReplace(length(), 0, s.srep->str, sLen);

    //
    // post conditions
    //

    assert((OLD.length() + s.length()) == length());
    assert(memcmp(cStr() + OLD.length(), s.cStr(), s.length()) == 0);

    return *this;
}
Exemple #18
0
void KEdit::replace_search_slot(){

  int line, col;

  if (!replace_dialog)
    return;

  QString to_find_string = replace_dialog->getText();

  int lineFrom, lineTo, colFrom, colTo;
  getSelection(&lineFrom, &colFrom, &lineTo, &colTo);

  // replace_dialog->get_direction() is true if searching backward
  if (replace_dialog->get_direction())
  {
    if (colFrom != -1)
    {
      col = colFrom - to_find_string.length();
      line = lineFrom;
    }
    else
    {
      getCursorPosition(&line,&col);
      col--;
    }
  }
  else
  {
    if (colTo != -1)
    {
      col = colTo;
      line = lineTo;
    }
    else
    {
      getCursorPosition(&line,&col);
    }
  }

again:

  int  result = doReplace(to_find_string, replace_dialog->case_sensitive(),
			 false, (!replace_dialog->get_direction()), line, col, false );

  if(!result){
    if(!replace_dialog->get_direction()){ // forward search

     int query = KMessageBox::questionYesNo(
			replace_dialog,
                        i18n("End of document reached.\n"\
                             "Continue from the beginning?"),
                        i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
     if (query == KMessageBox::Yes){
	line = 0;
	col = 0;
	goto again;
      }
    }
    else{ //backward search

     int query = KMessageBox::questionYesNo(
			replace_dialog,
                        i18n("Beginning of document reached.\n"\
                             "Continue from the end?"),
                        i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
      if (query == KMessageBox::Yes){
	QString string = textLine( numLines() - 1 );
	line = numLines() - 1;
	col  = string.length();
	last_replace = BACKWARD;
	goto again;
      }
    }
  }
  else{

    emit CursorPositionChanged();
  }
}