scratch – Diff between revs 75 and 125

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 75 Rev 125
Line 35... Line 35...
35 # @param [String] _char The character to use for trimming (default: '\\s') 35 # @param [String] _char The character to use for trimming (default: '\\s')
36 # 36 #
37 # @return [String] A trimmed string 37 # @return [String] A trimmed string
38 # 38 #
39 @trim: (str, _char = '\\s') -> 39 @trim: (str, _char = '\\s') ->
40 return str.trim() -  
41 regexLeft = @REGEX_LEFT_TRIM_BY_CHAR[_char] 40 regexLeft = @REGEX_LEFT_TRIM_BY_CHAR[_char]
42 unless regexLeft? 41 unless regexLeft?
43 @REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp '^'+_char+''+_char+'*' 42 @REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp '^'+_char+''+_char+'*'
44 regexLeft.lastIndex = 0 43 regexLeft.lastIndex = 0
45 regexRight = @REGEX_RIGHT_TRIM_BY_CHAR[_char] 44 regexRight = @REGEX_RIGHT_TRIM_BY_CHAR[_char]
Line 77... Line 76...
77 @REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp _char+''+_char+'*$' 76 @REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp _char+''+_char+'*$'
78 regexRight.lastIndex = 0 77 regexRight.lastIndex = 0
79 return str.replace(regexRight, '') 78 return str.replace(regexRight, '')
Line 80... Line 79...
80   79  
81   80  
82 # Checks if the given value is empty (null, undefined, empty string, string '0') 81 # Checks if the given value is empty (null, undefined, empty string, string '0', empty Array, empty Object)
83 # 82 #
84 # @param [Object] value The value to check 83 # @param [Object] value The value to check
85 # 84 #
86 # @return [Boolean] true if the value is empty 85 # @return [Boolean] true if the value is empty
87 # 86 #
Line -... Line 87...
-   87 @isEmpty: (value) ->
-   88 return not(value) or value is '' or value is '0' or (value instanceof Array and value.length is 0) or @isEmptyObject(value)
-   89  
-   90 # Checks if the given value is an empty object
-   91 #
-   92 # @param [Object] value The value to check
-   93 #
-   94 # @return [Boolean] true if the value is empty and is an object
Line 88... Line 95...
88 @isEmpty: (value) -> 95 #
89 return not(value) or value is '' or value is '0' or (value instanceof Array and value.length is 0) 96 @isEmptyObject: (value) ->
90   97 return value instanceof Object and (k for own k of value).length is 0
91   98  
Line 98... Line 105...
98 # 105 #
99 # @return [Integer] The number of occurences 106 # @return [Integer] The number of occurences
100 # 107 #
101 @subStrCount: (string, subString, start, length) -> 108 @subStrCount: (string, subString, start, length) ->
102 c = 0 109 c = 0
103 110  
104 string = '' + string 111 string = '' + string
105 subString = '' + subString 112 subString = '' + subString
106 113  
107 if start? 114 if start?
108 string = string[start..] 115 string = string[start..]
109 if length? 116 if length?
110 string = string[0...length] 117 string = string[0...length]
111 118  
112 len = string.length 119 len = string.length
113 sublen = subString.length 120 sublen = subString.length
114 for i in [0...len] 121 for i in [0...len]
115 if subString is string[i...sublen] 122 if subString is string[i...sublen]
116 c++ 123 c++
117 i += sublen - 1 124 i += sublen - 1
118 125  
119 return c 126 return c
Line 120... Line 127...
120   127  
121   128  
Line 256... Line 263...
256 tz_offset *= -1 263 tz_offset *= -1
Line 257... Line 264...
257   264  
258 # Compute date 265 # Compute date
259 date = new Date Date.UTC(year, month, day, hour, minute, second, fraction) 266 date = new Date Date.UTC(year, month, day, hour, minute, second, fraction)
260 if tz_offset 267 if tz_offset
Line 261... Line 268...
261 date.setTime date.getTime() + tz_offset 268 date.setTime date.getTime() - tz_offset
Line 262... Line 269...
262   269  
Line 306... Line 313...
306 callback(xhr.responseText) 313 callback(xhr.responseText)
307 else 314 else
308 callback(null) 315 callback(null)
309 xhr.open 'GET', path, true 316 xhr.open 'GET', path, true
310 xhr.send null 317 xhr.send null
311 318  
312 else 319 else
313 # Sync 320 # Sync
314 xhr.open 'GET', path, false 321 xhr.open 'GET', path, false
315 xhr.send null 322 xhr.send null