|
1 |
| -// Copyright (c) 2003-2018 SIL International |
| 1 | +// Copyright (c) 2003-2022 SIL International |
2 | 2 | // This software is licensed under the LGPL, version 2.1 or later
|
3 | 3 | // (http://www.gnu.org/licenses/lgpl-2.1.html)
|
4 | 4 |
|
5 | 5 | using System;
|
6 | 6 | using System.Collections;
|
7 | 7 | using System.Collections.Generic;
|
8 | 8 | using System.Diagnostics;
|
| 9 | +using System.Linq; |
| 10 | +using System.Text; |
| 11 | +using System.Text.RegularExpressions; |
9 | 12 | using Icu;
|
10 | 13 | using SIL.LCModel.Core.KernelInterfaces;
|
11 | 14 | using SIL.LCModel.Core.Scripture;
|
@@ -2117,25 +2120,78 @@ public override ITsString Reference(ISegment seg, int ich)
|
2117 | 2120 | {
|
2118 | 2121 | var stText = Owner as IStText;
|
2119 | 2122 | if (stText == null)
|
2120 |
| - return Cache.MakeUserTss("unknown"); // should never happen, I think? |
| 2123 | + return Cache.MakeUserTss(Strings.ksStars); // should never happen, I think? |
2121 | 2124 | if (stText.OwningFlid == ScrSectionTags.kflidContent)
|
2122 | 2125 | {
|
2123 | 2126 | // Body of Scripture. Figure a book/chapter/verse
|
2124 | 2127 | IScrBook book = (IScrBook) stText.Owner.Owner;
|
2125 | 2128 | string mainRef = ScriptureServices.FullScrRef(this, ich, book.BestUIAbbrev).Trim();
|
2126 | 2129 | return Cache.MakeUserTss(mainRef + ScriptureServices.VerseSegLabel(this, SegmentsOS.IndexOf(seg)));
|
2127 | 2130 | }
|
2128 |
| - if (stText.OwningFlid == ScrSectionTags.kflidHeading) |
| 2131 | + //if (stText.OwningFlid == ScrSectionTags.kflidHeading) |
| 2132 | + //{ |
| 2133 | + // // use the section title without qualifiers. |
| 2134 | + // return stText.Title.BestVernacularAnalysisAlternative; |
| 2135 | + //} |
| 2136 | + //if (stText.OwningFlid == ScrBookTags.kflidTitle) |
| 2137 | + //{ |
| 2138 | + // return stText.Title.BestVernacularAnalysisAlternative; |
| 2139 | + //} |
| 2140 | + return Cache.MakeUserTss(Strings.ksStars); // should never happen, I think? |
| 2141 | + } |
| 2142 | + |
| 2143 | + /// <inheritdoc/> |
| 2144 | + public override ITsString ReferenceForSorting(ISegment seg, int ich) |
| 2145 | + { |
| 2146 | + if (!(Owner is IStText stText)) |
2129 | 2147 | {
|
2130 |
| - // use the section title without qualifiers. |
2131 |
| - return stText.Title.BestVernacularAnalysisAlternative; |
| 2148 | + return Scripture.Name.NotFoundTss; |
| 2149 | + } |
| 2150 | + |
| 2151 | + // Use a prefix to make scripture references sort together when mixed with other references |
| 2152 | + // (Scripture is sorted canonically, but a comparer for mixed references would sort alphabetically) |
| 2153 | + var bldr = new StringBuilder(RefForSortingPrefix); |
| 2154 | + switch (stText.OwningFlid) |
| 2155 | + { |
| 2156 | + case ScrSectionTags.kflidContent: |
| 2157 | + var book = (IScrBook)stText.Owner.Owner; |
| 2158 | + // Append the book number to sort in canonical order. |
| 2159 | + bldr.Append(book.CanonicalNum); |
| 2160 | + // Append the book name. It makes no difference for sorting, but could make debugging easier. |
| 2161 | + bldr.Append("_").Append(book.BestUIAbbrev); |
| 2162 | + |
| 2163 | + var refSansBookBldr = new StringBuilder(ScriptureServices.FullScrRef(this, ich, string.Empty).Trim()); |
| 2164 | + var numbersInRef = new Regex(@"\d+").Matches(refSansBookBldr.ToString()); |
| 2165 | + foreach (var number in numbersInRef.Cast<Match>().Reverse()) |
| 2166 | + { |
| 2167 | + ZeroPadForStringComparison(refSansBookBldr, number.Index, number.Length); |
| 2168 | + } |
| 2169 | + bldr.Append(" ").Append(refSansBookBldr).Append(ScriptureServices.VerseSegLabel(this, SegmentsOS.IndexOf(seg))); |
| 2170 | + |
| 2171 | + // add ich |
| 2172 | + bldr.Append(" ").Append(ZeroPadForStringComparison(ich)); |
| 2173 | + return Cache.MakeUserTss(bldr.ToString()); |
2132 | 2174 | }
|
2133 |
| - if (stText.OwningFlid == ScrBookTags.kflidTitle) |
| 2175 | + return Cache.MakeUserTss(Strings.ksStars); |
| 2176 | + } |
| 2177 | + |
| 2178 | + protected internal const string RefForSortingPrefix = "0 Scr "; |
| 2179 | + |
| 2180 | + protected internal static void ZeroPadForStringComparison(StringBuilder bldr, int index, int cExistingDigits) |
| 2181 | + { |
| 2182 | + for (var remaining = 5 - cExistingDigits; remaining > 0; remaining--) |
2134 | 2183 | {
|
2135 |
| - return stText.Title.BestVernacularAnalysisAlternative; |
| 2184 | + bldr.Insert(index, "0"); |
2136 | 2185 | }
|
2137 |
| - return Cache.MakeUserTss("unknown"); // should never happen, I think? |
2138 | 2186 | }
|
| 2187 | + |
| 2188 | + protected internal static string ZeroPadForStringComparison(string intInRef) |
| 2189 | + { |
| 2190 | + var bldr = new StringBuilder(intInRef); |
| 2191 | + ZeroPadForStringComparison(bldr, 0, intInRef.Length); |
| 2192 | + return bldr.ToString(); |
| 2193 | + } |
| 2194 | + |
2139 | 2195 | /// ------------------------------------------------------------------------------------
|
2140 | 2196 | /// <summary>
|
2141 | 2197 | /// Gets the footnote sequence.
|
|
0 commit comments