<commit_before>﻿using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;

namespace StackExchange.Metrics
{
    /// <summary>
    /// Options used to customise how metrics are created.
    /// </summary>
    public class MetricSourceOptions : IOptions<MetricSourceOptions>
    {
        private static readonly NameTransformerDelegate s_defaultMetricNameTransformer = NameTransformers.Combine(NameTransformers.CamelToLowerSnakeCase, NameTransformers.Sanitize);
        private static readonly NameTransformerDelegate s_defaultTagNameTransformer = NameTransformers.Combine(NameTransformers.CamelToLowerSnakeCase, NameTransformers.Sanitize);
        private static readonly TagValueTransformerDelegate s_defaultTagValueTransformer = (_, value) => value.ToString().ToLowerInvariant();
        private static readonly ValidationDelegate s_defaultMetricNameValidator = MetricValidation.IsValidMetricName;
        private static readonly ValidationDelegate s_defaultTagNameValidator = MetricValidation.IsValidTagName;
        private static readonly ValidationDelegate s_defaultTagValueValidator = MetricValidation.IsValidTagValue;

        private NameTransformerDelegate _metricNameTransformer;
        private NameTransformerDelegate _tagNameTransformer;
        private TagValueTransformerDelegate _tagValueTransformer;
        private ValidationDelegate _metricNameValidator;
        private ValidationDelegate _tagNameValidator;
        private ValidationDelegate _tagValueValidator;

        /// <summary>
        /// Initializes a new instance of <see cref="MetricSourceOptions"/>.<commit_msg>Fix up tag value transformer<commit_after>﻿using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.RegularExpressions;

namespace StackExchange.Metrics
{
    /// <summary>
    /// Options used to customise how metrics are created.
    /// </summary>
    public class MetricSourceOptions : IOptions<MetricSourceOptions>
    {
        
        private static string SanitizeTag(string value)
        {
            if (string.IsNullOrEmpty(value)) return value;
            return s_tagValueSanitizer.Replace(value, "").ToLowerInvariant();
        }
        private static readonly Regex s_tagValueSanitizer = new Regex(@"[^-\w./]", RegexOptions.Compiled);
        private static readonly NameTransformerDelegate s_defaultMetricNameTransformer = NameTransformers.Combine(NameTransformers.CamelToLowerSnakeCase, NameTransformers.Sanitize);
        private static readonly NameTransformerDelegate s_defaultTagNameTransformer = NameTransformers.Combine(NameTransformers.CamelToLowerSnakeCase, NameTransformers.Sanitize);
        private static readonly TagValueTransformerDelegate s_defaultTagValueTransformer = (_, value) =>
        {
            if (value == null) return null;
            return s_tagValueSanitizer.Replace(value.ToString(), "").ToLowerInvariant();
        };
        private static readonly ValidationDelegate s_defaultMetricNameValidator = MetricValidation.IsValidMetricName;
        private static readonly ValidationDelegate s_defaultTagNameValidator = MetricValidation.IsValidTagName;
        private static readonly ValidationDelegate s_defaultTagValueValidator = MetricValidation.IsValidTagValue;

        private NameTransformerDelegate _metricNameTransformer;
        private NameTransformerDelegate _tagNameTransformer;
        private TagValueTransformerDelegate _tagValueTransformer;
        private ValidationDelegate _metricNameValidator;
        private ValidationDelegate _tagNameValidator;
        private ValidationDelegate _tagValueValidator;

        /// <summary>
        /// Initializes a new instance of <see cref="MetricSourceOptions"/>.
{'fraction_non_alphanumeric': 0.06317169069462647, 'fraction_numerical': 0.0, 'mean_word_length': 4.389830508474576, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '7242362', 'n_tokens_mistral': 898, 'n_tokens_neox': 881, 'n_words': 210}