< Summary

Information
Class: LeetCode.Algorithms.GenerateTagForVideoCaption.GenerateTagForVideoCaptionStringBuilder
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\GenerateTagForVideoCaption\GenerateTagForVideoCaptionStringBuilder.cs
Line coverage
80%
Covered lines: 25
Uncovered lines: 6
Coverable lines: 31
Total lines: 72
Line coverage: 80.6%
Branch coverage
78%
Covered branches: 11
Total branches: 14
Branch coverage: 78.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GenerateTag(...)78.57%151480.64%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\GenerateTagForVideoCaption\GenerateTagForVideoCaptionStringBuilder.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12using System.Text;
 13
 14namespace LeetCode.Algorithms.GenerateTagForVideoCaption;
 15
 16/// <inheritdoc />
 17public class GenerateTagForVideoCaptionStringBuilder : IGenerateTagForVideoCaption
 18{
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(n)
 22    /// </summary>
 23    /// <param name="caption"></param>
 24    /// <returns></returns>
 25    public string GenerateTag(string caption)
 326    {
 327        if (string.IsNullOrWhiteSpace(caption))
 028        {
 029            return "#";
 30        }
 31
 332        var words = caption.Split(' ', StringSplitOptions.RemoveEmptyEntries);
 33
 334        var tagStringBuilder = new StringBuilder(100, 100);
 35
 336        tagStringBuilder.Append('#');
 37
 338        var firstWord = words[0].ToLowerInvariant();
 39
 23040        foreach (var c in firstWord)
 11141        {
 11142            if (tagStringBuilder.Length == 100)
 143            {
 144                return tagStringBuilder.ToString();
 45            }
 46
 11047            tagStringBuilder.Append(c);
 11048        }
 49
 1650        for (var i = 1; i < words.Length; i++)
 651        {
 652            if (tagStringBuilder.Length == 100)
 053            {
 054                break;
 55            }
 56
 657            tagStringBuilder.Append(char.ToUpperInvariant(words[i][0]));
 58
 5459            for (var j = 1; j < words[i].Length; j++)
 2160            {
 2161                if (tagStringBuilder.Length == 100)
 062                {
 063                    break;
 64                }
 65
 2166                tagStringBuilder.Append(char.ToLowerInvariant(words[i][j]));
 2167            }
 668        }
 69
 270        return tagStringBuilder.ToString();
 371    }
 72}

Methods/Properties

GenerateTag(System.String)