internal char[] GetClassificationChars(CharClassification classification) { Debug.Assert(Enum.IsDefined(typeof(CharClassification), classification)); int msg; switch (classification) { case CharClassification.Whitespace: msg = NativeMethods.SCI_GETWHITESPACECHARS; break; case CharClassification.Word: msg = NativeMethods.SCI_GETWORDCHARS; break; default: msg = NativeMethods.SCI_GETPUNCTUATIONCHARS; break; } char[] chars; unsafe { byte* bp = stackalloc byte[256]; // Max possible according to Scintilla code int length = (int)Scintilla.DirectMessage(msg, IntPtr.Zero, (IntPtr)bp); chars = new char[length]; for (int i = 0; i < length; i++) chars[i] = (char)bp[i]; } return chars; }
/// <summary> /// Updates the classification of the characters specified. /// </summary> /// <param name="chars">The characters to reclassify.</param> /// <param name="classification">The new classification for the <paramref name="chars" />.</param> /// <remarks> /// The default character classifications are suitable for most text and do not affect the lexing process. /// Rather, character classifications specify how the <see cref="Scintilla" /> control interprets /// characters for operations such as skipping or selecting a word. Specifying the classification of /// Unicode characters is not supported. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="chars" /> is null.</exception> /// <exception cref="ArgumentException"> /// One or more of the values specified in <paramref name="chars" /> is not an ASCII character. /// </exception> /// <exception cref="InvalidEnumArgumentException"> /// The value assigned to <paramref name="classification" /> is not one of the <see cref="CharClassification" /> values. /// </exception> public void ReclassifyChars(IEnumerable <char> chars, CharClassification classification) { if (chars == null) { throw new ArgumentNullException("chars"); } if (!Enum.IsDefined(typeof(CharClassification), classification)) { throw new InvalidEnumArgumentException("classification", (int)classification, typeof(CharClassification)); } int msg; switch (classification) { case CharClassification.Whitespace: msg = NativeMethods.SCI_SETWHITESPACECHARS; break; case CharClassification.Word: msg = NativeMethods.SCI_SETWORDCHARS; break; default: msg = NativeMethods.SCI_SETPUNCTUATIONCHARS; break; } List <byte> bytes = new List <byte>(); foreach (char c in chars) { if (c < 0 || c >= 256) { throw new ArgumentException(Resources.Exception_MustBeASCII, "value"); } bytes.Add((byte)c); } // Null terminator bytes.Add(0); unsafe { fixed(byte *bp = bytes.ToArray()) Scintilla.DirectMessage(msg, IntPtr.Zero, (IntPtr)bp); } }
internal char[] GetClassificationChars(CharClassification classification) { Debug.Assert(Enum.IsDefined(typeof(CharClassification), classification)); int msg; switch (classification) { case CharClassification.Whitespace: msg = NativeMethods.SCI_GETWHITESPACECHARS; break; case CharClassification.Word: msg = NativeMethods.SCI_GETWORDCHARS; break; default: msg = NativeMethods.SCI_GETPUNCTUATIONCHARS; break; } char[] chars; unsafe { byte *bp = stackalloc byte[256]; // Max possible according to Scintilla code int length = (int)Scintilla.DirectMessage(msg, IntPtr.Zero, (IntPtr)bp); chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = (char)bp[i]; } } return(chars); }
/// <summary> /// Updates the classification of the characters specified. /// </summary> /// <param name="chars">The characters to reclassify.</param> /// <param name="classification">The new classification for the <paramref name="chars" />.</param> /// <remarks> /// The default character classifications are suitable for most text and do not affect the lexing process. /// Rather, character classifications specify how the <see cref="Scintilla" /> control interprets /// characters for operations such as skipping or selecting a word. Specifying the classification of /// Unicode characters is not supported. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="chars" /> is null.</exception> /// <exception cref="ArgumentException"> /// One or more of the values specified in <paramref name="chars" /> is not an ASCII character. /// </exception> /// <exception cref="InvalidEnumArgumentException"> /// The value assigned to <paramref name="classification" /> is not one of the <see cref="CharClassification" /> values. /// </exception> public void ReclassifyChars(IEnumerable<char> chars, CharClassification classification) { if (chars == null) throw new ArgumentNullException("chars"); if (!Enum.IsDefined(typeof(CharClassification), classification)) throw new InvalidEnumArgumentException("classification", (int)classification, typeof(CharClassification)); int msg; switch (classification) { case CharClassification.Whitespace: msg = NativeMethods.SCI_SETWHITESPACECHARS; break; case CharClassification.Word: msg = NativeMethods.SCI_SETWORDCHARS; break; default: msg = NativeMethods.SCI_SETPUNCTUATIONCHARS; break; } List<byte> bytes = new List<byte>(); foreach (char c in chars) { if (c < 0 || c >= 256) throw new ArgumentException(Resources.Exception_MustBeASCII, "value"); bytes.Add((byte)c); } // Null terminator bytes.Add(0); unsafe { fixed (byte* bp = bytes.ToArray()) Scintilla.DirectMessage(msg, IntPtr.Zero, (IntPtr)bp); } }