Show
Ignore:
Timestamp:
08/19/08 05:43:00 (5 months ago)
Author:
Chuck.Esterbrook
Message:

Code cleanup.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/Utils.cobra

    r1583 r1584  
    99extend String 
    1010 
     11/# 
     12        CC: parser error, this won''t fly: 
    1113        def capped as String 
    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:] 
    1449 
    1550class Utils 
     
    2863 
    2964                def normalizePath(path as String) as String 
    30                         # TODO: this needs cleanup 
    31                         while path.startsWith('.\\') 
    32                                 path = path.substring(2) 
    33                         while path.startsWith('./') 
    34                                 path = path.substring(2) 
     65                        while path.startsWith('.\\'), path = path[2:] 
     66                        while path.startsWith('./'), path = path[2:] 
    3567                        return path 
    3668 
     
    4880                        # Could be made more sophisitcated in the future 
    4981                        return name + 's' 
    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:] 
    7082 
    7183                def isCapped(s as String) as bool