From 22ce7472f3d717eb812bfe5b577864b649c5121a Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 27 Apr 2025 13:38:29 +0200 Subject: [PATCH] Refactor FindAllTextTags method to support multiple start tags and improve tag detection logic --- app/Build/Commands/CollectI18NKeysCommand.cs | 34 +++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/app/Build/Commands/CollectI18NKeysCommand.cs b/app/Build/Commands/CollectI18NKeysCommand.cs index f7a533f9..3108a488 100644 --- a/app/Build/Commands/CollectI18NKeysCommand.cs +++ b/app/Build/Commands/CollectI18NKeysCommand.cs @@ -133,24 +133,48 @@ public sealed partial class CollectI18NKeysCommand private List FindAllTextTags(ReadOnlySpan fileContent) { - const string START_TAG = """ + const string START_TAG1 = """ T(" """; + const string START_TAG2 = """ + TB(" + """; + const string END_TAG = """ ") """; + (int Index, int Len) FindNextStart(ReadOnlySpan content) + { + var startIdx1 = content.IndexOf(START_TAG1); + var startIdx2 = content.IndexOf(START_TAG2); + + if (startIdx1 == -1 && startIdx2 == -1) + return (-1, 0); + + if (startIdx1 == -1) + return (startIdx2, START_TAG2.Length); + + if (startIdx2 == -1) + return (startIdx1, START_TAG1.Length); + + if (startIdx1 < startIdx2) + return (startIdx1, START_TAG1.Length); + + return (startIdx2, START_TAG2.Length); + } + var matches = new List(); - var startIdx = fileContent.IndexOf(START_TAG); + var startIdx = FindNextStart(fileContent); var content = fileContent; - while (startIdx > -1) + while (startIdx.Index > -1) { // // In some cases, after the initial " there follow more " characters. // We need to skip them: // - content = content[(startIdx + START_TAG.Length)..]; + content = content[(startIdx.Index + startIdx.Len)..]; while(content[0] == '"') content = content[1..]; @@ -163,7 +187,7 @@ public sealed partial class CollectI18NKeysCommand match = match[..^1]; matches.Add(match.ToString()); - startIdx = content.IndexOf(START_TAG); + startIdx = FindNextStart(content); } return matches;