YAXLib.StringUtils.SplitPathNamespaceSafe C# (CSharp) Method

SplitPathNamespaceSafe() public static method

Splits a string at each instance of a '/' except where such slashes are within {}.
public static SplitPathNamespaceSafe ( this value ) : IEnumerable
value this The string to split
return IEnumerable
        public static IEnumerable<string> SplitPathNamespaceSafe(this string value)
        {
            int bracketCount = 0;
            int lastStart = 0;
            string temp = value;

            if (value.Length <= 1)
            {
                yield return value;
                yield break;
            }

            for(int i = 0; i < temp.Length; i++)
            {
                if (temp[i] == '{')
                    bracketCount++;
                else if (temp[i] == '}')
                    bracketCount--;
                else if (temp[i] == '/')
                {
                    if (bracketCount == 0)
                    {
                        yield return temp.Substring(lastStart, i - lastStart);
                        lastStart = i + 1;
                    }
                }
                else continue;
            }

            if (lastStart <= temp.Length - 1)
                yield return temp.Substring(lastStart);
        }