Ejemplo n.º 1
0
        // if at exit of function, idx < 0, the line could not be parsed
        private Tuple <int, int> parse_relative_part(string l, syntax_info.relative_pos part, ref int idx)
        {
            if (part.is_end_of_string)
            {
                // return remainder of the string
                int at = idx;
                idx = l.Length;
                return(new Tuple <int, int>(at, l.Length - at));
            }

            int start = -1, end = -1;

            if (part.start >= 0)
            {
                start = part.start;
            }
            else
            {
                if (idx >= l.Length)
                {
                    // passed the end of string
                    return(null);
                }

                start = l.IndexOf(part.start_str, idx);
                idx   = start >= 0 ? start + part.start_str.Length : -1;
                if (start >= 0)
                {
                    start += part.start_str.Length;
                }
            }

            if (idx >= 0)
            {
                if (part.len >= 0)
                {
                    end = start + part.len;
                    idx = end;
                }
                else
                {
                    if (part.end_str != null)
                    {
                        end = l.IndexOf(part.end_str, idx);
                    }
                    else
                    {
                        end = l.Length;
                        if (part.start_str != null)
                        {
                            start -= part.start_str.Length;
                        }
                    }
                    idx = end >= 0 ? end + (part.end_str != null ? part.end_str.Length : 0) : -1;
                }
            }

            return((start < l.Length && end <= l.Length) ? new Tuple <int, int>(start, end - start) : null);
        }
Ejemplo n.º 2
0
        // if at exit of function, idx < 0, the line could not be parsed
        private Tuple <int, int> parse_relative_part(string l, syntax_info.relative_pos part, ref int idx)
        {
            if (part.is_end_of_string)
            {
                // return remainder of the string
                int at = idx;
                idx = l.Length;
                //return new Tuple<int, int>(at, l.Length - at);
                // 1.8.4+ - this way, I can merge a consecutive line into this one
                return(new Tuple <int, int>(at, -1));
            }

            int start = -1, end = -1;

            if (part.start >= 0)
            {
                start = part.start;
            }
            else
            {
                if (idx >= l.Length)
                {
                    // passed the end of string
                    return(null);
                }

                start = l.IndexOf(part.start_str, idx);
                idx   = start >= 0 ? start + part.start_str.Length : -1;
                if (start >= 0)
                {
                    start += part.start_str.Length;
                }
            }

            if (idx >= 0)
            {
                if (part.len >= 0)
                {
                    end = start + part.len;
                    idx = end;
                }
                else
                {
                    if (part.end_str != null)
                    {
                        // 1.8.12 - care about min chars
                        end = l.IndexOf(part.end_str, idx + part.min_chars);
                    }
                    else
                    {
                        end = l.Length;
                        if (part.start_str != null)
                        {
                            start -= part.start_str.Length;
                        }
                    }
                    idx = end >= 0 ? end + (part.end_str != null ? part.end_str.Length : 0) : -1;
                }
            }

            return((start < l.Length && end <= l.Length) ? new Tuple <int, int>(start, end - start) : null);
        }