<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2008 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package flex.utils
{

import flash.utils.describeType;

import text.model.ICharacterAttributes;
import text.model.IContainerAttributes;
import text.model.IParagraphAttributes;
import text.model.LeafElement;
import text.model.Paragraph;
import text.model.TextFlow;

[ExcludeClass]

/**
 *  @private
 */
public class TextUtil
{
    include "../core/Version.as";
        
    //--------------------------------------------------------------------------
    //
    //  Class constants
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  An Array of the names of all text attributes, in no particular order.
     */
    public static var ALL_ATTRIBUTE_NAMES:Array = [];

    /**
     *  @private
     *  Maps the name of a text attribute to what kind of attribute it is.
     *  For example,
     *  paddingLeft -> container
     *  marginLeft -> paragraph
     *  fontSize -> character
     */
    public static var ATTRIBUTE_MAP:Object = {};
    
    /**
     *  @private
     */
    public static const CONTAINER:String = "container";
    
    /**
     *  @private
     */
    public static const PARAGRAPH:String = "paragraph";

    /**
     *  @private
     */
    public static const CHARACTER:String = "character";

    //--------------------------------------------------------------------------
    //
    //  Class initialization
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  Initializes the ATTRIBUTE_MAP by using describeType()
     *  to enumerate the properties of the IContainerAttribues,
     *  IParagraphAttributes, and ICharacterAttributes interfaces.
     */
    private static function initClass():void
    {
        var type:XML;
        var name:String;

        type = describeType(IContainerAttributes);
        for each (name in type.factory.accessor.@name)
        {
            ALL_ATTRIBUTE_NAMES.push(name);
            ATTRIBUTE_MAP[name] = CONTAINER;
        }
        
        type = describeType(IParagraphAttributes);
        for each (name in type.factory.accessor.@name)
        {
            ALL_ATTRIBUTE_NAMES.push(name);
            ATTRIBUTE_MAP[name] = PARAGRAPH;
        }
       
        type = describeType(ICharacterAttributes);
        for each (name in type.factory.accessor.@name)
        {
            ALL_ATTRIBUTE_NAMES.push(name);
            ATTRIBUTE_MAP[name] = CHARACTER;
        }
    }

    initClass();

    //--------------------------------------------------------------------------
    //
    //  Class methods
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    public static function extractText(textFlow:TextFlow):String
    {
        var text:String = "";
        
        var leaf:LeafElement = textFlow.getFirstLeaf();
        while (leaf)
        {
            var p:Paragraph = leaf.getParagraph();
            for (;;)
            {
                text += leaf.text;
                leaf = leaf.getNextLeaf(p);
                if (!leaf)
                    break;
            }
            leaf = p.getLastLeaf().getNextLeaf(null);
            if (leaf)
                text += "\n";
        }

        return text;
    }
}

}
<commit_msg>Transferred from the Adobe Open Source Subversion Repository<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2008 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package flex.utils
{

import flash.utils.describeType;

import text.model.ICharacterFormat;
import text.model.IContainerFormat;
import text.model.IParagraphFormat;
import text.model.LeafElement;
import text.model.Paragraph;
import text.model.TextFlow;

[ExcludeClass]

/**
 *  @private
 */
public class TextUtil
{
    include "../core/Version.as";
        
    //--------------------------------------------------------------------------
    //
    //  Class constants
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  An Array of the names of all text formats, in no particular order.
     */
    public static var ALL_FORMAT_NAMES:Array = [];

    /**
     *  @private
     *  Maps the name of a text attribute to what kind of attribute it is.
     *  For example,
     *  paddingLeft -> container
     *  marginLeft -> paragraph
     *  fontSize -> character
     */
    public static var FORMAT_MAP:Object = {};
    
    /**
     *  @private
     */
    public static const CONTAINER:String = "container";
    
    /**
     *  @private
     */
    public static const PARAGRAPH:String = "paragraph";

    /**
     *  @private
     */
    public static const CHARACTER:String = "character";

    //--------------------------------------------------------------------------
    //
    //  Class initialization
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  Initializes the FORMAT_MAP by using describeType()
     *  to enumerate the properties of the IContainerFormat,
     *  IParagraphFormat, and ICharacterFormat interfaces.
     */
    private static function initClass():void
    {
        var type:XML;
        var name:String;

        type = describeType(IContainerFormat);
        for each (name in type.factory.accessor.@name)
        {
            ALL_FORMAT_NAMES.push(name);
            FORMAT_MAP[name] = CONTAINER;
        }
        
        type = describeType(IParagraphFormat);
        for each (name in type.factory.accessor.@name)
        {
            ALL_FORMAT_NAMES.push(name);
            FORMAT_MAP[name] = PARAGRAPH;
        }
       
        type = describeType(ICharacterFormat);
        for each (name in type.factory.accessor.@name)
        {
            ALL_FORMAT_NAMES.push(name);
            FORMAT_MAP[name] = CHARACTER;
        }
    }

    initClass();

    //--------------------------------------------------------------------------
    //
    //  Class methods
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    public static function extractText(textFlow:TextFlow):String
    {
        var text:String = "";
        
        var leaf:LeafElement = textFlow.getFirstLeaf();
        while (leaf)
        {
            var p:Paragraph = leaf.getParagraph();
            for (;;)
            {
                text += leaf.text;
                leaf = leaf.getNextLeaf(p);
                if (!leaf)
                    break;
            }
            leaf = p.getLastLeaf().getNextLeaf(null);
            if (leaf)
                text += "\n";
        }

        return text;
    }
}

}

{'fraction_non_alphanumeric': 0.24873501997336883, 'fraction_numerical': 0.0010652463382157123, 'mean_word_length': 1.1313847900113507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7316147', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1842, 'n_words': 435}