diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-06 18:28:51 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-06 18:28:51 +0200 |
| commit | 4e48c569f1cae820ffade8a786354b2ba79b50b4 (patch) | |
| tree | 1bfbdf19f8c86cc1f1a1d8b900756b0cc2781d66 /Software/Visual_Studio/Tango.Editors/StringExtensions.cs | |
| parent | 7e6c673cc8b04086fa3c78cd1bf5e31085fd8cc8 (diff) | |
| download | Tango-4e48c569f1cae820ffade8a786354b2ba79b50b4.tar.gz Tango-4e48c569f1cae820ffade8a786354b2ba79b50b4.zip | |
Some improvements on hive.
Diffstat (limited to 'Software/Visual_Studio/Tango.Editors/StringExtensions.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Editors/StringExtensions.cs | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/Software/Visual_Studio/Tango.Editors/StringExtensions.cs b/Software/Visual_Studio/Tango.Editors/StringExtensions.cs deleted file mode 100644 index 0f5923512..000000000 --- a/Software/Visual_Studio/Tango.Editors/StringExtensions.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -/// <exclude/> -/// <summary> -/// A collection of <see cref="String"/> extension methods. -/// </summary> -internal static class StringExtensions -{ - private static Regex titleRegEx; - - /// <summary> - /// Initializes the <see cref="StringExtensions"/> class. - /// </summary> - static StringExtensions() - { - titleRegEx = new Regex(@" - (?<=[A-Z])(?=[A-Z][a-z]) | - (?<=[^A-Z])(?=[A-Z]) | - (?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace); - } - - /// <summary> - /// Returns true if the string is not null or contains white spaces. - /// </summary> - /// <param name="str">The string.</param> - /// <returns></returns> - internal static bool IsValid(this String str) - { - return !String.IsNullOrWhiteSpace(str); - } - - /// <summary> - /// Determines whether the string contains an existing file path. - /// </summary> - /// <param name="path">The path.</param> - /// <returns></returns> - internal static bool IsFileExists(this String path) - { - return System.IO.File.Exists(path); - } - - /// <summary> - /// Determines whether the string is valid as a file system path. - /// </summary> - /// <param name="path">The path.</param> - /// <returns></returns> - internal static bool IsPathValid(this String path) - { - return path.IsValid() && path.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1; - } - - /// <summary> - /// Returns a friendly file size of the file path. - /// </summary> - /// <param name="filePath">The file path.</param> - /// <returns></returns> - internal static String GetFileSizeString(this String filePath) - { - FileInfo f = new FileInfo(filePath); - double length = f.Length; - - string[] sizes = { "B", "KB", "MB", "GB" }; - double len = length; - int order = 0; - while (len >= 1024 && order + 1 < sizes.Length) - { - order++; - len = len / 1024; - } - - // Adjust the format string to your preferences. For example "{0:0.#}{1}" would - // show a single decimal place, and no space. - return String.Format("{0:0.##} {1}", len, sizes[order]); - } - - /// <summary> - /// If string is a path, returns the file name. - /// </summary> - /// <param name="filePath">The file path.</param> - /// <returns></returns> - internal static String GetFileName(this String filePath) - { - return Path.GetFileName(filePath); - } - - /// <summary> - /// If string is a path, returns the file extension. - /// </summary> - /// <param name="filePath">The file path.</param> - /// <returns></returns> - internal static String GetFileExtension(this String filePath) - { - return Path.GetExtension(filePath); - } - - internal static String ToTitle(this String str) - { - return titleRegEx.Replace(str, " "); - } -} - |
