mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
samples: add Hello/Demo samples for most BRUTAL packages
Add samples/, a collection of single-file .NET 10 apps run with `dotnet run <file>.cs`. Hello/ has one minimal sample per package that has a public API, many of them headless; Demo/ has fuller programs that combine packages into a more interesting application. samples/README.md indexes every sample and covers the layout, error handling and per-OS requirements.
This commit is contained in:
parent
a25cdf80b2
commit
b0c9fd9cdc
1 changed files with 4599 additions and 1 deletions
25
samples/Hello/HelloStrings.cs
Normal file
25
samples/Hello/HelloStrings.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* HelloStrings
|
||||
*
|
||||
* Works with UTF-8 text using String8 and StringBuilder<byte>, which are designed to avoid
|
||||
* allocations.
|
||||
*/
|
||||
|
||||
#:package Ahwoo.Brutal.Strings@2026.10.1
|
||||
|
||||
using Brutal.Strings;
|
||||
|
||||
var greeting = new String8("Hello, café!");
|
||||
|
||||
Console.WriteLine($"Text: {greeting.ToString16()}");
|
||||
Console.WriteLine($"UTF-8 bytes: {greeting.Length}, code points: {Unicode.GetRuneCount(greeting.AsSpan())}");
|
||||
Console.WriteLine($"Starts with \"Hello\": {greeting.StartsWith("Hello"u8)}");
|
||||
|
||||
// A StringBuilder that writes UTF-8 bytes directly.
|
||||
var builder = new StringBuilder<byte>();
|
||||
builder.Append($"Pi is roughly {Math.PI:F3}");
|
||||
builder.AppendLine();
|
||||
builder.Append("Built as UTF-8"u8);
|
||||
|
||||
Console.WriteLine(builder.ToString());
|
||||
Console.WriteLine($"Builder holds {builder.WrittenSpan.Length} UTF-8 bytes");
|
||||
Loading…
Reference in a new issue