コード例 #1
0
ファイル: MSSQLDAC.cs プロジェクト: Sphere10/Framework
        // This needs to be done properly!
        protected override IEnumerable <string> GetBatches(ISQLBuilder sqlBuilder)
        {
            yield return("SET XACT_ABORT ON;");

            yield return("BEGIN TRANSACTION;");

            // TODO: issue batches in smaller chunks
            var currentBatch = new FastStringBuilder();

            foreach (var statement in sqlBuilder.Statements.Where(x => x.Type != SQLStatementType.TCL))
            {
                if (statement.Type == SQLStatementType.DDL)
                {
                    if (currentBatch.Length > 0)
                    {
                        yield return(currentBatch.ToString());

                        currentBatch.Clear();
                    }
                    yield return(statement.SQL);
                }
                else
                {
                    currentBatch.Append(statement.SQL);
                }
            }
            if (currentBatch.Length > 0)
            {
                yield return(currentBatch.ToString());
            }
            yield return("COMMIT TRANSACTION;");
        }
コード例 #2
0
        public void Append_WhenCapacityThresholdIsHit(string initial, char append, string expected)
        {
            var a = new FastStringBuilder(initial);

            a.Append(append);
            Assert.AreEqual(expected, a.ToString());
        }
コード例 #3
0
        public void Length_Set(string initial, int len, string expected)
        {
            var a = new FastStringBuilder(initial);

            a.Length = len;
            Assert.AreEqual(expected, a.ToString());
        }
コード例 #4
0
        public void Replace_CanReplaceStrings(string text, string oldStr, string newStr, string expected)
        {
            var fastString = new FastStringBuilder(text);

            fastString.Replace(oldStr, newStr);

            Assert.AreEqual(expected, fastString.ToString());
        }
コード例 #5
0
        public void SetValue_SetsTheValueOfStringBuilderWithProvidedText()
        {
            var builder = new FastStringBuilder(10);

            builder.SetValue("abcd");

            Assert.AreEqual("abcd", builder.ToString());
        }
コード例 #6
0
        public void SetValue_IncreasesCapacity_AsNeeded()
        {
            var builder = new FastStringBuilder(0);

            builder.SetValue("abcd");

            Assert.AreEqual("abcd", builder.ToString());
        }
コード例 #7
0
        public void SetValue_CanCopyValueOfAnotherStringBuilder()
        {
            var builder1 = new FastStringBuilder("my holy moly text");
            var builder2 = new FastStringBuilder(10);

            builder2.SetValue(builder1);

            Assert.AreEqual(builder1.ToString(), builder2.ToString());
        }
コード例 #8
0
ファイル: GlyphFixerTests.cs プロジェクト: mnarimani/RTLTMPro
        public void GlyphFixer_ConvertsNumbers_Hindu()
        {
            var text   = GetEnglishNumbers();
            var output = new FastStringBuilder(10);

            GlyphFixer.Fix(text, output, false, false, false);

            Assert.AreEqual(GetHinduNumbers().ToString(), output.ToString());
        }
コード例 #9
0
ファイル: GlyphFixerTests.cs プロジェクト: mnarimani/RTLTMPro
        public void GlyphFixer_PreservesNumbers_WhenPreserveNumberIsTrue()
        {
            var text   = GetEnglishNumbers();
            var output = new FastStringBuilder(10);

            GlyphFixer.Fix(text, output, true, false, false);

            Assert.AreEqual(text.ToString(), output.ToString());
        }
コード例 #10
0
        public void Append_AddsACharacter()
        {
            var builder = new FastStringBuilder(10);

            builder.Append('a');
            builder.Append('b');
            builder.Append('c');

            Assert.AreEqual("abc", builder.ToString());
        }
コード例 #11
0
ファイル: GlyphFixerTests.cs プロジェクト: mnarimani/RTLTMPro
        public void GlyphFixer_FixesYah_WhenFarsiIsRequired()
        {
            var text = new FastStringBuilder(10);

            text.Append((char)ArabicGeneralLetters.Yeh);

            GlyphFixer.FixYah(text, true);

            Assert.AreEqual(((char)ArabicGeneralLetters.FarsiYeh).ToString(), text.ToString());
        }
コード例 #12
0
        public void Reverse_CanReversePartOfString_WhenLengthIsOdd(int start, int length, string expected)
        {
            // Arrange
            var builder = new FastStringBuilder("abcdefg");

            // Act
            builder.Reverse(start, length);

            // Assert
            Assert.AreEqual(expected, builder.ToString());
        }
コード例 #13
0
        public void SetValue_MakesIndependentCopies()
        {
            var builder1 = new FastStringBuilder("my holy moly text");
            var builder2 = new FastStringBuilder(10);

            builder2.SetValue(builder1);

            builder1.Set(5, 'f');

            Assert.AreNotEqual(builder1.ToString(), builder2.ToString());
        }
