/// <summary>Generate the html text for this tree of elements in 'sb'. Set 'indent' to -1 for no indenting</summary> public virtual StringBuilder Generate(StringBuilder?sb = null, int indent = 0) { sb = sb ?? new StringBuilder(); // Add the tag and attributes GenerateTagOpen(sb, ref indent); // Add the content. Note, using 'HasContent' because some // elements may have content other than stuff in 'm_elems' if (HasContent) { if (NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent : 0); } GenerateContent(sb, indent); if (NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent - 1 : 0); } } // Close the tag GenerateTagClose(sb, ref indent); return(sb); }
static string GetFirstLine(string text) { int start = 0; while (start < text.Length) { char ch = text [start]; if (ch != ' ' && ch != '\t') { break; } start++; } int end = start; while (end < text.Length) { char ch = text [end]; if (NewLine.IsNewLine(ch)) { break; } end++; } if (end <= start) { return(""); } return(text.Substring(start, end - start)); }
string WordWrapMaxLines(string Line, uint ID, int MaxLines) { int DefMaxWidth = this.MaxWidth; int MaxWidth; if (Dynamic) { MaxWidth = DynamicMaxWidth ?? WidthMap[ID]; } else { MaxWidth = DefMaxWidth; } int OverflowMaxWidth = (int)((double)(25 * DefMaxWidth) / 100) + DefMaxWidth; string NewLine; do { NewLine = Line.WordWrap(MaxWidth++); } while (NewLine.SplitLines().Length > MaxLines && MaxWidth < OverflowMaxWidth); return(NewLine); }
private MimeFormat(int folding, NewLine newLine, bool readOnly) { this.Folding = folding; this.NewLine = newLine; this.readOnly = readOnly; }
protected override void Run() { CommandRange range = _selector(); ChangeRange(range); if (range != CommandRange.Empty) { // Move caret inside if it is on on opening character and block is empty if (range.Length == 0 && Editor.Caret.Offset < range.Start) { Editor.Caret.Offset++; } else { // if block still has two newlines inside, then drop inside block and indent int del1 = NewLine.GetDelimiterLength(Editor.Text[range.Start - 1], Editor.Text[range.Start]); if (del1 > 0) { int del2Start = range.Start - 1 + del1; int del2 = NewLine.GetDelimiterLength(Editor.Text[del2Start], Editor.Text[del2Start + 1]); if (del2 > 0) { IndentCaretInBlock(range.Start - 2); } } } } }
private void Update() { if (Application.isPlaying) { return; } var changed = false; if (oldNewLine != newLine) { oldNewLine = newLine; changed = true; } var rectTransform = this.transform as RectTransform; if (oldWidth != rectTransform.sizeDelta.x) { oldWidth = rectTransform.sizeDelta.x; changed = true; } if (oldHeight != rectTransform.sizeDelta.y) { oldHeight = rectTransform.sizeDelta.y; changed = true; } if (changed) { ResetScrollSystem(); } }
public static bool PeekBlockText(CharStream cs) { char next = cs.PeekNext(); // if next char isn't a NewLine Character, we know for sure we // are not dealing with a block-text if (CharStream.IsEOF(next) || !CharStream.IsNL(next)) { return(false); } // from here on out, we're still not sure if we're dealing with a block-text // thus we start buffering so we can go back in time // here we check if we have the following pattern: `NL __ '|'` int bufferPos = cs.Position; NewLine.Parse(cs); WhiteSpace.Parse(cs); // if the next unbuffered char is not '|' we're not dealing with a block-text // and can return; next = cs.PeekNext(); cs.Rewind(bufferPos); return(next == '|'); }
protected DisplayWriter() { CoreNewLine = NewLine.ToCharArray().AsMemory(); _width = Console.BufferWidth - 1; _height = Console.WindowHeight - 1; _buffer = new Buffer(_width * _height); }
protected override void Run() { var range = _selector(); DeleteRange(range); if (range != CommandRange.Empty) { // Make sure there is no more than one newline left inside block int del1 = NewLine.GetDelimiterLength(Editor.Text[range.Start - 1], Editor.Text[range.Start]); if (del1 > 0) { int del2Start = range.Start - 1 + del1; int del2 = NewLine.GetDelimiterLength(Editor.Text[del2Start], Editor.Text[del2Start + 1]); if (del2 > 0) { Editor.SetSelection(del2Start, del2Start + del2); ClipboardActions.Cut(Editor); // put caret on closingChar int caret = Editor.Caret.Offset; while (Char.IsWhiteSpace(Editor.Text[caret])) { caret++; } Editor.Caret.Offset = caret; } } } }
public static FTL.AST.INode Parse(CharStream cs) { FTL.AST.INode expression = Expresson.Parse(cs); int bufferPos = cs.Position; WhiteSpace.Parse(cs); if (cs.PeekNext() != SEPERATOR[0]) { // it's not a select expression, so let's return early cs.Rewind(bufferPos); return(expression); } // it must be a select expression cs.SkipString(SEPERATOR); WhiteSpace.Parse(cs); // we expect now a memberList (REQUIRED) FTL.AST.MemberList memberList = MemberList.Parse(cs); // skip extra new-line in case one is available if (CharStream.IsNL(cs.PeekNext())) { NewLine.Parse(cs); } // return it all return(new FTL.AST.SelectExpression(expression, memberList)); }
/// <summary> /// Parses an entire charstream into an FTL AST /// </summary> public FTL.AST.Body Parse(StreamReader reader, Context ctx) { CharStream cs = new CharStream(reader); FTL.AST.Body root = new FTL.AST.Body(ctx); L20n.FTL.AST.INode entry; while (Entry.PeekAndParse(cs, ctx, out entry)) { if (entry != null) // could have been ommitted because of partial AST { root.AddEntry(entry); } if (!CharStream.IsNL(cs.PeekNext())) { break; } NewLine.Parse(cs); } if (!cs.EndOfStream()) { throw cs.CreateException( "didn't reach end of stream (EOF) while that was expected: `" + cs.ReadUntilEnd() + "`", null); } return(root); }
public StringSlice(string text, NewLine newLine) { Text = text; Start = 0; End = (Text?.Length ?? 0) - 1; NewLine = newLine; }
public static long ReadLines(Stream stream, Encoding encoding, NewLineAsString onNewLine, IMetricsHost metrics = null, CancellationToken cancellationToken = default) { unsafe { var pendingLength = 0; byte[] buffer = null; // TODO convert to allocator NewLine newLine = (lineNumber, partial, start, length, x, m) => { if (buffer == null) { buffer = new byte[Constants.ReadAheadSize * 2]; } var target = new Span <byte>(buffer, pendingLength, length); var segment = new ReadOnlySpan <byte>(start, length); segment.CopyTo(target); if (partial) { pendingLength = length; } else { var line = new ReadOnlySpan <byte>(buffer, 0, length + pendingLength); onNewLine?.Invoke(lineNumber, encoding.GetString(line), m); pendingLength = 0; buffer = null; } }; return(ReadOrCountLines(stream, encoding, Constants.Buffer, newLine, cancellationToken, metrics)); } }
public bool TryWriteLine(DateTime date, StandardFormat format) { if (!Utf8Formatter.TryFormat(date, Free, out int written, format)) return false; if (!NewLine.TryCopyTo(Free.Slice(written))) return false; _written += written + NewLine.Length; return true; }
public void NewLine(string s) { PrinterServiceFunction f = new NewLine(this); f.AddParameter("string", s); f.RunFunction(); }
public static bool PeekAndParse(CharStream cs, out FTL.AST.MemberList memberList) { // if next char is not a newline, we can just as well skip already char next = cs.PeekNext(); if (CharStream.IsEOF(next) || !CharStream.IsNL(next)) { memberList = null; return(false); } // let's keep peeking further, requiring our buffer int bufferPos = cs.Position; NewLine.Parse(cs); WhiteSpace.Parse(cs); // we'll always want to rewind no matter what bool isMemberList = Member.Peek(cs); cs.Rewind(bufferPos); if (isMemberList) { memberList = Parse(cs); return(true); } memberList = null; return(false); }
/// <summary> /// Reads all bytes from the input buffer. Will read the <see cref="NewLine"/> character(s) but will not return it. /// Note that this functions blocks until NewLine is seen. /// </summary> /// <returns></returns> public string ReadLine() { List <byte> bytes = new List <byte>(); char[] newLineCharArray = NewLine.ToCharArray(); while (true) { if (lowLevelSerialPort.BytesToRead < 1) { continue; } byte[] buffer = new byte[1]; lowLevelSerialPort.Read(buffer, 0, 1); bytes.Add(buffer[0]); if (bytes.Count < NewLine.Length) { continue; } bool foundNewLine = true; for (int i = 0; i < NewLine.Length; i++) { if (bytes[bytes.Count - i - 1] != newLineCharArray[NewLine.Length - i - 1]) { foundNewLine = false; break; } } if (foundNewLine) { return(System.Text.Encoding.Default.GetString(bytes.ToArray(), 0, bytes.Count - NewLine.Length)); } } }
internal StringSlice(string text, int start, int end, NewLine newLine, bool dummy) { Text = text; Start = start; End = end; NewLine = newLine; }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag]; Application wordApp = property.GetValue(context.DataContext) as Application; try { string textContent = TextContent.Get(context); Int32 newLine = NewLine.Get(context); for (int i = 0; i < newLine; i++) { wordApp.Selection.TypeParagraph(); } wordApp.Selection.TypeText(textContent); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message); CommonVariable.realaseProcessExit(wordApp); } m_Delegate = new runDelegate(Run); return(m_Delegate.BeginInvoke(callback, state)); }
public TextWriter CreateBufferedText(string filename, NewLine newline = NewLine.Lf) { MarkFile(filename); return(new StreamWriter(new BufferedFile(filename, this)) { NewLine = newline == NewLine.CrLf ? "\r\n" : "\n" }); }
/// <summary> /// Initializes a new instance of the <see cref="StringLine"/> struct. /// </summary> /// <param name="slice">The slice.</param> /// <param name="line">The line.</param> /// <param name="column">The column.</param> /// <param name="position">The position.</param> public StringLine(ref StringSlice slice, int line, int column, int position, NewLine newLine) { Slice = slice; Line = line; Column = column; Position = position; NewLine = newLine; }
public void IsMatch(string input, Token expectedValue) { var Result = new NewLine().IsMatch(new TokenizableStream <char>(input?.ToCharArray() ?? Array.Empty <char>())); Assert.Equal(expectedValue?.EndPosition, Result?.EndPosition); Assert.Equal(expectedValue?.StartPosition, Result?.StartPosition); Assert.Equal(expectedValue?.TokenType, Result?.TokenType); Assert.Equal(expectedValue?.Value, Result?.Value); }
public static long ReadLines(Stream stream, Encoding encoding, byte[] workingBuffer, NewLineAsString onNewLine, IMetricsHost metrics = null, CancellationToken cancellationToken = default) { unsafe { NewLine newLine = (n, p, s, l, e, m) => { onNewLine?.Invoke(n, e.GetString(s, l), m); }; return(ReadOrCountLines(stream, encoding, workingBuffer, newLine, cancellationToken, metrics)); } }
/// <summary> /// Prints the message in the specified colour on the Console /// </summary> public static void Print(string message, ConsoleColor colour, NewLine newLine = NewLine.No) { var beforeColour = Console.ForegroundColor; Console.ForegroundColor = colour; Print(message, newLine); Console.ForegroundColor = beforeColour; }
public TextWriter CreateText(string filename, NewLine newline = NewLine.Lf) { MarkFile(filename); CreateDirectory(Path.GetDirectoryName(filename)); Log.Event(IOEvent.Write, filename); return(new StreamWriter(filename) { NewLine = newline == NewLine.CrLf ? "\r\n" : "\n" }); }
internal TerminalParam() { _encoding = EncodingType.EUC_JP; _logtype = LogType.None; _terminalType = TerminalType.XTerm; _localecho = false; _lineFeedRule = LineFeedRule.Normal; _transmitnl = NewLine.CR; _renderProfile = null; }
/// <summary> /// Delimiter /// </summary> /// <param name="newLine">New Line</param> /// <returns>delimiter or null if doesn't exists</returns> public static string Delimiter(this NewLine newLine) { return(newLine switch { NewLine.Smart => null, NewLine.Default => Environment.NewLine, NewLine.N => "\n", NewLine.R => "\r", NewLine.RN => "\r\n", NewLine.NR => "\n\r", _ => null, });
public static void GetArray(int[,] array) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { Console.Write($"{array[i, j]}\t"); } NewLine?.Invoke(); } }
/// <summary>Add the content of this element to 'sb'</summary> protected virtual void GenerateContent(StringBuilder sb, int indent) { foreach (var x in Children) { x.Generate(sb, indent); if (x != Children.Back() && NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent : 0); } } }
private void ReadGrid(DataGridView dataGrid, TextBox textBox) { for (Int32 i = 0; i < dataGrid.RowCount; ++i) { for (Int32 j = 0; j < dataGrid.ColumnCount; ++j) { textBox.AppendText(String.Format("{0}\t", dataGrid.Rows[i].Cells[j].Value)); } textBox.AppendText(NewLine.ToString()); } }
public static long ReadLines(Stream stream, Encoding encoding, byte[] workingBuffer, string separator, NewValueAsSpan onNewValue, IMetricsHost metrics = null, CancellationToken cancellationToken = default) { unsafe { NewLine onNewLine = (lineNumber, start, length, e, m) => { LineValuesReader.ReadValues(lineNumber, start, length, e, separator, onNewValue, m); }; return(ReadLines(stream, encoding, workingBuffer, onNewLine, metrics, cancellationToken)); } }
public static char[] NewLineChars(NewLine nl) { switch (nl) { case NewLine.CR: return new char[1] { '\r' }; case NewLine.LF: return new char[1] { '\n' }; case NewLine.CRLF: return new char[2] { '\r', '\n' }; default: throw new ArgumentException("Unknown NewLine " + nl); } }
//TODO staticにしたほうがいい? うっかり破壊が怖いが public static byte[] NewLineBytes(NewLine nl) { switch (nl) { case NewLine.CR: return new byte[1] { (byte)'\r' }; case NewLine.LF: return new byte[1] { (byte)'\n' }; case NewLine.CRLF: return new byte[2] { (byte)'\r', (byte)'\n' }; default: throw new ArgumentException("Unknown NewLine " + nl); } }
public static NewLine NextNewLineOption(NewLine nl) { switch (nl) { case NewLine.CR: return NewLine.LF; case NewLine.LF: return NewLine.CRLF; case NewLine.CRLF: return NewLine.CR; default: throw new ArgumentException("Unknown NewLine " + nl); } }
public TerminalSettings() { IPoderosaCulture culture = TerminalEmulatorPlugin.Instance.PoderosaWorld.Culture; if (culture.IsJapaneseOS || culture.IsSimplifiedChineseOS || culture.IsTraditionalChineseOS || culture.IsKoreanOS) _encoding = EncodingType.UTF8; else _encoding = EncodingType.ISO8859_1; _terminalType = TerminalType.XTerm; _localecho = false; _lineFeedRule = LineFeedRule.Normal; _transmitnl = NewLine.CR; _renderProfile = null; _shellSchemeName = ShellSchemeCollection.DEFAULT_SCHEME_NAME; _enabledCharTriggerIntelliSense = false; _multiLogSettings = new MultiLogSettings(); _listeners = new ListenerList<ITerminalSettingsChangeListener>(); }
//Listener以外を持ってくる public virtual void Import(ITerminalSettings src) { _encoding = src.Encoding; _terminalType = src.TerminalType; _localecho = src.LocalEcho; _lineFeedRule = src.LineFeedRule; _transmitnl = src.TransmitNL; _caption = src.Caption; _icon = src.Icon; TerminalSettings src_r = (TerminalSettings)src; _shellSchemeName = src_r._shellSchemeName; //ちょっとインチキ if (src_r._shellScheme != null) { _shellScheme = src_r._shellScheme; TerminalEmulatorPlugin.Instance.ShellSchemeCollection.AddDynamicChangeListener(this); } _enabledCharTriggerIntelliSense = src.EnabledCharTriggerIntelliSense; _renderProfile = src.RenderProfile == null ? null : (RenderProfile)src.RenderProfile.Clone(); _multiLogSettings = src.LogSettings == null ? null : (IMultiLogSettings)_multiLogSettings.Clone(); }
/// <summary> /// Constructor by provide COM port name. /// </summary> /// <param name="comport"></param> public YModem(String comport) { sp = new SerialPort(comport); newLine += new NewLine(errorCheck); try { sp.Open(); sp.RtsEnable = true; sp.StopBits = System.IO.Ports.StopBits.One; sp.DataBits = 8; sp.BaudRate = 115200; sp.ReceivedBytesThreshold = 1; sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived); systemstatus = SYSTEMSTATUS.STARTED; //testSystemStatus(); } catch (Exception ex) { throw new Exception("Poort con niet geopend worden.", ex); } }
public virtual void Import(ConfigNode data) { _encoding = ParseEncoding(data["encoding"]); _terminalType = (TerminalType)EnumDescAttribute.For(typeof(TerminalType)).FromName(data["terminal-type"], TerminalType.VT100); _transmitnl = (NewLine)EnumDescAttribute.For(typeof(NewLine)).FromName(data["transmit-nl"], NewLine.CR); _localecho = GUtil.ParseBool(data["localecho"], false); //_lineFeedByCR = GUtil.ParseBool((string)data["linefeed-by-cr"], false); _lineFeedRule = (LineFeedRule)EnumDescAttribute.For(typeof(LineFeedRule)).FromName(data["linefeed"], LineFeedRule.Normal); _caption = data["caption"]; if(data.Contains("font-name")) //���ڂ��Ȃ����̂܂� _renderProfile = new RenderProfile(data); }
internal void Import(TerminalParam r) { _encoding = r._encoding; _logtype = r._logtype; _logpath = r._logpath; _localecho = r._localecho; _transmitnl = r._transmitnl; _lineFeedRule = r._lineFeedRule; _terminalType = r._terminalType; _renderProfile = r._renderProfile==null? null : new RenderProfile(r._renderProfile); _caption = r._caption; }
public LegacyCommunication(String comport, NewLine newLineDelegate) : this(comport) { newLine += newLineDelegate; }
private static CommandResult CmdNewLine(ICommandTarget target, NewLine nl) { ITerminalControlHost ts = TerminalCommandTarget.AsOpenTerminal(target); if (ts == null) return CommandResult.Failed; ITerminalSettings settings = ts.TerminalSettings; settings.BeginUpdate(); settings.TransmitNL = nl; settings.EndUpdate(); return CommandResult.Succeeded; }
public CommandResult SetTransmitNewLine(NewLine nl) { //Set Value _connection.Param.TransmitNL = nl; GFrame f = GApp.Frame; //ToolBar if(GApp.Options.ShowToolBar) { f.ToolBar.NewLineBox.SelectedIndex = (int)nl; f.ToolBar.Invalidate(true); } //Menu f.MenuNewLineCR.Checked = nl==NewLine.CR; f.MenuNewLineLF.Checked = nl==NewLine.LF; f.MenuNewLineCRLF.Checked = nl==NewLine.CRLF; return CommandResult.Success; }
public YModem(String comport, NewLine newLineDelegate) : this(comport) { newLine += newLineDelegate; }
public MimeFormat(int folding, NewLine newLine) : this(folding, newLine, false) { }