NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Common.IO.StringCoda Class Reference

Static Public Member Functions

static IEnumerable< string > WrappedLines (string self, params int[] widths)
 
static IEnumerable< string > WrappedLines (string self, IEnumerable< int > widths)
 

Static Private Member Functions

static IEnumerable< string > CreateWrappedLinesIterator (string self, IEnumerable< int > widths)
 
static int GetLineEnd (int start, int length, string description)
 
static int GetNextWidth (IEnumerator< int > ewidths, int curWidth, ref bool?eValid)
 
static bool IsEolChar (char c)
 

Detailed Description

Definition at line 164 of file Options.cs.

Member Function Documentation

static IEnumerable<string> Ntp.Common.IO.StringCoda.CreateWrappedLinesIterator ( string  self,
IEnumerable< int >  widths 
)
inlinestaticprivate

Definition at line 179 of file Options.cs.

References c.

180  {
181  if (string.IsNullOrEmpty(self))
182  {
183  yield return string.Empty;
184  yield break;
185  }
186  using (var ewidths = widths.GetEnumerator())
187  {
188  bool? hw = null;
189  var width = GetNextWidth(ewidths, int.MaxValue, ref hw);
190  var start = 0;
191  do
192  {
193  var end = GetLineEnd(start, width, self);
194  var c = self[end - 1];
195  if (char.IsWhiteSpace(c))
196  --end;
197  var needContinuation = end != self.Length && !IsEolChar(c);
198  var continuation = "";
199  if (needContinuation)
200  {
201  --end;
202  continuation = "-";
203  }
204  var line = self.Substring(start, end - start) + continuation;
205  yield return line;
206  start = end;
207  if (char.IsWhiteSpace(c))
208  ++start;
209  width = GetNextWidth(ewidths, width, ref hw);
210  } while (start < self.Length);
211  }
212  }
static int GetLineEnd(int start, int length, string description)
Definition: Options.cs:214
var c
Definition: bootstrap.min.js:6
static int GetNextWidth(IEnumerator< int > ewidths, int curWidth, ref bool?eValid)
Definition: Options.cs:230
static bool IsEolChar(char c)
Definition: Options.cs:245
static int Ntp.Common.IO.StringCoda.GetLineEnd ( int  start,
int  length,
string  description 
)
inlinestaticprivate

Definition at line 214 of file Options.cs.

215  {
216  var end = Math.Min(start + length, description.Length);
217  var sep = -1;
218  for (var i = start; i < end; ++i)
219  {
220  if (description[i] == '\n')
221  return i + 1;
222  if (IsEolChar(description[i]))
223  sep = i + 1;
224  }
225  if (sep == -1 || end == description.Length)
226  return end;
227  return sep;
228  }
static bool IsEolChar(char c)
Definition: Options.cs:245
static int Ntp.Common.IO.StringCoda.GetNextWidth ( IEnumerator< int >  ewidths,
int  curWidth,
ref bool?  eValid 
)
inlinestaticprivate

Definition at line 230 of file Options.cs.

References if().

231  {
232  if (eValid.HasValue && !eValid.Value)
233  return curWidth;
234 
235  curWidth = (eValid = ewidths.MoveNext()).Value ? ewidths.Current : curWidth;
236  // '.' is any character, - is for a continuation
237  const string minWidth = ".-";
238  if (curWidth < minWidth.Length)
239  throw new ArgumentOutOfRangeException(nameof(curWidth),
240  $"Element must be >= {minWidth.Length}, was {curWidth}.");
241  return curWidth;
242  // no more elements, use the last element.
243  }
if(typeof jQuery=== 'undefined')
Definition: bootstrap.js:7

Here is the call graph for this function:

static bool Ntp.Common.IO.StringCoda.IsEolChar ( char  c)
inlinestaticprivate

Definition at line 245 of file Options.cs.

246  {
247  return !char.IsLetterOrDigit(c);
248  }
var c
Definition: bootstrap.min.js:6
static IEnumerable<string> Ntp.Common.IO.StringCoda.WrappedLines ( string  self,
params int[]  widths 
)
inlinestatic

Definition at line 166 of file Options.cs.

Referenced by Ntp.Common.IO.OptionSet.GetLines().

167  {
168  IEnumerable<int> w = widths;
169  return WrappedLines(self, w);
170  }
static IEnumerable< string > WrappedLines(string self, params int[] widths)
Definition: Options.cs:166

Here is the caller graph for this function:

static IEnumerable<string> Ntp.Common.IO.StringCoda.WrappedLines ( string  self,
IEnumerable< int >  widths 
)
inlinestatic

Definition at line 172 of file Options.cs.

173  {
174  if (widths == null)
175  throw new ArgumentNullException(nameof(widths));
176  return CreateWrappedLinesIterator(self, widths);
177  }
static IEnumerable< string > CreateWrappedLinesIterator(string self, IEnumerable< int > widths)
Definition: Options.cs:179

The documentation for this class was generated from the following file: