private static void TextUtilitiesExample() { Console.OutputEncoding = System.Text.Encoding.UTF8; List <char> chars = new List <char>(); List <string> strings = new List <string>(); for (int i = 0; i < 65536; ++i) { char c = Convert.ToChar(i); if (TextSupport.IsCharacterEntity(c)) { chars.Add(c); strings.Add(TextSupport.PutCharacterEntity(c)); } } Console.WriteLine(chars.Count + " total character entities:"); string s = new string(chars.ToArray()); int j = 0; do { int l = Math.Min(20, s.Length - j); Console.WriteLine("\t" + s.Substring(j, l)); j += 20; } while (j < s.Length); Console.WriteLine(); for (int k = 0; k < chars.Count; ++k) { Console.WriteLine("\t" + chars[k] + " = " + strings[k]); } }
public void PutCharEntitiesTest() { string s0 = "<a>"; string s1 = "<a>"; string s = TextSupport.PutCharacterEntities(s0); Assert.Equal(s1, s); }
/// <summary>Copies the contents of buffer into the termBuffer array.</summary> /// <param name="buffer">the buffer to copy /// </param> public void SetTermBuffer(System.String buffer) { int length = buffer.Length; GrowTermBuffer(length); TextSupport.GetCharsFromString(buffer, 0, length, termBuffer, 0); termLength = length; }
/// <summary>Copies the contents of buffer, starting at offset and continuing /// for length characters, into the termBuffer array. /// </summary> /// <param name="buffer">the buffer to copy /// </param> /// <param name="offset">the index in the buffer of the first character to copy /// </param> /// <param name="length">the number of characters to copy /// </param> public void SetTermBuffer(System.String buffer, int offset, int length) { System.Diagnostics.Debug.Assert(offset <= buffer.Length); System.Diagnostics.Debug.Assert(offset + length <= buffer.Length); GrowTermBuffer(length); TextSupport.GetCharsFromString(buffer, offset, offset + length, termBuffer, 0); termLength = length; }
public void PutHexCharText() { for (int i = 0; i < 16; ++i) { char c1 = TextSupport.PutHexChar(i); Assert.Equal(c1, hexChars[i]); } Assert.Equal('\0', TextSupport.PutHexChar(100)); }
public void GetHexValueText() { for (int i = 0; i < hexChars.Length; ++i) { int v1 = TextSupport.GetHexValue(hexChars[i]); Assert.Equal(v1, hexValues[i]); } Assert.Equal(0, TextSupport.GetHexValue('Q')); }
public void PutTaggedBlockTest(string tag, string l0, string l1) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { l1 = l1.Replace("\r\n", Environment.NewLine); } string l = TextSupport.PutTaggedBlock(tag, l0, 1); Assert.Equal(l1, l); }
public void CharacterEntitiesTest() { for (int i = 0; i < characterEntities.Length; ++i) { char c0 = characterEntities[i]; Assert.True(TextSupport.IsCharacterEntity(c0), String.Format("{0} ({1}) at index {2} is not a character entity.", c0, Convert.ToInt32(c0), i)); string s0 = TextSupport.PutCharacterEntity(c0); Assert.NotEmpty(s0); char c1 = TextSupport.GetCharacterEntity(s0); Assert.Equal(c0, c1); } }
public void GetWrappedTextTest(string s0, int scol, int ecol, string s1) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { s1 = s1.Replace("\r\n", Environment.NewLine); } if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { s1 = s1.Replace("\r\n", Environment.NewLine); } string s = TextSupport.GetWrappedText(s0, scol, ecol); Assert.Equal(s1, s); }
public void Set(Term term) { if (term == null) { Reset(); return; } System.String termText = term.Text; int termLen = termText.Length; text.SetLength(termLen); TextSupport.GetCharsFromString(termText, 0, termLen, text.result, 0); dirty = true; field = term.Field; this.term = term; }
public static int ParseCharacter(string line, int i0, out char c, char dv = '\0') { int i = i0; if (!String.IsNullOrEmpty(line)) { char c0 = line[i++]; if (c0 != '\\') { c = c0; return(i); } if (i < line.Length) { char c1 = line[i++]; if (c1 == 'u') { i += 4; } else if (c1 == 'x') { int j0 = i; for (int j = j0; j < j0 + 4 && j < line.Length; j++) { if ("0123456789abcdefABCDEF".IndexOf(line[i]) < 0) { break; } i++; } } c = TextSupport.GetEscapedCharacter(line.Substring(i0, i - i0)); return(i); } } c = '\0'; return(i0); }
public void GetTaggedBlockTest(string l0, string l1, bool useFile, bool throws) { if (useFile) { using (StreamReader r = File.OpenText(_fixture.TaggedBlockFilePath)) { if (throws) { Assert.Throws <ApplicationException>(() => TextSupport.GetTaggedBlock(l0, r)); } else { string l = TextSupport.GetTaggedBlock(l0, r); Assert.Equal(l1, l); } } } else { string l = TextSupport.GetTaggedBlock(l0); Assert.Equal(l1, l); } }
public override int Read(System.Char[] c, int off, int len) { if (left > len) { TextSupport.GetCharsFromString(s, upto, upto + len, c, off); upto += len; left -= len; return(len); } else if (0 == left) { // don't keep a reference (s could have been very large) s = null; return(0); } else { TextSupport.GetCharsFromString(s, upto, upto + left, c, off); int r = left; left = 0; upto = s.Length; return(r); } }
public void RemoveCommentTest(string l0, char comment, bool allowInline, string l1) { string l = TextSupport.RemoveComment(l0, comment, allowInline); Assert.Equal(l1, l); }
public void UnquoteTest(string s0, char q, TextSupport.QuoteOptions q0, string s1) { string s = TextSupport.Unquote(s0, q, q0); Assert.Equal(s1, s); }
public void DetabTest(string s0, int tabSize, string s1) { string s = TextSupport.Detab(s0, tabSize); Assert.Equal(s1, s); }
public void GetColumnFromOffsetTest(string l0, int o0, int tabSize, int c1) { int c = TextSupport.GetColumnFromOffset(l0, o0, tabSize); Assert.Equal(c1, c); }
public void GetOffsetFromColumnTest(string l0, int c0, int tabSize, int o1) { int c = TextSupport.GetOffsetFromColumn(l0, c0, tabSize); Assert.Equal(o1, c); }
public void EvaluateCharacterEntitiesTest(string l0, string l1) { string l = TextSupport.EvaluateCharacterEntities(l0); Assert.Equal(l1, l); }