diff options
| author | Cliff Click <cliffc@acm.org> | 2026-11-08 14:20:21 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-12 13:48:30 -0800 |
| commit | 6fb3aac50c642ed73ec78e9ceb6e04b127796abb (patch) | |
| tree | b0f3df12b85add20a34cfe839bdfdba272237d9a /chapter31/docs/examples/Capitalize.smp | |
| parent | 394f0aba21eb7a73a00014b3ffcf2ad21eeb8e21 (diff) | |
| download | Simple-6fb3aac50c642ed73ec78e9ceb6e04b127796abb.tar.gz Simple-6fb3aac50c642ed73ec78e9ceb6e04b127796abb.zip | |
Start Chapter 31 from the completed Chapter 30 compiler
Diffstat (limited to 'chapter31/docs/examples/Capitalize.smp')
| -rw-r--r-- | chapter31/docs/examples/Capitalize.smp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/chapter31/docs/examples/Capitalize.smp b/chapter31/docs/examples/Capitalize.smp new file mode 100644 index 00000000..00fdd481 --- /dev/null +++ b/chapter31/docs/examples/Capitalize.smp @@ -0,0 +1,23 @@ + +// An implementation of +// https://sampleprograms.io/projects/capitalize/ + +val main = { u8[~][] args -> + if( args# > 2 ) { + sys.io.p("Use quotes around multiple strings.\n"); + return 0; + } + if( args# != 2 || args[1]# == 0 ) { + sys.io.p("Usage: please provide a string\n"); + return 0; + } + + u8[~] input = args[1]; + var output = new u8[input# + 1]; + u32 len = input#; + sys.ary.copy(output,0,input,0,len); + output[0] = sys.char.toupper(input[0]); + output[input#] = '\n'; + sys.io.p(output); + return 0; +}; |
