Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  ToxWhitespaceStripper.cxx   Sprache: C

 
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


#include <ToxWhitespaceStripper.hxx>

#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>


namespace sw {

ToxWhitespaceStripper::ToxWhitespaceStripper(std::u16string_view inputString)
{
    OUStringBuffer buffer;

    bool lastCharacterWasWhitespace = false;
    for (size_t pos = 0; pos < inputString.size(); ++pos) {
        sal_Unicode cur = inputString[pos];

        if (cur == ' ' || cur == '\n' || cur == '\t') {
            // merge consecutive whitespaces (and translate them to spaces)
            if (!lastCharacterWasWhitespace) {
                buffer.append(' ');
            }
            lastCharacterWasWhitespace = true;
        }
        else {
            buffer.append(cur);
            lastCharacterWasWhitespace = false;
        }
        mNewPositions.push_back(buffer.getLength()-1);
    }
    // strip the last whitespace (if there was one)
    if (lastCharacterWasWhitespace) {
        buffer.truncate(buffer.getLength() - 1);
    }
    mNewPositions.push_back(buffer.getLength());
    mStripped = buffer.makeStringAndClear();
}


sal_Int32
ToxWhitespaceStripper::GetPositionInStrippedString(sal_Int32 pos) const
{
    assert(0 <= pos);
    if (o3tl::make_unsigned(pos) >= mNewPositions.size()) {
        // TODO probably this should assert, not just warn?
        SAL_WARN("sw.core""Requested position of TOX entry text which does not exist. "
                            "Maybe the formatting hint is corrupt?");
        return mNewPositions.back();
    }
    return mNewPositions.at(pos);
}


}

Messung V0.5
C=90 H=95 G=92

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge