Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
abdf4853
Commit
abdf4853
authored
May 07, 2009
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Define Len() for JSON Map.
R=rsc APPROVED=rsc DELTA=6 (5 added, 0 deleted, 1 changed) OCL=28398 CL=28430
parent
9ab8129e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
1 deletion
+6
-1
generic.go
src/lib/json/generic.go
+2
-1
generic_test.go
src/lib/json/generic_test.go
+4
-0
No files found.
src/lib/json/generic.go
View file @
abdf4853
...
...
@@ -33,7 +33,7 @@ type Json interface {
Bool
()
bool
;
// boolean (BoolKind)
Get
(
s
string
)
Json
;
// field lookup (MapKind)
Elem
(
i
int
)
Json
;
// element lookup (ArrayKind)
Len
()
int
;
// length (ArrayKind)
Len
()
int
;
// length (ArrayKind
, MapKind
)
}
// JsonToString returns the textual JSON syntax representation
...
...
@@ -112,6 +112,7 @@ func (j *_Bool) String() string {
type
_Map
struct
{
m
map
[
string
]
Json
;
_Null
}
func
(
j
*
_Map
)
Kind
()
int
{
return
MapKind
}
func
(
j
*
_Map
)
Len
()
int
{
return
len
(
j
.
m
)
}
func
(
j
*
_Map
)
Get
(
s
string
)
Json
{
if
j
.
m
==
nil
{
return
Null
...
...
src/lib/json/generic_test.go
View file @
abdf4853
...
...
@@ -64,6 +64,10 @@ func TestJsonMap(t *testing.T) {
if
mapv
==
nil
{
t
.
Fatalf
(
"StringToJson(%#q) => nil, %v, %v"
,
mapstr
,
ok
,
errtok
);
}
if
cnt
:=
mapv
.
Len
();
cnt
!=
len
(
jsontests
)
{
t
.
Errorf
(
"StringToJson(%#q).Len() => %v, want %v"
,
mapstr
,
cnt
,
len
(
jsontests
));
}
for
k
,
v
:=
range
values
{
if
v1
:=
mapv
.
Get
(
k
);
!
Equal
(
v1
,
v
)
{
t
.
Errorf
(
"MapTest: Walk(%#q) => %v, want %v"
,
k
,
v1
,
v
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment