private IEnumerable<ClassificationLine> GetClassificationLines(string storyText) { var story = _parser.Parse(storyText, "ignore"); var bodyLines = story.Scenarios.SelectMany(x => x.Body); var scenarioLines = story.Scenarios.First().Background.Union(bodyLines); var allLines = new LineSplitter().Split(storyText); foreach (var line in allLines) { yield return new ClassificationLine { Text = line.Text, Type = GetClassificationType(line, scenarioLines, story.Scenarios) }; } }
public void DetectorTestTwoLinesArrivingTogether() { // Create a list to hold data packets. List <byte[]> result_lines = new List <byte[]>(); // Create a line splitter object. LineSplitter lineSplitter = new LineSplitter(); // When a new data packet is received, add it to the list of data packets. lineSplitter.LineReceived += result_lines.Add; // Send an array of bytes into the splitter. lineSplitter.OnIncomingBinaryBlock(new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x72, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x21, 0x0D, 0x0A, 0x53, 0x70, 0x61, 0x72, 0x78, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x65, 0x73, 0x74, 0x2E, 0x0D, 0x0A }); // Check that the line splitter correctly found two lines. Assert.AreEqual(2, result_lines.Count); }
public static void TestParse() { string content = "[root] -> Hello.\n" + "[root] -> Hi [nickname as name]!\n" + " Do you mind if I call you '[=name]'?\n" + "# Add more nicknames if required.\n" + "[nickname] -> mate\n" + "[nickname] -> buddy\n"; var lines = LineSplitter.getLines(content, "internal"); Console.WriteLine(lines.Count); foreach (var line in lines) { Console.WriteLine(line.ToString()); } }
ModelPart ReadBB(LineSplitter ls) { ModelPart result = new ModelPart(); string type = ls.Next(); int H = ls.NextInt(); int W = ls.NextInt(); Color c; string[] rgb; rgb = ls.Next().Split(':'); c = new Microsoft.Xna.Framework.Color(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])); TestParts.PartLight p = new TestParts.PartLight(c); p.Width = W; p.Height = H; result = p; return(result); }
void RenderToConsole(ActivityElement element, ICommandOutputProvider commandOutputProvider, string indent) { if (!IsPrintable(element)) { return; } if (element.Status == ActivityStatus.Success) { Console.ForegroundColor = ConsoleColor.Green; } else if (element.Status == ActivityStatus.SuccessWithWarning) { Console.ForegroundColor = ConsoleColor.Yellow; } else if (element.Status == ActivityStatus.Failed) { Console.ForegroundColor = ConsoleColor.Red; } Console.WriteLine("{0} {1}: {2}", indent, element.Status, element.Name); Console.ResetColor(); foreach (var logEntry in element.LogElements) { if (logEntry.Category == "Error" || logEntry.Category == "Fatal") { Console.ForegroundColor = ConsoleColor.Red; } else if (logEntry.Category == "Warning") { Console.ForegroundColor = ConsoleColor.Yellow; } Console.WriteLine("{0}{1,-8} {2}", indent, logEntry.Category, LineSplitter.Split(indent + new string(' ', 11), logEntry.MessageText)); Console.ResetColor(); } foreach (var child in element.Children) { RenderToConsole(child, commandOutputProvider, indent + " "); } }
public void SetHeader(string header) { var parts = LineSplitter.Split(header); if (ValidateLineParts(parts)) { for (var i = 2; i < parts.Length; i++) { _periods.Add(new PeriodDefinition() { Name = parts[i].Replace("Value", ""), PeriodIndex = i }); } } else { throw new Exception("Invalid Header format"); } }
int[] ReadMesh() { LineSplitter ls = new LineSplitter(lines[state.LineNumber].Replace(',', ' ')); List <int> indices = new List <int>(); //keep going until end mesh command while (ls.Next() != "#endmesh") { //rewind because of next ls.Reset(); while (!ls.EOL) //read the rest of the line as ints { indices.Add(ls.NextInt()); } //prepare for next line state.LineNumber++; ls = new LineSplitter(lines[state.LineNumber].Replace(',', ' ')); } return(indices.ToArray()); }
private IEnumerable <string[]> SplitLine(string path) { var creator = IsPlainText ? (IStreamCreator) new PlainTextMemoryStreamCreator() : new TextFileStreamCreator(); using (var stream = creator.Create(path, Encoding)) using (var reader = new StreamReader(stream, Encoding)) { while (0 <= reader.Peek()) { var line = reader.ReadLine(); if (line.Contains(EndOfFile)) { continue; } var fields = LineSplitter?.Split(line).Select(field => field.Trim()).ToArray(); yield return(fields); } } }
public async Task ParseFilesAsync(string folderPath, string searchPattern) { var repository = repositoryFactory(); await repository.TruncateDataAsync(); var filesEnumerator = FilesEnumerator.GetFilesEnumeratorBlock(); var fileCreator = FileCreator.GetFileCreatorBlock(); filesEnumerator.LinkToAndPropagateCompleted(fileCreator); var fileLinesEnumerator = FileLinesEnumerator.GetFileLinesEnumeratorBlock(); fileCreator.LinkToAndPropagateCompleted(fileLinesEnumerator); var lineSplitter = LineSplitter.GetLineSplitterBlock(); fileLinesEnumerator.LinkToAndPropagateCompleted(lineSplitter); var fileWordCreator = FileWordCreator.GetFileWordCreatorBlock(); lineSplitter.LinkToAndPropagateCompleted(fileWordCreator); var fileWordSaver = FileWordSaver.GetFileWordSaverBlock(repositoryFactory); fileWordCreator.LinkToAndPropagateCompleted(fileWordSaver); var nullTarget = DataflowBlock.NullTarget <FileWord>(); fileWordSaver.LinkTo(nullTarget); filesEnumerator.Post(new FilesEnumerator.EnumerateFolderTask { Folder = folderPath, SearchPattern = searchPattern }); filesEnumerator.Complete(); await fileWordSaver.Completion; }
public void Tildes_IsFilledCode() { LineSplitter .Split("~~~\nLine 1\nLine 2\n~~~") .Is(new List <LineOrFenced>() { new LineOrFenced("Line 1\nLine 2", true, null) }); LineSplitter .Split("~~~\nLine 1\nLine 2\n```") .IsNot(new List <LineOrFenced>() { new LineOrFenced("Line 1\nLine 2", true, null) }); LineSplitter .Split("~`~\nLine 1\nLine 2\n~`~") .IsNot(new List <LineOrFenced>() { new LineOrFenced("Line 1\nLine 2", true, null) }); }
/// <summary> /// Parses a line of tab delimited text into a process instruction /// </summary> /// <param name="processLine">A tab delimited line of text that confirms to the required format</param> public void AddProcessCommand(string processLine) { var parts = LineSplitter.Split(processLine); if (parts.Length != 3) { throw new Exception(string.Format("Invalid Configuration Line : {0}", processLine)); } var processor = new LineProcessor(); processor.VariableType = parts[0]; var statsOp = statisticCalculation.Invalid; if (parts[1].TryParseOperationType(out statsOp)) { processor.OperationType = statsOp; } else { throw new Exception(string.Format("Unrecognised statistics operation = {0}", parts[1])); } var period = periodChoice.Invalid; if (parts[2].TryParsePeriod(out period)) { processor.Period = period; } else { throw new Exception(string.Format("Unrecognised period choice = {0}", parts[2])); } _processors.Add(processor.Key, processor); }
public void ShouldSplitInputOnLines() { // should it be encoding aware?. var completer = new TaskCompletionSource <byte[]>(); var inputTask = completer.Task; var sut = new LineSplitter(); sut.InputTask = inputTask; var input = ("one" + Environment.NewLine + "two" + Environment.NewLine + "three").ToUtf8EncodedBytes(); completer.SetResult(input); var task = sut.GetItems(); task.Wait(); var expectedResult = new[] { "one".ToUtf8EncodedBytes(), "two".ToUtf8EncodedBytes(), "three".ToUtf8EncodedBytes() }; CollectionAssert.AreEqual(expectedResult, task.Result); }
private List <SubMatrix> GetLines() { LineSplitter lineSplitter = new LineSplitter(); return(lineSplitter.SplitToLines(matrix)); }
private FastCsvReader(IEnumerable <string> file, char separator = ',', IConverterSpec converter = null) { this.converter = converter ?? new DefaultConverterSpec(); enumerator = file.GetEnumerator(); splitter = new LineSplitter(separator); }
public IEnumerable <TotalTempLine> ParseLine(string line, ILineProcessInstructions instructions) { var result = new List <TotalTempLine>(); var parts = LineSplitter.Split(line); if (parts.Length < 3) { result.Add(new TotalTempLine(LineError.InvalidLineFormat(line))); return(result); } //first part - get the scenarie int sceneid; if (!int.TryParse(parts[0], out sceneid)) { result.Add(new TotalTempLine(LineError.InvalidSceneIdError(parts[0]))); return(result); } //get the variable type for this line var variableType = parts[1]; //only execute parsing and calculations if there is an instruction for this variable type if (instructions.Processors.Values.Any(e => e.VariableType == variableType)) { var periodValues = new List <PeriodValue>(); //parse the values for (var i = 2; i < parts.Length; i++) { double pv; if (double.TryParse(parts[i], out pv)) { periodValues.Add(new PeriodValue() { PeriodId = _periods[i - 2].Name, Value = pv }); } else { result.Add(new TotalTempLine(LineError.InvalidValueError(parts[i]))); } } instructions.ExtractPeriodValueOfInterest(periodValues, variableType).ForEach(r => result.Add(new TotalTempLine() { HasOperation = true, ScenarioId = sceneid, ValueOfRelevance = r.Value, VariableType = variableType, OperationType = r.Operation })); } return(result); }
public ModelGeometryCompiler(string input) { this.lines = SplitLines(input); LineSplitter ls = new LineSplitter(lines[state.LineNumber]); Dictionary <string, ModelPart> parts = new Dictionary <string, ModelPart>(); List <ModelPart> p = new List <ModelPart>(); string choreoname = ""; Vector3 offset = Vector3.Zero; string command = ls.Next(); while (command != "#endmodel") { switch (command) { case "#beginpart": { state.LineNumber++; parts.Add(ls.NextQuoted(), ReadPart()); break; } case "#beginassembly": { AssembleModel(parts); break; } case "#beginsymbols": { state.LineNumber++; BuildSymbolTable(); break; } case "#choreo": { choreoname = ls.NextQuoted(); break; } case "#offset": { float X, Y, Z; X = ls.NextFloat(); Y = ls.NextFloat(); Z = ls.NextFloat(); offset = new Vector3(X, Y, Z); break; } default: { //throw error here or something break; } } state.LineNumber++; ls = new LineSplitter(lines[state.LineNumber]); command = ls.Next(); } string choreofname = ModelBaseDir + "\\" + choreoname + ".mcf"; //create a dummy if doesn't exist. Dumb workaround but works for now if (!System.IO.File.Exists(choreofname)) { System.IO.FileStream s = System.IO.File.Create(choreofname); s.Close(); } Output.Choreo = LoadChoreo(System.IO.File.ReadAllText(choreofname)); Output.ChoreoName = choreoname; Output.Offset = offset; ls = null; }
// THIS FUNCTION BUILD INDIVIDUAL SUBOBJECTS FOR EACH OBJECT public static IEnumerable BuildSubtext (TTFTextInternal.LineLayout ll, LineSplitter split, int idx, Vector3 pos, TTFText tm) //out Bounds bounds, //out int num) { Vector3 adv = Vector3.zero; Bounds bounds = new Bounds (Vector3.zero, Vector3.zero); int num = 0; foreach (TTFTextInternal.LineLayout l in split(ll)) { //Debug.Log("ll=" + l.line + " pos=" + pos + " charpos0=" + l.charpositions[0] + " advlen=" + l.advance); GameObject go; // instantiate the letter bool b0 = ((l.line.Length > 0) && (l.GetCharStyle (0).GlyphPrefab != null)); if (b0 || (tm.GlyphPrefab != null)) { if (b0) { go = GameObject.Instantiate (l.GetCharStyle (0).GlyphPrefab) as GameObject; } else { go = GameObject.Instantiate (tm.GlyphPrefab) as GameObject; } } else { go = new GameObject (); go.AddComponent<MeshFilter> (); go.AddComponent<MeshRenderer> (); if (tm.gameObject.renderer != null) { if (tm.gameObject.renderer.sharedMaterials != null) { if ((tm.gameObject.renderer.sharedMaterials.Length != 0) && (tm.gameObject.renderer.sharedMaterials [0] != null)) { go.renderer.sharedMaterials = tm.gameObject.renderer.sharedMaterials; } } else { if (tm.gameObject.renderer.sharedMaterial != null) { go.renderer.sharedMaterial = tm.gameObject.renderer.sharedMaterial; } } } } // --------------------------------------------------------------------- // set up the letter/text positon and scale // --------------------------------------------------------------------- int no = idx + num; go.name = System.String.Format ("{0}. {1}", no, l.line); go.transform.parent = tm.transform; if (/*tm.rebuildLayout ||*/ (!tm.SaveTokenPos) || tm.TokenPos.Count <= no) { go.transform.localPosition = pos; go.transform.localRotation = Quaternion.identity; } else { TTFText.TrInfo tr = tm.TokenPos [no]; go.transform.localPosition = tr.localPosition; go.transform.localRotation = tr.localRotation; go.transform.localScale = tr.localScale; } if (l.line.Length > 0) { if ((l.GetCharStyle (0).sharedMaterials != null) && (l.GetCharStyle (0).sharedMaterials.Length > 0) && (l.GetCharStyle (0).sharedMaterials [0] != null)) { go.renderer.sharedMaterials = l.GetCharStyle (0).sharedMaterials; } } // ---------------------------------------------------------- // build the mesh associated with letter/text // ---------------------------------------------------------- Mesh mesh = new Mesh (); TTFTextInternal.Engine.BuildMesh (ref mesh, l, tm, out adv); Bounds b = mesh.bounds; b.center = b.center + pos; TTFTextInternal.Utilities.MergeBounds (ref bounds, b); // -------------------------------------------------------------------------- // set up some metadata so that the script attached to the letters may update // -------------------------------------------------------------------------- #if TTFTEXT_LITE if (tm.DemoMode) { #endif TTFSubtext st = go.GetComponent<TTFSubtext> (); if (st == null) { st = go.AddComponent<TTFSubtext> (); } #if !TTFTEXT_LITE st.Layout = l; #endif st.Text = l.line; st.LineNo = l.lineno; st.SequenceNo = idx + num; st.Advance = adv; #if TTFTEXT_LITE } #endif // --------------------------------------------------------------------- // // IF A SPECIAL TEXTURE IS AFFECTED TO THIS CHARACTER THIS IS THE MOMENT // // --------------------------------------------------------------------- if (l.line.Length >= 1) { if (((l.charmetadata [0] as TextureElement) != null)) { TextureElement tel = (l.charmetadata [0] as TextureElement); Material m = tel.material; Material [] mx = new Material[1]; if (m == null) { //m=new Material(Shader.Find("GUI/Text Shader")); m = new Material (Shader.Find ("Self-Illumin/Diffuse")); m.name = "[generated material for text]"; m.mainTexture = tel.texture; } mx [0] = m; go.renderer.sharedMaterials = mx; TTFTextReleaseTempResources rmod = go.GetComponent<TTFTextReleaseTempResources> (); if (rmod == null) { rmod = go.AddComponent<TTFTextReleaseTempResources> (); } if ((tel.material == null) && (tel.shouldReleaseMaterial)) { rmod.material = m; } if (tel.shouldReleaseTexture) { rmod.texture = tel.texture; } } else { int cmo = l.GetCharStyle (0).MaterialOffset; if (cmo != 0) { //Debug.Log(cmo); if (go.renderer != null) { if (go.renderer.sharedMaterials != null) { int ml = go.renderer.sharedMaterials.Length; int tml = 1; if (l.GetCharStyle (0).SplitSides) { tml = 3; TTFText.ExtrusionModeEnum em = l.GetCharStyle (0).ExtrusionMode; if (em == TTFText.ExtrusionModeEnum.None) { tml = 1; if (l.GetCharStyle (0).BackFace) { tml += 1; } } if (em == TTFText.ExtrusionModeEnum.Pipe) { tml = 1; } } int mo = ((cmo % ml) + ml) % ml; Material [] omx = go.renderer.sharedMaterials; Material [] nmx = new Material[tml]; //Debug.Log(mo); for (int i=0; i<tml; i++) { nmx [i] = omx [(i + mo) % ml]; } go.renderer.sharedMaterial = nmx [0]; //go.renderer.sharedMaterials=new Material[0] {nmx[0]}; //go.renderer. go.renderer.sharedMaterials = nmx; } } } } } // // time to update every one // UpdateComponentsWithNewMesh (go, mesh); pos += l.advance; num++; yield return bounds; } }
public void EmptyString() { var result = LineSplitter.TextAsCodeLines(string.Empty, TabCount); result[0].Line.ShouldBeEmpty(); }
public static Dictionary <string, Dictionary <string, PartAnimation> > LoadChoreo(string input) { Dictionary <string, Dictionary <string, PartAnimation> > result = new Dictionary <string, Dictionary <string, PartAnimation> >(); string[] filelines = SplitLines(input); int pointer = 0; Dictionary <string, PartAnimation> CurrentMove = new Dictionary <string, PartAnimation>(); string CurrentMoveName = ""; string CurrentPartName = ""; PartAnimation CurrentPart = new PartAnimation(); LineSplitter ls; while (pointer < filelines.Length) { ls = new LineSplitter(filelines[pointer]); string cmd = ls.Next(); switch (cmd) { case "#beginmove": { CurrentMove = new Dictionary <string, PartAnimation>(); CurrentMoveName = ls.NextQuoted(); break; } case "#endmove": { if (result.ContainsKey(CurrentMoveName)) { break; } result.Add(CurrentMoveName, CurrentMove); break; } case "#beginpart": { CurrentPart = new PartAnimation(); CurrentPartName = ls.NextQuoted(); break; } case "#endpart": { if (CurrentMove.ContainsKey(CurrentPartName)) { break; } CurrentMove.Add(CurrentPartName, CurrentPart); break; } case "#beginchoreo": { break; } case "#endchoreo": { break; } case "#moveparam": { break; } default: { ls.Reset(); float duration = ls.NextFloat(); Matrix transform = ls.NextTransform(); CurrentPart.Add(transform, duration); break; } } pointer++; } return(result); }
public LineSplitterTests() { _sut = new LineSplitter(); }
/// <summary> /// Split text by lines using line length /// </summary> /// <param name="text">splitted text</param> /// <param name="length">line length</param> /// <returns></returns> public static string[] SplitByLineLength(this string text, int length) { LineSplitter _splitter = new LineSplitter(length); return(_splitter.Split(text)); }
void AssembleModel(Dictionary <string, ModelPart> parts) { LineSplitter ls = new LineSplitter(lines[state.LineNumber]); ModelPart root = new ModelPart(); Stack <ModelPart> TreeBuilder = new Stack <ModelPart>(); ModelPart last; Model Model; int depth; while (ls.Next() != "#endassembly") { ls.Reset(); string name = ""; string first = ls.Next(); //first token if (first[0] == '*') //if first character is *, count { depth = first.Length; } else //root part { depth = 0; ls.Reset(); //rewind } name = ls.NextQuoted(); //part "name" used in animation string partname = ls.Next(); if (!parts.ContainsKey(partname)) //find part by name from loaded parts { state.LineNumber++; ls = new LineSplitter(lines[state.LineNumber]); continue; //skip if invalid part } Matrix m = ls.NextTransform(); //get whatever transforms are there ModelPart next = (ModelPart)parts[partname].Clone(); //both cool with 0 as default next.Phase = ls.NextFloat(); next.BoneFactor = ls.NextFloat(); next.Title = name; //determine correct parent while (depth < TreeBuilder.Count) //go back part by part until correct part is found ( { TreeBuilder.Pop(); } if (depth != 0) //the stack is not empty and its top is the last parent { TreeBuilder.Peek().Append(next, m); } else { root = next; } TreeBuilder.Push(next); //put current as last parent state.LineNumber++; ls = new LineSplitter(lines[state.LineNumber]); } Model = new Model(root); Output = Model; R = root; }