Exemple #1
0
        public static string[]  GetWordArray(string bufferToManage, char [] separatorArray)
        {
            if (bufferToManage == null)
            {
                throw new NolmeArgumentNullException();
            }
            if (separatorArray == null)
            {
                throw new NolmeArgumentNullException();
            }

            string[] ValueArray;
            string[] ValueArrayReturned;

            if (!StringUtility.IsValid(bufferToManage))
            {
                ValueArray = new string [0];
                return(ValueArray);
            }

            // This operation can return String.empty elements, scan & compute real string
            ValueArray = bufferToManage.Split(separatorArray);

            int i, iNullCounter = 0;

            for (i = 0; i < ValueArray.Length; i++)
            {
                if (!StringUtility.IsValid(ValueArray[i]))
                {
                    iNullCounter++;
                }
            }

            // Save new array
            int Offset = 0;

            ValueArrayReturned = new string [ValueArray.Length - iNullCounter];
            for (i = 0; i < ValueArray.Length; i++)
            {
                if (!StringUtility.IsValid(ValueArray[i]))
                {
                    // Don' save this element
                }
                else
                {
                    ValueArrayReturned [Offset] = ValueArray[i];
                    Offset++;
                }
            }
            return(ValueArrayReturned);
        }
Exemple #2
0
        static private string CreateMessage(int badValue, int minimumValue, int maximumValue, string additionalText)
        {
            string TemporaryBuffer;

            if (StringUtility.IsValid(additionalText))
            {
                TemporaryBuffer = String.Format(CultureInfo.InvariantCulture, "Nolmë Exception : BAD value '{0}' in [{1}..{2}] <{3}>", badValue.ToString(CultureInfo.InvariantCulture), minimumValue, maximumValue, additionalText);
            }
            else
            {
                TemporaryBuffer = String.Format(CultureInfo.InvariantCulture, "Nolmë Exception : BAD value '{0}' in [{1}..{2}]", badValue.ToString(CultureInfo.InvariantCulture), minimumValue, maximumValue);
            }
            return(TemporaryBuffer);
        }
Exemple #3
0
        static private string CreateMessage(string fullFileName, string additionalText)
        {
            if (fullFileName == null)
            {
                throw new NolmeArgumentNullException();
            }

            string TemporaryBuffer;

            if (StringUtility.IsValid(additionalText))
            {
                TemporaryBuffer = String.Format(CultureInfo.InvariantCulture, "Nolmë Exception : File NOT found '{0}' <{1}>", fullFileName, additionalText);
            }
            else
            {
                TemporaryBuffer = String.Format(CultureInfo.InvariantCulture, "Nolmë Exception : File NOT found '{0}'", fullFileName);
            }
            return(TemporaryBuffer);
        }
Exemple #4
0
        /// <summary>
        /// Convert a string to an array of words (use space & tabulation as separator)
        /// Quotes are managed here "word0 word1" will be 1 parameter
        /// </summary>
        public static string[]  GetWordArray2(string bufferToManage)
        {
            if (bufferToManage == null)
            {
                throw new NolmeArgumentNullException();
            }

            string[] ValueArray;
            int      ReadIndex, QuoteStart, QuoteEnd, NoQuoteEnd;
            int      SpaceAndTab;
            string   TemporaryString;

            char[]    SeparatorArray        = { ' ', (char)0x09 };
            ArrayList LocalElementArrayList = new ArrayList();

            if (!StringUtility.IsValid(bufferToManage))
            {
                ValueArray = new string [0];
                return(ValueArray);
            }

            // Check a quick case with no string inside
            QuoteStart = bufferToManage.IndexOf('\"');
            if (QuoteStart == -1)
            {
                // No string using quotes, only separated by space or tab
                ValueArray = StringUtility.GetWordArray(bufferToManage);
            }
            else
            {
                // convert bufferToManage to string[]
                ReadIndex = 0;
                while (ReadIndex < bufferToManage.Length)
                {
                    if (bufferToManage [ReadIndex] == '\"')
                    {
                        // separated by quotes, get end of quotes to retrieve datas
                        QuoteEnd = bufferToManage.IndexOf('\"', ReadIndex + 1);
                        if (QuoteEnd == -1)
                        {
                            QuoteEnd = bufferToManage.Length;
                        }
                        TemporaryString = bufferToManage.Substring(ReadIndex + 1, QuoteEnd - (ReadIndex + 1));

                        // Skip element found
                        ReadIndex += TemporaryString.Length + 2;                                // Add one to skip 2 quotes
                    }
                    else
                    {
                        // Not using quotes, only separated by space or tab
                        NoQuoteEnd = bufferToManage.IndexOfAny(SeparatorArray, ReadIndex + 1);
                        if (NoQuoteEnd == -1)
                        {
                            NoQuoteEnd = bufferToManage.Length;
                        }
                        TemporaryString = bufferToManage.Substring(ReadIndex, NoQuoteEnd - (ReadIndex));

                        // Skip element found
                        ReadIndex += TemporaryString.Length;
                    }

                    // Skip spaces & tabs
                    SpaceAndTab = ReadIndex;
                    while (SpaceAndTab < bufferToManage.Length)
                    {
                        if ((bufferToManage [SpaceAndTab] == ' ') || (bufferToManage [SpaceAndTab] == 0x09))
                        {
                            SpaceAndTab++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    ReadIndex = SpaceAndTab;

                    // Add element
                    LocalElementArrayList.Add(TemporaryString);
                }

                // Convert ArrayList to string[]
                ValueArray = new string [LocalElementArrayList.Count];
                for (int i = 0; i < LocalElementArrayList.Count; i++)
                {
                    ValueArray [i] = ((string)LocalElementArrayList[i]);
                }
            }
            return(ValueArray);
        }