<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Evbpc.Framework.Utilities
{
    public class IpHelpers
    {
        public static string IpToHex(string ip)
        {
            if (ip.Contains('.'))
            {
                return Ip4ToHex(ip);
            }
            else
            {
                return Ip6ToHex(ip);
            }
        }

        public static string Ip4ToHex(string ip)
        {
            return Ip6ToHex(Ip4ToIp6(ip));
        }

        public static string Ip4ToIp6(string ip)
        {
            string[] ipv4Strings = ip.Split('.');

            if (ipv4Strings.Length == 4)
            {
                string[] ipv4Bytes = new string[4];

                int i = 0;
                foreach (string ipv4String in ipv4Strings)
                {
                    ipv4Bytes[i] = Hex(ipv4String).PadLeft(2, '0');
                    i++;
                }

                return "::" + ipv4Bytes[0] + ipv4Bytes[1] + ":" + ipv4Bytes[2] + ipv4Bytes[3];
            }

            throw new ArgumentException($"The provided IP of {ip} is not a valid IP address.");
        }

        public static string Hex(string input)
        {
            string result = "";

            for (int i = input.Length / 2 - 1; i >= 0; i++)
            {
                result += Convert.ToByte(input.Substring(i * 2, 2), 16) + result;
            }

            return result;
        }

        public static string Ip6ToHex(string ip)
        {
            string result = "0x";

            ip = ExpandIp6(ip);<commit_msg>Replaced hex conversion for IP helpers.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Evbpc.Framework.Utilities
{
    public class IpHelpers
    {
        public static string IpToHex(string ip)
        {
            if (ip.Contains('.'))
            {
                return Ip4ToHex(ip);
            }
            else
            {
                return Ip6ToHex(ip);
            }
        }

        public static string Ip4ToHex(string ip)
        {
            return Ip6ToHex(Ip4ToIp6(ip));
        }

        public static string Ip4ToIp6(string ip)
        {
            string[] ipv4Strings = ip.Split('.');

            if (ipv4Strings.Length == 4)
            {
                string[] ipv4Bytes = StringArrayToHexArray(ip.Split('.'));

                return "::" + ipv4Bytes[0] + ipv4Bytes[1] + ":" + ipv4Bytes[2] + ipv4Bytes[3];
            }

            throw new ArgumentException($"The provided IP of {ip} is not a valid IP address.");
        }

        public static string[] StringArrayToHexArray(string[] input)
        {
            return input.ToList().Select(x => Convert.ToByte(x, 0x10).ToString("x")).ToArray();
        }

        public static string Ip6ToHex(string ip)
        {
            string result = "0x";

            ip = ExpandIp6(ip);
{'fraction_non_alphanumeric': 0.10865257595772787, 'fraction_numerical': 0.021136063408190225, 'mean_word_length': 1.4526315789473685, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, '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': '3503776', 'n_tokens_mistral': 916, 'n_tokens_neox': 879, 'n_words': 202}