예제 #1
0
        public static LineLocation ToLineLocation(this int position, string context)
        {
            if (position > context.Length)
            {
                Base.Compute.RecordError($"{position} not found in context");
                return(null);
            }
            if (position > context.Length)
            {
                throw new ArgumentException($"{position} not found in context");
            }

            string beforeStart = context.Substring(0, position);
            int    line        = beforeStart.Count((c) => c == '\n') + 1;
            int    column      = position - (beforeStart.LastIndexOf('\n') + 1);

            return(Create.LineLocation(line, column));
        }