Skip to content

Commit

Permalink
docs: Improve XML docs for NameGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmg committed Sep 3, 2024
1 parent 3c42305 commit 242ad1a
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/Moniker/NameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public static string Generate(MonikerStyle monikerStyle, string delimiter = Defa
/// </summary>
/// <param name="monikerStyle">The style of random name.</param>
/// <param name="adjective">The adjective part of the random name.</param>
/// <param name="noun">The adjective part of the random name.</param>
/// <returns>The generated random name.</returns>
/// <param name="noun">The noun part of the random name.</param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static void Generate(MonikerStyle monikerStyle, out Chars adjective, out Chars noun)
{
Expand All @@ -61,7 +60,8 @@ public static string GenerateMoniker(string delimiter = DefaultDelimiter)
/// <summary>
/// Generate a random name in the 'moniker' project style.
/// </summary>
/// <returns>The generated random name.</returns>
/// <param name="adjective">The adjective part of the random name.</param>
/// <param name="noun">The noun part of the random name.</param>
public static void GenerateMoniker(out Chars adjective, out Chars noun)
=> BuildNamePair(MonikerDescriptors.Strings, out adjective, MonikerAnimals.Strings, out noun);

Expand All @@ -77,22 +77,6 @@ public static string GenerateMoby(string delimiter = DefaultDelimiter)
return Join(adjective, delimiter, noun);
}

private static string Join(Chars adjective, ReadOnlySpan<char> delimiter, Chars noun)
{
var length = adjective.Length + delimiter.Length + noun.Length;
var chars = length <= 64 ? stackalloc char[length] : new char[length];

var writeCount = adjective.Write(chars);
Debug.Assert(writeCount == adjective.Length);

delimiter.CopyTo(chars[adjective.Length..]);

writeCount = noun.Write(chars[(adjective.Length + delimiter.Length)..]);
Debug.Assert(writeCount == noun.Length);

return new(chars);
}

/// <summary>
/// Generate a random name in the 'moby' project style.
/// </summary>
Expand Down Expand Up @@ -125,5 +109,21 @@ private static Chars GetRandomEntry(Utf8Strings entries)
var index = Random.Shared.Next(entries.Count);
return entries[index];
}

private static string Join(Chars adjective, ReadOnlySpan<char> delimiter, Chars noun)
{
var length = adjective.Length + delimiter.Length + noun.Length;
var chars = length <= 64 ? stackalloc char[length] : new char[length];

var writeCount = adjective.Write(chars);
Debug.Assert(writeCount == adjective.Length);

delimiter.CopyTo(chars[adjective.Length..]);

writeCount = noun.Write(chars[(adjective.Length + delimiter.Length)..]);
Debug.Assert(writeCount == noun.Length);

return new(chars);
}
}
}

0 comments on commit 242ad1a

Please sign in to comment.