diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs index bbb0f17c28..85f0805388 100644 --- a/BizHawk.Client.Common/PathManager.cs +++ b/BizHawk.Client.Common/PathManager.cs @@ -4,6 +4,7 @@ using System.IO; using System.Reflection; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Cores.Nintendo.SNES; @@ -176,8 +177,8 @@ namespace BizHawk.Client.Common int x = NumParentDirectories(path); if (x > 0) { - int y = StringHelpers.HowMany(path, "..\\"); - int z = StringHelpers.HowMany(workingpath, "\\"); + int y = path.HowMany("..\\"); + int z = workingpath.HowMany("\\"); if (y >= z) { //Return drive letter only, working path must be absolute? @@ -192,10 +193,10 @@ namespace BizHawk.Client.Common public static int NumParentDirectories(string path) { // determine the number of parent directories in path and return result - int x = StringHelpers.HowMany(path, '\\'); + int x = path.HowMany('\\'); if (x > 0) { - return StringHelpers.HowMany(path, "..\\"); + return path.HowMany("..\\"); } return 0; diff --git a/BizHawk.Client.Common/inputAdapters/InputAdapters.cs b/BizHawk.Client.Common/inputAdapters/InputAdapters.cs index e624652548..d1efb0cfc6 100644 --- a/BizHawk.Client.Common/inputAdapters/InputAdapters.cs +++ b/BizHawk.Client.Common/inputAdapters/InputAdapters.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; + using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.Common diff --git a/BizHawk.Client.Common/tools/WatchList.cs b/BizHawk.Client.Common/tools/WatchList.cs index 4da744a8c2..01c54b2759 100644 --- a/BizHawk.Client.Common/tools/WatchList.cs +++ b/BizHawk.Client.Common/tools/WatchList.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.Common @@ -444,7 +445,7 @@ namespace BizHawk.Client.Common continue; } - var numColumns = StringHelpers.HowMany(line, '\t'); + var numColumns = line.HowMany('\t'); int startIndex; if (numColumns == 5) { diff --git a/BizHawk.Client.DBMan/DirectoryScan.cs b/BizHawk.Client.DBMan/DirectoryScan.cs index e80cf20eac..bf2169aa87 100644 --- a/BizHawk.Client.DBMan/DirectoryScan.cs +++ b/BizHawk.Client.DBMan/DirectoryScan.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; using System.IO; -using BizHawk.Common; using Community.CsharpSqlite.SQLiteClient; +using BizHawk.Common.StringExtensions; + namespace BizHawk.Client.DBMan { public static class DirectoryScan diff --git a/BizHawk.Common/Extensions/StringExtensions.cs b/BizHawk.Common/Extensions/StringExtensions.cs index 9902242a61..b50734643b 100644 --- a/BizHawk.Common/Extensions/StringExtensions.cs +++ b/BizHawk.Common/Extensions/StringExtensions.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; -namespace BizHawk.Common +namespace BizHawk.Common.StringExtensions { public static class StringExtensions { @@ -13,20 +13,19 @@ namespace BizHawk.Common public static string GetPrecedingString(this string str, string value) { - int index = str.IndexOf(value); + var index = str.IndexOf(value); if (index < 0) { return null; } - else if (index == 0) + + if (index == 0) { - return String.Empty; - } - else - { - return str.Substring(0, index); + return string.Empty; } + + return str.Substring(0, index); } public static bool IsValidRomExtentsion(this string str, params string[] romExtensions) @@ -59,5 +58,24 @@ namespace BizHawk.Common { return options.All(opt => opt.ToLower() != str.ToLower()); } + + public static int HowMany(this string str, char c) + { + return !string.IsNullOrEmpty(str) ? str.Count(t => t == c) : 0; + } + + public static int HowMany(this string str, string s) + { + var count = 0; + for (var i = 0; i < (str.Length - s.Length); i++) + { + if (str.Substring(i, s.Length) == s) + { + count++; + } + } + + return count; + } } } diff --git a/BizHawk.Common/HawkFile.cs b/BizHawk.Common/HawkFile.cs index 8ec408862d..4c45e4ef74 100644 --- a/BizHawk.Common/HawkFile.cs +++ b/BizHawk.Common/HawkFile.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using BizHawk.Common.StringExtensions; + // the HawkFile class is excessively engineered with the IHawkFileArchiveHandler to decouple the archive handling from the basic file handling. // This is so we could drop in an unamanged dearchiver library optionally later as a performance optimization without ruining the portability of the code. // Also, we want to be able to use HawkFiles in BizHawk.Common withuot bringing in a large 7-zip dependency diff --git a/BizHawk.Common/InputValidate.cs b/BizHawk.Common/InputValidate.cs index 4b16cc4463..cec68bdc44 100644 --- a/BizHawk.Common/InputValidate.cs +++ b/BizHawk.Common/InputValidate.cs @@ -4,6 +4,8 @@ namespace BizHawk.Common { using System.Linq; + using BizHawk.Common.StringExtensions; + /// /// Includes helper functions to validate user input /// @@ -101,7 +103,7 @@ namespace BizHawk.Common /// public static bool IsFixedPoint(string str) { - return StringHelpers.HowMany(str, '.') <= 1 + return str.HowMany('.') <= 1 && str.All(IsFixedPoint); } @@ -118,7 +120,7 @@ namespace BizHawk.Common /// public static bool IsFloat(string str) { - return StringHelpers.HowMany(str, '.') <= 1 + return str.HowMany('.') <= 1 && IsFloat(str[0]) && str.Substring(1).All(IsFixedPoint); } diff --git a/BizHawk.Common/StringHelpers.cs b/BizHawk.Common/StringHelpers.cs index 584da4fd7b..736535ec09 100644 --- a/BizHawk.Common/StringHelpers.cs +++ b/BizHawk.Common/StringHelpers.cs @@ -2,29 +2,6 @@ namespace BizHawk.Common { - // TODO: these classes are worthless or need to be extensions, decide which - public static class StringHelpers - { - public static int HowMany(string str, char c) - { - return !string.IsNullOrEmpty(str) ? str.Count(t => t == c) : 0; - } - - public static int HowMany(string str, string s) - { - var count = 0; - for (int i = 0; i < (str.Length - s.Length); i++) - { - if (str.Substring(i, s.Length) == s) - { - count++; - } - } - - return count; - } - } - // TODO: put it in its own file public static class IntHelpers // TODO: a less lame name { diff --git a/BizHawk.Emulation.Cores/CPUs/68000/OpcodeTable.cs b/BizHawk.Emulation.Cores/CPUs/68000/OpcodeTable.cs index e1627a0487..14e11515ad 100644 --- a/BizHawk.Emulation.Cores/CPUs/68000/OpcodeTable.cs +++ b/BizHawk.Emulation.Cores/CPUs/68000/OpcodeTable.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using BizHawk.Common; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Components.M68000 { diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs index 5c9e88ea84..295654c9c2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.Components; using BizHawk.Emulation.Cores.Components.Z80;