| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Globalization; |
| | 6 | | using System.Text; |
| | 7 | |
|
| | 8 | | namespace Azure.Messaging.ServiceBus.Primitives |
| | 9 | | { |
| | 10 | | internal static class StringUtility |
| | 11 | | { |
| | 12 | |
|
| | 13 | | public static string GetFormattedLockTokens(IEnumerable<string> lockTokens) |
| | 14 | | { |
| 0 | 15 | | var lockTokenBuilder = new StringBuilder(); |
| 0 | 16 | | foreach (var lockToken in lockTokens) |
| | 17 | | { |
| 0 | 18 | | lockTokenBuilder.AppendFormat(CultureInfo.InvariantCulture, "<LockToken>{0}</LockToken>", lockToken); |
| | 19 | | } |
| | 20 | |
|
| 0 | 21 | | return lockTokenBuilder.ToString(); |
| | 22 | | } |
| | 23 | |
|
| | 24 | | public static string GetFormattedSequenceNumbers(IEnumerable<long> sequenceNumbers) |
| | 25 | | { |
| 0 | 26 | | var sequenceNumberBuilder = new StringBuilder(); |
| 0 | 27 | | foreach (var sequenceNumber in sequenceNumbers) |
| | 28 | | { |
| 0 | 29 | | sequenceNumberBuilder.AppendFormat(CultureInfo.InvariantCulture, "<SequenceNumber>{0}</SequenceNumber>", |
| | 30 | | } |
| | 31 | |
|
| 0 | 32 | | return sequenceNumberBuilder.ToString(); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Formats a string+parameters using CurrentCulture. |
| | 37 | | /// </summary> |
| | 38 | | public static string FormatForUser(this string format, params object[] args) |
| | 39 | | { |
| 0 | 40 | | return string.Format(CultureInfo.CurrentCulture, format, args); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// Formats a string+parameter using InvariantCulture. This overload avoids allocating an array when there's on |
| | 45 | | /// </summary> |
| | 46 | | public static string FormatInvariant(this string format, object arg0) |
| | 47 | | { |
| 0 | 48 | | return string.Format(CultureInfo.InvariantCulture, format, arg0); |
| | 49 | | } |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Formats a string+parameters using InvariantCulture. |
| | 53 | | /// </summary> |
| | 54 | | public static string FormatInvariant(this string format, params object[] args) |
| | 55 | | { |
| 0 | 56 | | return string.Format(CultureInfo.InvariantCulture, format, args); |
| | 57 | | } |
| | 58 | | } |
| | 59 | | } |