public static StringBuilder TrimFirstLine(this StringBuilder builder) { if (builder.Length == 0) { return(builder); } while (builder[0] == '\r' || builder[0] == '\n' || builder[0] == '\t') { builder.Remove(0, 1); } return(builder); }
public override string ToString(bool friendlyFormat, int indentation = 0) { var builder = new StringBuilder(); foreach (var selector in Selectors) { builder.Append(selector.ToString(friendlyFormat, indentation + 1)); builder.Append(Delimiter); } if (Delimiter.Length <= 0) { return(builder.ToString()); } if (builder.Length > 0) { builder.Remove(builder.Length - 1, 1); } return(builder.ToString()); }
public static string DeEntitize(string text) { if (text == null) { return(null); } if (text.Length == 0) { return(text); } #if !SALTARELLE StringBuilder entity = null; StringBuilder sb = null; #endif bool flag = false; HtmlEntity.ParseState parseState = HtmlEntity.ParseState.Text; for (int i = 0; i < text.Length; i++) { switch (parseState) { case HtmlEntity.ParseState.Text: { char c = text[i]; if (c == '&') { parseState = HtmlEntity.ParseState.EntityStart; } else { if (flag) { sb.Append(text[i]); } } break; } case HtmlEntity.ParseState.EntityStart: { if (!flag) { flag = true; if (sb == null) { #if SALTARELLE sb = new StringBuilder(text.Length); #else sb = ReseekableStringBuilder.AcquirePooledStringBuilder(); #endif } else { sb.Length = 0; } sb.Append(text, 0, i - 1); if (entity == null) { #if SALTARELLE entity = new StringBuilder(10); #else entity = ReseekableStringBuilder.AcquirePooledStringBuilder(); #endif } entity.Length = 0; } char c2 = text[i]; if (c2 == ';' || c2 == '<' || c2 == '"' || c2 == '\'' || HtmlEntity.IsWhiteSpace(c2)) { bool flag2 = c2 == ';'; if (!flag2) { i--; } if (entity.Length == 0) { if (c2 == ';') { sb.Append("&;"); } else { sb.Append('&'); } } else { if (entity[0] == '#') { string text2 = entity.ToString(); try { string text3 = text2.SubstringCached(1).Trim().ToLowerFast(); int fromBase; if (text3.StartsWith("x")) { fromBase = 16; text3 = text3.SubstringCached(1); } else { fromBase = 10; } #if SALTARELLE int num = int.Parse(text3, fromBase); #else int num = Convert.ToInt32(text3, fromBase); #endif if (num > 65535) { #if SALTARELLE sb.Append(StringFromCodePoint(num)); #else sb.Append(char.ConvertFromUtf32(num)); #endif } else { sb.Append((char)num); } goto IL_235; } catch { sb.Append("&#" + text2 + ";"); goto IL_235; } goto IL_1DC; } goto IL_1DC; IL_235: entity.Remove(0, entity.Length); goto IL_24B; IL_1DC: int num2; #if SALTARELLE num2 = HtmlEntity._entityValue[entity.ToStringCached()]; if (!Script.IsNullOrUndefined(num2)) { sb.Append((char)num2); goto IL_235; } #else if (HtmlEntity._entityValue.TryGetValue(entity.ToStringCached(), out num2)) { int num3 = num2; sb.Append((char)num3); goto IL_235; } #endif sb.Append('&'); sb.Append(entity); if (flag2) { sb.Append(';'); goto IL_235; } goto IL_235; } IL_24B: parseState = HtmlEntity.ParseState.Text; } else { if (c2 == '&') { sb.Append("&" + entity); entity.Remove(0, entity.Length); } else { entity.Append(text[i]); if (entity.Length > HtmlEntity._maxEntitySize) { parseState = HtmlEntity.ParseState.Text; sb.Append("&" + entity); entity.Remove(0, entity.Length); } } } break; } } } if (parseState == HtmlEntity.ParseState.EntityStart && flag) { sb.Append("&" + entity); } if (!flag) { return(text); } return(sb.ToStringCached()); }