コード例 #14
0
        public void Fix_Reverses_SimpleOpenAndClosingTagWithValue()
        {
            // Arrange
            var text = new FastStringBuilder("text </open> text <open=134>");

            // Act
            RichTextFixer.Fix(text);

            // Assert
            Assert.AreEqual("text >nepo/< text >431=nepo<", text.ToString());
        }
コード例 #15
0
        public void Fix_Reverses_SelfContainedTags()
        {
            // Arrange
            var text = new FastStringBuilder("text <self-contained/> text");

            // Act
            RichTextFixer.Fix(text);

            // Assert
            Assert.AreEqual("text >/deniatnoc-fles< text", text.ToString());
        }
コード例 #16
0
        public void Fix_Reverses_OpenTag_ThatDoesntHaveClosingTag()
        {
            // Arrange
            var text = new FastStringBuilder("text <open> text");

            // Act
            RichTextFixer.Fix(text);

            // Assert
            Assert.AreEqual("text >nepo< text", text.ToString());
        }
コード例 #17
0
        public void Reverse_CanReverseTheWholeString_WhenLengthIsOdd()
        {
            // Arrange
            var builder = new FastStringBuilder("abcdefg");

            // Act
            builder.Reverse(0, builder.Length);

            // Assert
            Assert.AreEqual("gfedcba", builder.ToString());
        }
コード例 #18
0
        public void GlyphFixer_ConvertsNumbers_Farsi()
        {
            var text   = GetEnglishNumbers();
            var output = new FastStringBuilder(10);

            GlyphFixer.Fix(text, output, false, true, false);

            Debug.Log("Output: " + output);

            Assert.AreEqual(GetFarsiNumbers().ToString(), output.ToString());
        }
コード例 #19
0
        public void Remove_RemovesAllOccurrencesOfCharacter()
        {
            // Arrange
            var builder = new FastStringBuilder("cabccdececgc");

            // Act
            builder.RemoveAll('c');

            // Assert
            Assert.AreEqual("abdeeg", builder.ToString());
        }
コード例 #20
0
        public void Insert_CanInsertPartOfAnotherFastStringBuilder(int position, int start, int length, string expected)
        {
            // Arrange
            var a = new FastStringBuilder("first");
            var b = new FastStringBuilder("second");

            // Act
            a.Insert(position, b, start, length);

            // Assert
            Assert.AreEqual(expected, a.ToString());
        }
コード例 #21
0
        public void GlyphFixer_FixesYah_WhenFarsiIsRequired()
        {
            var text = new FastStringBuilder(10);

            text.Append((char)GeneralLetters.Ya);

            Debug.Log("Before: " + text);

            GlyphFixer.FixYah(text, true);

            Debug.Log("After: " + text);

            Assert.AreEqual(((char)GeneralLetters.PersianYa).ToString(), text.ToString());
        }
コード例 #22
0
        public override string ToString()
        {
            var query = base.ToString();

            if (StatementCount <= 1)
            {
                query = query.Trim();                 // only trim for small queries as memory may be wasted otherwise
                if (query.EndsWith(StatementTerminator))
                {
                    query = query.Substring(0, query.Length - StatementTerminator.Length);
                }
            }
            else
            {
                var stringBuilder = new FastStringBuilder();
                stringBuilder.AppendFormat("SET TERM {0};{1}", StatementTerminator, Environment.NewLine);
                if (_variableDeclarations.Count > 0)
                {
                    stringBuilder.AppendLine("EXECUTE BLOCK AS");
                    stringBuilder.AppendLine("BEGIN");
                    foreach (var variable in _variableDeclarations.Keys)
                    {
                        stringBuilder.AppendFormat("DECLARE VARIABLE {0} {1}{2}{3}", variable, ConvertTypeToSQLType(_variableDeclarations[variable]), StatementTerminator, Environment.NewLine);
                    }
                }

                stringBuilder.Append(query);
                if (_variableDeclarations.Count > 0)
                {
                    stringBuilder.Append("END");
                }
                query = stringBuilder.ToString();
            }

            return(query);
        }
コード例 #23
0
 public override string ToString()
 {
     return(StringBuilder?.ToString());
 }
コード例 #24
0
        /// <summary>
        /// Gets an identifier from the reader such as a variable reference, null, true, or false.
        /// Follows C# rules, non-qouted string starting with a letter or "_" followed by letters digits or "_"
        /// </summary>
        /// <param name="start">the starting character</param>
        /// <param name="buffer">a buffer to hold input</param>
        /// <returns>identifier token</returns>
        private Token GetIdentifier(char start, FastStringBuilder buffer)
        {

            buffer.Append(start);
            int c;
            char ch;
            while ((c = _reader.Peek()) != -1)
            {
                ch = (char)c;
                if (char.IsLetterOrDigit(ch) || ch == '_')
                {
                    buffer.Append(ch);
                }
                else
                {
                    return new Token(TokenType.Identifier, buffer.ToString());
                }
                _reader.Read();
            }
            return new Token(TokenType.Identifier, buffer.ToString());
        }
