예제 #1
0
        private void TestParse(bool expectSuccess, int radix, UString input, float expected, ParseNumberFlag flags = 0)
        {
            float result  = ParseHelpers.TryParseFloat(ref input, radix, flags);
            bool  success = !float.IsNaN(result) && input.IsEmpty;

            AreEqual(expectSuccess, success);
            IsTrue(expected == result ||
                   expected == MathEx.NextLower(result) ||
                   expected == MathEx.NextHigher(result) ||
                   float.IsNaN(expected) && float.IsNaN(result));
        }
예제 #2
0
        public override void LoadDataFromXML()
        {
            bool exists = false;

            if (DataXMLDoc != null)
            {
                _objectID = ParseHelpers.GetStringFromVD2Data(DataXMLDoc, "objectID", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("objectID", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("objectID", EditorUI.UI.Ships.DoesPropertyExistInBaseData(objectID, "objectID"));
                }
                SetPropertyExists("objectID", exists);

                _materialName = ParseHelpers.GetStringFromVD2Data(DataXMLDoc, "materialName", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("materialName", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("materialName", EditorUI.UI.Ships.DoesPropertyExistInBaseData(GetObjectID(), "materialName"));
                }
                SetPropertyExists("materialName", exists);

                _factionType = new ObservableCollection <string>(ParseHelpers.GetStringListFromVD2Data(DataXMLDoc, "factionType", out exists));
                _factionType.CollectionChanged += OnfactionTypeChanged;
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("factionType", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("factionType", EditorUI.UI.Ships.DoesPropertyExistInBaseData(GetObjectID(), "factionType"));
                }
                SetPropertyExists("factionType", exists);

                _bGeneric = ParseHelpers.GetBoolFromVD2Data(DataXMLDoc, "bGeneric", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("bGeneric", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("bGeneric", EditorUI.UI.Ships.DoesPropertyExistInBaseData(GetObjectID(), "bGeneric"));
                }
                SetPropertyExists("bGeneric", exists);

                base.LoadDataFromXML();
            }
        }
예제 #3
0
 [Test] public void TestUnescape()
 {
     Assert.AreEqual("", ParseHelpers.UnescapeCStyle(""));
     Assert.AreEqual("foobar", ParseHelpers.UnescapeCStyle("foobar"));
     Assert.AreEqual("foo\nbar", ParseHelpers.UnescapeCStyle(@"foo\nbar"));
     Assert.AreEqual("\u2222\n\r\t", ParseHelpers.UnescapeCStyle(@"\u2222\n\r\t"));
     Assert.AreEqual("\a\b\f\vA", ParseHelpers.UnescapeCStyle(@"\a\b\f\v\x41"));
     Assert.AreEqual("ba\\z", ParseHelpers.UnescapeCStyle((UString)@"ba\z", false));
     Assert.AreEqual("baz", ParseHelpers.UnescapeCStyle((UString)@"ba\z", true));
     Assert.AreEqual("!!\n!!", ParseHelpers.UnescapeCStyle(@"<'!!\n!!'>".Slice(2, 6), true));
 }
예제 #4
0
        private void TestParse(bool expectSuccess, int radix, string input, long expected, int i, int i_out, bool skipSpaces = true)
        {
            long    result;
            UString input2  = input.Slice(i);
            bool    success = ParseHelpers.TryParseInt(ref input2, out result, radix,
                                                       skipSpaces ? ParseNumberFlag.SkipSpacesInFront : 0);

            AreEqual(expected, result);
            AreEqual(expectSuccess, success);
            AreEqual(i_out, input2.InternalStart);
        }
예제 #5
0
        internal static InlineParseResult Parse(string markdown, int start, int maxEnd)
        {
            if (start >= maxEnd - 1)
            {
                return(null);
            }

            // Check the start sequence.
            string startSequence = markdown.Substring(start, 1);

            if (startSequence != ":")
            {
                return(null);
            }

            // Find the end of the span.
            var innerStart = start + 1;
            int innerEnd   = Common.IndexOf(markdown, startSequence, innerStart, maxEnd);

            if (innerEnd == -1)
            {
                return(null);
            }

            // The span must contain at least one character.
            if (innerStart == innerEnd)
            {
                return(null);
            }

            // The first character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart]))
            {
                return(null);
            }

            // The last character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1]))
            {
                return(null);
            }

            var emojiName = markdown.Substring(innerStart, innerEnd - innerStart);

            if (DiscordEmoji.UnicodeEmojis.TryGetValue($":{emojiName}:", out var emojiCode))
            {
                var result = new EmojiInline {
                    Text = emojiCode, Type = MarkdownInlineType.Emoji
                };
                return(new InlineParseResult(result, start, innerEnd + 1));
            }

            return(null);
        }
예제 #6
0
        /// <summary>
        /// Attempts to parse a italic text span.
        /// </summary>
        /// <param name="markdown"> The markdown text. </param>
        /// <param name="start"> The location to start parsing. </param>
        /// <param name="maxEnd"> The location to stop parsing. </param>
        /// <returns> A parsed italic text span, or <c>null</c> if this is not a italic text span. </returns>
        internal static InlineParseResult Parse(string markdown, int start, int maxEnd)
        {
            // Check the first char.
            char startChar = markdown[start];

            if (start == maxEnd || (startChar != '*' && startChar != '_'))
            {
                return(null);
            }

            // Find the end of the span.  The end character (either '*' or '_') must be the same as
            // the start character.
            var innerStart = start + 1;
            int innerEnd   = Common.IndexOf(markdown, startChar, start + 1, maxEnd);

            if (innerEnd == -1)
            {
                return(null);
            }

            // The span must contain at least one character.
            if (innerStart == innerEnd)
            {
                return(null);
            }

            // The first character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart]))
            {
                return(null);
            }

            // The last character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1]))
            {
                return(null);
            }

            // Discord avoids italicising snake_case_for_some_reason
            if (startChar == '_' && innerEnd + 1 < maxEnd && !ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd + 1]))
            {
                return(null);
            }

            // We found something!
            var result = new ItalicTextInline
            {
                Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd)
            };

            return(new InlineParseResult(result, start, innerEnd + 1));
        }
