| 12 | | return Utils.capped(this) |
| 13 | | |
| | 14 | """ |
| | 15 | Returns the string with the first character capitalized. |
| | 16 | Returns a blank string for a blank string. |
| | 17 | """ |
| | 18 | # CC: contracts on extension methods |
| | 19 | # ensure |
| | 20 | # result.length == .length |
| | 21 | # result.length implies result[0] == result[0].toUpper |
| | 22 | test |
| | 23 | assert 'chuck'.capped == 'Chuck' |
| | 24 | assert 'Chuck'.capped == 'Chuck' |
| | 25 | assert ''.capped == '' |
| | 26 | assert ' foo'.capped == ' foo' |
| | 27 | assert 'f'.capped == 'F' |
| | 28 | assert '1aoeu'.capped == '1aoeu' |
| | 29 | body |
| | 30 | if .length == 0, return this |
| | 31 | return this[0:1].toUpper + this[1:] |
| | 32 | #/ |
| | 33 | |
| | 34 | def capped as String |
| | 35 | """ |
| | 36 | Returns the string with the first character capitalized. |
| | 37 | Returns a blank string for a blank string. |
| | 38 | """ |
| | 39 | test |
| | 40 | assert 'chuck'.capped == 'Chuck' |
| | 41 | assert 'Chuck'.capped == 'Chuck' |
| | 42 | assert ''.capped == '' |
| | 43 | assert ' foo'.capped == ' foo' |
| | 44 | assert 'f'.capped == 'F' |
| | 45 | assert '1aoeu'.capped == '1aoeu' |
| | 46 | body |
| | 47 | if .length == 0, return this |
| | 48 | return this[0:1].toUpper + this[1:] |
| 50 | | |
| 51 | | def capped(s as String) as String |
| 52 | | """ |
| 53 | | Returns the string with the first character capitalized. |
| 54 | | Returns a blank string for a blank string. |
| 55 | | """ |
| 56 | | ensure |
| 57 | | result.length == s.length |
| 58 | | result.length implies result[0] == result[0].toUpper |
| 59 | | test |
| 60 | | assert Utils.capped('chuck')=='Chuck' |
| 61 | | assert Utils.capped('Chuck')=='Chuck' |
| 62 | | assert Utils.capped('')=='' |
| 63 | | assert Utils.capped(' foo')==' foo' |
| 64 | | assert Utils.capped('f')=='F' |
| 65 | | assert Utils.capped('1aoeu')=='1aoeu' |
| 66 | | body |
| 67 | | if s.length==0 |
| 68 | | return s |
| 69 | | return s[0:1].toUpper + s[1:] |