-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tag option for omitting serialization of nil pointer values (#22)
Add omitnilptr tag option for omitting encoding of nil pointers. This prevents panicking when attempting encoding struct with nil pointer fields.
- Loading branch information
Showing
4 changed files
with
84 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package phpserialize | ||
|
||
import "strings" | ||
|
||
type tagOptions string | ||
|
||
func parseTag(tag string) (string, tagOptions) { | ||
if i := strings.Index(tag, ","); i != -1 { | ||
return tag[:i], tagOptions(tag[i+1:]) | ||
} | ||
return tag, "" | ||
} | ||
|
||
func (o tagOptions) Contains(option string) bool { | ||
if len(o) == 0 { | ||
return false | ||
} | ||
s := string(o) | ||
for s != "" { | ||
var next string | ||
i := strings.Index(s, ",") | ||
if i >= 0 { | ||
s, next = s[:i], s[i+1:] | ||
} | ||
if s == option { | ||
return true | ||
} | ||
s = next | ||
} | ||
return false | ||
} |