diff options
author | obscuren <geffobscura@gmail.com> | 2014-02-21 06:10:05 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-02-21 06:10:05 +0800 |
commit | 059ad352156b995aab9132aff9569c2e03c32b9b (patch) | |
tree | 8ac1275608075cadbfc02a1a35273c043ea2ee18 /ethutil | |
parent | 9bc5c4a0c5116cf3b49a55fc2aceb5f5c3b3e34d (diff) | |
download | dexon-059ad352156b995aab9132aff9569c2e03c32b9b.tar dexon-059ad352156b995aab9132aff9569c2e03c32b9b.tar.gz dexon-059ad352156b995aab9132aff9569c2e03c32b9b.tar.bz2 dexon-059ad352156b995aab9132aff9569c2e03c32b9b.tar.lz dexon-059ad352156b995aab9132aff9569c2e03c32b9b.tar.xz dexon-059ad352156b995aab9132aff9569c2e03c32b9b.tar.zst dexon-059ad352156b995aab9132aff9569c2e03c32b9b.zip |
Type checking
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/value.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/ethutil/value.go b/ethutil/value.go index d3a38f87f..03d23d559 100644 --- a/ethutil/value.go +++ b/ethutil/value.go @@ -36,7 +36,8 @@ func (val *Value) Len() int { if data, ok := val.Val.([]interface{}); ok { return len(data) } else if data, ok := val.Val.([]byte); ok { - // FIXME + return len(data) + } else if data, ok := val.Val.(string); ok { return len(data) } @@ -139,6 +140,19 @@ func (val *Value) SliceFromTo(from, to int) *Value { return NewValue(slice[from:to]) } +// TODO More type checking methods +func (val *Value) IsSlice() bool { + return val.Type() == reflect.Slice +} + +func (val *Value) IsStr() bool { + return val.Type() == reflect.String +} + +func (val *Value) IsEmpty() bool { + return (val.IsSlice() || val.IsStr()) && val.Len() == 0 +} + // Threat the value as a slice func (val *Value) Get(idx int) *Value { if d, ok := val.Val.([]interface{}); ok { |