Skip to content

Commit

Permalink
case-insensitive comparison of comment tags
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Aug 18, 2024
1 parent 725492d commit 424f69a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@
<value>2</value>
</data>
<data name="analyzeTab.Text" xml:space="preserve">
<value>Analyze</value>
<value>Find Duplicates</value>
</data>
<data name="&gt;&gt;analyzeTab.Name" xml:space="preserve">
<value>analyzeTab</value>
Expand Down
2 changes: 1 addition & 1 deletion Panels/AnalyzeControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void AnalyzeOnClick(object sender, EventArgs e)
Comment = d.Element("comment")?.Value
})
.Where(a => string.IsNullOrWhiteSpace(a.Comment) ||
!(a.Comment.Contains("SKIP") || a.Comment.Contains("NODUP")))
!(a.Comment.ContainsICIC("SKIP") || a.Comment.ContainsICIC("NODUP")))
.Select(d => d.Data);

Log($"Resx contains {data.Count()} strings" + NL);
Expand Down
14 changes: 7 additions & 7 deletions ResxProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static List<XElement> CollectStrings(XElement root)
// TODO: what is this for?
e.Attribute("name")?.Value.StartsWith(">>") != true &&
// SKIP is a special flag indicating this entry should not be translated
e.Element("comment")?.Value.Contains("SKIP") != true)
e.Element("comment")?.Value.ContainsICIC("SKIP") != true)
.ToList();
}

Expand All @@ -59,7 +59,7 @@ public static List<XElement> CollectNewStrings(List<XElement> data, string path)
d.Attribute("type") == null &&
(
// collect all edited entries
d.Element("comment")?.Value.Contains("EDIT") == true ||
d.Element("comment")?.Value.ContainsICIC("EDIT") == true ||
// collect entries that don't exist in target
!target.Elements("data")
.Any(e => e.Attribute("name")?.Value == d.Attribute("name").Value)
Expand All @@ -84,8 +84,8 @@ public static List<XElement> CollectNewStrings(List<XElement> data, string path)
public static int MergeHints(XElement root, XElement hints)
{
var count = 0;
foreach (var hint in hints.Elements())
{
foreach (var hint in hints.Elements())
{
var preferred = hint.Element("preferred").Value.Trim();

var element = root.Elements("data").FirstOrDefault(e =>
Expand All @@ -102,7 +102,7 @@ public static int MergeHints(XElement root, XElement hints)
}
}

return count;
return count;
}


Expand Down Expand Up @@ -131,8 +131,8 @@ public static void SortData(XElement root)
var files = data
.Where(e => e.Attribute("type") != null)
.Select(e => new { Element = e, Values = e.Element("value").Value.Split(';') })
.OrderBy(e => e.Values[1]) // type
.ThenBy(e => e.Values[0]) // path
.OrderBy(e => e.Values[1]) // type
.ThenBy(e => e.Values[0]) // path
.ThenBy(e => e.Element.Attribute("name").Value)
.Select(e => e.Element)
.ToList();
Expand Down
21 changes: 20 additions & 1 deletion StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//************************************************************************************************
// Copyright © 2020 Steven M Cohn. All rights reserved.
// Copyright © 2020 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace ResxTranslator
{
using System;
using System.Text;


Expand All @@ -24,6 +25,24 @@ internal static class StringExtensions
private static readonly char[] EscapeChars = new char[] { '<', '>', '&' };


/// <summary>
/// Compares a string against the given instance, as non-case-sensitive.
/// </summary>
/// <param name="s">The string instance</param>
/// <param name="value">The other string for comparison</param>
/// <returns>True if the instance contains at least one occurance of value</returns>
public static bool ContainsICIC(this string s, string value)
{
return s.IndexOf(value, StringComparison.InvariantCultureIgnoreCase) >= 0;
}


/// <summary>
/// Escapes special XML characters in the given text values so those characters
/// survive round-trips as user-input text
/// </summary>
/// <param name="str">The user input string</param>
/// <returns>The user string with special XML characters escaped</returns>
public static string XmlEscape(this string str)
{
if (str == null)
Expand Down
4 changes: 2 additions & 2 deletions Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public async Task<bool> TranslateResx(
continue;
}

var editing = data[index].Element("comment")?.Value.Contains("EDIT") == true;
var editing = data[index].Element("comment")?.Value.ContainsICIC("EDIT") == true;

var name = editing
? $"{data[index].Attribute("name").Value} (EDITED)"
Expand Down Expand Up @@ -478,7 +478,7 @@ public static int ClearMarkers(string path)
{
var root = XElement.Load(path);
var comments = root.Elements("data").Elements("comment")
.Where(e => e.Value.Contains("EDIT"));
.Where(e => e.Value.ContainsICIC("EDIT"));

if (comments.Any())
{
Expand Down

0 comments on commit 424f69a

Please sign in to comment.