コード例 #25
0
        /// <summary>
        /// Gets a number from the reader, which can be integer, floating point or scientific notation
        /// Examples: 123343, -123232, 12.345, -45.3434, 3.45E+10
        /// </summary>
        /// <param name="start">the starting character</param>
        /// <param name="buffer">buffer to hold input</param>
        /// <returns>number token</returns>
        private Token GetNumber(char start, FastStringBuilder buffer)
        {
            char ch = start;
            buffer.Append(ch);
            int i = (start == '.') ? 1 : 0;

            while (i < 3)
            {
                switch (i)
                {
                    case 0: // first part of integer
                        GetIntegerPart(buffer);
                        ch = (char)_reader.Peek();
                        if (ch == '.')
                        {
                            i=1;  // try to read fractional now
                            buffer.Append((char)_reader.Read());
                        }
                        else if (ch == 'e' || ch == 'E')
                        {
                            i = 2; // try to read exponent now
                            buffer.Append((char)_reader.Read());
                        }
                        else
                        {
                            i = 4;  //break out
                            break;
                        }
                        break;
                    case 1: // fractional part
                        GetIntegerPart(buffer);
                        ch = (char)_reader.Peek();
                        if (ch == '.')
                        {
                            throw new ParseException("Invalid number exception");
                        }
                        else if (ch == 'e' || ch == 'E')
                        {
                            i = 2; // read exponent
                            buffer.Append((char)_reader.Read());
                        }
                        else
                        {
                            i = 3; // break out
                        }
                        break;
                    case 2: // scientific notation
                        ch = (char)_reader.Peek();
                        //check for an optional sign
                        if (ch == '+' || ch == '-')
                        {
                            buffer.Append((char)_reader.Read());
                        }
                        GetIntegerPart(buffer);
                        ch = (char)_reader.Peek();
                        if (ch == '.')
                        {
                            throw new ParseException("Invalid number exception");
                        }
                        else
                        {
                            i = 3; // break out
                        }
                        break;
                }
            }
            return new Token(TokenType.Number, buffer.ToString());
        }
コード例 #26
0
        /// <summary>
        /// Gets a single or double qouted string from the reader, handling and escape characters
        /// </summary>
        /// <param name="start">the starting character</param>
        /// <param name="buffer">buffer for input</param>
        /// <returns>string token</returns>
        private Token GetQuotedString(char start, FastStringBuilder buffer)
        {
            char quoteChar = start;
            bool escape = false;
            char ch;
            int c;
            while ((c = _reader.Read()) != -1) {
                ch = (char) c;

                if (escape)
                {
                    switch (ch)
                    {
                        case 't': // horizantal tab
                            buffer.Append('\t');
                            break;
                        case 'n': // newline
                            buffer.Append('\n');
                            break;
                        case '\\': // reverse solidus
                            buffer.Append('\\');
                            break;
                        case '/':  // solidus
                            buffer.Append('/');
                            break;
                        case 'b':  // backspace
                            buffer.Append('\b');
                            break;
                        case 'f':  // formfeed
                            buffer.Append('\f');
                            break;
                        case 'r': // carriage return
                            buffer.Append('\r');
                            break;
                        case 'u': // unicode escape sequence \unnnn
                            {
                                char[] ucodeChar = new char[4];
                                int nRead = _reader.Read(ucodeChar, 0, 4);
                                if (nRead != 4)
                                    throw new ParseException("Invalid unicode escape sequence, expecting \"\\unnnn\", but got " + (new string(ucodeChar, 0, nRead)));
                                buffer.Append((char)uint.Parse(new string(ucodeChar), System.Globalization.NumberStyles.HexNumber));
                            }
                            break;
                        default:
                            buffer.Append(ch);
                            break;
                    }
                    escape = false;
                }
                else
                {
                    if (ch == '\\')
                    {
                        escape = true;
                    }
                    else if (ch == quoteChar)
                    {
                        return new Token(quoteChar == '"' ? TokenType.DoubleQuotedString : TokenType.SingleQuotedString, buffer.ToString());
                        buffer.Length = 0;
                    }
                    else
                    {
                        buffer.Append(ch);
                    }
                }
            }
            throw new ParseException("Unterminated string constant");
        }
コード例 #27
0
ファイル: StringValue.cs プロジェクト: ghord/SharpExpress
 public StringValue(FastStringBuilder builder) : base(StepValueKind.String,
                                                      builder?.ToString() ?? throw new ArgumentNullException(nameof(builder)))
 {
 }