Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Dec 9, 2015
1 parent a90b3af commit 9a2a37f
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions ArchiSteamFarm/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,11 @@ limitations under the License.
*/

using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ArchiSteamFarm {
internal static class Utilities {
private static readonly Random Random = new Random();

internal static int RandomNumber(int min, int max) {
return Random.Next(min, max + 1);
}

internal static byte RandomDice() {
return (byte) RandomNumber(1, 6);
}

internal static async Task SleepAsync(int miliseconds) {
await Task.Delay(miliseconds).ConfigureAwait(false);
}
Expand All @@ -48,16 +36,25 @@ internal static ulong OnlyNumbers(string inputString) {
return 0;
}

string resultString;
try {
Regex regexObj = new Regex(@"[^\d]");
resultString = regexObj.Replace(inputString, "");
} catch (ArgumentException e) {
Logging.LogGenericException("Utilities", e);
string resultString = OnlyNumbersString(inputString);
if (string.IsNullOrEmpty(resultString)) {
return 0;
}

ulong result;
if (!ulong.TryParse(resultString, out result)) {
return 0;
}

return ulong.Parse(resultString, CultureInfo.InvariantCulture);
return result;
}

internal static string OnlyNumbersString(string text) {
if (string.IsNullOrEmpty(text)) {
return null;
}

return Regex.Replace(text, @"[^\d]", "");
}
}
}

0 comments on commit 9a2a37f

Please sign in to comment.