예제 #7
0
파일: Program.cs 프로젝트: dadhi/ecsharp
        public static int RunMenu(IList <Pair <string, Func <int> > > menu, IEnumerator <char> input = null)
        {
            var reader     = input ?? ConsoleChars();
            int errorCount = 0;

            for (;;)
            {
                Console.WriteLine();
                Console.WriteLine("What do you want to do? (Esc to quit)");
                for (int i = 0; i < menu.Count; i++)
                {
                    Console.WriteLine(PrintHelpers.HexDigitChar(i + 1) + ". " + menu[i].Key);
                }
                Console.WriteLine("Space. Run all tests");

                if (!reader.MoveNext())
                {
                    break;
                }

                char c = reader.Current;
                if (c == ' ')
                {
                    errorCount = 0;
                    for (int i = 0; i < menu.Count; i++)
                    {
                        Console.WriteLine();
                        ConsoleMessageSink.WriteColoredMessage(ConsoleColor.White, i + 1, menu[i].Key);
                        errorCount += menu[i].Value();
                    }
                    if (errorCount == 0)
                    {
                        ConsoleMessageSink.WriteColoredMessage(ConsoleColor.White, null,
                                                               "All test(s) passed (except known failures, if any).");
                    }
                    else
                    {
                        ConsoleMessageSink.WriteColoredMessage(ConsoleColor.Red, null,
                                                               "{0} test(s) unexpectedly failed in total.".Localized(errorCount));
                    }
                }
                else
                {
                    int i = ParseHelpers.HexDigitValue(c);
                    if (i > 0 && i <= menu.Count)
                    {
                        errorCount += menu[i - 1].Value();
                    }
                }
            }
            return(errorCount);
        }
