<commit_before>/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_COMPHELPER_STRING_HXX
#define INCLUDED_COMPHELPER_STRING_HXX

#include <sal/config.h>

#include <cstddef>
#include <comphelper/comphelperdllapi.h>
#include <sal/types.h>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
#include <com/sun/star/uno/Sequence.hxx>

#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/i18n/XCollator.hpp>
#include <com/sun/star/i18n/XBreakIterator.hpp>

// OUString helper functions that are not widespread or mature enough to
// go into the stable URE API:
namespace comphelper { namespace string {

/** Compare an OString to a single char

    @param rIn      The input OString
    @param c        The character to compare againsg

    @return         true if rIn has one char and its equal to c
 */
inline bool equals(const OString& rIn, sal_Char c)
{ return rIn.getLength() == 1 && rIn[0] == c; }

/** Compare an OUString to a single char

    @param rIn      The input OUString
    @param c        The character to compare againsg

    @return         true if rIn has one char and its equal to c
 */
inline bool equals(const OUString& rIn, sal_Unicode c)
{ return rIn.getLength() == 1 && rIn[0] == c; }

/** Removes all occurrences of a character from within the source string

    @deprecated  Use OString::replaceAll(OString(c), OString())
    instead.

    @param rIn      The input OString
    @param c        The character to be removed

    @return         The resulting OString
 */
inline OString remove(const OString &rIn,
    sal_Char c)
{ return rIn.replaceAll(OString(c), OString()); }

/** Removes all occurrences of a character from within the source string

    @deprecated  Use
    OUString::replaceAll(OUString(c), OUString()) instead.

    @param rIn      The input OUString
    @param c        The character to be removed

    @return         The resulting OUString
 */
inline OUString remove(const OUString &rIn,
    sal_Unicode c)
{ return rIn.replaceAll(OUString(c), OUString()); }

/** Strips occurrences of a character from the start of the source string
<commit_msg>need a String::EraseAllChars-alike for OUStringBuffer<commit_after>/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_COMPHELPER_STRING_HXX
#define INCLUDED_COMPHELPER_STRING_HXX

#include <sal/config.h>

#include <cstddef>
#include <comphelper/comphelperdllapi.h>
#include <sal/types.h>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
#include <com/sun/star/uno/Sequence.hxx>

#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/i18n/XCollator.hpp>
#include <com/sun/star/i18n/XBreakIterator.hpp>

// OUString helper functions that are not widespread or mature enough to
// go into the stable URE API:
namespace comphelper { namespace string {

/** Compare an OString to a single char

    @param rIn      The input OString
    @param c        The character to compare againsg

    @return         true if rIn has one char and its equal to c
 */
inline bool equals(const OString& rIn, sal_Char c)
{ return rIn.getLength() == 1 && rIn[0] == c; }

/** Compare an OUString to a single char

    @param rIn      The input OUString
    @param c        The character to compare againsg

    @return         true if rIn has one char and its equal to c
 */
inline bool equals(const OUString& rIn, sal_Unicode c)
{ return rIn.getLength() == 1 && rIn[0] == c; }

/** Removes all occurrences of a character from within the source string

    @deprecated  Use OString::replaceAll(OString(c), OString())
    instead.

    @param rIn      The input OString
    @param c        The character to be removed

    @return         The resulting OString
 */
inline OString remove(const OString &rIn,
    sal_Char c)
{ return rIn.replaceAll(OString(c), OString()); }

/** Removes all occurrences of a character from within the source string

    @deprecated  Use
    OUString::replaceAll(OUString(c), OUString()) instead.

    @param rIn      The input OUString
    @param c        The character to be removed

    @return         The resulting OUString
 */
inline OUString remove(const OUString &rIn,
    sal_Unicode c)
{ return rIn.replaceAll(OUString(c), OUString()); }

/** Removes all occurrences of a character from within the source string

    @param rIn      The input OUStringBuffer
    @param c        The character to be removed

    @return         The resulting OUStringBuffer
 */
inline OUStringBuffer& remove(OUStringBuffer &rIn,
    sal_Unicode c)
{
    sal_Int32 index = 0;
    while (1)
    {
        if (index >= rIn.getLength())
            break;
        index = rIn.indexOf(c, index);
        if (index == -1)
            break;
        rIn.remove(index, 1);
    }
    return rIn;
}

/** Strips occurrences of a character from the start of the source string

{'fraction_non_alphanumeric': 0.09220401286567621, 'fraction_numerical': 0.006432838106907643, 'mean_word_length': 3.1250789639924195, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5691337', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1954, 'n_words': 763}