LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package template | 5 package template |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 return arg0 | 251 return arg0 |
252 } | 252 } |
253 | 253 |
254 // not returns the Boolean negation of its argument. | 254 // not returns the Boolean negation of its argument. |
255 func not(arg interface{}) (truth bool) { | 255 func not(arg interface{}) (truth bool) { |
256 truth, _ = isTrue(reflect.ValueOf(arg)) | 256 truth, _ = isTrue(reflect.ValueOf(arg)) |
257 return !truth | 257 return !truth |
258 } | 258 } |
259 | 259 |
260 // Comparison. | 260 // Comparison. |
| 261 |
| 262 // TODO: Perhaps allow comparison between signed and unsigned integers. |
261 | 263 |
262 var ( | 264 var ( |
263 errBadComparisonType = errors.New("invalid type for comparison") | 265 errBadComparisonType = errors.New("invalid type for comparison") |
264 errBadComparison = errors.New("incompatible types for comparison") | 266 errBadComparison = errors.New("incompatible types for comparison") |
265 ) | 267 ) |
266 | 268 |
267 type kind int | 269 type kind int |
268 | 270 |
269 const ( | 271 const ( |
270 invalidKind kind = iota | 272 invalidKind kind = iota |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // ne evaluates the comparison a != b. | 335 // ne evaluates the comparison a != b. |
334 func ne(arg1, arg2 interface{}) (bool, error) { | 336 func ne(arg1, arg2 interface{}) (bool, error) { |
335 // != is the inverse of ==. | 337 // != is the inverse of ==. |
336 equal, err := eq(arg1, arg2) | 338 equal, err := eq(arg1, arg2) |
337 return !equal, err | 339 return !equal, err |
338 } | 340 } |
339 | 341 |
340 // lt evaluates the comparison a < b. | 342 // lt evaluates the comparison a < b. |
341 func lt(arg1, arg2 interface{}) (bool, error) { | 343 func lt(arg1, arg2 interface{}) (bool, error) { |
342 v1 := reflect.ValueOf(arg1) | 344 v1 := reflect.ValueOf(arg1) |
343 v2 := reflect.ValueOf(arg2) | |
344 k1, err := basicKind(v1) | 345 k1, err := basicKind(v1) |
345 if err != nil { | 346 if err != nil { |
346 return false, err | 347 return false, err |
347 } | 348 } |
| 349 v2 := reflect.ValueOf(arg2) |
348 k2, err := basicKind(v2) | 350 k2, err := basicKind(v2) |
349 if err != nil { | 351 if err != nil { |
350 return false, err | 352 return false, err |
351 } | 353 } |
352 if k1 != k2 { | 354 if k1 != k2 { |
353 return false, errBadComparison | 355 return false, errBadComparison |
354 } | 356 } |
355 truth := false | 357 truth := false |
356 switch k1 { | 358 switch k1 { |
357 case boolKind, complexKind: | 359 case boolKind, complexKind: |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 func URLQueryEscaper(args ...interface{}) string { | 561 func URLQueryEscaper(args ...interface{}) string { |
560 s, ok := "", false | 562 s, ok := "", false |
561 if len(args) == 1 { | 563 if len(args) == 1 { |
562 s, ok = args[0].(string) | 564 s, ok = args[0].(string) |
563 } | 565 } |
564 if !ok { | 566 if !ok { |
565 s = fmt.Sprint(args...) | 567 s = fmt.Sprint(args...) |
566 } | 568 } |
567 return url.QueryEscape(s) | 569 return url.QueryEscape(s) |
568 } | 570 } |
LEFT | RIGHT |