Mono.TextEditor.TextViewMargin.TranslateToUTF8Index C# (CSharp) Method

TranslateToUTF8Index() public static method

public static TranslateToUTF8Index ( char charArray, uint textIndex, uint &curIndex, uint &byteIndex ) : uint
charArray char
textIndex uint
curIndex uint
byteIndex uint
return uint
		public static uint TranslateToUTF8Index (char[] charArray, uint textIndex, ref uint curIndex, ref uint byteIndex)
		{
			if (textIndex > charArray.Length)
				throw new ArgumentOutOfRangeException (nameof (textIndex), " must be <= charArrayLength (" + charArray.Length + ") was :" + textIndex);
			if (textIndex < curIndex) {
				byteIndex = (uint)Encoding.UTF8.GetByteCount (charArray, 0, (int)textIndex);
			} else {
				int count = System.Math.Min ((int)(textIndex - curIndex), charArray.Length - (int)curIndex);

				if (count > 0)
					byteIndex += (uint)Encoding.UTF8.GetByteCount (charArray, (int)curIndex, count);
			}
			curIndex = textIndex;
			return byteIndex;
		}

Usage Example

		void DrawErrorMarkers (TextEditor editor, Cairo.Context g, TextViewMargin.LayoutWrapper layout2, double x, double y)
		{
			uint curIndex = 0, byteIndex = 0;


			foreach (var task in errors.Select (t => t.Task)) {
				int index = (int)layout2.TranslateToUTF8Index ((uint)(task.Column - 1), ref curIndex, ref byteIndex);
				var pos = layout2.Layout.IndexToPos (index);
				g.Color = MarkerColor.Color;

				g.MoveTo (
					x + editor.TextViewMargin.TextStartPosition + pos.X / Pango.Scale.PangoScale,
					y + editor.LineHeight - 4
				);
				g.RelLineTo (3, 3);
				g.RelLineTo (-6, 0);
				g.ClosePath ();


				g.Fill ();
			}
		}