<commit_before>/*
 * Copyright (C) 2018 <NAME>
 *
 * Licensed 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <SFConfig.h>

#include "SFBase.h"
#include "SFCommon.h"
#include "SFData.h"
#include "SFGSUB.h"
#include "SFLocator.h"
#include "SFOpenType.h"

#include "SFGlyphDiscovery.h"
#include "SFGlyphManipulation.h"
#include "SFGlyphSubstitution.h"
#include "SFTextProcessor.h"

static SFBoolean _SFApplySingleSubst(SFTextProcessorRef textProcessor, SFData singleSubst);

static SFBoolean _SFApplyMultipleSubst(SFTextProcessorRef textProcessor, SFData multipleSubst);
static SFBoolean _SFApplySequenceTable(SFTextProcessorRef textProcessor, SFData sequence);

static SFBoolean _SFApplyAlternateSubst(SFTextProcessorRef textProcessor, SFData alternateSubst);
static SFBoolean _SFApplyAlternateSetTable(SFTextProcessorRef textProcessor, SFData alternateSet);

static SFBoolean _SFApplyLigatureSubst(SFTextProcessorRef textProcessor, SFData ligatureSubst);
static SFBoolean _SFApplyLigatureSetTable(SFTextProcessorRef textProcessor, SFData ligatureSet);

SF_PRIVATE SFBoolean _SFApplySubstitutionSubtable(SFTextProcessorRef textProcessor, SFLookupType lookupType, SFData subtable)
{
    switch (lookupType) {
        case SFLookupTypeSingle:
            return _SFApplySingleSubst(textProcessor, subtable);

        case SFLookupTypeMultiple:
            return _SFApplyMultipleSubst(textProcessor, subtable);

        case SFLookupTypeAlternate:
            return _SFApplyAlternateSubst(textProcessor, subtable);

        case SFLookupTypeLigature:
            return _SFApplyLigatureSubst(textProcessor, subtable);

        case SFLookupTypeContext:
            return _SFApplyContextSubtable(textProcessor, subtable);

        case SFLookupTypeChainingContext:
            return _SFApplyChainContextSubtable(textProcessor, subtable);

        case SFLookupTypeExtension:
            return _SFApplyExtensionSubtable(textProcessor, subtable);

        case SFLookupTypeReverseChainingContext:
            break;
    }

    return SFFalse;
}

static SFBoolean _SFApplySingleSubst(SFTextProcessorRef textProcessor, SFData singleSubst)
{
    SFAlbumRef album = textProcessor->_album;
    SFLocatorRef locator = &textProcessor->_locator;
    SFUInt16 substFormat;
<commit_msg>[lib] Enabled reverse chain substitution<commit_after>/*
 * Copyright (C) 2015-2018 <NAME>
 *
 * Licensed 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <SFConfig.h>

#include "SFBase.h"
#include "SFCommon.h"
#include "SFData.h"
#include "SFGSUB.h"
#include "SFLocator.h"
#include "SFOpenType.h"

#include "SFGlyphDiscovery.h"
#include "SFGlyphManipulation.h"
#include "SFGlyphSubstitution.h"
#include "SFTextProcessor.h"

static SFBoolean _SFApplySingleSubst(SFTextProcessorRef textProcessor, SFData singleSubst);

static SFBoolean _SFApplyMultipleSubst(SFTextProcessorRef textProcessor, SFData multipleSubst);
static SFBoolean _SFApplySequenceTable(SFTextProcessorRef textProcessor, SFData sequence);

static SFBoolean _SFApplyAlternateSubst(SFTextProcessorRef textProcessor, SFData alternateSubst);
static SFBoolean _SFApplyAlternateSetTable(SFTextProcessorRef textProcessor, SFData alternateSet);

static SFBoolean _SFApplyLigatureSubst(SFTextProcessorRef textProcessor, SFData ligatureSubst);
static SFBoolean _SFApplyLigatureSetTable(SFTextProcessorRef textProcessor, SFData ligatureSet);

SF_PRIVATE SFBoolean _SFApplySubstitutionSubtable(SFTextProcessorRef textProcessor, SFLookupType lookupType, SFData subtable)
{
    switch (lookupType) {
        case SFLookupTypeSingle:
            return _SFApplySingleSubst(textProcessor, subtable);

        case SFLookupTypeMultiple:
            return _SFApplyMultipleSubst(textProcessor, subtable);

        case SFLookupTypeAlternate:
            return _SFApplyAlternateSubst(textProcessor, subtable);

        case SFLookupTypeLigature:
            return _SFApplyLigatureSubst(textProcessor, subtable);

        case SFLookupTypeContext:
            return _SFApplyContextSubtable(textProcessor, subtable);

        case SFLookupTypeChainingContext:
            return _SFApplyChainContextSubtable(textProcessor, subtable);

        case SFLookupTypeExtension:
            return _SFApplyExtensionSubtable(textProcessor, subtable);

        case SFLookupTypeReverseChainingContext:
            return _SFApplyReverseChainSubst(textProcessor, subtable);
    }

    return SFFalse;
}

static SFBoolean _SFApplySingleSubst(SFTextProcessorRef textProcessor, SFData singleSubst)
{
    SFAlbumRef album = textProcessor->_album;
    SFLocatorRef locator = &textProcessor->_locator;
    SFUInt16 substFormat;

{'fraction_non_alphanumeric': 0.06546355272469923, 'fraction_numerical': 0.004246284501061571, 'mean_word_length': 4.851966873706004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '5421137', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1578, 'n_words': 428}