/// <summary> /// Fixes the provided string /// </summary> /// <param name="input">Text to fix</param> /// <param name="output">Fixed text</param> /// <param name="fixTextTags"></param> /// <param name="preserveNumbers"></param> /// <param name="farsi"></param> /// <returns>Fixed text</returns> public static void FixRTL( string input, FastStringBuilder output, bool farsi = true, bool fixTextTags = true, bool preserveNumbers = false) { inputBuilder.SetValue(input); TashkeelFixer.RemoveTashkeel(inputBuilder); // The shape of the letters in shapeFixedLetters is fixed according to their position in word. But the flow of the text is not fixed. GlyphFixer.Fix(inputBuilder, glyphFixerOutput, preserveNumbers, farsi, fixTextTags); //Restore tashkeel to their places. TashkeelFixer.RestoreTashkeel(glyphFixerOutput); // Fix flow of the text and put the result in FinalLetters field LigatureFixer.Fix(glyphFixerOutput, output, farsi, fixTextTags, preserveNumbers); if (fixTextTags) { RichTextFixer.Fix(output); } inputBuilder.Clear(); }
// 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;"); }
private static Token CreateString(RootNode rootNode, SourceReader Source, FastStringBuilder builder, char quote, TokenType literalType) { var token = rootNode.ProvideToken(); builder.Clear(); token.Type = literalType; //Opening quote Source.Pop(); token.Start = Source.Location; while (Source.Peek() != quote) { if (Source.Peek() == '\\') { builder.Append(Source.Pop()); } builder.Append(Source.Pop()); } ; //Closing quote Source.Pop(); token.End = Source.Location; token.Content = new FastString(rootNode, builder); return(token); }
public void FastStringBuilder_ShouldParseInt() { var builder = new FastStringBuilder(); builder.Append("1233321"); Assert.AreEqual(1233321, builder.ParseInt()); builder.Clear(); builder.Append("+1235321"); Assert.AreEqual(1235321, builder.ParseInt()); builder.Clear(); builder.Append("-1234321"); Assert.AreEqual(-1234321, builder.ParseInt()); }
private static Token WrapSymbol(RootNode rootNode, SourceReader Source, FastStringBuilder builder, TokenType type) { var token = rootNode.ProvideToken(); builder.Clear(); token.Type = type; token.Start = Source.Location; builder.Append(Source.Pop()); token.End = Source.Location; token.Content = new FastString(rootNode, builder); return(token); }
public static StepTokenKind ReadNext(FastBinaryReader reader, FastStringBuilder buffer) { int current; while ((current = reader.Read()) != -1) { var ch = (char)current; switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { buffer.Clear(); buffer.Append(ch); return(ParseNumberKind(reader, buffer)); }; case '-': case '+': { if (IsDigit(reader.Peek())) { buffer.Clear(); buffer.Append(ch); return(ParseNumberKind(reader, buffer)); } else { throw new UnexpectedCharacterException(ch); } } case '#': { if (!IsDigit(reader.Peek())) { throw new UnexpectedCharacterException(ch); } buffer.Clear(); do { buffer.Append((char)reader.Read()); }while (IsDigit(reader.Peek())); return(StepTokenKind.EntityInstanceName); } case '"': { throw new NotImplementedException("binary"); } case '\'': { buffer.Clear(); return(ParseStringKind(reader, buffer)); } case '!': { throw new NotImplementedException("user defined keyword"); } case '.': { if (!IsUpper(reader.Peek())) { throw new UnexpectedCharacterException(ch); } buffer.Clear(); do { buffer.Append((char)reader.Read()); } while (IsUpperOrDigit(reader.Peek())); if (reader.Peek() == '.') { reader.Read(); return(StepTokenKind.Enumeration); } else { throw new UnexpectedCharacterException((char)reader.Peek()); } } case '=': return(StepTokenKind.Assignment); case '*': return(StepTokenKind.Asterisk); case '$': return(StepTokenKind.Dollar); case ';': return(StepTokenKind.Semicolon); case '(': return(StepTokenKind.LeftParen); case ')': return(StepTokenKind.RightParen); case '/': { if (reader.Peek() == '*') { while ((current = reader.Read()) != -1) { if (current == '*' && reader.Peek() == '/') { reader.Read(); break; } } } else { return(StepTokenKind.Solidus); } } break; case ',': return(StepTokenKind.Comma); case ' ': break; default: { if (IsUpper(ch)) { buffer.Clear(); buffer.Append(ch); while (IsUpperOrDigitOrMinus(reader.Peek())) { buffer.Append((char)reader.Read()); } if (buffer.Equals("ISO-10303-21")) { return(StepTokenKind.Iso); } else if (buffer.Equals("END-ISO-10303-21")) { return(StepTokenKind.EndIso); } else if (buffer.Equals("HEADER")) { return(StepTokenKind.Header); } else if (buffer.Equals("ENDSEC")) { return(StepTokenKind.EndSection); } else if (buffer.Equals("DATA")) { return(StepTokenKind.Data); } else { return(StepTokenKind.StandardKeyword); } } else if (IsCharacter(ch)) { throw new UnexpectedCharacterException(ch); } break; } } } return(StepTokenKind.Eof); }