<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Text.RegularExpressions;

namespace DiscordBot
{
    public enum JsonFile
    {
        Settings,
        Commands,
        Roles,
        Achievements,
        PayWork,
        UserSettings
    }

    class SettingsHandler
    {
        public static Dictionary<string, string[]> SettingLine = new Dictionary<string, string[]>();

        private static string[] LoadValue(string path, JsonFile file)
        {
            string[] split = path.Split('/');
            int index = 0;
            List<string> keys = new List<string>();

            JObject data = JsonConvert.DeserializeObject<JObject>(GetJsonString(file.ToString()));

            while (index < split.Length)
            {
                string element = split[index];

                object value = data[element].Value<object>();

                if (value.GetType() == typeof(JValue))
                {
                    keys.Add(value.ToString());
                    break;
                }
                else if (value.GetType() == typeof(JObject))
                {
                    JObject v = value as JObject;
                    data = v;
                    index++;
                }
                else if (value.GetType() == typeof(JArray))
                {
                    keys.Add(value.ToString());
                    break;
                }
            }

            return keys.ToArray();
        }

        public static string[] LoadValueStringArray(string path, JsonFile file)
        {
            return StringToArray(LoadValue(path, file)[0]);
        }

        public static char LoadValueChar(string path, JsonFile file)
        {
            return char.Parse(LoadValue(path, file)[0]);
        }

        public static string LoadValueString(string path, JsonFile file)
        {
            return LoadValue(path, file)[0];
        }

        public static int LoadValueInt(string path, JsonFile file)
        {
            return int.Parse(LoadValue(path, file)[0]);
        }

        public static ulong LoadValueUlong(string path, JsonFile file)
        {
            return ulong.Parse(LoadValue(path, file)[0]);
        }

        public static float LoadValueFloat(string path, JsonFile file)
        {
            return float.Parse(LoadValue(path, file)[0]);
        }

        public static bool LoadValueBool(string path, JsonFile file)
        {
            return LoadValue(path, file)[0] != "0";
        }

        public static string[] StringToArray(string value)
        {
            List<string> values = new List<string>();
            string[] split = value.Split(new string[] {"\","}, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < split.Length; i++)
            {
                string newS = split[i];

                newS = newS.Replace("\"", "").Replace(",", "");
                //newS = Regex.Replace(newS, @"\s", "");
                newS = Regex.Replace(newS, @"\r", "");
                newS = Regex.Replace(newS, @"\n", "");
                newS = Regex.Replace(newS, @"\t", "");
                newS.Trim();
                if (string.IsNullOrWhiteSpace(newS)) continue;
                values.Add(i == 0 ? newS.Substring(1, newS.Length - 1).Trim() : i == split.Length - 1 ? newS.Substring(0, newS.Length - 1).Trim() : newS.Trim());
            }

            //Console.WriteLine("Length of: " + values.Count);
            return values.ToArray();
        }<commit_msg>Changed JSON string array method to actually utilize JSON parsing instead of relying on janky regex...<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Text.RegularExpressions;

namespace DiscordBot
{
    public enum JsonFile
    {
        Settings,
        Commands,
        Roles,
        Achievements,
        PayWork,
        UserSettings
    }

    class SettingsHandler
    {
        public static Dictionary<string, string[]> SettingLine = new Dictionary<string, string[]>();

        private static string[] LoadValue(string path, JsonFile file)
        {
            string[] split = path.Split('/');
            int index = 0;
            List<string> keys = new List<string>();

            JObject data = JsonConvert.DeserializeObject<JObject>(GetJsonString(file.ToString()));

            while (index < split.Length)
            {
                string element = split[index];

                object value = data[element].Value<object>();

                if (value.GetType() == typeof(JValue))
                {
                    keys.Add(value.ToString());
                    break;
                }
                else if (value.GetType() == typeof(JObject))
                {
                    JObject v = value as JObject;
                    data = v;
                    index++;
                }
                else if (value is JArray)
                {
                    foreach (JValue val in (value as JArray))
                    {
                        keys.Add(val.ToString());
                    }

                    break;
                }
            }

            return keys.ToArray();
        }

        public static string[] LoadValueStringArray(string path, JsonFile file)
        {
            return LoadValue(path, file);
        }

        public static char LoadValueChar(string path, JsonFile file)
        {
            return char.Parse(LoadValue(path, file)[0]);
        }

        public static string LoadValueString(string path, JsonFile file)
        {
            return LoadValue(path, file)[0];
        }

        public static int LoadValueInt(string path, JsonFile file)
        {
            return int.Parse(LoadValue(path, file)[0]);
        }

        public static ulong LoadValueUlong(string path, JsonFile file)
        {
            return ulong.Parse(LoadValue(path, file)[0]);
        }

        public static float LoadValueFloat(string path, JsonFile file)
        {
            return float.Parse(LoadValue(path, file)[0]);
        }

        public static bool LoadValueBool(string path, JsonFile file)
        {
            return LoadValue(path, file)[0] != "0";
        }

       /* public static string[] StringToArray(string value)
        {
            List<string> values = new List<string>();
            string[] split = value.Split(new string[] {"\","}, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < split.Length; i++)
            {
                string newS = split[i];

                newS = newS.Replace("\"", "").Replace(",", "");
                //newS = Regex.Replace(newS, @"\s", "");
                newS = Regex.Replace(newS, @"\r", "");
                newS = Regex.Replace(newS, @"\n", "");
                newS = Regex.Replace(newS, @"\t", "");
                newS.Trim();
                if (string.IsNullOrWhiteSpace(newS)) continue;
                values.Add(i == 0 ? newS.Substring(1, newS.Length - 1).Trim() : i == split.Length - 1 ? newS.Substring(0, newS.Length - 1).Trim() : newS.Trim());
            }

            //Console.WriteLine("Length of: " + values.Count);
            return values.ToArray();
        }*/
{'fraction_non_alphanumeric': 0.11931818181818182, 'fraction_numerical': 0.004193722943722944, 'mean_word_length': 1.5741643454038998, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, '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': '304873', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1903, 'n_words': 463}