Beispiel #1
0
        /// <summary>
        /// Url encoding some string
        /// </summary>
        /// <param name="value">target</param>
        /// <param name="encoding">using encode</param>
        /// <param name="upper">helix cast to upper</param>
        /// <returns>encoded string</returns>
        public static string UrlEncode(string value, Encoding encoding, bool upper)
        {
            StringBuilder result = new StringBuilder();

            byte[] data = encoding.GetBytes(value);
            int    len  = data.Length;

            for (int i = 0; i < len; i++)
            {
                int c = data[i];
                if (c < 0x80 && AllowedChars.IndexOf((char)c) != -1)
                {
                    result.Append((char)c);
                }
                else
                {
                    if (upper)
                    {
                        result.Append('%' + String.Format("{0:X2}", (int)data[i]));
                    }
                    else
                    {
                        result.Append('%' + String.Format("{0:x2}", (int)data[i]));
                    }
                }
            }
            return(result.ToString());
        }
Beispiel #2
0
        public static bool IsValidZeroFormat(string lowerCaseIntroducedNumber, int initialIndex, out int newIndex)
        {
            const string AllowedChars = ".e";

            newIndex = initialIndex;

            if (lowerCaseIntroducedNumber == null)
            {
                return(false);
            }

            if (lowerCaseIntroducedNumber[initialIndex] != '0')
            {
                return(true);
            }

            newIndex++;

            bool existNextChar = lowerCaseIntroducedNumber.Length > newIndex;

            if (!existNextChar)
            {
                return(true);
            }

            return(AllowedChars.IndexOf(lowerCaseIntroducedNumber[initialIndex + 1]) >= 0);
        }
Beispiel #3
0
        public static bool IsValidPointFormat(string lowerCaseIntroducedNumber, int index, out int incrementIndex)
        {
            const string AllowedChars = "0123456789";

            incrementIndex = 1;

            if (lowerCaseIntroducedNumber == null)
            {
                return(false);
            }

            if (lowerCaseIntroducedNumber[index] != '.')
            {
                return(true);
            }

            bool pointOnFirstPosition = index == 0;
            bool existNextChar        = lowerCaseIntroducedNumber.Length > index + 1;

            if (pointOnFirstPosition || !existNextChar)
            {
                return(false);
            }

            incrementIndex++;

            bool nextCharIsNumber    = AllowedChars.IndexOf(lowerCaseIntroducedNumber[index + 1]) >= 0;
            bool noExistAnotherPoint = lowerCaseIntroducedNumber.IndexOf('.', index + 1) == -1;

            return(nextCharIsNumber && noExistAnotherPoint);
        }
Beispiel #4
0
        public static bool IsValidEFormat(string lowerCaseIntroducedNumber, int index, out int incrementIndex)
        {
            const int    OnlyNumbers  = 2;
            const string AllowedChars = "-+0123456789";

            incrementIndex = 1;

            if (lowerCaseIntroducedNumber == null)
            {
                return(false);
            }

            if (lowerCaseIntroducedNumber[index] != 'e')
            {
                return(true);
            }

            bool charEOnFirstPosition = index == 0;
            bool existNextChar        = lowerCaseIntroducedNumber.Length > index + incrementIndex;

            if (charEOnFirstPosition || !existNextChar)
            {
                return(false);
            }

            bool existAnotherE     = lowerCaseIntroducedNumber.IndexOf('e', index + incrementIndex) >= 0;
            bool existPointInFront = lowerCaseIntroducedNumber.IndexOf('.', index + incrementIndex) >= 0;

            if (existAnotherE || existPointInFront)
            {
                return(false);
            }

            bool nextCharIsNumber = AllowedChars.IndexOf(lowerCaseIntroducedNumber[index + incrementIndex], OnlyNumbers) != -1;

            if (nextCharIsNumber)
            {
                incrementIndex++;
                return(true);
            }

            bool isMinusOrPlus = AllowedChars.IndexOf(lowerCaseIntroducedNumber[index + incrementIndex], 0, OnlyNumbers) != -1;

            if (!isMinusOrPlus)
            {
                return(false);
            }

            incrementIndex++;

            existNextChar = lowerCaseIntroducedNumber.Length > index + incrementIndex;

            if (!existNextChar)
            {
                return(false);
            }

            nextCharIsNumber = AllowedChars.IndexOf(lowerCaseIntroducedNumber[index + incrementIndex], OnlyNumbers) != -1;

            incrementIndex++;

            return(nextCharIsNumber);
        }