<commit_before>import Foundation
import MobileCoreServices
import UIKit


// MARK: - Pasteboard Helpers
//
extension UIPasteboard
{
    ///
    ///
    private struct StringOptions {
        static let RTFText = [NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType]
        static let RTFDText = [NSDocumentTypeDocumentAttribute: NSRTFDTextDocumentType]
        static let plainText = [NSDocumentTypeDocumentAttribute: NSPlainTextDocumentType]
    }

    ///
    ///
    private func unarchiveAttributedString(fromPasteboardCFType type: CFString, with options: [String: Any]) -> NSAttributedString? {
        guard let data = data(forPasteboardType: String(type)) else {
            return nil
        }

        return try? NSAttributedString(data: data, options: options, documentAttributes: nil)
    }


    ///
    ///
    func loadAttributedString() -> NSAttributedString? {
        if let string = aztecAttributedString {
            return string
        }

        if let string = RTFAttributedString {
            return string
        }

        if let string = RTFDAttributedString {
            return string
        }

        if let string = richTextAttributedString {
            return string
        }

        return plainTextAttributedString
    }

    ///
    ///
    private var RTFAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypeRTF, with: StringOptions.RTFText)
    }

    ///
    ///
    private var RTFDAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypeFlatRTFD, with: StringOptions.RTFDText)
    }

    ///
    ///
    private var richTextAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypeText, with: StringOptions.RTFText)
    }

    ///
    ///
    private var plainTextAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypePlainText, with: StringOptions.plainText)
    }


    ///
    ///
    private var aztecAttributedString: NSAttributedString? {
        guard let data = data(forPasteboardType: NSAttributedString.pastesboardUTI) else {
            return nil
        }

        return NSAttributedString.unarchive(with: data)
    }


//        let fullRange = stripped.rangeOfEntireString
//        stripped.removeAttribute(NSFontAttributeName, range: fullRange)
//        stripped.removeAttribute(NSStrikethroughStyleAttributeName, range: fullRange)
//        stripped.removeAttribute(NSUnderlineStyleAttributeName, range: fullRange)
}
<commit_msg>UIPasteboard+Helpers: Documenting Helper<commit_after>import Foundation
import MobileCoreServices
import UIKit


// MARK: - Pasteboard Helpers
//
extension UIPasteboard {

    /// Attempts to load the Pasteboard's contents into a NSAttributedString Instance, if possible.
    ///
    func loadAttributedString() -> NSAttributedString? {

        if let string = aztecAttributedString {
            return string
        }

        if let string = RTFAttributedString {
            return string
        }

        if let string = RTFDAttributedString {
            return string
        }

        if let string = richTextAttributedString {
            return string
        }

        return plainTextAttributedString
    }
}


// MARK: - Pasteboard Private Helpers
//
private extension UIPasteboard {

    /// Attempts to unarchive the Pasteboard's RTF contents into an Attributed String
    ///
    var RTFAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypeRTF, with: StringOptions.RTFText)
    }

    /// Attempts to unarchive the Pasteboard's RTFD contents into an Attributed String
    ///
    var RTFDAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypeFlatRTFD, with: StringOptions.RTFDText)
    }

    /// Attempts to unarchive the Pasteboard's Text contents into an Attributed String
    ///
    var richTextAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypeText, with: StringOptions.RTFText)
    }

    /// Attempts to unarchive the Pasteboard's Plain Text contents into an Attributed String
    ///
    var plainTextAttributedString: NSAttributedString? {
        return unarchiveAttributedString(fromPasteboardCFType: kUTTypePlainText, with: StringOptions.plainText)
    }

    /// Attempts to unarchive the Pasteboard's Aztec-Archived String
    ///
    var aztecAttributedString: NSAttributedString? {
        guard let data = data(forPasteboardType: NSAttributedString.pastesboardUTI) else {
            return nil
        }

        return NSAttributedString.unarchive(with: data)
    }

    // MARK: - Helpers

    /// String Initialization Options
    ///
    private struct StringOptions {
        static let RTFText = [NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType]
        static let RTFDText = [NSDocumentTypeDocumentAttribute: NSRTFDTextDocumentType]
        static let plainText = [NSDocumentTypeDocumentAttribute: NSPlainTextDocumentType]
    }

    /// Attempts to unarchive a Pasteboard's Entry into a NSAttributedString Instance.
    ///
    /// - Parameters:
    ///     - type: Pasteboard's Attribute Key
    ///     - options: Properties to be utilized during the NSAttributedString Initialization.
    ///
    /// - Returns: NSAttributed String with the contents of the specified Pasteboard entry, if any.
    ///
    private func unarchiveAttributedString(fromPasteboardCFType type: CFString, with options: [String: Any]) -> NSAttributedString? {
        guard let data = data(forPasteboardType: String(type)) else {
            return nil
        }

        return try? NSAttributedString(data: data, options: options, documentAttributes: nil)
    }
}

{'fraction_non_alphanumeric': 0.0732575886043751, 'fraction_numerical': 0.0, 'mean_word_length': 2.7831943553559975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4663896', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1579, 'n_words': 392}