예제 #8
0
        /// <summary>
        /// Attempts to parse a bold text span.
        /// </summary>
        /// <param name="markdown"> The markdown text. </param>
        /// <param name="start"> The location to start parsing. </param>
        /// <param name="maxEnd"> The location to stop parsing. </param>
        /// <returns> A parsed bold text span, or <c>null</c> if this is not a bold text span. </returns>
        internal static InlineParseResult Parse(string markdown, int start, int maxEnd)
        {
            if (start >= maxEnd - 1)
            {
                return(null);
            }

            // Check the start sequence.
            string startSequence = markdown.Substring(start, 2);

            if (startSequence != "**" && startSequence != "__")
            {
                return(null);
            }

            // Find the end of the span.  The end sequence (either '**' or '__') must be the same
            // as the start sequence.
            var innerStart = start + 2;
            int innerEnd   = Common.IndexOf(markdown, startSequence, innerStart, maxEnd);

            if (innerEnd == -1)
            {
                return(null);
            }

            // The span must contain at least one character.
            if (innerStart == innerEnd)
            {
                return(null);
            }

            // The first character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart]))
            {
                return(null);
            }

            // The last character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1]))
            {
                return(null);
            }

            // We found something!
            var result = new BoldTextInline
            {
                Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd)
            };

            return(new InlineParseResult(result, start, innerEnd + 2));
        }
예제 #9
0
        private static object ParseSpecialFloatValue(UString source, bool isNegative, int radix, Symbol typeSuffix, ref string error)
        {
            if (typeSuffix == _F)
            {
                float result = ParseHelpers.TryParseFloat(ref source, radix, ParseNumberFlag.SkipUnderscores);
                if (float.IsNaN(result))
                {
                    error = Localize.Localized("Syntax error in '{0}' literal", "float");
                }
                else if (float.IsInfinity(result))
                {
                    error = Localize.Localized("Overflow in '{0}' literal", "float");
                }
                if (isNegative)
                {
                    result = -result;
                }
                return(result);
            }
            else
            {
                string type = "double";
                if (typeSuffix == _M)
                {
                    error = "Support for hex and binary literals of type decimal is not implemented. Converting from double instead.";
                    type  = "decimal";
                }

                double result = ParseHelpers.TryParseDouble(ref source, radix, ParseNumberFlag.SkipUnderscores);
                if (double.IsNaN(result))
                {
                    error = Localize.Localized("Syntax error in '{0}' literal", type);
                }
                else if (double.IsInfinity(result))
                {
                    error = Localize.Localized("Overflow in '{0}' literal", type);
                }
                if (isNegative)
                {
                    result = -result;
                }
                if (typeSuffix == _M)
                {
                    return((decimal)result);
                }
                else
                {
                    return(result);
                }
            }
        }
예제 #10
0
        static bool ParseULong(UString s, out ulong u)
        {
            u = 0;
            bool negative;
            int  radix = GetSignAndRadix(ref s, out negative);

            if (radix == 0 || negative)
            {
                return(false);
            }
            var flags = ParseNumberFlag.SkipSingleQuotes | ParseNumberFlag.SkipUnderscores | ParseNumberFlag.StopBeforeOverflow;

            return(ParseHelpers.TryParseUInt(ref s, out u, radix, flags) && s.Length == 0);
        }
예제 #11
0
        private static int ParseChar(string s, ref int i)         // used by TryParse
        {
            int  oldi = i;
            char c    = ParseHelpers.UnescapeChar(s, ref i);

            if (c == '\\' && i == oldi + 1)
            {
                c = s[i++];
                if (c == '$')
                {
                    return(-1);                    // \$ is -1 is EOF
                }
            }
            return(c);
        }
