From 17e63d2518174307dd60410349f7524063d124b4 Mon Sep 17 00:00:00 2001 From: tombogle Date: Fri, 15 Jul 2022 15:34:37 -0400 Subject: [PATCH] Miscellaneous code cleanup --- HearThis.sln.DotSettings | 4 ++ src/HearThis/Publishing/ClipRepository.cs | 9 ++--- src/HearThis/Publishing/PublishingModel.cs | 5 ++- src/HearThis/Script/ParatextProjectProxy.cs | 6 +-- src/HearThis/Script/ParatextScriptProvider.cs | 38 ++++--------------- .../SentenceClauseSplitterTests.cs | 30 +++++++-------- 6 files changed, 37 insertions(+), 55 deletions(-) diff --git a/HearThis.sln.DotSettings b/HearThis.sln.DotSettings index 1c49682f..98132c63 100644 --- a/HearThis.sln.DotSettings +++ b/HearThis.sln.DotSettings @@ -2,6 +2,7 @@ LCS MVP UI + True True True True @@ -15,8 +16,10 @@ True True True + True True True + True True True True @@ -24,6 +27,7 @@ True True True + True True True True diff --git a/src/HearThis/Publishing/ClipRepository.cs b/src/HearThis/Publishing/ClipRepository.cs index 6ac3f92a..27459ae1 100644 --- a/src/HearThis/Publishing/ClipRepository.cs +++ b/src/HearThis/Publishing/ClipRepository.cs @@ -712,7 +712,7 @@ public static void PublishAllBooks(PublishingModel publishingModel, string proje var bookNames = new List(Directory.GetDirectories(Program.GetApplicationDataFolder(projectName)).Select(GetFileName)); bookNames.Sort(publishingModel.PublishingInfoProvider.BookNameComparer); - foreach (string bookName in bookNames) + foreach (var bookName in bookNames) { if (progress.CancelRequested) return; @@ -765,8 +765,7 @@ private static void PublishSingleChapter(PublishingModel publishingModel, string clipFiles = clipFiles.OrderBy(name => { - int result; - if (TryParse(GetFileNameWithoutExtension(name), out result)) + if (TryParse(GetFileNameWithoutExtension(name), out var result)) return result; throw new Exception(Format(LocalizationManager.GetString("ClipRepository.UnexpectedWavFile", "Unexpected WAV file: {0}"), name)); }).ToArray(); @@ -944,7 +943,7 @@ internal static string GetCueSheetContents(string[] verseFiles, IPublishingInfoP for (int i = 0; i < verseFiles.Length; i++) { - bldr.AppendLine(Format(" TRACK {0:000} AUDIO", (i + 1))); + bldr.AppendLine($" TRACK {(i + 1):000} AUDIO"); // " TRACK 0" + (i + 1) + " AUDIO"); //else // " TRACK " + (i + 1) + " AUDIO"; @@ -1194,7 +1193,7 @@ private void UpdateSubPhrase() private void AppendLabel(double start, double end, string label) { - string timeRange = Format("{0:0.######}\t{1:0.######}\t", start, end); + string timeRange = $"{start:0.######}\t{end:0.######}\t"; bldr.AppendLine(timeRange + label + (subPhrase >= 0 ? ((char)('a' + subPhrase)).ToString() : Empty)); accumClipTimeFromPrevBlocks = 0.0; } diff --git a/src/HearThis/Publishing/PublishingModel.cs b/src/HearThis/Publishing/PublishingModel.cs index 5f697e4e..e2a580e7 100644 --- a/src/HearThis/Publishing/PublishingModel.cs +++ b/src/HearThis/Publishing/PublishingModel.cs @@ -16,6 +16,7 @@ using L10NSharp; using SIL.Progress; using SIL.Reporting; +using static System.String; namespace HearThis.Publishing { @@ -61,7 +62,7 @@ internal bool PublishOnlyCurrentBook public string AudioFormat { - get { return _audioFormat; } + get => _audioFormat; set { if (PublishingMethod != null) @@ -77,7 +78,7 @@ public string PublishRootPath { get { - if (string.IsNullOrEmpty(Settings.Default.PublishRootPath) || !Directory.Exists(Settings.Default.PublishRootPath)) + if (IsNullOrEmpty(Settings.Default.PublishRootPath) || !Directory.Exists(Settings.Default.PublishRootPath)) { PublishRootPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } diff --git a/src/HearThis/Script/ParatextProjectProxy.cs b/src/HearThis/Script/ParatextProjectProxy.cs index 93b46c89..500f438a 100644 --- a/src/HearThis/Script/ParatextProjectProxy.cs +++ b/src/HearThis/Script/ParatextProjectProxy.cs @@ -1,7 +1,7 @@ // -------------------------------------------------------------------------------------------- -#region // Copyright (c) 2020, SIL International. All Rights Reserved. -// -// Copyright (c) 2020, SIL International. All Rights Reserved. +#region // Copyright (c) 2022, SIL International. All Rights Reserved. +// +// Copyright (c) 2022, SIL International. All Rights Reserved. // // Distributable under the terms of the MIT License (https://sil.mit-license.org/) // diff --git a/src/HearThis/Script/ParatextScriptProvider.cs b/src/HearThis/Script/ParatextScriptProvider.cs index b394ff49..33447a5d 100644 --- a/src/HearThis/Script/ParatextScriptProvider.cs +++ b/src/HearThis/Script/ParatextScriptProvider.cs @@ -25,9 +25,8 @@ public class ParatextScriptProvider : ScriptProviderBase, IScrProjectSettingsPro private readonly IScripture _paratextProject; private readonly Dictionary>> _script; // book private readonly Dictionary _chapterVerseCount; //book - private const char kSpace = ' '; - private HashSet _allEncounteredParagraphStyleNames; // This will not include the ones that are always ignored. - private IBibleStats _versificationInfo; + private readonly HashSet _allEncounteredParagraphStyleNames; // This will not include the ones that are always ignored. + private readonly IBibleStats _versificationInfo; /// /// These are markers that ARE paragraph and IsPublishable, but we don't want to read them. @@ -62,18 +61,9 @@ public ParatextScriptProvider(IScripture paratextProject) }); } - public override string FontName - { - get - { - return _paratextProject.DefaultFont; - } - } + public override string FontName => _paratextProject.DefaultFont; - public override bool RightToLeft - { - get { return _paratextProject.RightToLeft; } - } + public override bool RightToLeft => _paratextProject.RightToLeft; public override string EthnologueCode => _paratextProject.EthnologueCode; @@ -426,15 +416,9 @@ private void LoadBookData(int bookNumber0Based, Dictionary PopulateSkippedFlag(bookNumber0Based, currentChapter1Based, chapterLines); } - public override string ProjectFolderName - { - get { return _paratextProject.Name; } - } + public override string ProjectFolderName => _paratextProject.Name; - public IScrProjectSettings ScrProjectSettings - { - get { return _paratextProject; } - } + public IScrProjectSettings ScrProjectSettings => _paratextProject; public override IEnumerable AllEncounteredParagraphStyleNames { @@ -445,15 +429,9 @@ public override IEnumerable AllEncounteredParagraphStyleNames } } - public override bool NestedQuotesEncountered - { - get { return _sentenceSplitter.NestedQuotesEncountered; } - } + public override bool NestedQuotesEncountered => _sentenceSplitter.NestedQuotesEncountered; - public override IBibleStats VersificationInfo - { - get { return _versificationInfo; } - } + public override IBibleStats VersificationInfo => _versificationInfo; private void EmitChapterString(ParatextParagraph paragraph, bool labelScopeIsBook, bool labelIsSupplied, bool characterIsSupplied, string chapLabel, string chapCharacter) diff --git a/src/HearThisTests/SentenceClauseSplitterTests.cs b/src/HearThisTests/SentenceClauseSplitterTests.cs index 89040b8e..d893a2e6 100644 --- a/src/HearThisTests/SentenceClauseSplitterTests.cs +++ b/src/HearThisTests/SentenceClauseSplitterTests.cs @@ -103,7 +103,7 @@ public void BreakIntoChunks_BreakSentencesWithMultiCharacterQuotationMarks_Yield } [Test] - public void BreakIntoChunks_MultisentenceQuotes_YieldsChunksForIndividualSentencesWithinQuotation() + public void BreakIntoChunks_MultiSentenceQuotes_YieldsChunksForIndividualSentencesWithinQuotation() { var splitter = new SentenceClauseSplitter(null, true, new ChevronQuotesProject()); var result = splitter.BreakIntoChunks("<> said Fred.").ToList(); @@ -142,23 +142,23 @@ public void BreakIntoChunks_SpeedTest() internal class CurlyQuotesProject : IScrProjectSettings { - public string FirstLevelStartQuotationMark { get { return "“"; } } - public string FirstLevelEndQuotationMark { get { return "”"; } } - public string SecondLevelStartQuotationMark { get { return "‘"; } } - public string SecondLevelEndQuotationMark { get { return "’"; } } - public string ThirdLevelStartQuotationMark { get { return "“"; } } - public string ThirdLevelEndQuotationMark { get { return "”"; } } - public bool FirstLevelQuotesAreUnique { get { return false; } } + public string FirstLevelStartQuotationMark => "“"; + public string FirstLevelEndQuotationMark => "”"; + public string SecondLevelStartQuotationMark => "‘"; + public string SecondLevelEndQuotationMark => "’"; + public string ThirdLevelStartQuotationMark => "“"; + public string ThirdLevelEndQuotationMark => "”"; + public bool FirstLevelQuotesAreUnique => false; } internal class ChevronQuotesProject : IScrProjectSettings { - public string FirstLevelStartQuotationMark { get { return "<<"; } } - public string FirstLevelEndQuotationMark { get { return ">>"; } } - public string SecondLevelStartQuotationMark { get { return "<"; } } - public string SecondLevelEndQuotationMark { get { return ">"; } } - public string ThirdLevelStartQuotationMark { get { return "<<"; } } - public string ThirdLevelEndQuotationMark { get { return ">>"; } } - public bool FirstLevelQuotesAreUnique { get { return false; } } + public string FirstLevelStartQuotationMark => "<<"; + public string FirstLevelEndQuotationMark => ">>"; + public string SecondLevelStartQuotationMark => "<"; + public string SecondLevelEndQuotationMark => ">"; + public string ThirdLevelStartQuotationMark => "<<"; + public string ThirdLevelEndQuotationMark => ">>"; + public bool FirstLevelQuotesAreUnique => false; } }