Example #1
0
        public string GetTextBeforeOffset(int offset,
                                          TextBoundary boundaryType,
                                          out int startOffset,
                                          out int endOffset)
        {
            startOffset = 0;
            endOffset   = 0;
            try {
                switch (boundaryType)
                {
                case Atk.TextBoundary.WordEnd:
                    endOffset   = BackwardToNextSeparator(wordSeparators, offset, false);
                    startOffset = BackwardToNextSeparator(wordSeparators, endOffset, false);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.WordStart:
                    BackwardToNextSeparator(wordSeparators, offset, out endOffset, out startOffset);
                    startOffset = BackwardToNextSeparator(wordSeparators, startOffset, true);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.LineEnd:
                    endOffset   = BackwardToNextSeparator(newLineSeparators, offset, false);
                    startOffset = BackwardToNextSeparator(newLineSeparators, endOffset, false);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.LineStart:
                    BackwardToNextSeparator(newLineSeparators, offset, out endOffset, out startOffset);
                    startOffset = BackwardToNextSeparator(newLineSeparators, startOffset, true);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.Char:
                    offset      = Clamp(offset, 0, Text.Length);
                    startOffset = Clamp(offset - 1, 0, Text.Length);
                    endOffset   = Clamp(offset, 0, Text.Length);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.SentenceEnd:
                    endOffset   = BackwardToNextSeparator(sentenceSeparators, offset, false);
                    startOffset = BackwardToNextSeparator(sentenceSeparators, endOffset, false);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.SentenceStart:
                    BackwardToNextSeparator(sentenceSeparators, offset, out endOffset, out startOffset);
                    startOffset = BackwardToNextSeparator(sentenceSeparators, startOffset, true);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                default:
                    throw GetNotSupportedBoundary(boundaryType);
                }
            } catch (System.IndexOutOfRangeException) {
                return(String.Empty);
            } finally {
                selectionStartOffset = startOffset;
                selectionEndOffset   = endOffset;
            }
        }
        /// <summary>
        /// Checks if the offset is valid, gets the RuleStatus and
        /// RuleStatusVector for the offset and returns that TextBoundary.
        /// </summary>
        /// <param name="offset">Offset to check in text.</param>
        /// <param name="textBoundary">TextBoundary for the given offset.</param>
        /// <returns>true if the offset is valid; false otherwise.</returns>
        private bool TryGetTextBoundaryFromOffset(int offset, out TextBoundary textBoundary)
        {
            textBoundary = default(TextBoundary);

            if (offset == DONE)
            {
                return(false);
            }

            const int length = 128;

            int[] vector = new int[length];

            ErrorCode errorCode;
            int       actualLen = NativeMethods.ubrk_getRuleStatusVec(_breakIterator, vector, length, out errorCode);

            if (errorCode.IsFailure())
            {
                throw new Exception("BreakIterator.GetRuleStatusVector failed! " + errorCode);
            }

            if (actualLen > length)
            {
                vector = new int[actualLen];
                NativeMethods.ubrk_getRuleStatusVec(_breakIterator, vector, vector.Length, out errorCode);

                if (errorCode.IsFailure())
                {
                    throw new Exception("BreakIterator.GetRuleStatusVector failed! " + errorCode);
                }
            }

            int[] ruleStatuses;

            // Constrain the size of the array to actual number of elements
            // that were returned.
            if (actualLen < vector.Length)
            {
                ruleStatuses = new int[actualLen];
                Array.Copy(vector, ruleStatuses, actualLen);
            }
            else
            {
                ruleStatuses = vector;
            }

            textBoundary = new TextBoundary(offset, ruleStatuses);

            return(true);
        }
        string TextImplementor.GetTextAfterOffset(int offset, TextBoundary boundary_type, out int start_offset, out int end_offset)
        {
            LineSegment line;

            switch (boundary_type)
            {
            case Atk.TextBoundary.Char:
                start_offset = offset;
                end_offset   = offset + 1;
                break;

            case Atk.TextBoundary.SentenceEnd:
            case Atk.TextBoundary.LineEnd:
                line         = Document.GetLineByOffset(offset);
                start_offset = offset;
                end_offset   = line.Offset + line.EditableLength;
                break;

            case Atk.TextBoundary.SentenceStart:
            case Atk.TextBoundary.LineStart:
                line         = Document.GetLineByOffset(offset);
                start_offset = line.Offset;
                end_offset   = offset;
                break;

            case Atk.TextBoundary.WordEnd:
                start_offset = offset;
                end_offset   = TextEditorData.FindCurrentWordEnd(offset);
                break;

            case Atk.TextBoundary.WordStart:
                start_offset = TextEditorData.FindCurrentWordStart(offset);
                end_offset   = offset;
                break;

            default:
                start_offset = end_offset = offset;
                break;
            }
            start_offset = System.Math.Min(start_offset, offset);
            return(Document.GetTextBetween(start_offset, end_offset));
        }
		string TextImplementor.GetTextAfterOffset (int offset, TextBoundary boundary_type, out int start_offset, out int end_offset)
		{
			LineSegment line;
			switch (boundary_type) {
			case Atk.TextBoundary.Char:
				start_offset = offset;
				end_offset = offset + 1;
				break;
				
			case Atk.TextBoundary.SentenceEnd:
			case Atk.TextBoundary.LineEnd:
				line = Document.GetLineByOffset (offset);
				start_offset = offset;
				end_offset = line.Offset + line.EditableLength;
				break;
			case Atk.TextBoundary.SentenceStart:
			case Atk.TextBoundary.LineStart:
				line = Document.GetLineByOffset (offset);
				start_offset = line.Offset;
				end_offset = offset;
				break;
			case Atk.TextBoundary.WordEnd:
				start_offset = offset;
				end_offset = TextEditorData.FindCurrentWordEnd (offset);
				break;
			case Atk.TextBoundary.WordStart:
				start_offset = TextEditorData.FindCurrentWordStart (offset);
				end_offset = offset;
				break;
			default:
				start_offset = end_offset = offset;
				break;
			}
			start_offset = System.Math.Min (start_offset, offset);
			return Document.GetTextBetween (start_offset, end_offset);	
		}
