public ArrayRun Append(int elementCount) { var lastArrayCharacterIndex = FormatString.LastIndexOf(ArrayEnd); var newFormat = FormatString.Substring(0, lastArrayCharacterIndex + 1); if (newFormat != FormatString) { newFormat += ElementCount + elementCount; } return(new ArrayRun(owner, newFormat, LengthFromAnchor, Start, ElementCount + elementCount, ElementContent, PointerSources, PointerSourcesForInnerElements)); }
private string Format(string text) { if (string.IsNullOrEmpty(FormatString)) { return(text); } var ret = ""; if (FormatString[0] == '{' && FormatString[FormatString.Length - 1] == '}') { var arr = FormatString.Substring(1, FormatString.Length - 2).Split(":".ToCharArray()); var type = Convert.ToInt16(arr[0]); var size = Convert.ToInt16(arr[1]); ret = RandomStringHelper.RandomString((RandomType)Enum.Parse(typeof(RandomType), type.ToString()), size); } return(ret); }
public override string ToString() { if (!String.IsNullOrEmpty(Error)) { return($"Error: {Error}"); } string shortData = FormatString?.Substring(0, 100) ?? TWP_API_UTILS.API_UNSET_TOKEN; string retval = $"Data: {shortData}"; if (FormatBinary ?? false) { retval = "Binary " + retval; } if (!String.IsNullOrEmpty(MimeType)) { retval = $"MimeType: {MimeType}" + retval; } return(retval); }
public override string ToString() { if (!String.IsNullOrEmpty(Error)) { return($"Error: {Error}"); } string shortData = FormatString?.Substring(0, 100) ?? TWPApiUtil.Api_Unset_Token; string retval = $"Data: {shortData}"; if (FormatBinary ?? false) { retval = "Binary " + retval; } if (!String.IsNullOrEmpty(MimeType)) { retval = $"MimeType: {MimeType}" + retval; } return(retval); }
private void OnContentChanged() { // Re-arrange the children: theTextBlock.Inlines.Clear(); if (FormatString != null) { var matchedUpToIndex = 0; // 1) determine which items are to be used as string and which are to be inserted as controls: // allowed according to https://msdn.microsoft.com/de-de/library/system.windows.documents.inlinecollection%28v=vs.110%29.aspx are // Inline, String (creates an implicit Run), UIElement (creates an implicit InlineUIContainer with the supplied UIElement inside), if (Gaps != null) { var match = Regex.Match(FormatString, RegexPattern); while (match.Success) { // Handle match here... var wholeMatch = match.Groups[0].Value; // contains string and simple placeholder at the end. var formatStringPartial = match.Groups[1].Value; // has still to be formatted TODO or even better bound accordingly by lex:loc binding var itemIndex = int.Parse(match.Groups[2].Value); // it's secure to parse an int here as this follows from the regex. matchedUpToIndex += wholeMatch.Length; // get next match: match = match.NextMatch(); // add the inlines: // 1) the prefix that is formatted with the whole gaps parameters: theTextBlock.Inlines.Add(string.Format(formatStringPartial, Gaps)); // Check availability of a classified gap. if (Gaps.Count <= itemIndex) { continue; } var gap = Gaps[itemIndex]; // 2) the item encoded in the placeholder: try { if (gap is UIElement) { var item = DeepCopy((UIElement)gap); theTextBlock.Inlines.Add(item); } else if (gap is Inline) { var item = DeepCopy((Inline)gap); theTextBlock.Inlines.Add(item); } else if (gap != null) { theTextBlock.Inlines.Add(gap.ToString()); } } catch (Exception e) { // break for now } } } // add the remaining part: theTextBlock.Inlines.Add(string.Format(FormatString.Substring(matchedUpToIndex), Gaps)); InvalidateVisual(); } else { throw new Exception("FormatString is not a string!"); } }
// Constructs the formatted text private void buildBlocks() { if (AssociatedObject == null || FormatString == null || Values == null) { return; } int i = 0; int last = 0; Paragraph p = new Paragraph(); // Loop through each value while (i <= Values.Count) { // Get the index of the current substitution placeholder in the format string int current = FormatString.IndexOf("{" + i + "}"); // Get the section of the format string between the last placeholder and the current one string subSection = i < Values.Count || current >= 0 ? FormatString.Substring(last, current - last) : FormatString.Substring(last); // Add the section to the formatted text if (!string.IsNullOrEmpty(subSection)) { p.Inlines.Add(new Run() { Text = subSection }); } // If the last value has already been processed, exit if (i == Values.Count || current < 0) { break; } // Get the value and add it to the formatted text object val = Values[i]; if (val is string) { p.Inlines.Add(new Run() { Text = (string)val }); } else if (val is Inline) { p.Inlines.Add((Inline)val); } else if (val is UIElement) { p.Inlines.Add(new InlineUIContainer() { Child = (UIElement)val }); } last = current + 3; i++; } // Update the associated RichTextBlock's content AssociatedObject.Blocks.Clear(); AssociatedObject.Blocks.Add(p); }