Skip to content

Commit

Permalink
Merge pull request #241 from sillsdev/minor-code-improvements
Browse files Browse the repository at this point in the history
Miscellaneous code cleanup
  • Loading branch information
JohnThomson authored Jul 15, 2022
2 parents 4e031b3 + 17e63d2 commit 0dbe281
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 55 deletions.
4 changes: 4 additions & 0 deletions HearThis.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LCS/@EntryIndexedValue">LCS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MVP/@EntryIndexedValue">MVP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Addl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Analytics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Charis/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Colossians/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -15,15 +16,18 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=glyssenscript/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Glyssen_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=graphemes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ignorees/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=kludgy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=localizers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Margetts/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=megavoice/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=multivoice/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Palaso/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Paratext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Paratext_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scriptio/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=selah/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=shntool/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undelete/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undeleted/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unrecordable/@EntryIndexedValue">True</s:Boolean>
Expand Down
9 changes: 4 additions & 5 deletions src/HearThis/Publishing/ClipRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public static void PublishAllBooks(PublishingModel publishingModel, string proje
var bookNames = new List<string>(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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/HearThis/Publishing/PublishingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using L10NSharp;
using SIL.Progress;
using SIL.Reporting;
using static System.String;

namespace HearThis.Publishing
{
Expand Down Expand Up @@ -61,7 +62,7 @@ internal bool PublishOnlyCurrentBook

public string AudioFormat
{
get { return _audioFormat; }
get => _audioFormat;
set
{
if (PublishingMethod != null)
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/HearThis/Script/ParatextProjectProxy.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// --------------------------------------------------------------------------------------------
#region // Copyright (c) 2020, SIL International. All Rights Reserved.
// <copyright from='2015' to='2020' company='SIL International'>
// Copyright (c) 2020, SIL International. All Rights Reserved.
#region // Copyright (c) 2022, SIL International. All Rights Reserved.
// <copyright from='2015' to='2022' company='SIL International'>
// Copyright (c) 2022, SIL International. All Rights Reserved.
//
// Distributable under the terms of the MIT License (https://sil.mit-license.org/)
// </copyright>
Expand Down
38 changes: 8 additions & 30 deletions src/HearThis/Script/ParatextScriptProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class ParatextScriptProvider : ScriptProviderBase, IScrProjectSettingsPro
private readonly IScripture _paratextProject;
private readonly Dictionary<int, Dictionary<int, List<ScriptLine>>> _script; // book <chapter, lines>
private readonly Dictionary<int, int[]> _chapterVerseCount; //book <chapter, verseCount>
private const char kSpace = ' ';
private HashSet<string> _allEncounteredParagraphStyleNames; // This will not include the ones that are always ignored.
private IBibleStats _versificationInfo;
private readonly HashSet<string> _allEncounteredParagraphStyleNames; // This will not include the ones that are always ignored.
private readonly IBibleStats _versificationInfo;

/// <summary>
/// These are markers that ARE paragraph and IsPublishable, but we don't want to read them.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -426,15 +416,9 @@ private void LoadBookData(int bookNumber0Based, Dictionary<int, List<ScriptLine>
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<string> AllEncounteredParagraphStyleNames
{
Expand All @@ -445,15 +429,9 @@ public override IEnumerable<string> 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)
Expand Down
30 changes: 15 additions & 15 deletions src/HearThisTests/SentenceClauseSplitterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<<This is fine. This is nice. This is good,>> said Fred.").ToList();
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 0dbe281

Please sign in to comment.