<commit_before>//
//  Translation.swift
//  Ilion
//
//  Created by <NAME> on 2018. 10. 10..
//  Copyright © 2018. <NAME>. All rights reserved.
//

import Foundation

enum Translation {
    case `static`(String)
    case `dynamic`(LocalizedFormat)
    
    func toString() -> String {
        switch self {
        case .static(let text): return text
        case .dynamic(let format):
            let config = format.toStringsDictEntry()
            let nsFormat = format.baseFormat as NSString
            let locFormat = nsFormat.perform(NSSelectorFromString("_copyFormatStringWithConfiguration:"), with: config)
                .takeUnretainedValue()
            return locFormat as! String
        }
    }
}

extension Translation {
    func addingStartEndMarkers() -> Translation {
        switch self {
        case .static(let text): return .static("[\(text)]")
        case .dynamic(let format): return .dynamic(format.prepending("[").appending("]"))
        }
    }
    
    func applyingPseudoLocalization() -> Translation {
        switch self {
        case .static(let text):
            return .static(text.applyingPseudoLanguageTransformation())
            
        case .dynamic(let format):
            let transformedFormat = format.applyingTransform { slices in
                slices.map { $0.applyingPseudoLanguageTransformation() }
            }
            return .dynamic(transformedFormat)
        }
    }
    
    func simulatingExpansion(by factor: Double) -> Translation {
        func paddingText(forLength length: Int) -> String {
            let growth = Int(floor(Double(length) * factor)) - length
            let pattern = "lorem ipsum dolor sit amet consectetur adipiscing elit "
            let paddingSource = String(repeating: pattern, count: (growth / pattern.count) + 1)
            let padding = paddingSource[paddingSource.startIndex ..< paddingSource.index(paddingSource.startIndex, offsetBy: growth)]
            return "$\(padding)$"
        }
        
        switch self {
        case .static(let text):
            let padding = paddingText(forLength: text.count)
            return .static(text.appending(padding))<commit_msg>Switched to a narrower delimiter<commit_after>//
//  Translation.swift
//  Ilion
//
//  Created by <NAME> on 2018. 10. 10..
//  Copyright © 2018. <NAME>. All rights reserved.
//

import Foundation

enum Translation {
    case `static`(String)
    case `dynamic`(LocalizedFormat)
    
    func toString() -> String {
        switch self {
        case .static(let text): return text
        case .dynamic(let format):
            let config = format.toStringsDictEntry()
            let nsFormat = format.baseFormat as NSString
            let locFormat = nsFormat.perform(NSSelectorFromString("_copyFormatStringWithConfiguration:"), with: config)
                .takeUnretainedValue()
            return locFormat as! String
        }
    }
}

extension Translation {
    func addingStartEndMarkers() -> Translation {
        switch self {
        case .static(let text): return .static("[\(text)]")
        case .dynamic(let format): return .dynamic(format.prepending("[").appending("]"))
        }
    }
    
    func applyingPseudoLocalization() -> Translation {
        switch self {
        case .static(let text):
            return .static(text.applyingPseudoLanguageTransformation())
            
        case .dynamic(let format):
            let transformedFormat = format.applyingTransform { slices in
                slices.map { $0.applyingPseudoLanguageTransformation() }
            }
            return .dynamic(transformedFormat)
        }
    }
    
    func simulatingExpansion(by factor: Double) -> Translation {
        func paddingText(forLength length: Int) -> String {
            let growth = Int(floor(Double(length) * factor)) - length
            let pattern = "lorem ipsum dolor sit amet consectetur adipiscing elit "
            let paddingSource = String(repeating: pattern, count: (growth / pattern.count) + 1)
            let padding = paddingSource[paddingSource.startIndex ..< paddingSource.index(paddingSource.startIndex, offsetBy: growth)]
            return "{\(padding)}"
        }
        
        switch self {
        case .static(let text):
            let padding = paddingText(forLength: text.count)
            return .static(text.appending(padding))
{'fraction_non_alphanumeric': 0.10377142857142857, 'fraction_numerical': 0.0064, 'mean_word_length': 2.2247605011053797, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 2, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6475224', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1126, 'n_words': 297}