本文整理汇总了C#中StringBuilder.IsNewLine方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.IsNewLine方法的具体用法?C# StringBuilder.IsNewLine怎么用?C# StringBuilder.IsNewLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.IsNewLine方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public void Process(
XmlReader xmlReader,
StringBuilder output,
ElementProcessContext elementProcessContext)
{
if (elementProcessContext.Current.IsPreservingSpace)
{
output.Append("</").Append(xmlReader.Name).Append(">");
}
else if (elementProcessContext.Current.IsSignificantWhiteSpace && !output.IsNewLine())
{
output.Append("</").Append(xmlReader.Name).Append(">");
}
else if ((elementProcessContext.Current.ContentType == ContentTypeEnum.None)
&& this.options.RemoveEndingTagOfEmptyElement)
{
// Shrink the current element, if it has no content.
// E.g., <Element> </Element> => <Element />
output = output.TrimEnd(' ', '\t', '\r', '\n');
int bracketIndex = output.LastIndexOf('>');
output.Insert(bracketIndex, '/');
if ((output[bracketIndex - 1] != '\t')
&& (output[bracketIndex - 1] != ' ')
&& this.options.SpaceBeforeClosingSlash)
{
output.Insert(bracketIndex, ' ');
}
}
else if ((elementProcessContext.Current.ContentType == ContentTypeEnum.SingleLineTextOnly)
&& !elementProcessContext.Current.IsMultlineStartTag)
{
int bracketIndex = output.LastIndexOf('>');
string text = output.Substring((bracketIndex + 1), (output.Length - bracketIndex - 1)).Trim();
output.Length = (bracketIndex + 1);
output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
}
else
{
string currentIndentString = this.indentService.GetIndentString(xmlReader.Depth);
if (!output.IsNewLine())
{
output.Append(Environment.NewLine);
}
output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
}
elementProcessContext.Pop();
}
示例2: Process
public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
{
if (elementProcessContext.Current.IsPreservingSpace)
{
output.Append("</").Append(xmlReader.Name).Append(">");
}
else if (elementProcessContext.Current.IsSignificantWhiteSpace && !output.IsNewLine())
{
output.Append("</").Append(xmlReader.Name).Append(">");
}
// Shrink the current element, if it has no content.
// E.g., <Element> </Element> => <Element />
else if (elementProcessContext.Current.ContentType == ContentTypeEnum.NONE && _options.RemoveEndingTagOfEmptyElement)
{
#region shrink element with no content
output = output.TrimEnd(' ', '\t', '\r', '\n');
int bracketIndex = output.LastIndexOf('>');
output.Insert(bracketIndex, '/');
if (output[bracketIndex - 1] != '\t' && output[bracketIndex - 1] != ' ' && _options.SpaceBeforeClosingSlash)
{
output.Insert(bracketIndex, ' ');
}
#endregion shrink element with no content
}
else if (elementProcessContext.Current.ContentType == ContentTypeEnum.SINGLE_LINE_TEXT_ONLY && elementProcessContext.Current.IsMultlineStartTag == false)
{
int bracketIndex = output.LastIndexOf('>');
string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();
output.Length = bracketIndex + 1;
output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
}
else
{
string currentIndentString = _indentService.GetIndentString(xmlReader.Depth);
if (!output.IsNewLine())
{
output.Append(Environment.NewLine);
}
output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
}
elementProcessContext.Pop();
}
示例3: Process
public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
{
elementProcessContext.UpdateParentElementProcessStatus(ContentTypeEnum.Mixed);
string currentIndentString = this.indentService.GetIndentString(xmlReader.Depth);
string content = xmlReader.Value;
if ((output.Length > 0) && !output.IsNewLine())
{
output.Append(Environment.NewLine);
}
if (content.Contains("<") && content.Contains(">"))
{
output.Append(currentIndentString);
output.Append("<!--");
if (content.Contains("\n"))
{
output.Append(String.Join(Environment.NewLine, content.GetLines().Select(_ => _.TrimEnd(' '))));
if (content.TrimEnd(' ').EndsWith("\n"))
{
output.Append(currentIndentString);
}
}
else
{
output.Append(content);
}
output.Append("-->");
}
else if (content.Contains("#region") || content.Contains("#endregion"))
{
output.Append(currentIndentString).Append("<!--").Append(content.Trim()).Append("-->");
}
else if (content.Contains("\n"))
{
output.Append(currentIndentString).Append("<!--");
var contentIndentString = this.indentService.GetIndentString(xmlReader.Depth + 1);
foreach (var line in content.Trim().GetLines())
{
output.Append(Environment.NewLine).Append(contentIndentString).Append(line.Trim());
}
output.Append(Environment.NewLine).Append(currentIndentString).Append("-->");
}
else
{
output
.Append(currentIndentString)
.Append("<!--")
.Append(' ', this.options.CommentSpaces)
.Append(content.Trim())
.Append(' ', this.options.CommentSpaces)
.Append("-->");
}
}
示例4: Process
public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
{
// If there is linefeed(s) between element and CDATA then treat CDATA as element and
// indent accordingly, otherwise treat as single line text.
if (output.IsNewLine())
{
elementProcessContext.UpdateParentElementProcessStatus(ContentTypeEnum.MultiLineTextOnly);
if (!elementProcessContext.Current.IsPreservingSpace)
{
string currentIndentString = this.indentService.GetIndentString(xmlReader.Depth);
output.Append(currentIndentString);
}
}
else
{
elementProcessContext.UpdateParentElementProcessStatus(ContentTypeEnum.SingleLineTextOnly);
}
// All newlines are returned by XmlReader as '\n' due to requirements in the XML Specification.
// http://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends
// Change them back into the environment newline characters.
output.Append("<![CDATA[")
.Append(xmlReader.Value.Replace("\n", Environment.NewLine))
.Append("]]>");
}
示例5: Process
public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
{
elementProcessContext.UpdateParentElementProcessStatus(ContentTypeEnum.MIXED);
string currentIndentString = _indentService.GetIndentString(xmlReader.Depth);
if (!output.IsNewLine())
{
output.Append(Environment.NewLine);
}
output.Append(currentIndentString).Append("<?Mapping ").Append(xmlReader.Value).Append(" ?>");
}
示例6: ProcessInstruction
private void ProcessInstruction(XmlReader xmlReader, StringBuilder output)
{
string currentIndentString = this.GetIndentString(xmlReader.Depth);
if (!output.IsNewLine())
{
output.Append(Environment.NewLine);
}
output.Append(currentIndentString).Append("<?Mapping ").Append(xmlReader.Value).Append(" ?>");
}
示例7: ProcessEndElement
private void ProcessEndElement(XmlReader xmlReader, StringBuilder output)
{
if (this.ElementProcessStatusStack.Peek().IsPreservingSpace)
{
output.Append("</").Append(xmlReader.Name).Append(">");
}
else if (this.ElementProcessStatusStack.Peek().IsSignificantWhiteSpace && !output.IsNewLine())
{
output.Append("</").Append(xmlReader.Name).Append(">");
}
// Shrink the current element, if it has no content.
// E.g., <Element> </Element> => <Element />
else if ((ContentTypeEnum.None == this.ElementProcessStatusStack.Peek().ContentType)
&& Options.RemoveEndingTagOfEmptyElement)
{
#region shrink element with no content
output = output.TrimEnd(' ', '\t', '\r', '\n');
int bracketIndex = output.LastIndexOf('>');
output.Insert(bracketIndex, '/');
if ((output[bracketIndex - 1] != '\t')
&& (output[bracketIndex - 1] != ' ')
&& Options.SpaceBeforeClosingSlash)
{
output.Insert(bracketIndex, ' ');
}
#endregion shrink element with no content
}
else if ((ContentTypeEnum.SingleLineTextOnly == this.ElementProcessStatusStack.Peek().ContentType)
&& !this.ElementProcessStatusStack.Peek().IsMultlineStartTag)
{
int bracketIndex = output.LastIndexOf('>');
string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();
output.Length = bracketIndex + 1;
output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
}
else
{
string currentIndentString = this.GetIndentString(xmlReader.Depth);
if (!output.IsNewLine())
{
output.Append(Environment.NewLine);
}
output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
}
}
示例8: ProcessElement
private void ProcessElement(XmlReader xmlReader, StringBuilder output)
{
string currentIndentString = GetIndentString(xmlReader.Depth);
string elementName = xmlReader.Name;
// Calculate how element should be indented
if (!this.ElementProcessStatusStack.Peek().IsPreservingSpace)
{
// "Run" get special treatment to try to preserve spacing. Use xml:space='preserve' to make sure!
if (elementName.Equals("Run"))
{
this.ElementProcessStatusStack.Peek().Parent.IsSignificantWhiteSpace = true;
if ((output.Length == 0) || output.IsNewLine())
{
output.Append(currentIndentString);
}
}
else
{
this.ElementProcessStatusStack.Peek().Parent.IsSignificantWhiteSpace = false;
if ((output.Length == 0) || output.IsNewLine())
{
output.Append(currentIndentString);
}
else
{
output.Append(Environment.NewLine).Append(currentIndentString);
}
}
}
// Output the element itself
output.Append('<').Append(xmlReader.Name);
bool isEmptyElement = xmlReader.IsEmptyElement;
bool hasPutEndingBracketOnNewLine = false;
var list = new List<AttributeInfo>(xmlReader.AttributeCount);
if (xmlReader.HasAttributes)
{
while (xmlReader.MoveToNextAttribute())
{
string attributeName = xmlReader.Name;
string attributeValue = xmlReader.Value;
AttributeOrderRule orderRule = OrderRules.GetRuleFor(attributeName);
list.Add(new AttributeInfo(attributeName, attributeValue, orderRule));
// Check for xml:space as defined in http://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space
if (xmlReader.IsXmlSpaceAttribute())
{
this.ElementProcessStatusStack.Peek().IsPreservingSpace = (xmlReader.Value == "preserve");
}
}
if (this.Options.EnableAttributeReordering)
{
list.Sort(AttributeInfoComparison);
}
currentIndentString = this.GetIndentString(xmlReader.Depth);
var noLineBreakInAttributes = (list.Count <= this.Options.AttributesTolerance)
|| this.IsNoLineBreakElement(elementName);
var forceLineBreakInAttributes = false;
// Root element?
if (this.ElementProcessStatusStack.Count == 2)
{
switch (this.Options.RootElementLineBreakRule)
{
case LineBreakRule.Default:
break;
case LineBreakRule.Always:
noLineBreakInAttributes = false;
forceLineBreakInAttributes = true;
break;
case LineBreakRule.Never:
noLineBreakInAttributes = true;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
// No need to break attributes
if (noLineBreakInAttributes)
{
foreach (var attrInfo in list)
{
output.Append(' ').Append(attrInfo.ToSingleLineString());
}
this.ElementProcessStatusStack.Peek().IsMultlineStartTag = false;
}
// Need to break attributes
else
{
IList<String> attributeLines = new List<String>();
var currentLineBuffer = new StringBuilder();
//.........这里部分代码省略.........
示例9: ProcessComment
private void ProcessComment(XmlReader xmlReader, StringBuilder output)
{
string currentIndentString = GetIndentString(xmlReader.Depth);
string content = xmlReader.Value;
if (output.Length > 0 && !output.IsNewLine())
{
output.Append(Environment.NewLine);
}
if (content.Contains("<") && content.Contains(">"))
{
output.Append(currentIndentString);
output.Append("<!--");
if (content.Contains("\n"))
{
output.Append(String.Join(Environment.NewLine, content.GetLines().Select(_ => _.TrimEnd(' '))));
if (content.TrimEnd(' ').EndsWith("\n"))
{
output.Append(currentIndentString);
}
}
else
{
output.Append(content);
}
output.Append("-->");
}
else if (content.Contains("#region") || content.Contains("#endregion"))
{
output.Append(currentIndentString).Append("<!--").Append(content.Trim()).Append("-->");
}
else if (content.Contains("\n"))
{
output.Append(currentIndentString).Append("<!--");
var contentIndentString = this.GetIndentString(xmlReader.Depth + 1);
foreach (var line in content.Trim().GetLines())
{
output.Append(Environment.NewLine).Append(contentIndentString).Append(line.Trim());
}
output.Append(Environment.NewLine).Append(currentIndentString).Append("-->");
}
else
{
output.Append(currentIndentString)
.Append("<!--")
.Append(' ', Options.CommentPadding)
.Append(content.Trim())
.Append(' ', Options.CommentPadding)
.Append("-->");
}
}
示例10: ProcessEndElement
private void ProcessEndElement(XmlReader xmlReader, StringBuilder output)
{
// Shrink the current element, if it has no content.
// E.g., <Element> </Element> => <Element />
if (ContentTypeEnum.NONE == _elementProcessStatusStack.Peek().ContentType
&& Options.RemoveEndingTagOfEmptyElement)
{
#region shrink element with no content
output = output.TrimEnd(' ', '\t', '\r', '\n');
int bracketIndex = output.LastIndexOf('>');
output.Insert(bracketIndex, '/');
if (output[bracketIndex - 1] != '\t' && output[bracketIndex - 1] != ' ' && Options.SpaceBeforeClosingSlash)
{
output.Insert(bracketIndex, ' ');
}
#endregion shrink element with no content
}
else if (ContentTypeEnum.SINGLE_LINE_TEXT_ONLY == _elementProcessStatusStack.Peek().ContentType
&& false == _elementProcessStatusStack.Peek().IsMultlineStartTag)
{
int bracketIndex = output.LastIndexOf('>');
string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();
output.Length = bracketIndex + 1;
output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
}
else
{
string currentIndentString = GetIndentString(xmlReader.Depth);
if (!output.IsNewLine())
{
output.Append(Environment.NewLine);
}
output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
}
}
示例11: ProcessElement
private void ProcessElement(XmlReader xmlReader, StringBuilder output)
{
string currentIndentString = GetIndentString(xmlReader.Depth);
string elementName = xmlReader.Name;
if ("Run".Equals(elementName))
{
if (output.IsNewLine())
{
// Shall not add extra whitespaces (including linefeeds) before <Run/>,
// because it will affect the rendering of <TextBlock><Run/><Run/></TextBlock>
output
.Append(currentIndentString)
.Append('<')
.Append(xmlReader.Name);
}
else
{
output.Append('<');
output.Append(xmlReader.Name);
}
}
else if (output.Length == 0 || output.IsNewLine())
{
output
.Append(currentIndentString)
.Append('<')
.Append(xmlReader.Name);
}
else
{
output
.Append(Environment.NewLine)
.Append(currentIndentString)
.Append('<')
.Append(xmlReader.Name);
}
bool isEmptyElement = xmlReader.IsEmptyElement;
bool hasPutEndingBracketOnNewLine = false;
var list = new List<AttributeInfo>(xmlReader.AttributeCount);
if (xmlReader.HasAttributes)
{
while (xmlReader.MoveToNextAttribute())
{
string attributeName = xmlReader.Name;
string attributeValue = xmlReader.Value;
AttributeOrderRule orderRule = OrderRules.GetRuleFor(attributeName);
list.Add(new AttributeInfo(attributeName, attributeValue, orderRule));
}
if (Options.OrderAttributesByName)
list.Sort();
currentIndentString = GetIndentString(xmlReader.Depth);
var noLineBreakInAttributes = (list.Count <= Options.AttributesTolerance) || IsNoLineBreakElement(elementName);
// Root element?
if (_elementProcessStatusStack.Count == 2)
{
switch (Options.RootElementLineBreakRule)
{
case LineBreakRule.Default:
break;
case LineBreakRule.Always:
noLineBreakInAttributes = false;
break;
case LineBreakRule.Never:
noLineBreakInAttributes = true;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
// No need to break attributes
if (noLineBreakInAttributes)
{
foreach (var attrInfo in list)
{
output
.Append(' ')
.Append(attrInfo.ToSingleLineString());
}
_elementProcessStatusStack.Peek().IsMultlineStartTag = false;
}
// Need to break attributes
else
{
IList<String> attributeLines = new List<String>();
var currentLineBuffer = new StringBuilder();
int attributeCountInCurrentLineBuffer = 0;
AttributeInfo lastAttributeInfo = null;
foreach (AttributeInfo attrInfo in list)
{
//.........这里部分代码省略.........
示例12: Process
public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
{
elementProcessContext.UpdateParentElementProcessStatus(ContentTypeEnum.MIXED);
var elementName = xmlReader.Name;
elementProcessContext.Push(
new ElementProcessStatus
{
Parent = elementProcessContext.Current,
Name = elementName,
ContentType = ContentTypeEnum.NONE,
IsMultlineStartTag = false,
IsPreservingSpace = elementProcessContext.Current.IsPreservingSpace
}
);
var currentIndentString = _indentService.GetIndentString(xmlReader.Depth);
var attributeIndetationString = GetAttributeIndetationString(xmlReader);
// Calculate how element should be indented
if (!elementProcessContext.Current.IsPreservingSpace)
{
// "Run" get special treatment to try to preserve spacing. Use xml:space='preserve' to make sure!
if (elementName.Equals("Run"))
{
elementProcessContext.Current.Parent.IsSignificantWhiteSpace = true;
if (output.Length == 0 || output.IsNewLine())
{
output.Append(currentIndentString);
}
}
else
{
elementProcessContext.Current.Parent.IsSignificantWhiteSpace = false;
if (output.Length == 0 || output.IsNewLine())
{
output.Append(currentIndentString);
}
else
{
output
.Append(Environment.NewLine)
.Append(currentIndentString);
}
}
}
// Output the element itself
output
.Append('<')
.Append(elementName);
bool isEmptyElement = xmlReader.IsEmptyElement;
if (xmlReader.HasAttributes)
{
bool isNoLineBreakElement = IsNoLineBreakElement(elementName);
ProcessAttributes(xmlReader, output, elementProcessContext, isNoLineBreakElement, attributeIndetationString);
}
// Determine if to put ending bracket on new line
bool putEndingBracketOnNewLine = (_options.PutEndingBracketOnNewLine && elementProcessContext.Current.IsMultlineStartTag);
if(putEndingBracketOnNewLine)
{
// Indent ending bracket just like an attribute
output
.Append(Environment.NewLine)
.Append(attributeIndetationString);
}
if (isEmptyElement)
{
if (putEndingBracketOnNewLine == false && _options.SpaceBeforeClosingSlash)
{
output.Append(' ');
}
output.Append("/>");
// Self closing element. Remember to pop element context.
elementProcessContext.Pop();
}
else
{
output.Append(">");
}
}