/// <summary> /// Serializes an object to a delimited file. Throws an exception if any of the property names, column names, or values contain either the <see cref="ColumnDelimiter"/> or the <see cref="RowDelimiter"/>. /// </summary> /// <typeparam name="T">The type of the object to serialize.</typeparam> /// <param name="items">A list of the items to serialize.</param> /// <returns>The serialized string.</returns> public string Serialize <T>(IEnumerable <T> items) { var result = new ExtendedStringBuilder(); var properties = _getProperties(items.First()); if (IncludeHeader) { result += _buildHeader(items.First(), properties); } foreach (var item in items) { if (result.HasBeenAppended) { result += RowDelimiter; } result += _buildRow(item, properties); } if (IncludeEmptyRow) { result += RowDelimiter; result += ""; } return(result); }
static void GenerateMatrixSwizzles(ExtendedStringBuilder builder, String baseType, int yDim, int xDim) { String matrixTypeName = String.Format("{0}{1}x{2}", baseType, yDim, xDim); builder.AppendLine(String.Format("function Test{0}()", matrixTypeName)); builder.AppendLine("{"); builder.PushScope(); builder.AppendLine(String.Format("var m = {0}();", matrixTypeName)); builder.AppendLine(String.Format("var s = {0}();", baseType)); //ExtendedStringBuilder test = new ExtendedStringBuilder(); for (var y = 1; y <= yDim; ++y) { for (var x = 1; x <= xDim; ++x) { var member = String.Format("s = m.M{0}{1};", y - 1, x - 1); builder.AppendLine(member); } } builder.PopScope(); builder.AppendLine("}"); builder.AppendLine(); }
static void GenerateMultiplyUpNoDivide(ExtendedStringBuilder results, String fnName, String matrixType, String scalarType, int sizeX, int sizeY, String promotionValue) { String inputVectorType = String.Format("{0}{1}", scalarType, sizeY - 1); if (sizeY - 1 == 1) { inputVectorType = scalarType; } String multiplyVectorType = String.Format("{0}{1}", scalarType, sizeY); String memberAccessStr = "X"; if (sizeY > 2) { memberAccessStr += "Y"; } if (sizeY > 3) { memberAccessStr += "Z"; } if (sizeY > 4) { memberAccessStr += "W"; } results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function {0}(by : {1}, the : {2}) : {2}", fnName, matrixType, inputVectorType)); results.AppendLine("{"); results.AppendLine(String.Format(" var promotedVector = {0}(the, {1});", multiplyVectorType, promotionValue)); results.AppendLine(String.Format(" return Math.Multiply(by, promotedVector).{0};", memberAccessStr)); results.AppendLine("}"); }
static void GenerateMultiplyUpWithDivision(ExtendedStringBuilder results, String fnName, String matrixType, String scalarType, int sizeX, int sizeY, String promotionValue) { String inputVectorType = String.Format("{0}{1}", scalarType, sizeY - 1); if (sizeY - 1 == 1) { inputVectorType = scalarType; } String multiplyVectorType = String.Format("{0}{1}", scalarType, sizeY); var memberAccessStrings = new List <string>() { "X", "Y", "Z", "W" }; String memberAccessStr = ""; for (var i = 0; i < sizeY - 1; ++i) { memberAccessStr += memberAccessStrings[i]; } results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function {0}(by : {1}, the : {2}) : {2}", fnName, matrixType, inputVectorType)); results.AppendLine("{"); results.AppendLine(String.Format(" var promotedVector = {0}(the, {1});", multiplyVectorType, promotionValue)); results.AppendLine(String.Format(" var transformedVector = Math.Multiply(by, promotedVector);")); results.AppendLine(String.Format(" var result = transformedVector.{0} / transformedVector.{1};", memberAccessStr, memberAccessStrings[sizeY - 1])); results.AppendLine(" return result;"); results.AppendLine("}"); }
protected override void BroadcastPlayerOptions() { if (!IsHost) { return; } var sb = new ExtendedStringBuilder(PLAYER_OPTIONS_BROADCAST_COMMAND + " ", true); sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR; foreach (PlayerInfo pInfo in Players.Concat(AIPlayers)) { sb.Append(pInfo.Name); sb.Append(pInfo.SideId); sb.Append(pInfo.ColorId); sb.Append(pInfo.StartingLocation); sb.Append(pInfo.TeamId); sb.Append(Convert.ToInt32(pInfo.IsAI || pInfo.Ready)); sb.Append(pInfo.IPAddress); if (pInfo.IsAI) { sb.Append(pInfo.AILevel); } else { sb.Append("-1"); } } BroadcastMessage(sb.ToString()); }
protected override void OnGameOptionChanged() { base.OnGameOptionChanged(); if (!IsHost) { return; } var sb = new ExtendedStringBuilder(GAME_OPTIONS_COMMAND + " ", true); sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR; foreach (GameLobbyCheckBox chkBox in CheckBoxes) { sb.Append(Convert.ToInt32(chkBox.Checked)); } foreach (GameLobbyDropDown dd in DropDowns) { sb.Append(dd.SelectedIndex); } sb.Append(RandomSeed); sb.Append(Map.SHA1); sb.Append(GameMode.Name); sb.Append(FrameSendRate); sb.Append(Convert.ToInt32(RemoveStartingLocations)); BroadcastMessage(sb.ToString()); }
static void GenerateLengthSq(ExtendedStringBuilder results, String type) { results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function LengthSq(value : {0}) : Real", type)); results.AppendLine("{"); results.AppendLine(" return Math.Dot(value, value);"); results.AppendLine("}"); }
static void GenerateFMod(ExtendedStringBuilder results, String type) { results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function FMod(numerator : {0}, denominator : {0}) : {0}", type)); results.AppendLine("{"); results.AppendLine(" return numerator - denominator * Math.Truncate(numerator / denominator);"); results.AppendLine("}"); }
static void GenerateLog10(ExtendedStringBuilder results, String type) { results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function Log10(value : {0}) : {0}", type)); results.AppendLine("{"); results.AppendLine(String.Format(" return Math.Log(value) / Math.Log(10);", type)); results.AppendLine("}"); }
static void GenerateSaturate(ExtendedStringBuilder results, String type) { results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function Saturate(value : {0}) : {0}", type)); results.AppendLine("{"); results.AppendLine(String.Format(" return Math.Clamp(value, {0}(0), {0}(1));", type)); results.AppendLine("}"); }
static void GenerateCeilPlaces(ExtendedStringBuilder results, String type) { results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function Ceil(value : {0}, places : Integer) : {0}", type)); results.AppendLine("{"); results.AppendLine(String.Format(" return Math.Ceil(value, places, 10);", type)); results.AppendLine("}"); }
static void GenerateVectorSwizzles(ExtendedStringBuilder builder, String baseType, int vectorDim) { List <String> componentNames = new List <String>() { "X", "Y", "Z", "W" }; List <String> vectorTypeNames = new List <String>(); vectorTypeNames.Add(baseType); vectorTypeNames.Add(String.Format("{0}2", baseType)); vectorTypeNames.Add(String.Format("{0}3", baseType)); vectorTypeNames.Add(String.Format("{0}4", baseType)); builder.AppendLine(String.Format("function Test{0}()", vectorTypeNames[vectorDim - 1])); builder.AppendLine("{"); builder.PushScope(); var maxCount = 4; builder.AppendLine(String.Format("var v = {0}();", vectorTypeNames[vectorDim - 1])); List <String> vectorNames = new List <String>(); for (var i = 1; i <= maxCount; ++i) { String varName = String.Format("v{0}", i); vectorNames.Add(varName); builder.AppendLine(String.Format("var v{0} = {1}();", i, vectorTypeNames[i - 1])); } builder.AppendLine(); for (var count = 1; count <= maxCount; ++count) { List <int> indices = new List <int>() { 0, 0, 0, 0 }; do { StringBuilder nameBuilder = new StringBuilder(); for (int i = 1; i <= count; ++i) { var index = indices[i - 1]; nameBuilder.Append(componentNames[index]); } String name = nameBuilder.ToString(); builder.AppendLine(String.Format("{0} = v.{1};", vectorNames[count - 1], name)); } while (EvolvePermutation(indices, count, vectorDim)); } builder.PopScope(); builder.AppendLine("}"); builder.AppendLine(); }
private ExtendedStringBuilder _buildHeader(object item, IEnumerable <Property> properties, bool root = true) { var columnLine = new ExtendedStringBuilder(); foreach (var property in properties) { if (!property.CanSerialize) { continue; } var name = string.Empty; if (property.Attribute.Traverse) { var itemValue = property.Info.GetValue(item); name = _buildHeader(itemValue, _getProperties(itemValue), false); } else { name = property.Attribute?.Name ?? property.Info.Name; if (InvalidColumnReplace != null) { name = name.Replace(ColumnDelimiter, InvalidColumnReplace); } if (InvalidRowReplace != null) { name = name.Replace(RowDelimiter, InvalidRowReplace); } if (DoubleQuoteEscape != null) { name = name.Replace("\"", DoubleQuoteEscape); } _validateCharacters(name, ColumnDelimiter, "column name"); _validateCharacters(name, RowDelimiter, "column name"); if (QuoteValues) { name = "\"" + name + "\""; } } if (columnLine.HasBeenAppended) { columnLine += ColumnDelimiter; } columnLine += name; } if (root && IncludeTrailingDelimiter) { columnLine += ColumnDelimiter; } return(columnLine); }
static void GenerateCeilPlacesBase(ExtendedStringBuilder results, String type) { results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function Ceil(value : {0}, places : Integer, numericalBase : Integer) : {0}", type)); results.AppendLine("{"); results.AppendLine(" var scale = Math.Pow(numericalBase, places);"); results.AppendLine(" return Math.Ceil(value / scale) * scale;"); results.AppendLine("}"); }
protected override void SendChatMessage(string message) { var sb = new ExtendedStringBuilder(CHAT_COMMAND + " ", true); sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR; sb.Append(chatColorIndex); sb.Append(message); SendMessageToHost(sb.ToString()); }
static void GenerateProjectOnPlane(ExtendedStringBuilder results, String type) { String varName = type.ToLower(); results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function ProjectOnPlane(toBeProjected : {0}, planeNormal : {0}) : {0}", type)); results.AppendLine("{"); results.AppendLine(" return toBeProjected - Math.ProjectOnVector(toBeProjected, planeNormal);"); results.AppendLine("}"); }
static void GenerateRotateTowards(ExtendedStringBuilder results, String type) { String varName = type.ToLower(); results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function RotateTowards(p0 : {0}, p1 : {0}, maxRadians : Real) : {0}", type)); results.AppendLine("{"); results.AppendLine(String.Format(" return MathGenericRotateTowards[{0}].RotateTowards(p0, p1, maxRadians);", type)); results.AppendLine("}"); }
static void GenerateReflectAcrossVector(ExtendedStringBuilder results, String type) { String varName = type.ToLower(); results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function ReflectAcrossVector(toBeReflected : {0}, vector : {0}) : {0}", type)); results.AppendLine("{"); results.AppendLine(" return Math.ReflectAcrossPlane(-toBeReflected, vector);"); results.AppendLine("}"); }
static void GenerateSetByIndex(ExtendedStringBuilder results, String type) { results.AppendLine(String.Format("[Extension(typeid({0}))][Implements]", type)); results.AppendLine("function SetByIndex(index : Integer, value : Real)"); results.AppendLine("{"); results.AppendLine(" var indexX = index % this.CountX;"); results.AppendLine(" var indexY = index / this.CountX;"); results.AppendLine(" this[indexY][indexX] = value;"); results.AppendLine("}"); }
protected override void RequestPlayerOptions(int side, int color, int start, int team) { var sb = new ExtendedStringBuilder(PLAYER_OPTIONS_REQUEST_COMMAND + " ", true); sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR; sb.Append(side); sb.Append(color); sb.Append(start); sb.Append(team); SendMessageToHost(sb.ToString()); }
static void GenerateDistanceSq(ExtendedStringBuilder results, String type) { String varName = type.ToLower(); results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function DistanceSq({0}0 : {1}, {0}1 : {1}) : Real", varName, type)); results.AppendLine("{"); results.AppendLine(String.Format(" var vector = {0}0 - {0}1;", varName)); results.AppendLine(" return Math.LengthSq(vector);"); results.AppendLine("}"); }
public override string ToString() { var sb = new ExtendedStringBuilder(); sb.Append("Search engines", SearchEngines); sb.Append("Priority engines", PriorityEngines); sb.Append("Filtering", Filtering); sb.Append("Notification", Notification); sb.Append("Notification image", NotificationImage); return(sb.ToString()); }
static void GenerateGetAxis(ExtendedStringBuilder results, String type) { String varName = type.ToLower(); results.AppendLine(String.Format("[Static][Extension(typeid({0}))][Implements]", type)); results.AppendLine(String.Format("function GetAxis(value : Integer) : {0}", type)); results.AppendLine("{"); results.AppendLine(String.Format(" var axis = {0}();", type)); results.AppendLine(" axis[value] = 1;"); results.AppendLine(" return axis;"); results.AppendLine("}"); }
private IEnumerable <string> _readLines(Stream stream, Encoding encoding) { var buffer = new byte[512]; var decoder = encoding.GetDecoder(); var readSize = buffer.Length; var esb = new ExtendedStringBuilder(); while (stream.Position < stream.Length) { var remaining = stream.Length - stream.Position; if (remaining < buffer.Length) { readSize = (int)remaining; } stream.Read(buffer, 0, readSize); var chars = new char[decoder.GetCharCount(buffer, 0, readSize)]; decoder.GetChars(buffer, 0, readSize, chars, 0); foreach (char c in chars) { esb += c; } if (esb.Contains(RowDelimiter)) { string str = esb; string[] parts = str.QuotedSplit(RowDelimiter).ToArray(); for (int i = 0; i < parts.Length - 1; i++) { yield return(parts[i]); } esb.Length = 0; esb += parts[parts.Length - 1]; } } { string str = esb; string[] parts = str.QuotedSplit(RowDelimiter).ToArray(); for (int i = 0; i < parts.Length; i++) { yield return(parts[i]); } } }
static void GenerateSquareMatrixClass(ExtendedStringBuilder results, String className, MatrixFnCall fnCall) { results.AppendLine("[Implements]"); results.AppendLine(String.Format("struct {0}", className)); results.AppendLine("{"); results.PushScope(); fnCall(results, "Real2x2", "Real", 2, 2); fnCall(results, "Real3x3", "Real", 3, 3); fnCall(results, "Real4x4", "Real", 4, 4); results.PopScope(); results.AppendLine("}"); }
static void GenerateAngleBetween(ExtendedStringBuilder results, String type) { String varName = type.ToLower(); String var0Name = varName + "0"; String var1Name = varName + "1"; results.AppendLine("[Static][Extension(typeid(Math))][Implements]"); results.AppendLine(String.Format("function AngleBetween({0} : {2}, {1} : {2}) : Real", var0Name, var1Name, type)); results.AppendLine("{"); results.AppendLine(String.Format(" var dotVal = Math.Dot({0}, {1});", var0Name, var1Name)); results.AppendLine(" dotVal = Math.Clamp(dotVal, -1.0, 1.0);"); results.AppendLine(" return Math.ACos(dotVal);"); results.AppendLine("}"); }
public override string ToString() { var sb = new ExtendedStringBuilder(true, ','); sb.Append(Name); sb.Append(SideId); sb.Append(StartingLocation); sb.Append(ColorId); sb.Append(TeamId); sb.Append(AILevel); sb.Append(IsAI.ToString()); sb.Append(Index); return(sb.ToString()); }
static void Main(string[] args) { ExtendedStringBuilder builder = new ExtendedStringBuilder(); GenerateVectorSwizzlesForType(builder, "Real"); GenerateVectorSwizzlesForType(builder, "Integer"); GenerateVectorSwizzlesForType(builder, "Boolean"); GenerateMatrixSwizzlesForType(builder, "Real"); String result = builder.ToString(); Clipboard.SetText(result); }
static void GenerateClass(ExtendedStringBuilder results, String className, List <String> types, FnCall fnCall) { results.AppendLine("[Implements]"); results.AppendLine(String.Format("struct {0}", className)); results.AppendLine("{"); results.PushScope(); foreach (var type in types) { fnCall(results, type); } results.PopScope(); results.AppendLine("}"); }
public static string BuildQueryString(Dictionary <string, string> values) { var sb = new ExtendedStringBuilder(); foreach (var kvp in values) { if (sb.Length > 0) { sb += '&'; } sb.Append(kvp.Key).Append('=').Append(kvp.Value); } return(sb); }
/// <summary> /// Converts a byte-array to an RFC4648 (https://tools.ietf.org/html/rfc4648) Base32 string. /// </summary> /// <param name="input">The input byte-array.</param> /// <param name="options">Any of <see cref="Base32FormattingOptions"/> enumeration values.</param> /// <returns>The input byte-array encoded into a Base32 string, following the provided options.</returns> public static string ToBase32String(this byte[] input, Base32FormattingOptions options = Base32FormattingOptions.RequirePaddingCharacter) { string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="; if ((options & Base32FormattingOptions.CrockfordAlphabet) == Base32FormattingOptions.CrockfordAlphabet) { alphabet = "0123456789ABCDEFGHJKMNPQRSTVWXYZ="; } else if ((options & Base32FormattingOptions.Hex32Alphabet) == Base32FormattingOptions.Hex32Alphabet) { alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUV="; } else if ((options & Base32FormattingOptions.VowelSafeAlphabet) == Base32FormattingOptions.VowelSafeAlphabet) { alphabet = "0123456789bcdfhjkmnpqrtvxyDFGHJL="; } ExtendedStringBuilder workingResult = new ExtendedStringBuilder(); int originalLength = input.Length; int newLength = originalLength; if (input.Length % 5 != 0) { newLength += originalLength % 5; } byte[] workingSet = new byte[newLength]; for (int i = 0; i < originalLength; i++) { workingSet[i] = input[i]; } for (int g = 0; g < newLength / 5; g++) { int indexOffset = g * 5; int temp = (workingSet[indexOffset] & 0xF4) >> 3; workingResult += alphabet[temp]; temp = (workingSet[indexOffset] & 0x03) << 2; if (indexOffset + 1 < input.Length) { temp |= (workingSet[indexOffset + 1] & 0xC0) >> 6; workingResult += alphabet[temp]; temp = (workingSet[indexOffset + 1] & 0x3E) >> 1; workingResult += alphabet[temp]; temp = (workingSet[indexOffset + 1] & 0x01) << 4; if (indexOffset + 2 < input.Length) { temp |= (workingSet[indexOffset + 2] & 0xF0) >> 4; workingResult += alphabet[temp]; temp = (workingSet[indexOffset + 2] & 0x0F) << 1; if (indexOffset + 3 < input.Length) { temp |= (workingSet[indexOffset + 3] & 0x80) >> 7; workingResult += alphabet[temp]; temp = (workingSet[indexOffset + 3] & 0x7C) >> 2; workingResult += alphabet[temp]; temp = (workingSet[indexOffset + 3] & 0x03) << 3; if (indexOffset + 4 < input.Length) { temp |= (workingSet[indexOffset + 4] & 0xE0) >> 5; workingResult += alphabet[temp]; temp = workingSet[indexOffset + 4] & 0x1F; workingResult += alphabet[temp]; } else { workingResult += alphabet[temp]; if ((options & Base32FormattingOptions.RequirePaddingCharacter) == Base32FormattingOptions.RequirePaddingCharacter) { workingResult += alphabet[32]; } } } else { workingResult += alphabet[temp]; if ((options & Base32FormattingOptions.RequirePaddingCharacter) == Base32FormattingOptions.RequirePaddingCharacter) { workingResult += alphabet[32]; workingResult += alphabet[32]; workingResult += alphabet[32]; } } } else { workingResult += alphabet[temp]; if ((options & Base32FormattingOptions.RequirePaddingCharacter) == Base32FormattingOptions.RequirePaddingCharacter) { workingResult += alphabet[32]; workingResult += alphabet[32]; workingResult += alphabet[32]; workingResult += alphabet[32]; } } } else { workingResult += alphabet[temp]; if ((options & Base32FormattingOptions.RequirePaddingCharacter) == Base32FormattingOptions.RequirePaddingCharacter) { workingResult += alphabet[32]; workingResult += alphabet[32]; workingResult += alphabet[32]; workingResult += alphabet[32]; workingResult += alphabet[32]; workingResult += alphabet[32]; } } } if (((options & Base32FormattingOptions.RequirePaddingCharacter) == Base32FormattingOptions.RequirePaddingCharacter) && (originalLength != newLength)) { for (int padCount = 0; padCount < newLength - originalLength; padCount++) { workingResult += alphabet[32]; } } return workingResult; }
/// <summary> /// Converts a string of dash-separated, or underscore-separated words to a PascalCase string. /// </summary> /// <param name="s">The string to convert.</param> /// <returns>The resulting PascalCase string.</returns> public static string ToPascalCase(this string s) { var words = s.Split(new char[3] { '-', '_', ' ' }, StringSplitOptions.RemoveEmptyEntries); var sb = new ExtendedStringBuilder(words.Sum(x => x.Length)); foreach (string word in words) { var stringInfo = new StringInfo(word); sb += stringInfo.SubstringByTextElements(0, 1).ToUpper(); sb += stringInfo.SubstringByTextElements(1).ToLower(); } return sb.ToString(); }
/// <summary> /// Converts a byte-array to an RFC4648 (https://tools.ietf.org/html/rfc4648) Base64 string. /// </summary> /// <param name="input">The input byte-array.</param> /// <param name="options">Any of <see cref="Base64FormattingOptions"/> enumeration values.</param> /// <param name="charactersPerLine">If this is a non-zero uinteger, than the number of characters per line will be equivalent to this value.</param> /// <returns>The input byte-array encoded into a Base64 string, following the provided options.</returns> public static string ToBase64String(this byte[] input, Base64FormattingOptions options = Base64FormattingOptions.RequirePaddingCharacter, uint charactersPerLine = 0) { string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; if ((options & Base64FormattingOptions.UrlFilenameSafeAlphabet) == Base64FormattingOptions.UrlFilenameSafeAlphabet) { alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; } else if ((options & Base64FormattingOptions.UnixCryptAlphabet) == Base64FormattingOptions.UnixCryptAlphabet) { alphabet = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz="; } ExtendedStringBuilder workingResult = new ExtendedStringBuilder(); for (int i = 0; i < input.Length; i += 3) { int temp = (input[i] & 0xFC) >> 2; workingResult += alphabet[temp]; temp = (input[i] & 0x03) << 4; if (i + 1 < input.Length) { temp |= (input[i + 1] & 0xF0) >> 4; workingResult += alphabet[temp]; temp = (input[i + 1] & 0x0F) << 2; if (i + 2 < input.Length) { temp |= (input[i + 2] & 0xC0) >> 6; workingResult += alphabet[temp]; workingResult += alphabet[((input[i + 2] & 0x3F))]; } else { workingResult += alphabet[temp]; if ((options & Base64FormattingOptions.RequirePaddingCharacter) == Base64FormattingOptions.RequirePaddingCharacter) { workingResult += alphabet[64]; } } } else { workingResult += alphabet[temp]; if ((options & Base64FormattingOptions.RequirePaddingCharacter) == Base64FormattingOptions.RequirePaddingCharacter) { workingResult += alphabet[64]; workingResult += alphabet[64]; } } } uint lineBreaks = 0; if (charactersPerLine > 0) { lineBreaks = charactersPerLine; } else if ((options & Base64FormattingOptions.BreakLinesAt64Characters) == Base64FormattingOptions.BreakLinesAt64Characters) { lineBreaks = 64; } else if ((options & Base64FormattingOptions.BreakLinesAt76Characters) == Base64FormattingOptions.BreakLinesAt76Characters) { lineBreaks = 76; } ExtendedStringBuilder result = new ExtendedStringBuilder(); string workingString = workingResult; if (lineBreaks > 0) { for (uint line = 0; line < workingResult.Length / lineBreaks; line++) { result += workingString.Substring((int)(line * lineBreaks), (int)lineBreaks); string lineBreak = ""; if ((options & Base64FormattingOptions.UseCarraigeReturnNewline) == Base64FormattingOptions.UseCarraigeReturnNewline) { lineBreak += "\r"; } if ((options & Base64FormattingOptions.UseLineBreakNewLine) == Base64FormattingOptions.UseLineBreakNewLine) { lineBreak += "\n"; } if (lineBreak == "") { lineBreak = "\r\n"; } result += lineBreak; } } else { result += workingResult; } return result.ToString(); }
public static string BuildQueryString(Dictionary<string, string> values) { var sb = new ExtendedStringBuilder(); foreach (var kvp in values) { if (sb.Length > 0) { sb += '&'; } sb.Append(kvp.Key).Append('=').Append(kvp.Value); } return sb; }
/// <summary> /// Inserts a <code>string</code> into another <code>string</code> before each occurrence of the specified <see cref="CharacterType"/>. /// </summary> /// <param name="source">The <code>string</code> to insert into.</param> /// <param name="type">The <see cref="CharacterType"/> to insert before.</param> /// <param name="insert">The <code>string</code> to insert.</param> /// <returns>The resultant <code>string</code>.</returns> /// <remarks> /// In the case of the first character of <code>source</code> matching the specified <see cref="CharacterType"/>, the <code>insert</code> will not be inserted. /// </remarks> public static string InsertOnCharacter(this string source, CharacterType type, string insert) { var esb = new ExtendedStringBuilder(source.Length); var firstRun = false; foreach (var c in source) { var cType = c.GetCharacterType(); if (firstRun && cType == type) { esb += insert; } esb += c; firstRun = true; } return esb; }