Example #5
0
        public string GetTextAtOffset(int offset,
                                      TextBoundary boundaryType,
                                      out int startOffset,
                                      out int endOffset)
        {
            string text = Text;

            startOffset = 0;
            endOffset   = 0;
            try {
                switch (boundaryType)
                {
                case Atk.TextBoundary.WordEnd:
                    startOffset = BackwardToNextSeparator(wordSeparators, offset, false);
                    endOffset   = ForwardToNextSeparator(wordSeparators, offset, true);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.WordStart:
                    startOffset = BackwardToNextSeparator(wordSeparators, offset, true);
                    endOffset   = ForwardToNextSeparator(wordSeparators, offset, false);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.LineEnd:
                    startOffset = BackwardToNextSeparator(newLineSeparators, offset, false);
                    endOffset   = ForwardToNextSeparator(newLineSeparators, offset, true);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.LineStart:
                    startOffset = BackwardToNextSeparator(newLineSeparators, offset, true);
                    endOffset   = ForwardToNextSeparator(newLineSeparators, offset, false);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.SentenceEnd:
                    startOffset = BackwardToNextSeparator(sentenceSeparators, offset, false);
                    endOffset   = ForwardToNextSeparator(sentenceSeparators, offset, true);

                    int testEndOffset, nextEndOffset;
                    ForwardToNextSeparator(softSentenceSeparators, startOffset, out testEndOffset, out nextEndOffset);
                    if (testEndOffset == endOffset)
                    {
                        endOffset = nextEndOffset;
                    }

                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.SentenceStart:
                    startOffset = BackwardToNextSeparator(sentenceSeparators, offset, true);
                    endOffset   = ForwardToNextSeparator(sentenceSeparators, offset, false);
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                case Atk.TextBoundary.Char:
                    startOffset = offset;
                    if (startOffset < 0)
                    {
                        startOffset = text.Length;
                        endOffset   = text.Length;
                    }
                    else if (offset >= text.Length)
                    {
                        startOffset = endOffset = text.Length;
                    }
                    else
                    {
                        endOffset = offset + 1;
                    }
                    return(ReturnTextWrtOffset(startOffset, endOffset));

                default:
                    throw GetNotSupportedBoundary(boundaryType);
                }
            } catch (System.IndexOutOfRangeException) {
                return(String.Empty);
            } finally {
                selectionStartOffset = startOffset;
                selectionEndOffset   = endOffset;
            }
        }
