Esempio n. 1
0
        //=========================================================================================
        /// <summary>Get char index by col position.</summary>
        int GetChar(string line, int col, CharSearchingMode mode)
        {
            int iCol = 0;

            for (int i = 0; i < line.Length; i++)
            {
                int iNewCol = iCol;
                if (line[i] == '\t')
                {
                    do
                    {
                        iNewCol++;
                    }while (iNewCol % this.Parent.Viewer._TabSize != 0);
                }
                else
                {
                    iNewCol++;
                }
                switch (mode)
                {
                case CharSearchingMode.Before:
                    if (iNewCol > col)
                    {
                        return(i);
                    }
                    break;

                case CharSearchingMode.After:
                    if (iCol >= col)
                    {
                        return(i);
                    }
                    break;

                case CharSearchingMode.Near:
                    if (iNewCol > col)
                    {
                        if (col - iCol <= iNewCol - col)
                        {
                            return(i);
                        }
                    }
                    break;

                default:
                    throw new NotSupportedException(((int)mode).ToString());
                }
                iCol = iNewCol;
            }
            return(line.Length);
        }
Esempio n. 2
0
		//=========================================================================================
		/// <summary>Get char index by col position.</summary>
		int GetChar(string line, int col, CharSearchingMode mode)
		{
			int iCol = 0;
			for (int i = 0; i < line.Length; i++)
			{
				int iNewCol = iCol;
				if (line[i] == '\t')
				{
					do
						iNewCol++;
					while (iNewCol % this.Parent.Viewer._TabSize != 0);
				}
				else
					iNewCol++;
				switch (mode)
				{
					case CharSearchingMode.Before:
						if (iNewCol > col)
							return i;
						break;
					case CharSearchingMode.After:
						if (iCol >= col)
							return i;
						break;
					case CharSearchingMode.Near:
						if (iNewCol > col)
						{
							if (col - iCol <= iNewCol - col)
								return i;
						}
						break;
					default:
						throw new NotSupportedException(((int)mode).ToString());
				}
				iCol = iNewCol;
			}
			return line.Length;
		}