public void EscapeTest_CSharp_None3() { CharEscapeOptions options = new CharEscapeOptions() { EscapeLanguage = CharEscapeLanguage.CSharp, EscapeLetter = CharEscapeLetter.None3 }; char original = 'A'; Assert.Throws <ArgumentException>(() => CharUtils.Escape(original, options)); }
public void EscapeTest_FSharp_LowerCaseX1() { CharEscapeOptions options = new CharEscapeOptions() { EscapeLanguage = CharEscapeLanguage.FSharp, EscapeLetter = CharEscapeLetter.LowerCaseX1 }; char original = 'A'; Assert.Throws <ArgumentException>(() => CharUtils.Escape(original, options)); }
/// <summary> /// 刷新,根据所有数据刷新显示,这个排版方式虽然还可以,但是过于不优雅了. /// 日后需要从引擎层面加以改善,目前是notepad排版,然后用这个拼 /// </summary> public void Refresh(Character character) { ColorStringBuilder sb = new ColorStringBuilder(); sb.AppendString("-[", DefaultColor); sb.AppendString(CharUtils.SubStr(character.ClassName, 2), Color.Blue); sb.AppendString("][", DefaultColor); sb.AppendString(CharUtils.SubStr(character.CharacterName, 12), Color.DarkCyan); sb.AppendString("]-[HP]", DefaultColor); string hp = "[ " + CharUtils.ParseNum(character.HP, 4) + "/" + CharUtils.ParseNum(character.MaxHP, 4) + "]"; sb.AppendString(hp); if (character.Buffs.Count > 0) { sb.AppendString("-[", DefaultColor); sb.AppendString(character.Buffs[0].Icon); } #region 略 太丑了 if (character.Buffs.Count > 1) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[1].Icon); } if (character.Buffs.Count > 2) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[2].Icon); } if (character.Buffs.Count > 3) { sb.AppendString("] -[", DefaultColor); sb.AppendString(character.Buffs[3].Icon); } if (character.Buffs.Count > 4) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[4].Icon); } #endregion if (character.Buffs.Count > 5) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[5].Icon); sb.AppendString("] ", DefaultColor); } labelCom.Rendering(sb.ToRenderer()); progressBar.MaxValue = character.MaxHP; progressBar.Value = character.HP; }
private void SkipDecimalDigits(StringBuilder builder) { char digit; while (CharUtils.IsDecimal(digit = _reader.Peek().GetValueOrDefault()) || digit == '_') { if (digit != '_') { builder.Append(digit); } _reader.Position += 1; } }
private void CheckToDigit(Char c, Int32 fromBase, Boolean success, Int32 expected, String message) { try { Int32 actual = CharUtils.ToDigit(c, fromBase); Assert.IsTrue(success, message); Assert.AreEqual(expected, actual, message); } catch (FormatException) { Assert.IsFalse(success, message); } }
public override real MeasureString(string s) { //Here we don't have chars > 255, so there are no unicode surrogates. //Kern and Width tables are for Win 1252, so we need to pass that byte in the si[] array. byte[] b = CharUtils.GetWin1252Bytes_PDF(s); int[] si = new int[b.Length]; bool[] ignore = new bool[b.Length]; for (int i = 0; i < s.Length; i++) { si[i] = (int)b[i]; } return(FontMeasures.MeasureString(si, Width, Kern, 1000, ignore)); }
private string GetExpText(One node) { string esc = CharUtils.EscapeWhiteSpace(node.Tokens[0].Text[0]); if (esc == null) { return(node.Tokens[0].Text); } else { return(esc); } }
public static string Trim(string value) { var startIdx = 0; var endIdx = value.Length - 1; while (CharUtils.IsWhitespace(value[startIdx])) { startIdx++; } while (CharUtils.IsWhitespace(value[endIdx])) { endIdx--; } return(value[startIdx..(endIdx + 1)]);
private bool IsValidStartChar(char c) { if (CharUtils.IsLetter(c)) { return(true); } if ("_@".IndexOf(c) >= 0) { return(true); } return(false); }
public void TestCharUtilsIsUnreserved() { char[] arr = { '-', '.', 'a', '9', 'Z', '_', 'f' }; foreach (var a in arr) { Assert.True(CharUtils.IsUnreserved(a)); } char[] arr2 = { ' ', '!', '(', '\n' }; foreach (var a in arr2) { Assert.False(CharUtils.IsUnreserved(a)); } }
public void TestCharUtilsIsAlpha() { char[] arr = { 'a', 'Z', 'f', 'X' }; foreach (var a in arr) { Assert.True(CharUtils.IsAlpha(a)); } char[] arr2 = { '0', '9', '[', '~' }; foreach (var a in arr2) { Assert.False(CharUtils.IsAlpha(a)); } }
public void IsEnglishAlphabet() { Assert.AreEqual(true, CharUtils.IsEnglishAlphabet('a')); Assert.AreEqual(true, CharUtils.IsEnglishAlphabet('b')); Assert.AreEqual(true, CharUtils.IsEnglishAlphabet('z')); Assert.AreEqual(true, CharUtils.IsEnglishAlphabet('A')); Assert.AreEqual(true, CharUtils.IsEnglishAlphabet('Y')); Assert.AreEqual(true, CharUtils.IsEnglishAlphabet('Z')); Assert.AreEqual(false, CharUtils.IsEnglishAlphabet('æ')); Assert.AreEqual(false, CharUtils.IsEnglishAlphabet('ü')); Assert.AreEqual(false, CharUtils.IsEnglishAlphabet('2')); Assert.AreEqual(false, CharUtils.IsEnglishAlphabet('!')); }
public void TestCharUtilsIsHex() { char[] arr = { 'a', 'A', '0', '9' }; foreach (var a in arr) { Assert.True(CharUtils.IsHex(a)); } char[] arr2 = { '~', ';', 'Z', 'g' }; foreach (var a in arr2) { Assert.False(CharUtils.IsHex(a)); } }
public void TestCharUtilsIsAlphaNumeric() { char[] arr = { 'a', 'G', '3', '9' }; foreach (var a in arr) { Assert.True(CharUtils.IsAlphaNumeric(a)); } char[] arr2 = { '~', '-', '_', '\n' }; foreach (var a in arr2) { Assert.False(CharUtils.IsAlphaNumeric(a)); } }
private int ConsumeHexDigits() { var start = TextWindow.Position; char digit; while (CharUtils.IsHexadecimal(digit = TextWindow.PeekChar()) || digit == '_') { if (digit != '_') { _builder.Append(digit); } TextWindow.AdvanceChar(); } return(TextWindow.Position - start); }
private int ConsumeDecimalDigits(StringBuilder?builder) { var start = TextWindow.Position; char digit; while (CharUtils.IsDecimal(digit = TextWindow.PeekChar()) || digit == '_') { if (digit != '_') { builder?.Append(digit); } TextWindow.AdvanceChar(); } return(TextWindow.Position - start); }
/// <summary> /// Removes TAB (0x09), CR (0x0d), and LF (0x0a) from the URL /// @param urlPart The part of the url we are canonicalizing /// </summary> /// <param name="urlPart"></param> /// <returns></returns> protected internal static string RemoveSpecialSpaces(string urlPart) { var stringBuilder = new StringBuilder(urlPart); for (var i = 0; i < stringBuilder.Length; i++) { var curr = stringBuilder[i]; if (CharUtils.IsWhiteSpace(curr)) { stringBuilder.Remove(i, 1); } } return(stringBuilder.ToString()); }
public void TestCharUtilsIsNumeric() { char[] arr = { '0', '4', '6', '9' }; foreach (var a in arr) { Assert.True(CharUtils.IsNumeric(a)); } // Seems you can do this Zero thing in java but not c# char[] arr2 = { 'a', '~', 'A' /*, 0*/ }; foreach (var a in arr2) { Assert.False(CharUtils.IsNumeric(a)); } }
private static void DrawTileMap(LayerInfo layer, int x, int y, TileMap tileMap) { for (int ax = 0; ax < tileMap.Width; ax++) { for (int ay = 0; ay < tileMap.Height; ay++) { Tile tile = tileMap.Layers[0].Tiles[ay, ax]; var color = Color.FromArgb(tile.ForegroundRed, tile.ForegroundGreen, tile.ForegroundBlue); Terminal.Layer(1); Terminal.Color(color); layer.Put(x + ax, ay + y, CharUtils.ToUnicode(tile.CharacterCode)); } } }
public override TPdfFont Fallback(char c, int FallbackLevel) { if (CharUtils.IsWin1252((int)c)) { return(this); } TPdfFont Fallbk = FallbackFont(FallbackLevel); if (Fallbk != null) { return(Fallbk.Fallback(c, FallbackLevel + 1)); } return(null); }
/// <summary> /// Decodes the url by iteratively removing hex characters with backtracking. /// For example: %2525252525252525 becomes % /// </summary> /// <param name="url"></param> /// <returns></returns> public static string Decode(string url) { var stringBuilder = new StringBuilder(url); var nonDecodedPercentIndices = new Stack <int>(); var i = 0; while (i < stringBuilder.Length - 2) { var curr = stringBuilder[i]; if (curr == '%') { if (CharUtils.IsHex(stringBuilder[i + 1]) && CharUtils.IsHex(stringBuilder[i + 2])) { var startIndex = i + 1; var endIndex = i + 3; var decodedChar = (char)Convert.ToInt16(stringBuilder.ToString().Substring(startIndex, endIndex - startIndex), 16); stringBuilder.Remove(i, endIndex - i); //delete the % and two hex digits stringBuilder.Insert(i, decodedChar); //add decoded character if (decodedChar == '%') { i--; //backtrack one character to check for another decoding with this %. } else if (!nonDecodedPercentIndices.IsEmpty() && CharUtils.IsHex(decodedChar) && CharUtils.IsHex(stringBuilder[i - 1]) && i - nonDecodedPercentIndices.Peek() == 2) { //Go back to the last non-decoded percent sign if it's decodable. //We only need to go back if it's of form %[HEX][HEX] i = nonDecodedPercentIndices.Pop() - 1; //backtrack to the % sign. } else if (!nonDecodedPercentIndices.IsEmpty() && i == stringBuilder.Length - 2) { //special case to handle %[HEX][Unknown][end of string] i = nonDecodedPercentIndices.Pop() - 1; //backtrack to the % sign. } } else { nonDecodedPercentIndices.Push(i); } } i++; } return(stringBuilder.ToString()); }
private double ParseOctalNumber() { // Skip leading 0s while (_reader.Peek().GetValueOrDefault() == '0') { _reader.Position += 1; } var num = 0L; var digits = 0; var hasUnderscores = false; char digit; while (CharUtils.IsInRange('0', digit = _reader.Peek().GetValueOrDefault(), '7') || digit == '_') { _reader.Position += 1; if (digit == '_') { hasUnderscores = true; continue; } num = (num << 3) | (digit - (long)'0'); digits++; } if (!Options.SyntaxOptions.AcceptOctalNumbers) { AddError(ErrorCode.ERR_OctalNumericLiteralNotSupportedInVersion); } if (!Options.SyntaxOptions.AcceptUnderscoreInNumberLiterals && hasUnderscores) { AddError(ErrorCode.ERR_UnderscoreInNumericLiteralNotSupportedInVersion); } if (digits < 1) { num = 0; // Safe default AddError(ErrorCode.ERR_InvalidNumber); } if (digits > 21) { num = 0; // Safe default AddError(ErrorCode.ERR_NumericLiteralTooLarge); } return(num); }
public void IsDigit() { Assert.AreEqual(true, CharUtils.IsDigit('0')); Assert.AreEqual(true, CharUtils.IsDigit('1')); Assert.AreEqual(true, CharUtils.IsDigit('2')); Assert.AreEqual(true, CharUtils.IsDigit('3')); Assert.AreEqual(true, CharUtils.IsDigit('4')); Assert.AreEqual(true, CharUtils.IsDigit('5')); Assert.AreEqual(true, CharUtils.IsDigit('6')); Assert.AreEqual(true, CharUtils.IsDigit('7')); Assert.AreEqual(true, CharUtils.IsDigit('8')); Assert.AreEqual(true, CharUtils.IsDigit('9')); Assert.AreEqual(false, CharUtils.IsDigit('.')); Assert.AreEqual(false, CharUtils.IsDigit('A')); Assert.AreEqual(false, CharUtils.IsDigit(' ')); Assert.AreEqual(false, CharUtils.IsDigit('z')); }
public static LColor HexToColor(string c) { try { if (c.StartsWith("#")) { return(HexToColor(c.Substring(1))); } else { return(new LColor((int)CharUtils.FromHexToLong(c))); } } catch (Throwable) { return(new LColor()); } }
internal static string GetColorStringFromDCinema(string s) { if (string.IsNullOrWhiteSpace(s)) { return(s); } var hex = s.TrimStart('#'); for (int i = s.Length - 1; i >= 0; i--) { if (!CharUtils.IsHexadecimal(s[i])) { return(s); } } return("#" + hex); }
protected void AcceptLineWithBlockComments(ParserContext context, SpanFactory spanFactory) { // Read to the end of the line checking for plan9 block comments bool keepReading = true; while (keepReading) { if (CharUtils.IsNewLine(context.CurrentCharacter)) { context.AcceptNewLine(); keepReading = false; } else if (!TryParseComment(spanFactory)) { context.AcceptCurrent(); } } }
public void EscapeTest_FSharp_None3_Fallback() { CharEscapeOptions options = new CharEscapeOptions() { EscapeLanguage = CharEscapeLanguage.FSharp, EscapeLetter = CharEscapeLetter.None3 }; char original = 'ㄱ'; options.EscapeLetterFallback = CharEscapeLetter.LowerCaseU4; Assert.Equal("\\u3131", CharUtils.Escape(original, options)); options.EscapeLetterFallback = CharEscapeLetter.UpperCaseU8; Assert.Equal("\\U00003131", CharUtils.Escape(original, options)); options.EscapeLetterFallback = CharEscapeLetter.None3; // bad Assert.Throws <ArgumentException>(() => CharUtils.Escape(original, options)); }
public void Refresh(Character c) { label1.Rendering(c.ClassName + " " + c.CharacterName); label2.Rendering(c.Description); string hp = "[ " + CharUtils.ParseNum(c.HP, 4) + "/" + CharUtils.ParseNum(c.MaxHP, 4) + "]"; labelHP.Rendering("[HP]" + hp); string mp = "[ " + CharUtils.ParseNum(c.MP, 4) + "/" + CharUtils.ParseNum(c.MaxMP, 4) + "]"; labelMP.Rendering("[MP]" + mp); hpSlider.Value = c.HP; hpSlider.MaxValue = c.MaxHP; mpSlider.Value = c.MP; mpSlider.MaxValue = c.MaxMP; }
private void SaveWidths(TPdfStream DataStream) { //Docs say it is prefered to save as indirect object, but acrobat writes it directly. //Widths object. TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.WidthsName) + " " + TPdfTokens.GetString(TPdfToken.OpenArray)); int fc = FirstChar; if (fc < 0) { fc = 0; } for (int i = fc; i <= LastChar; i++) //characters on winansi are NOT the same as in low byte unicode. For example char 0x92 (146) is a typographic ' in winansi, not defined in unicode. { int z = (int)CharUtils.GetUniFromWin1252_PDF((byte)i); TPdfBaseRecord.WriteLine(DataStream, PdfConv.CoordsToString(Math.Round(FTrueTypeData.GlyphWidth(FTrueTypeData.Glyph(z, false))))); //don't log the erorr here, character doesn't need to exist. } TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.CloseArray)); }
public static bool ContainsOnlyNumber(string input) { int len = input.Length; // 10 = length of int.MaxValue (2147483647); +1 if starts with '/' if (len == 0 || len > 11 || input[0] != '/') { return(false); } int halfLen = len / 2; for (int i = 1; i <= halfLen; i++) // /10.0 (Do not parse double) { if (!(CharUtils.IsDigit(input[i]) && CharUtils.IsDigit(input[len - i]))) { return(false); } } return(true); }