Exemplo n.º 1
0
        public void SplitOnCharacter()
        {
            var str   = new StringSlice("hello cruel world!");
            var parts = str.Split(' ', 5);

            Assert.That(parts, Is.EqualTo(new[] {
                new StringSlice("hello"),
                new StringSlice("cruel"),
                new StringSlice("world!")
            }));
            parts = str.Split(' ', 2);
            Assert.That(parts, Is.EqualTo(new[] {
                new StringSlice("hello"),
                new StringSlice("cruel world!")
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extracts comma-separated string arguments from the StringArgument.
        /// </summary>
        public TempList8 <StringSlice> ExtractStringArgs()
        {
            TempList8 <StringSlice> args = default(TempList8 <StringSlice>);

            StringArgument.Split(s_CommaSplitter ?? (s_CommaSplitter = new StringUtils.ArgsList.Splitter()), StringSplitOptions.None, ref args);
            return(args);
        }
Exemplo n.º 3
0
        static public void CanSplitCSV()
        {
            string firstString = CSVString;

            StringSlice[] split = StringSlice.Split(firstString, new StringUtils.CSV.Splitter(true), StringSplitOptions.RemoveEmptyEntries);

            Assert.AreEqual(3, split.Length);
            Assert.AreEqual("Test", split[0].ToString());
            Assert.AreEqual("Test, with Comma", split[1].ToString());
            Assert.AreEqual("Quoted \"Test\", with Comma", split[2].ToString());
        }
Exemplo n.º 4
0
        static public void CanSplitOnLineBreak()
        {
            string firstString = MultiLineString;

            StringSlice[] split = StringSlice.Split(firstString, new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            Assert.AreEqual(3, split.Length);

            split = StringSlice.Split(firstString, new char[] { '\n', '\r' }, StringSplitOptions.None);

            Assert.AreEqual(5, split.Length);
        }
Exemplo n.º 5
0
            private bool InvokeMethod(object inThis, StringSlice inData, SplitResources inSplitResources)
            {
                if (m_Parameters.Length > 0)
                {
                    lock (inSplitResources.LockObj)
                    {
                        inSplitResources.ArgList.Clear();

                        if (m_RequiredParamCount == 1 && m_Parameters.Length == 1)
                        {
                            if (!StringParser.TryConvertTo(inData, m_Parameters[0].ParameterType, out m_MethodParams[0]))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            int providedArgCount = inData.Split(inSplitResources.Splitter, StringSplitOptions.None, inSplitResources.ArgList);
                            if (providedArgCount < m_RequiredParamCount || providedArgCount > m_Parameters.Length)
                            {
                                return(false);
                            }

                            for (int i = 0; i < providedArgCount; ++i)
                            {
                                if (!StringParser.TryConvertTo(inSplitResources.ArgList[i], m_Parameters[i].ParameterType, out m_MethodParams[i]))
                                {
                                    return(false);
                                }
                            }

                            for (int i = providedArgCount; i < m_Parameters.Length; ++i)
                            {
                                m_MethodParams[i] = m_DefaultParams[i];
                            }
                        }
                    }
                }

                try
                {
                    m_Method.Invoke(inThis, m_MethodParams);
                    return(true);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    return(false);
                }
            }
Exemplo n.º 6
0
        private IEnumerable <IRSRuntimeEntity> EnumerateEntityLinks(MultiReturn <IRSRuntimeEntity> inEntities, string inLinks, bool inbUseFirstLink)
        {
            using (PooledList <StringSlice> paths = PooledList <StringSlice> .Alloc())
            {
                int sliceCount = StringSlice.Split(inLinks, EntityLinkSplitChars, StringSplitOptions.None, paths);

                foreach (var entity in inEntities)
                {
                    IRSRuntimeEntity currentEntity = entity;
                    for (int i = 0; currentEntity != null && i < sliceCount - 1; ++i)
                    {
                        StringSlice path = paths[i];
                        currentEntity = currentEntity.Links?.EntityWithLink(path);
                    }

                    if (currentEntity != null)
                    {
                        var links = currentEntity.Links;
                        if (links == null)
                        {
                            continue;
                        }

                        if (inbUseFirstLink)
                        {
                            yield return(links.EntityWithLink(paths[sliceCount - 1]));
                        }
                        else
                        {
                            foreach (var linkedEntity in links.EntitiesWithLink(paths[sliceCount - 1]))
                            {
                                yield return(linkedEntity);
                            }
                        }
                    }
                }
            }
        }