예제 #12
0
        Token Number()
        {
            int la0, la1;

            Skip();
            // Line 39: ([0-9])*
            for (;;)
            {
                la0 = LA0;
                if (la0 >= '0' && la0 <= '9')
                {
                    Skip();
                }
                else
                {
                    break;
                }
            }
            // Line 39: ([.] [0-9] ([0-9])*)?
            la0 = LA0;
            if (la0 == '.')
            {
                la1 = LA(1);
                if (la1 >= '0' && la1 <= '9')
                {
                    Skip();
                    Skip();
                    // Line 39: ([0-9])*
                    for (;;)
                    {
                        la0 = LA0;
                        if (la0 >= '0' && la0 <= '9')
                        {
                            Skip();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
                        #line 40 "Grammars.ecs"
            var text = Text();
            return(T(TT.Number, ParseHelpers.TryParseDouble(ref text, radix: 10)));

                        #line default
        }
예제 #13
0
 /// <summary>Prints a character as a string, e.g. <c>'a' -> "'a'"</c>, with
 /// the special value -1 representing EOF, so PrintChar(-1, ...) == "EOF".</summary>
 protected void PrintChar(int c, StringBuilder sb)
 {
     if (c == -1)
     {
         sb.Append("EOF");
     }
     else if (c >= 0 && c < 0xFFFC)
     {
         sb.Append('\'');
         ParseHelpers.EscapeCStyle((char)c, sb, EscapeC.Default | EscapeC.SingleQuotes);
         sb.Append('\'');
     }
     else
     {
         sb.Append(c);
     }
 }
예제 #14
0
        private bool TryMatchUnaryOperator(string expressionValue, out string unaryExpression)
        {
            unaryExpression = null;
            var leftPattern = BuildFieldNameRegexPattern();
            var aggregatedUnaryOperators = DataApiSqlOperators.UnaryOperators.Aggregate((a, b) => a + "|" + b);
            var combinedPattern          = $"^{leftPattern}\\s*({aggregatedUnaryOperators})$";
            var regex = Regex.Match(expressionValue, combinedPattern, RegexOptions.IgnoreCase);

            if (!regex.Success)
            {
                return(false);
            }
            var unaryOperator = regex.Groups[2].Value;
            var fieldName     = ParseHelpers.StripQuotes(regex.Groups[1].Value);

            unaryExpression = syntaxBuilder.BuildUnaryExpression(fieldName, unaryOperator.Trim());
            return(true);
        }
예제 #15
0
        /// <summary>
        /// Attempts to parse a strikethrough text span.
        /// </summary>
        /// <param name="markdown"> The markdown text. </param>
        /// <param name="start"> The location to start parsing. </param>
        /// <param name="maxEnd"> The location to stop parsing. </param>
        /// <returns> A parsed strikethrough text span, or <c>null</c> if this is not a strikethrough text span. </returns>
        internal static InlineParseResult Parse(string markdown, int start, int maxEnd)
        {
            // Check the start sequence.
            if (start >= maxEnd - 1 || markdown.Substring(start, 2) != "~~")
            {
                return(null);
            }

            // Find the end of the span.
            var innerStart = start + 2;
            int innerEnd   = Common.IndexOf(markdown, "~~", innerStart, maxEnd);

            if (innerEnd == -1)
            {
                return(null);
            }

            // The span must contain at least one character.
            if (innerStart == innerEnd)
            {
                return(null);
            }

            // The first character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart]))
            {
                return(null);
            }

            // The last character inside the span must NOT be a space.
            if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1]))
            {
                return(null);
            }

            // We found something!
            var result = new StrikethroughTextInline
            {
                Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd)
            };

            return(new InlineParseResult(result, start, innerEnd + 2));
        }
예제 #16
0
        private static bool ParseDouble(UString s, out double d)
        {
            d = double.NaN;
            bool negative;
            int  radix = GetSignAndRadix(ref s, out negative);

            if (radix == 0)
            {
                return(false);
            }
            var flags = ParseNumberFlag.SkipSingleQuotes | ParseNumberFlag.SkipUnderscores | ParseNumberFlag.StopBeforeOverflow;

            d = ParseHelpers.TryParseDouble(ref s, radix, flags);
            if (negative)
            {
                d = -d;
            }
            return(!double.IsNaN(d) && s.Length == 0);
        }
