예제 #1
0
bool EmacsBuffer::translate(mintchar_t mark, const MintString& trstr) {
    // This function does not change the number of characters or
    // newlines in the buffer
    mintcount_t p1 = getMarkPosition(MARK_POINT);
    mintcount_t p2 = getMarkPosition(mark);
    if (p1 > p2) {
        std::swap(p1, p2);
    } // if
    if (p1 != p2) {
        MintString translated;
        const_iterator last = _text.begin() + p2;
        for (const_iterator i = _text.begin() + p1; i < last; ++i) {
            umintchar_t ch = static_cast<umintchar_t>(*i);
            if ((ch != EOLCHAR) && (ch < trstr.size())) {
                ch = trstr[ch];
            } // if
            translated.push_back(ch);
        } // for
#if defined(USE_BUFFER_ROPE) && !defined(USE_MINTSTRING_ROPE)
        _text.replace(p1, p2, translated.data(), translated.size());
#else
        _text.replace(p1, p2, translated);
#endif
    } // if
    return true;
} // translate
예제 #2
0
bool EmacsBuffers::setSearchString(const MintString& str, bool fold_case) {
    regbase::flag_type flags = regbase::literal | (fold_case ? regbase::icase : 0);
    _regex_empty = str.empty();
    if (!_regex_empty) {
        std::string s;
        std::copy(str.begin(), str.end(), std::back_inserter(s));
        _regex.assign(s.c_str(), flags);
    } // if
    return true;
} // setSearchString
예제 #3
0
bool EmacsBuffers::setSearchRegex(const MintString& exp, bool fold_case) {
#if 1
    regbase::flag_type flags = boost::regex::basic | boost::regex::bk_vbar;
#else
    regbase::flag_type flags = boost::regex::normal | boost::regex::bk_braces
                               | boost::regex::bk_parens | boost::regex::bk_vbar;
#endif
    if (fold_case)
        flags |= regbase::icase;
    _regex_empty = exp.empty();
    if (!_regex_empty) {
        std::string s;
        std::copy(exp.begin(), exp.end(), std::back_inserter(s));
        _regex.assign(s.c_str(), flags);
    } // if
    return true;
} // setSearchRegex
예제 #4
0
MintString getStringIntPrefix(const MintString& s, int base) {
    // Max base uses all digits + letters
    base = std::max(2, std::min(base, 36));
    mintchar_t end_number = '0' + std::min(10, base);
    mintchar_t end_letter = 'A' + std::max(0, base - 10);
    MintString::const_iterator plast = s.end();
    while (plast != s.begin()) {
        --plast;
        mintchar_t ch = std::toupper(*plast);
        if ((ch >= '0' && ch < end_number) || (ch >= 'A' && ch < end_letter)) {
            // This digit is OK, get another one
        } else {
            // Skip the minus sign if we have one
            if (ch != '-') {
                ++plast;
            } // if
            break;
        } // else
    } // for
    return MintString(s.begin(), plast);
} // getStringIntPrefix
예제 #5
0
bool EmacsBuffer::insertString(const MintString& str) {
    if (!str.empty()) {
        _modified = true;
#if defined(USE_BUFFER_ROPE) && !defined(USE_MINTSTRING_ROPE)
        _text.insert(_point, str.data(), str.size());
#else
        _text.insert(_point, str);
#endif
        mintcount_t extra_chars = str.size();
        mintcount_t extra_newlines = countNewlines(_point, _point + extra_chars);
        _countNewlines += extra_newlines;
        _pointLine += extra_newlines;
        if (_topline > _point) {
            // topline moves if it is after point
            _topline += extra_chars;
            _toplineLine += extra_newlines;
        } // if
        adjustMarksIns(extra_chars);
        _point += extra_chars;
    } // if
    return true;
} // EmacsBuffer::insertString
예제 #6
0
int getStringIntValue(const MintString& s, int base) {
    // Max base uses all digits + letters
    base = std::max(2, std::min(base, 36));
    mintchar_t end_number = '0' + std::min(10, base);
    mintchar_t end_letter = 'A' + std::max(0, base - 10);
    int multval = 1;
    MintString::const_reverse_iterator rbi = s.rbegin();
    MintString::const_reverse_iterator i = rbi;
    while (i != s.rend()) {
        mintchar_t ch = std::toupper(*i);
        if ((ch >= '0' && ch < end_number) || (ch >= 'A' && ch < end_letter)) {
            // This digit is OK, get another one
            ++i;
        } else {
            if (ch == '-') {
                multval = -1;
            } // if
            break;
        } // else
    } // for
    int number = 0;
    if (i != rbi) {
        do {
            --i;
            mintchar_t ch = std::toupper(*i);
            if ((ch >= '0') && (ch < end_number)) {
                int digit = ch - '0';
                number *= base;
                number += digit;
            } else if ((base > 10) && (ch >= 'A' && ch < end_letter)) {
                int digit = 10 + (ch - 'A');
                number *= base;
                number += digit;
            } // else if
        } while (i != rbi);
    } // if
    return number * multval;
} // getStringIntValue
예제 #7
0
bool EmacsBuffer::deleteToMarks(const MintString& marks) {
    // Stops on first delete that fails
    std::find_if(marks.begin(), marks.end(), 
                 std::not1(std::bind1st(std::mem_fun(&EmacsBuffer::deleteToMark), this)));
    return true;
} // EmacsBuffer::DeleteToMarks
예제 #8
0
void EmacsBuffer::setPointToMarks(const MintString& marks) {
    std::for_each(marks.begin(), marks.end(),
                  std::bind1st(std::mem_fun(&EmacsBuffer::setPointToMark), this));
} // setPointToMarks