private static bool Match(string query, string haystack, bool strictOnly, float strictWeight, float looseWeight, out float score, bool[] indices) { score = 0; var isStreaking = false; var haystackIndex = 0; var matchedAny = false; for (var queryIndex = 0; queryIndex < query.Length; queryIndex++) { var queryCharacter = query[queryIndex]; if (StringUtility.IsWordDelimiter(queryCharacter)) { continue; } var matched = false; for (; haystackIndex < haystack.Length; haystackIndex++) { var haystackCharacter = haystack[haystackIndex]; if (StringUtility.IsWordDelimiter(haystackCharacter)) { isStreaking = false; continue; } var matchesLoose = Compare(queryCharacter, haystackCharacter); var matchesStrict = matchesLoose && (isStreaking || StringUtility.IsWordBeginning(haystack, haystackIndex)); var matches = strictOnly ? matchesStrict : matchesLoose; if (matches) { score += matchesStrict ? strictWeight : looseWeight; matched = true; if (indices != null) { indices[haystackIndex] = true; } isStreaking = true; haystackIndex++; break; } else { isStreaking = false; } } if (matched) { matchedAny = true; } else { return(false); } } if (!matchedAny) { return(false); } score /= query.Length; return(true); }
public override string ToString() { return(StringUtility.FallbackWhitespace(title, base.ToString())); }
public static void GenerateLicenseFile(string path) { var acknowledgements = PluginContainer.plugins .SelectMany(plugin => plugin.resources.acknowledgements) .Distinct() .ToArray(); var sb = new StringBuilder(); sb.AppendLine("The Unity Asset Store policy requires that all third-party"); sb.AppendLine("licenses be contained in a single LICENSES files."); sb.AppendLine("This file is auto-generated for this purpose."); sb.AppendLine(); sb.AppendLine("However, you can find a more readable version of each product's"); sb.AppendLine("acknowledgements in its About window, found in the Tools menu."); sb.AppendLine(); sb.AppendLine("Acknowledgements below:"); foreach (var acknowledgement in acknowledgements) { sb.AppendLine(" - " + acknowledgement.title); } foreach (var acknowledgement in acknowledgements) { sb.AppendLine(); sb.AppendLine("============================="); sb.AppendLine(); sb.AppendLine(acknowledgement.title); var hasAuthor = !StringUtility.IsNullOrWhiteSpace(acknowledgement.author); var hasCopyright = acknowledgement.copyrightYear != null; if (hasAuthor && hasCopyright) { sb.AppendLine($"Copyright \u00a9 {acknowledgement.copyrightYear} {acknowledgement.author}"); } else if (hasAuthor) { sb.AppendLine($"Author: {acknowledgement.author}"); } else if (hasCopyright) { sb.AppendLine($"Copyright \u00a9 {acknowledgement.copyrightYear}"); } if (!StringUtility.IsNullOrWhiteSpace(acknowledgement.url)) { sb.AppendLine(acknowledgement.url); } if (!StringUtility.IsNullOrWhiteSpace(acknowledgement.licenseName)) { sb.AppendLine("License: " + acknowledgement.licenseName.Trim()); } if (!StringUtility.IsNullOrWhiteSpace(acknowledgement.licenseText)) { var licenseText = string.Join("\n\n", acknowledgement.licenseText.Split(new[] { "\r\n\r\n", "\n\n" }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Replace("\r\n", "").Replace("\n", "")).ToArray()); sb.AppendLine(); sb.AppendLine(licenseText); } } if (path == null) { path = EditorUtility.SaveFilePanelInProject("License File", "LICENSES", "txt", null); } if (path != null) { File.WriteAllText(path, sb.ToString()); AssetDatabase.Refresh(); } }