예제 #17
0
        public override void LoadDataFromXML()
        {
            bool exists = false;

            if (DataXMLDoc != null)
            {
                _objectID = ParseHelpers.GetStringFromVD2Data(DataXMLDoc, "objectID", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("objectID", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("objectID", EditorUI.UI.Ships.DoesPropertyExistInBaseData(objectID, "objectID"));
                }
                SetPropertyExists("objectID", exists);

                _meshName = ParseHelpers.GetStringFromVD2Data(DataXMLDoc, "meshName", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("meshName", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("meshName", EditorUI.UI.Ships.DoesPropertyExistInBaseData(GetObjectID(), "meshName"));
                }
                SetPropertyExists("meshName", exists);

                _offsetPosition = ParseHelpers.GetVector3DFromVD2Data(DataXMLDoc, "offsetPosition", out exists);
                _offsetPosition.OnElementChanged += offsetPosition_OnElementChanged;
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("offsetPosition", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("offsetPosition", EditorUI.UI.Ships.DoesPropertyExistInBaseData(GetObjectID(), "offsetPosition"));
                }
                SetPropertyExists("offsetPosition", exists);

                base.LoadDataFromXML();
            }
        }
예제 #18
0
        internal static void MapearSocio(ref IList <Socio> socios, string linha, long id)
        {
            var socio = new Socio();

            socio.Id                     = id;
            socio.CnpjEmpresa            = linha.Substring(3, 14);
            socio.IdentificadorSocio     = (eIdentificadorSocio)int.Parse(linha.Substring(17, 1));
            socio.Nome                   = linha.Substring(18, 150);
            socio.CpfCnpj                = linha.Substring(168, 14);
            socio.Qualificacao           = linha.Substring(182, 2);
            socio.CapitalSocial          = int.Parse(linha.Substring(184, 5));
            socio.DataEntrada            = ParseHelpers.StringToDateTime(linha.Substring(189, 8));
            socio.CodigoPais             = linha.Substring(197, 3);
            socio.NomePais               = linha.Substring(200, 70);
            socio.CpfRepresentanteLegal  = linha.Substring(270, 11);
            socio.NomeRepresentanteLegal = linha.Substring(281, 60);
            socio.CodigoQualificacaoRepresentanteLegal = linha.Substring(341, 2);
            socios.Add(socio);
        }
예제 #19
0
        internal static void MapearEmpresa(ref IList <Empresa> empresas, string linha, long id)
        {
            var empresa = new Empresa();

            empresa.Id   = id;
            empresa.Cnpj = linha.Substring(3, 14);
            empresa.IdentificadorEmpresa    = (eIdentificadorEmpresa)int.Parse(linha.Substring(17, 1));
            empresa.RazaoSocial             = linha.Substring(18, 150);
            empresa.NomeFantasia            = linha.Substring(168, 55);
            empresa.SistuacaoCadastral      = (eSituacaoCadastral)int.Parse(linha.Substring(223, 2));
            empresa.DataSituacaoCadastral   = ParseHelpers.StringToDateTime(linha.Substring(225, 8));
            empresa.MotivoSituacaoCadastral = int.Parse(linha.Substring(233, 2));
            empresa.NomeCidadeExterior      = linha.Substring(235, 55);
            empresa.CodigoPais              = linha.Substring(290, 3);
            empresa.NomePais                = linha.Substring(293, 70);
            empresa.CodigoNaturezaJuridica  = int.Parse(linha.Substring(363, 4));
            empresa.DataInicioAtividade     = ParseHelpers.StringToDateTime(linha.Substring(367, 8));
            empresa.CnaeFiscal              = int.Parse(linha.Substring(375, 7));
            empresa.DescricaoTipoLogradouro = linha.Substring(382, 20);
            empresa.Logradouro              = linha.Substring(402, 60);
            empresa.Numero                  = linha.Substring(462, 6);
            empresa.Complemento             = linha.Substring(468, 156);
            empresa.Bairro                  = linha.Substring(624, 50);
            empresa.CEP                     = linha.Substring(674, 8);
            empresa.UF                      = linha.Substring(682, 2);
            empresa.CodigoMunicipio         = int.Parse(linha.Substring(684, 4));
            empresa.Municipio               = linha.Substring(688, 50);
            empresa.DddTelefone1            = linha.Substring(738, 4);
            empresa.Telefone1               = linha.Substring(742, 8);
            empresa.DddTelefone2            = linha.Substring(750, 4);
            empresa.Telefone2               = linha.Substring(754, 8);
            empresa.Email                   = linha.Substring(774, 115);
            empresa.QualificacaoResponsavel = int.Parse(linha.Substring(889, 2));
            empresa.CapitalSocial           = long.Parse(linha.Substring(891, 14));
            empresa.PorteEmpresa            = (ePorteEmpresa)int.Parse(linha.Substring(905, 2));
            empresa.OpcaoSimples            = (eOpcaoSimples)int.Parse(linha.Substring(907, 1));
            empresa.DataOpcaoSimples        = ParseHelpers.StringToDateTime(linha.Substring(908, 8));
            empresa.DataExclusaoSimples     = ParseHelpers.StringToDateTime(linha.Substring(916, 8));
            empresa.OpcaoPeloMEI            = linha.Substring(924, 1) == "S" ? true : false;
            empresa.SituacaoEspecial        = linha.Substring(925, 23);
            empresa.DataSituacaoEspecial    = ParseHelpers.StringToDateTime(linha.Substring(948, 8));
            empresas.Add(empresa);
        }
예제 #20
0
        public static int RunMenu(List <Pair <string, Func <int> > > menu)
        {
            int errorCount = 0;

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("What do you want to do? (Esc to quit)");
                for (int i = 0; i < menu.Count; i++)
                {
                    Console.WriteLine(PrintHelpers.HexDigitChar(i + 1) + ". " + menu[i].Key);
                }
                Console.WriteLine("Space. Run all tests");

                char c = default(char);
                for (ConsoleKeyInfo k; (k = Console.ReadKey(true)).Key != ConsoleKey.Enter;)
                {
                    if (k.Key == ConsoleKey.Escape)
                    {
                        return(errorCount);
                    }
                    else
                    {
                        c = k.KeyChar;
                        break;
                    }
                }

                if (c == ' ')
                {
                    errorCount += RunAllTests(menu);
                }
                else
                {
                    int i = ParseHelpers.HexDigitValue(c);
                    if (i > 0 && i <= menu.Count)
                    {
                        errorCount += menu[i - 1].Value();
                    }
                }
            }
        }
예제 #21
0
        static bool ScanUnicodeEscape(ref UString text, StringBuilder parsed, char c)
        {
            // I can't imagine why this exists in C# in the first place. Unicode
            // escapes inside identifiers are required to be letters or digits,
            // although my lexer doesn't enforce this (EC# needs no such rule.)
            if (c != '\\')
            {
                return(false);
            }
            char u   = text.TryGet(1, '\0');
            int  len = 4;

            if (u == 'u' || u == 'U')
            {
                if (u == 'U')
                {
                    len = 8;
                }
                if (text.Length < 2 + len)
                {
                    return(false);
                }

                var digits = text.Substring(2, len);
                int code;
                if (ParseHelpers.TryParseHex(digits, out code) && code <= 0x0010FFFF)
                {
                    if (code >= 0x10000)
                    {
                        parsed.Append((char)(0xD800 + ((code - 0x10000) >> 10)));
                        parsed.Append((char)(0xDC00 + ((code - 0x10000) & 0x3FF)));
                    }
                    else
                    {
                        parsed.Append((char)code);
                    }
                    text = text.Substring(2 + len);
                    return(true);
                }
            }
            return(false);
        }
        public override void LoadDataFromXML()
        {
            bool exists = false;

            if (DataXMLDoc != null)
            {
                _objectID = ParseHelpers.GetStringFromVD2Data(DataXMLDoc, "objectID", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("objectID", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("objectID", EditorUI.UI.Ships.DoesPropertyExistInBaseData(objectID, "objectID"));
                }
                SetPropertyExists("objectID", exists);

                _systemName = ParseHelpers.GetStringFromVD2Data(DataXMLDoc, "systemName", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("systemName", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("systemName", EditorUI.UI.Ships.DoesPropertyExistInBaseData(GetObjectID(), "systemName"));
                }
                SetPropertyExists("systemName", exists);

                _renderDistance = ParseHelpers.GetInt32FromVD2Data(DataXMLDoc, "renderDistance", out exists);
                if (Source.ShortName == "Base")
                {
                    SetPropertyExistsInBaseData("renderDistance", exists);
                }
                else
                {
                    SetPropertyExistsInBaseData("renderDistance", EditorUI.UI.Ships.DoesPropertyExistInBaseData(GetObjectID(), "renderDistance"));
                }
                SetPropertyExists("renderDistance", exists);

                base.LoadDataFromXML();
            }
        }
예제 #23
0
        static bool ParseSigned(UString s, out long n)
        {
            n = 0;
            bool negative;
            int  radix = GetSignAndRadix(ref s, out negative);

            if (radix == 0)
            {
                return(false);
            }
            var   flags = ParseNumberFlag.SkipSingleQuotes | ParseNumberFlag.SkipUnderscores | ParseNumberFlag.StopBeforeOverflow;
            ulong u;

            if (ParseHelpers.TryParseUInt(ref s, out u, radix, flags) && s.Length == 0)
            {
                n = negative ? -(long)u : (long)u;
                return((long)u >= 0);
            }
            return(false);
        }
예제 #24
0
        public static int RunMenu(IList <Pair <string, Func <int> > > menu, IEnumerable <char> input)
        {
            var reader     = (input ?? ConsoleChars()).GetEnumerator();
            int errorCount = 0;

            for (;;)
            {
                Console.WriteLine();
                Console.WriteLine("What do you want to do? (Esc to quit)");
                for (int i = 0; i < menu.Count; i++)
                {
                    Console.WriteLine(PrintHelpers.HexDigitChar(i + 1) + ". " + menu[i].Key);
                }
                Console.WriteLine("Space. Run all tests");

                if (!reader.MoveNext())
                {
                    break;
                }

                char c = reader.Current;
                if (c == ' ')
                {
                    for (int i = 0; i < menu.Count; i++)
                    {
                        Console.WriteLine();
                        ConsoleMessageSink.WriteColoredMessage(ConsoleColor.White, i + 1, menu[i].Key);
                        errorCount += menu[i].Value();
                    }
                }
                else
                {
                    int i = ParseHelpers.HexDigitValue(c);
                    if (i > 0 && i <= menu.Count)
                    {
                        errorCount += menu[i - 1].Value();
                    }
                }
            }
            return(errorCount);
        }
예제 #25
0
        [Test] public void TestUnescape2()
        {
            EscapeC encountered;

            Assert.AreEqual(@"abcd", ParseHelpers.UnescapeCStyle(@"abcd", out encountered, false).ToString());
            Assert.AreEqual(encountered, default(EscapeC));
            Assert.AreEqual("\0ab", ParseHelpers.UnescapeCStyle(@"\0abc".Slice(0, 4), out encountered, false).ToString());
            Assert.AreEqual(EscapeC.HasEscapes, encountered);
            Assert.AreEqual("a\bc", ParseHelpers.UnescapeCStyle(@"a\bc", out encountered, false).ToString());
            Assert.AreEqual(EscapeC.HasEscapes | EscapeC.ABFV, encountered);
            Assert.AreEqual("\n", ParseHelpers.UnescapeCStyle(@"\u000A", out encountered, false).ToString());
            Assert.AreEqual(EscapeC.HasEscapes | EscapeC.Control, encountered);
            Assert.AreEqual("xx\x88", ParseHelpers.UnescapeCStyle(@"xx\x88", out encountered, false).ToString());
            Assert.AreEqual(EscapeC.HasEscapes | EscapeC.NonAscii | EscapeC.BackslashX, encountered);
            Assert.AreEqual("\u0088" + "99", ParseHelpers.UnescapeCStyle(@"\x8899", out encountered, false).ToString());
            Assert.AreEqual(EscapeC.HasEscapes | EscapeC.NonAscii | EscapeC.BackslashX, encountered);
            Assert.AreEqual("ba\\z", ParseHelpers.UnescapeCStyle(@"ba\z", out encountered, false).ToString());
            Assert.AreEqual(EscapeC.HasEscapes | EscapeC.Unrecognized, encountered);
            Assert.AreEqual("baz", ParseHelpers.UnescapeCStyle(@"ba\z", out encountered, true).ToString());
            Assert.AreEqual(EscapeC.HasEscapes | EscapeC.Unrecognized, encountered);
        }
예제 #26
0
        private static string GetStringsNotEqualMessage(string a, string b)
        {
            // TODO: test this code
            if (a == null || b == null)
            {
                return(GetObjectMismatchMessage(a, b));
            }
            else
            {
                int i, c = System.Math.Min((a ?? "").Length, (b ?? "").Length);
                for (i = 0; i < c; i++)
                {
                    if (a[i] != b[i])
                    {
                        break;
                    }
                }
                StringBuilder msg = new StringBuilder();
                if (a.Length == b.Length)
                {
                    msg.AppendFormat("  String lengths are both {0}. Strings differ at index {1}.\n", c, i);
                }
                else
                {
                    msg.AppendFormat("  Expected string length {0} but was {1}. Strings differ at index {2}.\n", a.Length, b.Length, i);
                }
                int a_i = i, b_i = i, maxlen = System.Math.Max(a.Length, b.Length);
                msg.AppendFormat("  Expected: {0}\n", GetQuotedString(ref a, ref a_i, maxlen));
                msg.AppendFormat("  But was:  {0}\n", GetQuotedString(ref b, ref b_i, maxlen));

                int TailLength = "-----------".Length;
                var prefix     = b.Left(b_i);
                int i_adjusted = ParseHelpers.EscapeCStyle(prefix, EscapeC.Control | EscapeC.DoubleQuotes, '"').Length;
                msg.Append(' ', 2);
                msg.Append('-', TailLength + i_adjusted);
                msg.Append("^\n");
                return(msg.ToString());
            }
        }
예제 #27
0
        static bool ParseSigned(UString s, out BigInteger n)
        {
            n = 0;
            bool negative;
            int  radix = GetSignAndRadix(ref s, out negative);

            if (radix == 0)
            {
                return(false);
            }
            var flags = ParseNumberFlag.SkipSingleQuotes | ParseNumberFlag.SkipUnderscores | ParseNumberFlag.StopBeforeOverflow;

            if (ParseHelpers.TryParseUInt(ref s, out n, radix, flags) && s.Length == 0)
            {
                if (negative)
                {
                    n = -n;
                }
                return(true);
            }
            return(false);
        }
예제 #28
0
        static string GetQuotedString(ref string s, ref int dif_i, int len)
        {
            int maxw = TruncateStringsLongerThan;

            if (len > maxw)
            {
                if (dif_i < maxw / 2)
                {
                    s = s.Left(maxw - 3) + "...";                     // "beginning..."
                }
                else if (len - dif_i < maxw / 2)
                {
                    s      = "..." + s.SafeSubstring(len - (maxw - 3));                // "...ending"
                    dif_i -= len - maxw;
                }
                else
                {
                    s     = "..." + s.SafeSubstring(dif_i - maxw / 2 + 3, maxw - 6) + "...";
                    dif_i = maxw / 2;                     // "...middle..."
                }
            }
            return("\"" + ParseHelpers.EscapeCStyle(s, EscapeC.Default, '"') + "\"");
        }
예제 #29
0
 private static void Append(StringBuilder sb, int c)
 {
     if (c < 32 || c == '\\' || c == ']')
     {
         if (c <= -1)
         {
             sb.Append(@"\$");
         }
         else
         {
             sb.Append(ParseHelpers.EscapeCStyle(((char)c).ToString(), EscapeC.Control | EscapeC.ABFV, ']'));
         }
     }
     else if (c == '-' || c == '^' && sb.Length == 1)
     {
         sb.Append('\\');
         sb.Append((char)c);
     }
     else
     {
         sb.Append((char)c);
     }
 }
예제 #30
0
        /// <summary>
        /// Parsing helper method.
        /// </summary>
        private static void AppendTextToListItem(ListItemBlock listItem, string markdown, int start, int end, bool newLine = false)
        {
            ListItemBuilder listItemBuilder = null;

            if (listItem.Blocks.Count > 0)
            {
                listItemBuilder = listItem.Blocks[listItem.Blocks.Count - 1] as ListItemBuilder;
            }

            if (listItemBuilder == null)
            {
                // Add a new block.
                listItemBuilder = new ListItemBuilder();
                listItem.Blocks.Add(listItemBuilder);
            }

            var builder = listItemBuilder.Builder;

            if (builder.Length >= 2 &&
                ParseHelpers.IsMarkdownWhiteSpace(builder[builder.Length - 2]) &&
                ParseHelpers.IsMarkdownWhiteSpace(builder[builder.Length - 1]))
            {
                builder.Length -= 2;
                builder.AppendLine();
            }
            else if (builder.Length > 0)
            {
                builder.Append(' ');
            }

            if (newLine)
            {
                builder.Append(Environment.NewLine);
            }

            builder.Append(markdown.Substring(start, end - start));
        }