diff options
| author | Cliff Click <cliffc@acm.org> | 2026-11-15 16:11:39 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-15 16:11:39 -0800 |
| commit | 9fe7c6f9697b5bbf3041261fdc60040e75cc674f (patch) | |
| tree | d92a8ff20ed984938d90ad8917b4d67fba9fb745 /chapter32/docs/examples/Capitalize.smp | |
| parent | f0a6c6757a795b8e186de0076836a87acef59fa7 (diff) | |
| download | Simple-9fe7c6f9697b5bbf3041261fdc60040e75cc674f.tar.gz Simple-9fe7c6f9697b5bbf3041261fdc60040e75cc674f.zip | |
Split off chapter 31ch32
Ch 32 will be focused on compiler performance issues.
Diffstat (limited to 'chapter32/docs/examples/Capitalize.smp')
| -rw-r--r-- | chapter32/docs/examples/Capitalize.smp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/chapter32/docs/examples/Capitalize.smp b/chapter32/docs/examples/Capitalize.smp new file mode 100644 index 00000000..00fdd481 --- /dev/null +++ b/chapter32/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; +}; |
