/// <summary> /// Gets the next line from a string, starting at a given position /// The returned string doesn't include the line ending, but we return /// what kind it was. The next point to read from is passed back in nextLineStart /// </summary> /// <param name="diff"></param> /// <param name="start"></param> /// <param name="le"></param> /// <param name="nextLineStart"></param> /// <returns></returns> public static string GetNextLineFromString(string diff, int start, out LineEndingType le, out int nextLineStart) { int pos = diff.Length; le = LineEndingType.Unknown; nextLineStart = diff.Length; int windowsLineEndingPos = diff.IndexOf("\r\n", start); int unixLineEnding = diff.IndexOf('\n', start); // make sure we get the closest line ending value if (windowsLineEndingPos != -1 && windowsLineEndingPos < unixLineEnding && windowsLineEndingPos + 1 < diff.Length) { le = LineEndingType.Win32; nextLineStart = windowsLineEndingPos + 2; pos = windowsLineEndingPos; } else if (unixLineEnding != -1) { le = LineEndingType.Unix; nextLineStart = unixLineEnding + 1; pos = unixLineEnding; } int len = pos - start; return(len > 0 ? diff.Substring(start, len) : string.Empty); }
public static string ForceLineEndings(string fileData, LineEndingType type) { var ret = new StringBuilder(fileData.Length); string ending; switch(type) { case LineEndingType.Windows: ending = "\r\n"; break; case LineEndingType.Posix: ending = "\n"; break; case LineEndingType.MacOS9: ending = "\r"; break; default: throw new Exception("Specify an explicit line ending type"); } foreach (var line in fileData.Split('\n')) { var fixedLine = line.Replace("\r", ""); ret.Append(fixedLine); ret.Append(ending); } return ret.ToString(); }
private static string GetLineEndingName(LineEndingType lineEndingType) { switch (lineEndingType) { case LineEndingType.Unknown: return("Unknown"); case LineEndingType.CRLF: return("Windows CR+LF"); case LineEndingType.LF: return("Unix LF"); case LineEndingType.CR: return("Macintosh CR"); case LineEndingType.LS: return("Unicode Line Separator"); case LineEndingType.PS: return("Unicode Paragraph Separator"); case LineEndingType.Mixed: return("Mixed"); } throw new InvalidOperationException("This line must never be reached."); }
public MainForm() { InitializeComponent(); Application.EnableVisualStyles(); this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); serialParityCmBx.SelectedIndex = 0; serialStopBitsCmBx.SelectedIndex = 1; serialBaudCmBx.SelectedIndex = 0; UpdateSerialPorts(); formatCmBx.SelectedIndex = 0; lineEndingCmBx.SelectedIndex = 0; LoadSerialSettigns(); LoadTcpSettings(); LoadUdpSettings(); LoadGlobalSettings(); searcher = new TxtBoxSearch(ref displayTxt); string selectedTxtFormat = formatCmBx.GetItemText(formatCmBx.SelectedItem); txtFormat = StringToTextFormatType(selectedTxtFormat); string selectedLineEnding = lineEndingCmBx.GetItemText(lineEndingCmBx.SelectedItem); lineEnding = StringToLineEndingType(selectedLineEnding); }
static void WriteStringToFile(string path, string fileData, LineEndingType lineType, bool emitUTF8Preamble) { using (var of = File.Open(path, FileMode.Create)) { var buf = Encoding.UTF8.GetBytes(ForceLineEndings(fileData, lineType)); if (emitUTF8Preamble) { of.Write(Encoding.UTF8.GetPreamble(), 0, Encoding.UTF8.GetPreamble().Length); } of.Write(buf, 0, buf.Length); } }
public static string ForceLineEndings(string fileData, LineEndingType type) { var ret = new StringBuilder(fileData.Length); string ending; switch (type) { case LineEndingType.Windows: ending = "\r\n"; break; case LineEndingType.Posix: ending = "\n"; break; case LineEndingType.MacOS9: ending = "\r"; break; default: throw new Exception("Specify an explicit line ending type"); } foreach (var line in fileData.Split('\n')) { var fixedLine = line.Replace("\r", ""); ret.Append(fixedLine); ret.Append(ending); } // Don't add new lines to the end of the file. string str = ret.ToString(); return(str.Substring(0, str.Length - ending.Length)); }
private static string GetLineEndingName(LineEndingType lineEndingType) { switch (lineEndingType) { case LineEndingType.Unknown: return "Unknown"; case LineEndingType.CRLF: return "Windows CR+LF"; case LineEndingType.LF: return "Unix LF"; case LineEndingType.CR: return "Macintosh CR"; case LineEndingType.LS: return "Unicode Line Separator"; case LineEndingType.PS: return "Unicode Paragraph Separator"; case LineEndingType.Mixed: return "Mixed"; } throw new InvalidOperationException("This line must never be reached."); }
static void WriteStringToFile(string path, string fileData, LineEndingType lineType) { using(var of = File.OpenWrite(path)) { var buf = Encoding.UTF8.GetBytes(ForceLineEndings(fileData, lineType)); of.Write(buf, 0, buf.Length); } }
static void WriteStringToFile(string path, string fileData, LineEndingType lineType, bool emitUTF8Preamble) { using (var of = File.Open(path, FileMode.Create)) { var buf = Encoding.UTF8.GetBytes(ForceLineEndings(fileData, lineType)); if (emitUTF8Preamble) of.Write(Encoding.UTF8.GetPreamble(), 0, Encoding.UTF8.GetPreamble().Length); of.Write(buf, 0, buf.Length); } }
public static string Get(this LineEndingType self) { return(self == LineEndingType.CRLF ? CRLF : LF); }
private static void GetTextStatistics(string text, out int numberOfWords, out LineEndingType lineEndingType) { // Examples: // "blah." = 1 word // "blah & blah" = 3 words // "blah-blah" = 1 word // Make sure the text ends with a space. text = text + " "; int numberOfCRLF = 0; int numberOfCR = 0; int numberOfLF = 0; int numberOfLS = 0; int numberOfPS = 0; numberOfWords = 0; for (int i = 0; i < text.Length - 1; i++) { // Every word ends with a whitespace character. if (char.IsWhiteSpace(text[i + 1]) && (char.IsLetterOrDigit(text[i]) || char.IsPunctuation(text[i]))) { numberOfWords++; } if (text[i] == CarriageReturn) { if (text[i + 1] == LineFeed) { numberOfCRLF++; } else { numberOfCR++; } } else if (text[i] == LineFeed) { // CRLF was already counted. if (i == 0 || text[i - 1] != CarriageReturn) { numberOfLF++; } } else if (text[i] == LineSeparator) { numberOfLS++; } else if (text[i] == ParagraphSeparator) { numberOfPS++; } } if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLF == 0 && numberOfLS == 0 && numberOfPS == 0) { lineEndingType = LineEndingType.Unknown; } else if (numberOfCR == 0 && numberOfLF == 0 && numberOfLS == 0 && numberOfPS == 0) { lineEndingType = LineEndingType.CRLF; } else if (numberOfCRLF == 0 && numberOfLF == 0 && numberOfLS == 0 && numberOfPS == 0) { lineEndingType = LineEndingType.CR; } else if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLS == 0 && numberOfPS == 0) { lineEndingType = LineEndingType.LF; } else if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLF == 0 && numberOfPS == 0) { lineEndingType = LineEndingType.LS; } else if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLF == 0 && numberOfLS == 0) { lineEndingType = LineEndingType.PS; } else { lineEndingType = LineEndingType.Mixed; } }
private static void GetTextStatistics(string text, out int numberOfWords, out LineEndingType lineEndingType) { // Examples: // "blah." = 1 word // "blah & blah" = 3 words // "blah-blah" = 1 word // Make sure the text ends with a space. text = text + " "; int numberOfCRLF = 0; int numberOfCR = 0; int numberOfLF = 0; int numberOfLS = 0; int numberOfPS = 0; numberOfWords = 0; for (int i = 0; i < text.Length - 1; i++) { // Every word ends with a whitespace character. if (char.IsWhiteSpace(text[i + 1]) && (char.IsLetterOrDigit(text[i]) || char.IsPunctuation(text[i]))) numberOfWords++; if (text[i] == CarriageReturn) { if (text[i + 1] == LineFeed) numberOfCRLF++; else numberOfCR++; } else if (text[i] == LineFeed) { // CRLF was already counted. if (i == 0 || text[i - 1] != CarriageReturn) numberOfLF++; } else if (text[i] == LineSeparator) { numberOfLS++; } else if (text[i] == ParagraphSeparator) { numberOfPS++; } } if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLF == 0 && numberOfLS == 0 && numberOfPS == 0) lineEndingType = LineEndingType.Unknown; else if (numberOfCR == 0 && numberOfLF == 0 && numberOfLS == 0 && numberOfPS == 0) lineEndingType = LineEndingType.CRLF; else if (numberOfCRLF == 0 && numberOfLF == 0 && numberOfLS == 0 && numberOfPS == 0) lineEndingType = LineEndingType.CR; else if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLS == 0 && numberOfPS == 0) lineEndingType = LineEndingType.LF; else if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLF == 0 && numberOfPS == 0) lineEndingType = LineEndingType.LS; else if (numberOfCRLF == 0 && numberOfCR == 0 && numberOfLF == 0 && numberOfLS == 0 ) lineEndingType = LineEndingType.PS; else lineEndingType = LineEndingType.Mixed; }
///// Create ///// public void GenerateCreateMesh(Vector2 pos, Polygon2D.PolygonType polygonType, float polygonSize, Controller.Extended.CreateController.CreateType createType, List <Vector2D> complexSlicerPointsList, Pair2D linearPair, float minVertexDistance, Transform transform, float lineWidth, float zPosition, float squareSize, LineEndingType endingType, int edges) { float size = squareSize; if (createType == Controller.Extended.CreateController.CreateType.Slice) { if (complexSlicerPointsList.Count > 0) { linearPair.A = new Vector2D(complexSlicerPointsList.First()); linearPair.B = new Vector2D(complexSlicerPointsList.Last()); GenerateSquare(linearPair.A.ToVector2(), size, transform, lineWidth, zPosition, endingType, edges); GenerateSquare(linearPair.B.ToVector2(), size, transform, lineWidth, zPosition, endingType, edges); Vector2D vA, vB; foreach (Pair2 pair in Pair2.GetList(complexSlicerPointsList, true)) { vA = new Vector2D(pair.a); vB = new Vector2D(pair.b); vA.Push(Vector2D.Atan2(pair.a, pair.b), -minVertexDistance / 5); vB.Push(Vector2D.Atan2(pair.a, pair.b), minVertexDistance / 5); CreateLine(new Pair2(vA.ToVector2(), vB.ToVector2()), transform.localScale, lineWidth, zPosition); } } } else { Polygon2D poly = Polygon2D.Create(polygonType, polygonSize).ToOffset(pos); Vector2D vA, vB; foreach (Pair2 pair in Pair2.GetList(poly.pointsList, true)) { vA = new Vector2D(pair.a); vB = new Vector2D(pair.b); vA.Push(Vector2D.Atan2(pair.a, pair.b), -minVertexDistance / 5); vB.Push(Vector2D.Atan2(pair.a, pair.b), minVertexDistance / 5); CreateLine(new Pair2(vA.ToVector2(), vB.ToVector2()), transform.localScale, lineWidth, zPosition); } } }
///// GENERAL ///// public void GenerateSquare(Vector2 point, float size, Transform transform, float width, float z, LineEndingType endingType, int edges) { if (endingType == LineEndingType.Square) { CreateLine(new Pair2(new Vector2(point.x - size, point.y - size), new Vector2(point.x + size, point.y - size)), transform.localScale, width, z); CreateLine(new Pair2(new Vector2(point.x - size, point.y - size), new Vector2(point.x - size, point.y + size)), transform.localScale, width, z); CreateLine(new Pair2(new Vector2(point.x + size, point.y + size), new Vector2(point.x + size, point.y - size)), transform.localScale, width, z); CreateLine(new Pair2(new Vector2(point.x + size, point.y + size), new Vector2(point.x - size, point.y + size)), transform.localScale, width, z); } else { float step = 360f / edges; for (int i = 0; i < edges; i++) { float x0 = Mathf.Cos((i - 1) * step * Mathf.Deg2Rad) * size; float y0 = Mathf.Sin((i - 1) * step * Mathf.Deg2Rad) * size; float x1 = Mathf.Cos(i * step * Mathf.Deg2Rad) * size; float y1 = Mathf.Sin(i * step * Mathf.Deg2Rad) * size; CreateLine(new Pair2(new Vector2(point.x + x0, point.y + y0), new Vector2(point.x + x1, point.y + y1)), transform.localScale, width, z); } } }
public void Linear_GenerateTrackerMesh(Vector2 pos, Dictionary <Sliceable2D, Tracker.Object> trackerList, Transform transform, float lineWidth, float zPosition, float size, LineEndingType endingType, int edges) { GenerateSquare(pos, size, transform, lineWidth, zPosition, endingType, edges); CreateLine(new Pair2(pos, pos), transform.localScale, lineWidth, zPosition); foreach (KeyValuePair <Sliceable2D, Tracker.Object> trackerPair in trackerList) { Tracker.Object tracker = trackerPair.Value; if (trackerPair.Key != null && tracker.tracking) { foreach (Pair2 pair in Pair2.GetList(Vector2DList.PointsToWorldSpace(trackerPair.Key.transform, tracker.GetLinearPoints()), false)) { CreateLine(pair, transform.localScale, lineWidth, zPosition); } } } }
//// LINEAR ///// public void Linear_GenerateMesh(Pair2 linearPair, Transform transform, float lineWidth, float zPosition, float size, float lineEndWidth, LineEndingType endingType, int edges) { CreateLine(linearPair, transform.localScale, lineWidth, zPosition); GenerateSquare(linearPair.a, size, transform, lineEndWidth, zPosition, endingType, edges); GenerateSquare(linearPair.b, size, transform, lineEndWidth, zPosition, endingType, edges); }
public void Complex_GenerateTrackerMesh(Vector2 pos, Dictionary <Sliceable2D, Tracker.Object> trackerList, Transform transform, float lineWidth, float zPosition, float squareSize, LineEndingType endingType, int edges) { float size = squareSize; GenerateSquare(pos, size, transform, lineWidth, zPosition, endingType, edges); CreateLine(new Pair2(pos, pos), transform.localScale, lineWidth, zPosition); foreach (KeyValuePair <Sliceable2D, Tracker.Object> trackerPair in trackerList) { Tracker.Object tracker = trackerPair.Value; if (trackerPair.Key != null && tracker.tracking) { List <Vector2D> pointListWorld = Vector2DList.PointsToWorldSpace(trackerPair.Key.transform, tracker.pointsList); pointListWorld.Add(new Vector2D(pos)); List <Pair2> pairList = Pair2.GetList(pointListWorld, false); foreach (Pair2 pair in pairList) { CreateLine(pair, transform.localScale, lineWidth, zPosition); } } } }
private void lineEndingCmBx_SelectedIndexChanged(object sender, EventArgs e) { string selectedLineEnding = lineEndingCmBx.GetItemText(lineEndingCmBx.SelectedItem); lineEnding = StringToLineEndingType(selectedLineEnding); }