Progmasoft Git

tazel

A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.

Clonegit clone https://git.progmasoft.com/tazel

refactor(cadre-celeste): move verbatim token copying out of StepNormalize

Motivation: Codacy (Lizard) measured a cyclomatic complexity of 12 for
AbiFingerprint.StepNormalize after the raw-string, digit-separator and
header-name cases were added; the limit is 10.

Changes: the three verbatim cases and the plain string/character literal
move into TryCopyVerbatim, which returns whether it copied a token.
Behavior is unchanged.

Verification: Release build with warnings as errors (0 errors); full suite
757 passed, 1 skipped; dotnet format --verify-no-changes.
Commit
1640cfe70d6ba37be9cf18b57fd5b9828e88b65b
Author
Leitwolf11 ·
Parents
18825fb2f8ce

Files · Download .tar.gz

Changes

 .../AbiFingerprint.cs                              | 26 +++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs b/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs
index a42cb78..03ca037 100644
--- a/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs
+++ b/src/Progmasoft.Tazel.CadreCeleste/AbiFingerprint.cs
@@ -85,26 +85,42 @@ public static class AbiFingerprint
             pendingSpace = false;
         }
 
+        if (TryCopyVerbatim(source, ref i, sb))
+        {
+            return i;
+        }
+
+        sb.Append(ch);
+        return i + 1;
+    }
+
+    /// <summary>
+    /// Copies, unchanged, a token whose text is never a comment and whose spacing matters: a raw string, a header name
+    /// of an include line, or a string or character literal. Returns false when the character at
+    /// <paramref name="i"/> starts none of them.
+    /// </summary>
+    private static bool TryCopyVerbatim(string source, ref int i, StringBuilder sb)
+    {
+        var ch = source[i];
         if (ch == '"' && IsRawStringStart(source, i))
         {
             CopyRawStringLiteral(source, ref i, sb);
-            return i;
+            return true;
         }
 
         if (ch == '<' && IsIncludeLine(sb))
         {
             CopyHeaderName(source, ref i, sb);
-            return i;
+            return true;
         }
 
         if (ch == '"' || (ch == '\'' && !IsDigitSeparator(source, i)))
         {
             CopyQuotedLiteral(source, ref i, ch, sb);
-            return i;
+            return true;
         }
 
-        sb.Append(ch);
-        return i + 1;
+        return false;
     }
 
     /// <summary>