Example #6
0
		public string GetTextBeforeOffset (int offset,
		                                   TextBoundary boundaryType,
		                                   out int startOffset,
		                                   out int endOffset)
		{
			startOffset = 0;
			endOffset = 0;
			try {
				switch (boundaryType) {
				case Atk.TextBoundary.WordEnd:
					endOffset = BackwardToNextSeparator (wordSeparators, offset, false);
					startOffset = BackwardToNextSeparator (wordSeparators, endOffset, false);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.WordStart:
					BackwardToNextSeparator (wordSeparators, offset, out endOffset, out startOffset);
					startOffset = BackwardToNextSeparator (wordSeparators, startOffset, true);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.LineEnd:
					endOffset = BackwardToNextSeparator (newLineSeparators, offset, false);
					startOffset = BackwardToNextSeparator (newLineSeparators, endOffset, false);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.LineStart:
					BackwardToNextSeparator (newLineSeparators, offset, out endOffset, out startOffset);
					startOffset = BackwardToNextSeparator (newLineSeparators, startOffset, true);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.Char:
					offset = Clamp (offset, 0, Text.Length);
					startOffset = Clamp (offset - 1, 0, Text.Length);
					endOffset = Clamp (offset, 0, Text.Length);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.SentenceEnd:
					endOffset = BackwardToNextSeparator (sentenceSeparators, offset, false);
					startOffset = BackwardToNextSeparator (sentenceSeparators, endOffset, false);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.SentenceStart:
					BackwardToNextSeparator (sentenceSeparators, offset, out endOffset, out startOffset);
					startOffset = BackwardToNextSeparator (sentenceSeparators, startOffset, true);
					return ReturnTextWrtOffset (startOffset, endOffset);

				default:
					throw GetNotSupportedBoundary (boundaryType);
				}
			} catch (System.IndexOutOfRangeException) {
				return String.Empty;
			} finally {
				selectionStartOffset = startOffset;
				selectionEndOffset = endOffset;
			}
		}
Example #7
0
		public string GetTextAtOffset (int offset,
		                               TextBoundary boundaryType,
		                               out int startOffset,
		                               out int endOffset)
		{
			string text = Text;

			startOffset = 0;
			endOffset = 0;
			try {
				switch (boundaryType) {
				case Atk.TextBoundary.WordEnd:
					startOffset = BackwardToNextSeparator (wordSeparators, offset, false);
					endOffset = ForwardToNextSeparator (wordSeparators, offset, true);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.WordStart:
					startOffset = BackwardToNextSeparator (wordSeparators, offset, true);
					endOffset = ForwardToNextSeparator (wordSeparators, offset, false);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.LineEnd:
					startOffset = BackwardToNextSeparator (newLineSeparators, offset, false);
					endOffset = ForwardToNextSeparator (newLineSeparators, offset, true);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.LineStart:
					startOffset = BackwardToNextSeparator (newLineSeparators, offset, true);
					endOffset = ForwardToNextSeparator (newLineSeparators, offset, false);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.SentenceEnd:
					startOffset = BackwardToNextSeparator (sentenceSeparators, offset, false);
					endOffset = ForwardToNextSeparator (sentenceSeparators, offset, true);

					int testEndOffset, nextEndOffset;
					ForwardToNextSeparator(softSentenceSeparators, startOffset, out testEndOffset, out nextEndOffset);
					if (testEndOffset == endOffset)
						endOffset = nextEndOffset;

					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.SentenceStart:
					startOffset = BackwardToNextSeparator (sentenceSeparators, offset, true);
					endOffset = ForwardToNextSeparator (sentenceSeparators, offset, false);
					return ReturnTextWrtOffset (startOffset, endOffset);

				case Atk.TextBoundary.Char:
					startOffset = offset;
					if (startOffset < 0) {
						startOffset = text.Length;
						endOffset = text.Length;
					}
					else if (offset >= text.Length)
						startOffset = endOffset = text.Length;
					else
						endOffset = offset + 1;
					return ReturnTextWrtOffset (startOffset, endOffset);

				default:
					throw GetNotSupportedBoundary (boundaryType);
				}
			} catch (System.IndexOutOfRangeException) {
				return String.Empty;
			} finally {
				selectionStartOffset = startOffset;
				selectionEndOffset = endOffset;
			}
		}