Exemple #1
0
        /// <summary>
        /// Static method which Validate the input Expression
        /// </summary>
        /// <param name="expression">
        /// Expression to validate
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool ValidateExpression(string expression)
        {
            if (expression.Length == 0)
            {
                return(false);
            }

            expression = expression.Trim();
            expression = expression.Replace(" ", string.Empty);
            while (expression.IndexOf("--", StringComparison.Ordinal) > -1
                   | expression.IndexOf("++", StringComparison.Ordinal) > -1
                   | expression.IndexOf("^^", StringComparison.Ordinal) > -1
                   | expression.IndexOf("xx", StringComparison.Ordinal) > -1)
            {
                expression = expression.Replace("--", "-");
                expression = expression.Replace("++", "+");
                expression = expression.Replace("^^", "^");
                expression = expression.Replace("xx", "x");
            }

            const string ValidChars = "+-x1234567890^";

            bool result = true;

            foreach (char c in expression)
            {
                if (ValidChars.IndexOf(c) == -1)
                {
                    result = false;
                }
            }

            return(result);
        }
Exemple #2
0
 protected virtual bool IsValid(string path)
 {
     foreach (var c in path)
     {
         if (!ValidChars.Contains(c))
         {
             return(false);
         }
     }
     return(true);
 }
 private bool MatchWithChars(ref Token token)
 {
     foreach (var c in token.ValueAsSpan)
     {
         if (!ValidChars.Contains(c))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #4
0
        /// <summary>
        /// Normaliza un nombre de archivo
        /// </summary>
        public static string Normalize(string fileName, int length, bool withAccents = true)
        {
            const string ValidChars    = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .-,";
            const string WithAccent    = "áéíóúàèìòùÁÉÍÓÚÀÈÌÒÙ";
            const string WithOutAccent = "aeiouaeiouAEIOUAEIOU";
            string       target        = "";

            // Normaliza el nombre
            if (!string.IsNullOrEmpty(fileName))
            {
                // Normaliza el nombre de archivo
                foreach (char chr in fileName)
                {
                    if (chr == '\\' || chr == '/')
                    {
                        target += "_";
                    }
                    else if (!withAccents && WithAccent.IndexOf(chr) >= 0)
                    {
                        target += WithOutAccent[WithAccent.IndexOf(chr)];
                    }
                    else if (ValidChars.IndexOf(chr) >= 0)
                    {
                        target += chr;
                    }
                }
                // Limpia los espacios
                target = target.TrimIgnoreNull();
                // Quita los puntos iniciales
                while (target.Length > 0 && target[0] == '.')
                {
                    target = target.Substring(1);
                }
                // Obtiene los n primeros caracteres del nombre de archivo
                if (length > 0 && target.Length > length)
                {
                    target = target.Substring(0, length);
                }
            }
            // Devuelve la cadena de salida
            return(target);
        }
Exemple #5
0
    /// <summary>
    /// Sets the valid words property to all words that are valid.
    /// </summary>
    internal static IEnumerator Init(this TextAsset words)
    {
        global::Init.isFirstToGenerate = false;

        // If the method has run at least once, we do not need to initalize this again.
        if (ValidWords != null)
        {
            yield break;
        }

        ValidChars    = Enum.GetNames(typeof(ButtonType)).GetAllChars();
        ValidAlphabet = ValidChars.Join("").Distinct().OrderBy(c => c).Join("");
        Colors        = Enum.GetValues(typeof(ButtonType)).Cast <ButtonType>().IterateColors();

        yield return(words.StartThread());

        if (Application.isEditor)
        {
            var thread = new Thread(() => Log());
            thread.Start();
        }
    }
Exemple #6
0
    /// <summary>
    /// Logs all information about the variables.
    /// </summary>
    private static void Log()
    {
        Debug.LogWarningFormat("Log method initalized. Dumping all variables... Make sure that you only receive at most 430 warnings! (Press the warning icon in the top-right part of the console to hide this logging!)");

        for (int i = 0; i < ValidWords.Length; i++)
        {
            Debug.LogWarningFormat("{0}: {1}.", i, ValidWords[i].Join(", "));
        }

        Debug.LogWarningFormat("Valid alphabet: {0}.", ValidAlphabet.Join(", "));
        Debug.LogWarningFormat("Valid character sequence: {0}.", ValidChars.Join(", "));

        Debug.LogWarningFormat("The shortest words are: {0}.", GetShortest().Join(", "));
        Debug.LogWarningFormat("The longest words are: {0}.", GetLongest().Join(", "));

        Debug.LogWarningFormat("The smallest length of a given index is: {0}", GetShortestLength());
        Debug.LogWarningFormat("The longest length of a given index is: {0}", GetLongestLength());

        Debug.LogWarningFormat("The indexes that don't meet the required {0} length are: {1}", MinAcceptableWordSet, ValidWords.Where(a => a.Length < MinAcceptableWordSet).Select(a => Array.IndexOf(ValidWords, a)).Join(", "));

        Debug.LogWarningFormat("The amount of distinct to total words are: {0}/{1}.", GetCount(distinct: true), GetCount(distinct: false));
        Debug.LogWarningFormat("The words that are completely unique are: {0}.", ValidDistinctWords.GroupBy(x => x).Where(g => g.Count() == 1).Select(y => y.Key).Join(", "));
    }