Initial commit
This commit is contained in:
1
vendor/github.com/cloudfoundry-incubator/candiedyaml/.gitignore
generated
vendored
Normal file
1
vendor/github.com/cloudfoundry-incubator/candiedyaml/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.coverprofile
|
||||
201
vendor/github.com/cloudfoundry-incubator/candiedyaml/LICENSE
generated
vendored
Normal file
201
vendor/github.com/cloudfoundry-incubator/candiedyaml/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
18
vendor/github.com/cloudfoundry-incubator/candiedyaml/NOTICE
generated
vendored
Normal file
18
vendor/github.com/cloudfoundry-incubator/candiedyaml/NOTICE
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
Copyright (c) 2015-Present CloudFoundry.org Foundation, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
This project may include a number of subcomponents with separate
|
||||
copyright notices and license terms. Your use of these subcomponents
|
||||
is subject to the terms and conditions of each subcomponent's license,
|
||||
as noted in the LICENSE file.
|
||||
70
vendor/github.com/cloudfoundry-incubator/candiedyaml/README.md
generated
vendored
Normal file
70
vendor/github.com/cloudfoundry-incubator/candiedyaml/README.md
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
[](https://godoc.org/github.com/cloudfoundry-incubator/candiedyaml)
|
||||
|
||||
|
||||
candiedyaml
|
||||
===========
|
||||
|
||||
-----
|
||||
|
||||
DEPRECATION NOTICE
|
||||
------------------
|
||||
|
||||
The `candiedyaml` library is no longer under active development and will soon
|
||||
be moved to the [cloudfoundry-attic](https://github.com/cloudfoundry-attic)
|
||||
GitHub organization. We recommend the use of an alternative library such as
|
||||
[`gopkg.in/yaml.v2`](https://gopkg.in/yaml.v2) instead.
|
||||
|
||||
-----
|
||||
|
||||
YAML for Go
|
||||
|
||||
A YAML 1.1 parser with support for YAML 1.2 features
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
```go
|
||||
package myApp
|
||||
|
||||
import (
|
||||
"github.com/cloudfoundry-incubator/candiedyaml"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
file, err := os.Open("path/to/some/file.yml")
|
||||
if err != nil {
|
||||
println("File does not exist:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
document := new(interface{})
|
||||
decoder := candiedyaml.NewDecoder(file)
|
||||
err = decoder.Decode(document)
|
||||
|
||||
if err != nil {
|
||||
println("Failed to decode document:", err.Error())
|
||||
}
|
||||
|
||||
println("parsed yml into interface:", fmt.Sprintf("%#v", document))
|
||||
|
||||
fileToWrite, err := os.Create("path/to/some/new/file.yml")
|
||||
if err != nil {
|
||||
println("Failed to open file for writing:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer fileToWrite.Close()
|
||||
|
||||
encoder := candiedyaml.NewEncoder(fileToWrite)
|
||||
err = encoder.Encode(document)
|
||||
|
||||
if err != nil {
|
||||
println("Failed to encode document:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
```
|
||||
834
vendor/github.com/cloudfoundry-incubator/candiedyaml/api.go
generated
vendored
Normal file
834
vendor/github.com/cloudfoundry-incubator/candiedyaml/api.go
generated
vendored
Normal file
@@ -0,0 +1,834 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
/*
|
||||
* Create a new parser object.
|
||||
*/
|
||||
|
||||
func yaml_parser_initialize(parser *yaml_parser_t) bool {
|
||||
*parser = yaml_parser_t{
|
||||
raw_buffer: make([]byte, 0, INPUT_RAW_BUFFER_SIZE),
|
||||
buffer: make([]byte, 0, INPUT_BUFFER_SIZE),
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a parser object.
|
||||
*/
|
||||
func yaml_parser_delete(parser *yaml_parser_t) {
|
||||
*parser = yaml_parser_t{}
|
||||
}
|
||||
|
||||
/*
|
||||
* String read handler.
|
||||
*/
|
||||
|
||||
func yaml_string_read_handler(parser *yaml_parser_t, buffer []byte) (int, error) {
|
||||
if parser.input_pos == len(parser.input) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
n := copy(buffer, parser.input[parser.input_pos:])
|
||||
parser.input_pos += n
|
||||
return n, nil
|
||||
}
|
||||
|
||||
/*
|
||||
* File read handler.
|
||||
*/
|
||||
|
||||
func yaml_file_read_handler(parser *yaml_parser_t, buffer []byte) (int, error) {
|
||||
return parser.input_reader.Read(buffer)
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a string input.
|
||||
*/
|
||||
|
||||
func yaml_parser_set_input_string(parser *yaml_parser_t, input []byte) {
|
||||
if parser.read_handler != nil {
|
||||
panic("input already set")
|
||||
}
|
||||
|
||||
parser.read_handler = yaml_string_read_handler
|
||||
|
||||
parser.input = input
|
||||
parser.input_pos = 0
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a reader input
|
||||
*/
|
||||
func yaml_parser_set_input_reader(parser *yaml_parser_t, reader io.Reader) {
|
||||
if parser.read_handler != nil {
|
||||
panic("input already set")
|
||||
}
|
||||
|
||||
parser.read_handler = yaml_file_read_handler
|
||||
parser.input_reader = reader
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a generic input.
|
||||
*/
|
||||
|
||||
func yaml_parser_set_input(parser *yaml_parser_t, handler yaml_read_handler_t) {
|
||||
if parser.read_handler != nil {
|
||||
panic("input already set")
|
||||
}
|
||||
|
||||
parser.read_handler = handler
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the source encoding.
|
||||
*/
|
||||
|
||||
func yaml_parser_set_encoding(parser *yaml_parser_t, encoding yaml_encoding_t) {
|
||||
if parser.encoding != yaml_ANY_ENCODING {
|
||||
panic("encoding already set")
|
||||
}
|
||||
|
||||
parser.encoding = encoding
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new emitter object.
|
||||
*/
|
||||
|
||||
func yaml_emitter_initialize(emitter *yaml_emitter_t) {
|
||||
*emitter = yaml_emitter_t{
|
||||
buffer: make([]byte, OUTPUT_BUFFER_SIZE),
|
||||
raw_buffer: make([]byte, 0, OUTPUT_RAW_BUFFER_SIZE),
|
||||
states: make([]yaml_emitter_state_t, 0, INITIAL_STACK_SIZE),
|
||||
events: make([]yaml_event_t, 0, INITIAL_QUEUE_SIZE),
|
||||
}
|
||||
}
|
||||
|
||||
func yaml_emitter_delete(emitter *yaml_emitter_t) {
|
||||
*emitter = yaml_emitter_t{}
|
||||
}
|
||||
|
||||
/*
|
||||
* String write handler.
|
||||
*/
|
||||
|
||||
func yaml_string_write_handler(emitter *yaml_emitter_t, buffer []byte) error {
|
||||
*emitter.output_buffer = append(*emitter.output_buffer, buffer...)
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
* File write handler.
|
||||
*/
|
||||
|
||||
func yaml_writer_write_handler(emitter *yaml_emitter_t, buffer []byte) error {
|
||||
_, err := emitter.output_writer.Write(buffer)
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a string output.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_output_string(emitter *yaml_emitter_t, buffer *[]byte) {
|
||||
if emitter.write_handler != nil {
|
||||
panic("output already set")
|
||||
}
|
||||
|
||||
emitter.write_handler = yaml_string_write_handler
|
||||
emitter.output_buffer = buffer
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a file output.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_output_writer(emitter *yaml_emitter_t, w io.Writer) {
|
||||
if emitter.write_handler != nil {
|
||||
panic("output already set")
|
||||
}
|
||||
|
||||
emitter.write_handler = yaml_writer_write_handler
|
||||
emitter.output_writer = w
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a generic output handler.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_output(emitter *yaml_emitter_t, handler yaml_write_handler_t) {
|
||||
if emitter.write_handler != nil {
|
||||
panic("output already set")
|
||||
}
|
||||
|
||||
emitter.write_handler = handler
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the output encoding.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_encoding(emitter *yaml_emitter_t, encoding yaml_encoding_t) {
|
||||
if emitter.encoding != yaml_ANY_ENCODING {
|
||||
panic("encoding already set")
|
||||
}
|
||||
|
||||
emitter.encoding = encoding
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the canonical output style.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_canonical(emitter *yaml_emitter_t, canonical bool) {
|
||||
emitter.canonical = canonical
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the indentation increment.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_indent(emitter *yaml_emitter_t, indent int) {
|
||||
if indent < 2 || indent > 9 {
|
||||
indent = 2
|
||||
}
|
||||
emitter.best_indent = indent
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the preferred line width.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_width(emitter *yaml_emitter_t, width int) {
|
||||
if width < 0 {
|
||||
width = -1
|
||||
}
|
||||
emitter.best_width = width
|
||||
}
|
||||
|
||||
/*
|
||||
* Set if unescaped non-ASCII characters are allowed.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_unicode(emitter *yaml_emitter_t, unicode bool) {
|
||||
emitter.unicode = unicode
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the preferred line break character.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_break(emitter *yaml_emitter_t, line_break yaml_break_t) {
|
||||
emitter.line_break = line_break
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a token object.
|
||||
*/
|
||||
|
||||
// yaml_DECLARE(void)
|
||||
// yaml_token_delete(yaml_token_t *token)
|
||||
// {
|
||||
// assert(token); /* Non-NULL token object expected. */
|
||||
//
|
||||
// switch (token.type)
|
||||
// {
|
||||
// case yaml_TAG_DIRECTIVE_TOKEN:
|
||||
// yaml_free(token.data.tag_directive.handle);
|
||||
// yaml_free(token.data.tag_directive.prefix);
|
||||
// break;
|
||||
//
|
||||
// case yaml_ALIAS_TOKEN:
|
||||
// yaml_free(token.data.alias.value);
|
||||
// break;
|
||||
//
|
||||
// case yaml_ANCHOR_TOKEN:
|
||||
// yaml_free(token.data.anchor.value);
|
||||
// break;
|
||||
//
|
||||
// case yaml_TAG_TOKEN:
|
||||
// yaml_free(token.data.tag.handle);
|
||||
// yaml_free(token.data.tag.suffix);
|
||||
// break;
|
||||
//
|
||||
// case yaml_SCALAR_TOKEN:
|
||||
// yaml_free(token.data.scalar.value);
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// memset(token, 0, sizeof(yaml_token_t));
|
||||
// }
|
||||
|
||||
/*
|
||||
* Check if a string is a valid UTF-8 sequence.
|
||||
*
|
||||
* Check 'reader.c' for more details on UTF-8 encoding.
|
||||
*/
|
||||
|
||||
// static int
|
||||
// yaml_check_utf8(yaml_char_t *start, size_t length)
|
||||
// {
|
||||
// yaml_char_t *end = start+length;
|
||||
// yaml_char_t *pointer = start;
|
||||
//
|
||||
// while (pointer < end) {
|
||||
// unsigned char octet;
|
||||
// unsigned int width;
|
||||
// unsigned int value;
|
||||
// size_t k;
|
||||
//
|
||||
// octet = pointer[0];
|
||||
// width = (octet & 0x80) == 0x00 ? 1 :
|
||||
// (octet & 0xE0) == 0xC0 ? 2 :
|
||||
// (octet & 0xF0) == 0xE0 ? 3 :
|
||||
// (octet & 0xF8) == 0xF0 ? 4 : 0;
|
||||
// value = (octet & 0x80) == 0x00 ? octet & 0x7F :
|
||||
// (octet & 0xE0) == 0xC0 ? octet & 0x1F :
|
||||
// (octet & 0xF0) == 0xE0 ? octet & 0x0F :
|
||||
// (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;
|
||||
// if (!width) return 0;
|
||||
// if (pointer+width > end) return 0;
|
||||
// for (k = 1; k < width; k ++) {
|
||||
// octet = pointer[k];
|
||||
// if ((octet & 0xC0) != 0x80) return 0;
|
||||
// value = (value << 6) + (octet & 0x3F);
|
||||
// }
|
||||
// if (!((width == 1) ||
|
||||
// (width == 2 && value >= 0x80) ||
|
||||
// (width == 3 && value >= 0x800) ||
|
||||
// (width == 4 && value >= 0x10000))) return 0;
|
||||
//
|
||||
// pointer += width;
|
||||
// }
|
||||
//
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
/*
|
||||
* Create STREAM-START.
|
||||
*/
|
||||
|
||||
func yaml_stream_start_event_initialize(event *yaml_event_t, encoding yaml_encoding_t) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_STREAM_START_EVENT,
|
||||
encoding: encoding,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create STREAM-END.
|
||||
*/
|
||||
|
||||
func yaml_stream_end_event_initialize(event *yaml_event_t) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_STREAM_END_EVENT,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create DOCUMENT-START.
|
||||
*/
|
||||
|
||||
func yaml_document_start_event_initialize(event *yaml_event_t,
|
||||
version_directive *yaml_version_directive_t,
|
||||
tag_directives []yaml_tag_directive_t,
|
||||
implicit bool) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_DOCUMENT_START_EVENT,
|
||||
version_directive: version_directive,
|
||||
tag_directives: tag_directives,
|
||||
implicit: implicit,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create DOCUMENT-END.
|
||||
*/
|
||||
|
||||
func yaml_document_end_event_initialize(event *yaml_event_t, implicit bool) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_DOCUMENT_END_EVENT,
|
||||
implicit: implicit,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create ALIAS.
|
||||
*/
|
||||
|
||||
func yaml_alias_event_initialize(event *yaml_event_t, anchor []byte) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_ALIAS_EVENT,
|
||||
anchor: anchor,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SCALAR.
|
||||
*/
|
||||
|
||||
func yaml_scalar_event_initialize(event *yaml_event_t,
|
||||
anchor []byte, tag []byte,
|
||||
value []byte,
|
||||
plain_implicit bool, quoted_implicit bool,
|
||||
style yaml_scalar_style_t) {
|
||||
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_SCALAR_EVENT,
|
||||
anchor: anchor,
|
||||
tag: tag,
|
||||
value: value,
|
||||
implicit: plain_implicit,
|
||||
quoted_implicit: quoted_implicit,
|
||||
style: yaml_style_t(style),
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SEQUENCE-START.
|
||||
*/
|
||||
|
||||
func yaml_sequence_start_event_initialize(event *yaml_event_t,
|
||||
anchor []byte, tag []byte, implicit bool, style yaml_sequence_style_t) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_SEQUENCE_START_EVENT,
|
||||
anchor: anchor,
|
||||
tag: tag,
|
||||
implicit: implicit,
|
||||
style: yaml_style_t(style),
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SEQUENCE-END.
|
||||
*/
|
||||
|
||||
func yaml_sequence_end_event_initialize(event *yaml_event_t) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_SEQUENCE_END_EVENT,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create MAPPING-START.
|
||||
*/
|
||||
|
||||
func yaml_mapping_start_event_initialize(event *yaml_event_t,
|
||||
anchor []byte, tag []byte, implicit bool, style yaml_mapping_style_t) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_MAPPING_START_EVENT,
|
||||
anchor: anchor,
|
||||
tag: tag,
|
||||
implicit: implicit,
|
||||
style: yaml_style_t(style),
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create MAPPING-END.
|
||||
*/
|
||||
|
||||
func yaml_mapping_end_event_initialize(event *yaml_event_t) {
|
||||
*event = yaml_event_t{
|
||||
event_type: yaml_MAPPING_END_EVENT,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy an event object.
|
||||
*/
|
||||
|
||||
func yaml_event_delete(event *yaml_event_t) {
|
||||
*event = yaml_event_t{}
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Create a document object.
|
||||
// */
|
||||
//
|
||||
// func yaml_document_initialize(document *yaml_document_t,
|
||||
// version_directive *yaml_version_directive_t,
|
||||
// tag_directives []yaml_tag_directive_t,
|
||||
// start_implicit, end_implicit bool) bool {
|
||||
//
|
||||
//
|
||||
// {
|
||||
// struct {
|
||||
// YAML_error_type_t error;
|
||||
// } context;
|
||||
// struct {
|
||||
// yaml_node_t *start;
|
||||
// yaml_node_t *end;
|
||||
// yaml_node_t *top;
|
||||
// } nodes = { NULL, NULL, NULL };
|
||||
// yaml_version_directive_t *version_directive_copy = NULL;
|
||||
// struct {
|
||||
// yaml_tag_directive_t *start;
|
||||
// yaml_tag_directive_t *end;
|
||||
// yaml_tag_directive_t *top;
|
||||
// } tag_directives_copy = { NULL, NULL, NULL };
|
||||
// yaml_tag_directive_t value = { NULL, NULL };
|
||||
// YAML_mark_t mark = { 0, 0, 0 };
|
||||
//
|
||||
// assert(document); /* Non-NULL document object is expected. */
|
||||
// assert((tag_directives_start && tag_directives_end) ||
|
||||
// (tag_directives_start == tag_directives_end));
|
||||
// /* Valid tag directives are expected. */
|
||||
//
|
||||
// if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error;
|
||||
//
|
||||
// if (version_directive) {
|
||||
// version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t));
|
||||
// if (!version_directive_copy) goto error;
|
||||
// version_directive_copy.major = version_directive.major;
|
||||
// version_directive_copy.minor = version_directive.minor;
|
||||
// }
|
||||
//
|
||||
// if (tag_directives_start != tag_directives_end) {
|
||||
// yaml_tag_directive_t *tag_directive;
|
||||
// if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE))
|
||||
// goto error;
|
||||
// for (tag_directive = tag_directives_start;
|
||||
// tag_directive != tag_directives_end; tag_directive ++) {
|
||||
// assert(tag_directive.handle);
|
||||
// assert(tag_directive.prefix);
|
||||
// if (!yaml_check_utf8(tag_directive.handle,
|
||||
// strlen((char *)tag_directive.handle)))
|
||||
// goto error;
|
||||
// if (!yaml_check_utf8(tag_directive.prefix,
|
||||
// strlen((char *)tag_directive.prefix)))
|
||||
// goto error;
|
||||
// value.handle = yaml_strdup(tag_directive.handle);
|
||||
// value.prefix = yaml_strdup(tag_directive.prefix);
|
||||
// if (!value.handle || !value.prefix) goto error;
|
||||
// if (!PUSH(&context, tag_directives_copy, value))
|
||||
// goto error;
|
||||
// value.handle = NULL;
|
||||
// value.prefix = NULL;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy,
|
||||
// tag_directives_copy.start, tag_directives_copy.top,
|
||||
// start_implicit, end_implicit, mark, mark);
|
||||
//
|
||||
// return 1;
|
||||
//
|
||||
// error:
|
||||
// STACK_DEL(&context, nodes);
|
||||
// yaml_free(version_directive_copy);
|
||||
// while (!STACK_EMPTY(&context, tag_directives_copy)) {
|
||||
// yaml_tag_directive_t value = POP(&context, tag_directives_copy);
|
||||
// yaml_free(value.handle);
|
||||
// yaml_free(value.prefix);
|
||||
// }
|
||||
// STACK_DEL(&context, tag_directives_copy);
|
||||
// yaml_free(value.handle);
|
||||
// yaml_free(value.prefix);
|
||||
//
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * Destroy a document object.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(void)
|
||||
// yaml_document_delete(document *yaml_document_t)
|
||||
// {
|
||||
// struct {
|
||||
// YAML_error_type_t error;
|
||||
// } context;
|
||||
// yaml_tag_directive_t *tag_directive;
|
||||
//
|
||||
// context.error = yaml_NO_ERROR; /* Eliminate a compliler warning. */
|
||||
//
|
||||
// assert(document); /* Non-NULL document object is expected. */
|
||||
//
|
||||
// while (!STACK_EMPTY(&context, document.nodes)) {
|
||||
// yaml_node_t node = POP(&context, document.nodes);
|
||||
// yaml_free(node.tag);
|
||||
// switch (node.type) {
|
||||
// case yaml_SCALAR_NODE:
|
||||
// yaml_free(node.data.scalar.value);
|
||||
// break;
|
||||
// case yaml_SEQUENCE_NODE:
|
||||
// STACK_DEL(&context, node.data.sequence.items);
|
||||
// break;
|
||||
// case yaml_MAPPING_NODE:
|
||||
// STACK_DEL(&context, node.data.mapping.pairs);
|
||||
// break;
|
||||
// default:
|
||||
// assert(0); /* Should not happen. */
|
||||
// }
|
||||
// }
|
||||
// STACK_DEL(&context, document.nodes);
|
||||
//
|
||||
// yaml_free(document.version_directive);
|
||||
// for (tag_directive = document.tag_directives.start;
|
||||
// tag_directive != document.tag_directives.end;
|
||||
// tag_directive++) {
|
||||
// yaml_free(tag_directive.handle);
|
||||
// yaml_free(tag_directive.prefix);
|
||||
// }
|
||||
// yaml_free(document.tag_directives.start);
|
||||
//
|
||||
// memset(document, 0, sizeof(yaml_document_t));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get a document node.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(yaml_node_t *)
|
||||
// yaml_document_get_node(document *yaml_document_t, int index)
|
||||
// {
|
||||
// assert(document); /* Non-NULL document object is expected. */
|
||||
//
|
||||
// if (index > 0 && document.nodes.start + index <= document.nodes.top) {
|
||||
// return document.nodes.start + index - 1;
|
||||
// }
|
||||
// return NULL;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get the root object.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(yaml_node_t *)
|
||||
// yaml_document_get_root_node(document *yaml_document_t)
|
||||
// {
|
||||
// assert(document); /* Non-NULL document object is expected. */
|
||||
//
|
||||
// if (document.nodes.top != document.nodes.start) {
|
||||
// return document.nodes.start;
|
||||
// }
|
||||
// return NULL;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * Add a scalar node to a document.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_document_add_scalar(document *yaml_document_t,
|
||||
// yaml_char_t *tag, yaml_char_t *value, int length,
|
||||
// yaml_scalar_style_t style)
|
||||
// {
|
||||
// struct {
|
||||
// YAML_error_type_t error;
|
||||
// } context;
|
||||
// YAML_mark_t mark = { 0, 0, 0 };
|
||||
// yaml_char_t *tag_copy = NULL;
|
||||
// yaml_char_t *value_copy = NULL;
|
||||
// yaml_node_t node;
|
||||
//
|
||||
// assert(document); /* Non-NULL document object is expected. */
|
||||
// assert(value); /* Non-NULL value is expected. */
|
||||
//
|
||||
// if (!tag) {
|
||||
// tag = (yaml_char_t *)yaml_DEFAULT_SCALAR_TAG;
|
||||
// }
|
||||
//
|
||||
// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
|
||||
// tag_copy = yaml_strdup(tag);
|
||||
// if (!tag_copy) goto error;
|
||||
//
|
||||
// if (length < 0) {
|
||||
// length = strlen((char *)value);
|
||||
// }
|
||||
//
|
||||
// if (!yaml_check_utf8(value, length)) goto error;
|
||||
// value_copy = yaml_malloc(length+1);
|
||||
// if (!value_copy) goto error;
|
||||
// memcpy(value_copy, value, length);
|
||||
// value_copy[length] = '\0';
|
||||
//
|
||||
// SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark);
|
||||
// if (!PUSH(&context, document.nodes, node)) goto error;
|
||||
//
|
||||
// return document.nodes.top - document.nodes.start;
|
||||
//
|
||||
// error:
|
||||
// yaml_free(tag_copy);
|
||||
// yaml_free(value_copy);
|
||||
//
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * Add a sequence node to a document.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_document_add_sequence(document *yaml_document_t,
|
||||
// yaml_char_t *tag, yaml_sequence_style_t style)
|
||||
// {
|
||||
// struct {
|
||||
// YAML_error_type_t error;
|
||||
// } context;
|
||||
// YAML_mark_t mark = { 0, 0, 0 };
|
||||
// yaml_char_t *tag_copy = NULL;
|
||||
// struct {
|
||||
// yaml_node_item_t *start;
|
||||
// yaml_node_item_t *end;
|
||||
// yaml_node_item_t *top;
|
||||
// } items = { NULL, NULL, NULL };
|
||||
// yaml_node_t node;
|
||||
//
|
||||
// assert(document); /* Non-NULL document object is expected. */
|
||||
//
|
||||
// if (!tag) {
|
||||
// tag = (yaml_char_t *)yaml_DEFAULT_SEQUENCE_TAG;
|
||||
// }
|
||||
//
|
||||
// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
|
||||
// tag_copy = yaml_strdup(tag);
|
||||
// if (!tag_copy) goto error;
|
||||
//
|
||||
// if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error;
|
||||
//
|
||||
// SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end,
|
||||
// style, mark, mark);
|
||||
// if (!PUSH(&context, document.nodes, node)) goto error;
|
||||
//
|
||||
// return document.nodes.top - document.nodes.start;
|
||||
//
|
||||
// error:
|
||||
// STACK_DEL(&context, items);
|
||||
// yaml_free(tag_copy);
|
||||
//
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * Add a mapping node to a document.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_document_add_mapping(document *yaml_document_t,
|
||||
// yaml_char_t *tag, yaml_mapping_style_t style)
|
||||
// {
|
||||
// struct {
|
||||
// YAML_error_type_t error;
|
||||
// } context;
|
||||
// YAML_mark_t mark = { 0, 0, 0 };
|
||||
// yaml_char_t *tag_copy = NULL;
|
||||
// struct {
|
||||
// yaml_node_pair_t *start;
|
||||
// yaml_node_pair_t *end;
|
||||
// yaml_node_pair_t *top;
|
||||
// } pairs = { NULL, NULL, NULL };
|
||||
// yaml_node_t node;
|
||||
//
|
||||
// assert(document); /* Non-NULL document object is expected. */
|
||||
//
|
||||
// if (!tag) {
|
||||
// tag = (yaml_char_t *)yaml_DEFAULT_MAPPING_TAG;
|
||||
// }
|
||||
//
|
||||
// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
|
||||
// tag_copy = yaml_strdup(tag);
|
||||
// if (!tag_copy) goto error;
|
||||
//
|
||||
// if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error;
|
||||
//
|
||||
// MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end,
|
||||
// style, mark, mark);
|
||||
// if (!PUSH(&context, document.nodes, node)) goto error;
|
||||
//
|
||||
// return document.nodes.top - document.nodes.start;
|
||||
//
|
||||
// error:
|
||||
// STACK_DEL(&context, pairs);
|
||||
// yaml_free(tag_copy);
|
||||
//
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * Append an item to a sequence node.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_document_append_sequence_item(document *yaml_document_t,
|
||||
// int sequence, int item)
|
||||
// {
|
||||
// struct {
|
||||
// YAML_error_type_t error;
|
||||
// } context;
|
||||
//
|
||||
// assert(document); /* Non-NULL document is required. */
|
||||
// assert(sequence > 0
|
||||
// && document.nodes.start + sequence <= document.nodes.top);
|
||||
// /* Valid sequence id is required. */
|
||||
// assert(document.nodes.start[sequence-1].type == yaml_SEQUENCE_NODE);
|
||||
// /* A sequence node is required. */
|
||||
// assert(item > 0 && document.nodes.start + item <= document.nodes.top);
|
||||
// /* Valid item id is required. */
|
||||
//
|
||||
// if (!PUSH(&context,
|
||||
// document.nodes.start[sequence-1].data.sequence.items, item))
|
||||
// return 0;
|
||||
//
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * Append a pair of a key and a value to a mapping node.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_document_append_mapping_pair(document *yaml_document_t,
|
||||
// int mapping, int key, int value)
|
||||
// {
|
||||
// struct {
|
||||
// YAML_error_type_t error;
|
||||
// } context;
|
||||
//
|
||||
// yaml_node_pair_t pair;
|
||||
//
|
||||
// assert(document); /* Non-NULL document is required. */
|
||||
// assert(mapping > 0
|
||||
// && document.nodes.start + mapping <= document.nodes.top);
|
||||
// /* Valid mapping id is required. */
|
||||
// assert(document.nodes.start[mapping-1].type == yaml_MAPPING_NODE);
|
||||
// /* A mapping node is required. */
|
||||
// assert(key > 0 && document.nodes.start + key <= document.nodes.top);
|
||||
// /* Valid key id is required. */
|
||||
// assert(value > 0 && document.nodes.start + value <= document.nodes.top);
|
||||
// /* Valid value id is required. */
|
||||
//
|
||||
// pair.key = key;
|
||||
// pair.value = value;
|
||||
//
|
||||
// if (!PUSH(&context,
|
||||
// document.nodes.start[mapping-1].data.mapping.pairs, pair))
|
||||
// return 0;
|
||||
//
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
27
vendor/github.com/cloudfoundry-incubator/candiedyaml/candiedyaml_suite_test.go
generated
vendored
Normal file
27
vendor/github.com/cloudfoundry-incubator/candiedyaml/candiedyaml_suite_test.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCandiedyaml(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Candiedyaml Suite")
|
||||
}
|
||||
622
vendor/github.com/cloudfoundry-incubator/candiedyaml/decode.go
generated
vendored
Normal file
622
vendor/github.com/cloudfoundry-incubator/candiedyaml/decode.go
generated
vendored
Normal file
@@ -0,0 +1,622 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Unmarshaler interface {
|
||||
UnmarshalYAML(tag string, value interface{}) error
|
||||
}
|
||||
|
||||
// A Number represents a JSON number literal.
|
||||
type Number string
|
||||
|
||||
// String returns the literal text of the number.
|
||||
func (n Number) String() string { return string(n) }
|
||||
|
||||
// Float64 returns the number as a float64.
|
||||
func (n Number) Float64() (float64, error) {
|
||||
return strconv.ParseFloat(string(n), 64)
|
||||
}
|
||||
|
||||
// Int64 returns the number as an int64.
|
||||
func (n Number) Int64() (int64, error) {
|
||||
return strconv.ParseInt(string(n), 10, 64)
|
||||
}
|
||||
|
||||
type Decoder struct {
|
||||
parser yaml_parser_t
|
||||
event yaml_event_t
|
||||
replay_events []yaml_event_t
|
||||
useNumber bool
|
||||
|
||||
anchors map[string][]yaml_event_t
|
||||
tracking_anchors [][]yaml_event_t
|
||||
}
|
||||
|
||||
type ParserError struct {
|
||||
ErrorType YAML_error_type_t
|
||||
Context string
|
||||
ContextMark YAML_mark_t
|
||||
Problem string
|
||||
ProblemMark YAML_mark_t
|
||||
}
|
||||
|
||||
func (e *ParserError) Error() string {
|
||||
return fmt.Sprintf("yaml: [%s] %s at line %d, column %d", e.Context, e.Problem, e.ProblemMark.line+1, e.ProblemMark.column+1)
|
||||
}
|
||||
|
||||
type UnexpectedEventError struct {
|
||||
Value string
|
||||
EventType yaml_event_type_t
|
||||
At YAML_mark_t
|
||||
}
|
||||
|
||||
func (e *UnexpectedEventError) Error() string {
|
||||
return fmt.Sprintf("yaml: Unexpect event [%d]: '%s' at line %d, column %d", e.EventType, e.Value, e.At.line+1, e.At.column+1)
|
||||
}
|
||||
|
||||
func recovery(err *error) {
|
||||
if r := recover(); r != nil {
|
||||
if _, ok := r.(runtime.Error); ok {
|
||||
panic(r)
|
||||
}
|
||||
|
||||
var tmpError error
|
||||
switch r := r.(type) {
|
||||
case error:
|
||||
tmpError = r
|
||||
case string:
|
||||
tmpError = errors.New(r)
|
||||
default:
|
||||
tmpError = errors.New("Unknown panic: " + reflect.ValueOf(r).String())
|
||||
}
|
||||
|
||||
*err = tmpError
|
||||
}
|
||||
}
|
||||
|
||||
func Unmarshal(data []byte, v interface{}) error {
|
||||
d := NewDecoder(bytes.NewBuffer(data))
|
||||
return d.Decode(v)
|
||||
}
|
||||
|
||||
func NewDecoder(r io.Reader) *Decoder {
|
||||
d := &Decoder{
|
||||
anchors: make(map[string][]yaml_event_t),
|
||||
tracking_anchors: make([][]yaml_event_t, 1),
|
||||
}
|
||||
yaml_parser_initialize(&d.parser)
|
||||
yaml_parser_set_input_reader(&d.parser, r)
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *Decoder) Decode(v interface{}) (err error) {
|
||||
defer recovery(&err)
|
||||
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||
return fmt.Errorf("Expected a pointer or nil but was a %s at %s", rv.String(), d.event.start_mark)
|
||||
}
|
||||
|
||||
if d.event.event_type == yaml_NO_EVENT {
|
||||
d.nextEvent()
|
||||
|
||||
if d.event.event_type != yaml_STREAM_START_EVENT {
|
||||
return errors.New("Invalid stream")
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
}
|
||||
|
||||
d.document(rv)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Decoder) UseNumber() { d.useNumber = true }
|
||||
|
||||
func (d *Decoder) error(err error) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
func (d *Decoder) nextEvent() {
|
||||
if d.event.event_type == yaml_STREAM_END_EVENT {
|
||||
d.error(errors.New("The stream is closed"))
|
||||
}
|
||||
|
||||
if d.replay_events != nil {
|
||||
d.event = d.replay_events[0]
|
||||
if len(d.replay_events) == 1 {
|
||||
d.replay_events = nil
|
||||
} else {
|
||||
d.replay_events = d.replay_events[1:]
|
||||
}
|
||||
} else {
|
||||
if !yaml_parser_parse(&d.parser, &d.event) {
|
||||
yaml_event_delete(&d.event)
|
||||
|
||||
d.error(&ParserError{
|
||||
ErrorType: d.parser.error,
|
||||
Context: d.parser.context,
|
||||
ContextMark: d.parser.context_mark,
|
||||
Problem: d.parser.problem,
|
||||
ProblemMark: d.parser.problem_mark,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
last := len(d.tracking_anchors)
|
||||
// skip aliases when tracking an anchor
|
||||
if last > 0 && d.event.event_type != yaml_ALIAS_EVENT {
|
||||
d.tracking_anchors[last-1] = append(d.tracking_anchors[last-1], d.event)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) document(rv reflect.Value) {
|
||||
if d.event.event_type != yaml_DOCUMENT_START_EVENT {
|
||||
d.error(fmt.Errorf("Expected document start at %s", d.event.start_mark))
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
d.parse(rv)
|
||||
|
||||
if d.event.event_type != yaml_DOCUMENT_END_EVENT {
|
||||
d.error(fmt.Errorf("Expected document end at %s", d.event.start_mark))
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
}
|
||||
|
||||
func (d *Decoder) parse(rv reflect.Value) {
|
||||
if !rv.IsValid() {
|
||||
// skip ahead since we cannot store
|
||||
d.valueInterface()
|
||||
return
|
||||
}
|
||||
|
||||
anchor := string(d.event.anchor)
|
||||
switch d.event.event_type {
|
||||
case yaml_SEQUENCE_START_EVENT:
|
||||
d.begin_anchor(anchor)
|
||||
d.sequence(rv)
|
||||
d.end_anchor(anchor)
|
||||
case yaml_MAPPING_START_EVENT:
|
||||
d.begin_anchor(anchor)
|
||||
d.mapping(rv)
|
||||
d.end_anchor(anchor)
|
||||
case yaml_SCALAR_EVENT:
|
||||
d.begin_anchor(anchor)
|
||||
d.scalar(rv)
|
||||
d.end_anchor(anchor)
|
||||
case yaml_ALIAS_EVENT:
|
||||
d.alias(rv)
|
||||
case yaml_DOCUMENT_END_EVENT:
|
||||
default:
|
||||
d.error(&UnexpectedEventError{
|
||||
Value: string(d.event.value),
|
||||
EventType: d.event.event_type,
|
||||
At: d.event.start_mark,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) begin_anchor(anchor string) {
|
||||
if anchor != "" {
|
||||
events := []yaml_event_t{d.event}
|
||||
d.tracking_anchors = append(d.tracking_anchors, events)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) end_anchor(anchor string) {
|
||||
if anchor != "" {
|
||||
events := d.tracking_anchors[len(d.tracking_anchors)-1]
|
||||
d.tracking_anchors = d.tracking_anchors[0 : len(d.tracking_anchors)-1]
|
||||
// remove the anchor, replaying events shouldn't have anchors
|
||||
events[0].anchor = nil
|
||||
// we went one too many, remove the extra event
|
||||
events = events[:len(events)-1]
|
||||
// if nested, append to all the other anchors
|
||||
for i, e := range d.tracking_anchors {
|
||||
d.tracking_anchors[i] = append(e, events...)
|
||||
}
|
||||
d.anchors[anchor] = events
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) indirect(v reflect.Value, decodingNull bool) (Unmarshaler, reflect.Value) {
|
||||
// If v is a named type and is addressable,
|
||||
// start with its address, so that if the type has pointer methods,
|
||||
// we find them.
|
||||
if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
|
||||
v = v.Addr()
|
||||
}
|
||||
for {
|
||||
// Load value from interface, but only if the result will be
|
||||
// usefully addressable.
|
||||
if v.Kind() == reflect.Interface && !v.IsNil() {
|
||||
e := v.Elem()
|
||||
if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) {
|
||||
v = e
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if v.Kind() != reflect.Ptr {
|
||||
break
|
||||
}
|
||||
|
||||
if v.Elem().Kind() != reflect.Ptr && decodingNull && v.CanSet() {
|
||||
break
|
||||
}
|
||||
|
||||
if v.IsNil() {
|
||||
v.Set(reflect.New(v.Type().Elem()))
|
||||
}
|
||||
|
||||
if v.Type().NumMethod() > 0 {
|
||||
if u, ok := v.Interface().(Unmarshaler); ok {
|
||||
var temp interface{}
|
||||
return u, reflect.ValueOf(&temp)
|
||||
}
|
||||
}
|
||||
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
return nil, v
|
||||
}
|
||||
|
||||
func (d *Decoder) sequence(v reflect.Value) {
|
||||
if d.event.event_type != yaml_SEQUENCE_START_EVENT {
|
||||
d.error(fmt.Errorf("Expected sequence start at %s", d.event.start_mark))
|
||||
}
|
||||
|
||||
u, pv := d.indirect(v, false)
|
||||
if u != nil {
|
||||
defer func() {
|
||||
if err := u.UnmarshalYAML(yaml_SEQ_TAG, pv.Interface()); err != nil {
|
||||
d.error(err)
|
||||
}
|
||||
}()
|
||||
_, pv = d.indirect(pv, false)
|
||||
}
|
||||
|
||||
v = pv
|
||||
|
||||
// Check type of target.
|
||||
switch v.Kind() {
|
||||
case reflect.Interface:
|
||||
if v.NumMethod() == 0 {
|
||||
// Decoding into nil interface? Switch to non-reflect code.
|
||||
v.Set(reflect.ValueOf(d.sequenceInterface()))
|
||||
return
|
||||
}
|
||||
// Otherwise it's invalid.
|
||||
fallthrough
|
||||
default:
|
||||
d.error(fmt.Errorf("Expected an array, slice or interface{} but was a %s at %s", v, d.event.start_mark))
|
||||
case reflect.Array:
|
||||
case reflect.Slice:
|
||||
break
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
|
||||
i := 0
|
||||
done:
|
||||
for {
|
||||
switch d.event.event_type {
|
||||
case yaml_SEQUENCE_END_EVENT, yaml_DOCUMENT_END_EVENT:
|
||||
break done
|
||||
}
|
||||
|
||||
// Get element of array, growing if necessary.
|
||||
if v.Kind() == reflect.Slice {
|
||||
// Grow slice if necessary
|
||||
if i >= v.Cap() {
|
||||
newcap := v.Cap() + v.Cap()/2
|
||||
if newcap < 4 {
|
||||
newcap = 4
|
||||
}
|
||||
newv := reflect.MakeSlice(v.Type(), v.Len(), newcap)
|
||||
reflect.Copy(newv, v)
|
||||
v.Set(newv)
|
||||
}
|
||||
if i >= v.Len() {
|
||||
v.SetLen(i + 1)
|
||||
}
|
||||
}
|
||||
|
||||
if i < v.Len() {
|
||||
// Decode into element.
|
||||
d.parse(v.Index(i))
|
||||
} else {
|
||||
// Ran out of fixed array: skip.
|
||||
d.parse(reflect.Value{})
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
if i < v.Len() {
|
||||
if v.Kind() == reflect.Array {
|
||||
// Array. Zero the rest.
|
||||
z := reflect.Zero(v.Type().Elem())
|
||||
for ; i < v.Len(); i++ {
|
||||
v.Index(i).Set(z)
|
||||
}
|
||||
} else {
|
||||
v.SetLen(i)
|
||||
}
|
||||
}
|
||||
if i == 0 && v.Kind() == reflect.Slice {
|
||||
v.Set(reflect.MakeSlice(v.Type(), 0, 0))
|
||||
}
|
||||
|
||||
if d.event.event_type != yaml_DOCUMENT_END_EVENT {
|
||||
d.nextEvent()
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) mapping(v reflect.Value) {
|
||||
u, pv := d.indirect(v, false)
|
||||
if u != nil {
|
||||
defer func() {
|
||||
if err := u.UnmarshalYAML(yaml_MAP_TAG, pv.Interface()); err != nil {
|
||||
d.error(err)
|
||||
}
|
||||
}()
|
||||
_, pv = d.indirect(pv, false)
|
||||
}
|
||||
v = pv
|
||||
|
||||
// Decoding into nil interface? Switch to non-reflect code.
|
||||
if v.Kind() == reflect.Interface && v.NumMethod() == 0 {
|
||||
v.Set(reflect.ValueOf(d.mappingInterface()))
|
||||
return
|
||||
}
|
||||
|
||||
// Check type of target: struct or map[X]Y
|
||||
switch v.Kind() {
|
||||
case reflect.Struct:
|
||||
d.mappingStruct(v)
|
||||
return
|
||||
case reflect.Map:
|
||||
default:
|
||||
d.error(fmt.Errorf("Expected a struct or map but was a %s at %s ", v, d.event.start_mark))
|
||||
}
|
||||
|
||||
mapt := v.Type()
|
||||
if v.IsNil() {
|
||||
v.Set(reflect.MakeMap(mapt))
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
|
||||
keyt := mapt.Key()
|
||||
mapElemt := mapt.Elem()
|
||||
|
||||
var mapElem reflect.Value
|
||||
done:
|
||||
for {
|
||||
switch d.event.event_type {
|
||||
case yaml_MAPPING_END_EVENT:
|
||||
break done
|
||||
case yaml_DOCUMENT_END_EVENT:
|
||||
return
|
||||
}
|
||||
|
||||
key := reflect.New(keyt)
|
||||
d.parse(key.Elem())
|
||||
|
||||
if !mapElem.IsValid() {
|
||||
mapElem = reflect.New(mapElemt).Elem()
|
||||
} else {
|
||||
mapElem.Set(reflect.Zero(mapElemt))
|
||||
}
|
||||
|
||||
d.parse(mapElem)
|
||||
|
||||
v.SetMapIndex(key.Elem(), mapElem)
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
}
|
||||
|
||||
func (d *Decoder) mappingStruct(v reflect.Value) {
|
||||
|
||||
structt := v.Type()
|
||||
fields := cachedTypeFields(structt)
|
||||
|
||||
d.nextEvent()
|
||||
|
||||
done:
|
||||
for {
|
||||
switch d.event.event_type {
|
||||
case yaml_MAPPING_END_EVENT:
|
||||
break done
|
||||
case yaml_DOCUMENT_END_EVENT:
|
||||
return
|
||||
}
|
||||
|
||||
key := ""
|
||||
d.parse(reflect.ValueOf(&key))
|
||||
|
||||
// Figure out field corresponding to key.
|
||||
var subv reflect.Value
|
||||
|
||||
var f *field
|
||||
for i := range fields {
|
||||
ff := &fields[i]
|
||||
if ff.name == key {
|
||||
f = ff
|
||||
break
|
||||
}
|
||||
|
||||
if f == nil && strings.EqualFold(ff.name, key) {
|
||||
f = ff
|
||||
}
|
||||
}
|
||||
|
||||
if f != nil {
|
||||
subv = v
|
||||
for _, i := range f.index {
|
||||
if subv.Kind() == reflect.Ptr {
|
||||
if subv.IsNil() {
|
||||
subv.Set(reflect.New(subv.Type().Elem()))
|
||||
}
|
||||
subv = subv.Elem()
|
||||
}
|
||||
subv = subv.Field(i)
|
||||
}
|
||||
}
|
||||
d.parse(subv)
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
}
|
||||
|
||||
func (d *Decoder) scalar(v reflect.Value) {
|
||||
val := string(d.event.value)
|
||||
wantptr := null_values[val]
|
||||
|
||||
u, pv := d.indirect(v, wantptr)
|
||||
|
||||
var tag string
|
||||
if u != nil {
|
||||
defer func() {
|
||||
if err := u.UnmarshalYAML(tag, pv.Interface()); err != nil {
|
||||
d.error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
_, pv = d.indirect(pv, wantptr)
|
||||
}
|
||||
v = pv
|
||||
|
||||
var err error
|
||||
tag, err = resolve(d.event, v, d.useNumber)
|
||||
if err != nil {
|
||||
d.error(err)
|
||||
}
|
||||
|
||||
d.nextEvent()
|
||||
}
|
||||
|
||||
func (d *Decoder) alias(rv reflect.Value) {
|
||||
val, ok := d.anchors[string(d.event.anchor)]
|
||||
if !ok {
|
||||
d.error(fmt.Errorf("missing anchor: '%s' at %s", d.event.anchor, d.event.start_mark))
|
||||
}
|
||||
|
||||
d.replay_events = val
|
||||
d.nextEvent()
|
||||
d.parse(rv)
|
||||
}
|
||||
|
||||
func (d *Decoder) valueInterface() interface{} {
|
||||
var v interface{}
|
||||
|
||||
anchor := string(d.event.anchor)
|
||||
switch d.event.event_type {
|
||||
case yaml_SEQUENCE_START_EVENT:
|
||||
d.begin_anchor(anchor)
|
||||
v = d.sequenceInterface()
|
||||
case yaml_MAPPING_START_EVENT:
|
||||
d.begin_anchor(anchor)
|
||||
v = d.mappingInterface()
|
||||
case yaml_SCALAR_EVENT:
|
||||
d.begin_anchor(anchor)
|
||||
v = d.scalarInterface()
|
||||
case yaml_ALIAS_EVENT:
|
||||
rv := reflect.ValueOf(&v)
|
||||
d.alias(rv)
|
||||
return v
|
||||
case yaml_DOCUMENT_END_EVENT:
|
||||
d.error(&UnexpectedEventError{
|
||||
Value: string(d.event.value),
|
||||
EventType: d.event.event_type,
|
||||
At: d.event.start_mark,
|
||||
})
|
||||
|
||||
}
|
||||
d.end_anchor(anchor)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (d *Decoder) scalarInterface() interface{} {
|
||||
_, v := resolveInterface(d.event, d.useNumber)
|
||||
|
||||
d.nextEvent()
|
||||
return v
|
||||
}
|
||||
|
||||
// sequenceInterface is like sequence but returns []interface{}.
|
||||
func (d *Decoder) sequenceInterface() []interface{} {
|
||||
var v = make([]interface{}, 0)
|
||||
|
||||
d.nextEvent()
|
||||
|
||||
done:
|
||||
for {
|
||||
switch d.event.event_type {
|
||||
case yaml_SEQUENCE_END_EVENT, yaml_DOCUMENT_END_EVENT:
|
||||
break done
|
||||
}
|
||||
|
||||
v = append(v, d.valueInterface())
|
||||
}
|
||||
|
||||
if d.event.event_type != yaml_DOCUMENT_END_EVENT {
|
||||
d.nextEvent()
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// mappingInterface is like mapping but returns map[interface{}]interface{}.
|
||||
func (d *Decoder) mappingInterface() map[interface{}]interface{} {
|
||||
m := make(map[interface{}]interface{})
|
||||
|
||||
d.nextEvent()
|
||||
|
||||
done:
|
||||
for {
|
||||
switch d.event.event_type {
|
||||
case yaml_MAPPING_END_EVENT, yaml_DOCUMENT_END_EVENT:
|
||||
break done
|
||||
}
|
||||
|
||||
key := d.valueInterface()
|
||||
|
||||
// Read value.
|
||||
m[key] = d.valueInterface()
|
||||
}
|
||||
|
||||
if d.event.event_type != yaml_DOCUMENT_END_EVENT {
|
||||
d.nextEvent()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
915
vendor/github.com/cloudfoundry-incubator/candiedyaml/decode_test.go
generated
vendored
Normal file
915
vendor/github.com/cloudfoundry-incubator/candiedyaml/decode_test.go
generated
vendored
Normal file
@@ -0,0 +1,915 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Decode", func() {
|
||||
It("Decodes a file", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_1.yaml")
|
||||
d := NewDecoder(f)
|
||||
var v interface{}
|
||||
err := d.Decode(&v)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
Context("strings", func() {
|
||||
It("Decodes an empty string", func() {
|
||||
d := NewDecoder(strings.NewReader(`""
|
||||
`))
|
||||
var v string
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(""))
|
||||
})
|
||||
|
||||
It("Decodes an empty string to an interface", func() {
|
||||
d := NewDecoder(strings.NewReader(`""
|
||||
`))
|
||||
var v interface{}
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(""))
|
||||
})
|
||||
|
||||
It("Decodes a map containing empty strings to an interface", func() {
|
||||
d := NewDecoder(strings.NewReader(`"" : ""
|
||||
`))
|
||||
var v interface{}
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[interface{}]interface{}{"": ""}))
|
||||
})
|
||||
|
||||
It("Decodes strings starting with a colon", func() {
|
||||
d := NewDecoder(strings.NewReader(`:colon
|
||||
`))
|
||||
var v interface{}
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(":colon"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Sequence", func() {
|
||||
It("Decodes to interface{}s", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_1.yaml")
|
||||
d := NewDecoder(f)
|
||||
var v interface{}
|
||||
err := d.Decode(&v)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect((v).([]interface{})).To(Equal([]interface{}{"Mark McGwire", "Sammy Sosa", "Ken Griffey"}))
|
||||
})
|
||||
|
||||
It("Decodes to []string", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_1.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make([]string, 0, 3)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal([]string{"Mark McGwire", "Sammy Sosa", "Ken Griffey"}))
|
||||
})
|
||||
|
||||
It("Decodes a sequence of maps", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_12.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make([]map[string]interface{}, 1)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal([]map[string]interface{}{
|
||||
{"item": "Super Hoop", "quantity": int64(1)},
|
||||
{"item": "Basketball", "quantity": int64(4)},
|
||||
{"item": "Big Shoes", "quantity": int64(1)},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
Describe("As structs", func() {
|
||||
It("Simple struct", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_4.yaml")
|
||||
d := NewDecoder(f)
|
||||
|
||||
type batter struct {
|
||||
Name string
|
||||
HR int64
|
||||
AVG float64
|
||||
}
|
||||
v := make([]batter, 0, 1)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal([]batter{
|
||||
batter{Name: "Mark McGwire", HR: 65, AVG: 0.278},
|
||||
batter{Name: "Sammy Sosa", HR: 63, AVG: 0.288},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("Tagged struct", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_4.yaml")
|
||||
d := NewDecoder(f)
|
||||
|
||||
type batter struct {
|
||||
N string `yaml:"name"`
|
||||
H int64 `yaml:"hr"`
|
||||
A float64 `yaml:"avg"`
|
||||
}
|
||||
v := make([]batter, 0, 1)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal([]batter{
|
||||
batter{N: "Mark McGwire", H: 65, A: 0.278},
|
||||
batter{N: "Sammy Sosa", H: 63, A: 0.288},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("handles null values", func() {
|
||||
type S struct {
|
||||
Default interface{}
|
||||
}
|
||||
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
default:
|
||||
`))
|
||||
var s S
|
||||
err := d.Decode(&s)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(s).To(Equal(S{Default: nil}))
|
||||
|
||||
})
|
||||
|
||||
It("ignores missing tags", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_4.yaml")
|
||||
d := NewDecoder(f)
|
||||
|
||||
type batter struct {
|
||||
N string `yaml:"name"`
|
||||
HR int64
|
||||
A float64
|
||||
}
|
||||
v := make([]batter, 0, 1)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal([]batter{
|
||||
batter{N: "Mark McGwire", HR: 65},
|
||||
batter{N: "Sammy Sosa", HR: 63},
|
||||
}))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
It("Decodes a sequence of sequences", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_5.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make([][]interface{}, 1)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal([][]interface{}{
|
||||
{"name", "hr", "avg"},
|
||||
{"Mark McGwire", int64(65), float64(0.278)},
|
||||
{"Sammy Sosa", int64(63), float64(0.288)},
|
||||
}))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("Maps", func() {
|
||||
It("Decodes to interface{}s", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_2.yaml")
|
||||
d := NewDecoder(f)
|
||||
var v interface{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect((v).(map[interface{}]interface{})).To(Equal(map[interface{}]interface{}{
|
||||
"hr": int64(65),
|
||||
"avg": float64(0.278),
|
||||
"rbi": int64(147),
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("Decodes to a struct", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_2.yaml")
|
||||
d := NewDecoder(f)
|
||||
|
||||
type batter struct {
|
||||
HR int64
|
||||
AVG float64
|
||||
RBI int64
|
||||
}
|
||||
v := batter{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(batter{HR: 65, AVG: 0.278, RBI: 147}))
|
||||
})
|
||||
|
||||
It("Decodes to a map of string arrays", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_9.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string][]string)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string][]string{"hr": []string{"Mark McGwire", "Sammy Sosa"}, "rbi": []string{"Sammy Sosa", "Ken Griffey"}}))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Sequence of Maps", func() {
|
||||
It("Decodes to interface{}s", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_4.yaml")
|
||||
d := NewDecoder(f)
|
||||
var v interface{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect((v).([]interface{})).To(Equal([]interface{}{
|
||||
map[interface{}]interface{}{"name": "Mark McGwire", "hr": int64(65), "avg": float64(0.278)},
|
||||
map[interface{}]interface{}{"name": "Sammy Sosa", "hr": int64(63), "avg": float64(0.288)},
|
||||
}))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
It("Decodes ascii art", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_13.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := ""
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(`\//||\/||
|
||||
// || ||__
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("Decodes folded strings", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_15.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := ""
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal("Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n"))
|
||||
})
|
||||
|
||||
It("Decodes literal and folded strings with indents", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_16.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]string)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]string{
|
||||
"name": "Mark McGwire",
|
||||
"accomplishment": `Mark set a major league home run record in 1998.
|
||||
`,
|
||||
"stats": `65 Home Runs
|
||||
0.278 Batting Average
|
||||
`,
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("Decodes single quoted", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_17_quoted.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]string)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]string{
|
||||
"quoted": ` # not a 'comment'.`,
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
Context("ints", func() {
|
||||
It("Decodes into an interface{}", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_19.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]interface{})
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"canonical": int64(12345),
|
||||
"decimal": int64(12345),
|
||||
"octal": int64(12),
|
||||
"hexadecimal": int64(12),
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("Decodes into int64", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_19.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]int64)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]int64{
|
||||
"canonical": int64(12345),
|
||||
"decimal": int64(12345),
|
||||
"octal": int64(12),
|
||||
"hexadecimal": int64(12),
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
Context("boundary values", func() {
|
||||
intoInt64 := func(val int64) {
|
||||
It("Decodes into an int64 value", func() {
|
||||
var v int64
|
||||
|
||||
d := NewDecoder(strings.NewReader(strconv.FormatInt(val, 10)))
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(val))
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
intoInt := func(val int) {
|
||||
It("Decodes into an int value", func() {
|
||||
var v int
|
||||
|
||||
d := NewDecoder(strings.NewReader(strconv.FormatInt(int64(val), 10)))
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(val))
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
intoInterface := func(val int64) {
|
||||
It("Decodes into an interface{}", func() {
|
||||
var v interface{}
|
||||
|
||||
d := NewDecoder(strings.NewReader(strconv.FormatInt(val, 10)))
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(val))
|
||||
})
|
||||
}
|
||||
|
||||
intoInt64(math.MaxInt64)
|
||||
intoInterface(math.MaxInt64)
|
||||
|
||||
intoInt64(math.MinInt64)
|
||||
intoInterface(math.MinInt64)
|
||||
|
||||
intoInt(math.MaxInt32)
|
||||
intoInt(math.MinInt32)
|
||||
})
|
||||
})
|
||||
|
||||
It("Decodes a variety of floats", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_20.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]float64)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(math.IsNaN(v["not a number"])).To(BeTrue())
|
||||
delete(v, "not a number")
|
||||
|
||||
Expect(v).To(Equal(map[string]float64{
|
||||
"canonical": float64(1230.15),
|
||||
"exponential": float64(1230.15),
|
||||
"fixed": float64(1230.15),
|
||||
"negative infinity": math.Inf(-1),
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("Decodes booleans, nil and strings", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_21.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]interface{})
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"": interface{}(nil),
|
||||
"true": true,
|
||||
"false": false,
|
||||
"string": "12345",
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("Decodes a null ptr", func() {
|
||||
d := NewDecoder(strings.NewReader(`null
|
||||
`))
|
||||
var v *bool
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(BeNil())
|
||||
})
|
||||
|
||||
It("Decodes dates/time", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_22.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]time.Time)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]time.Time{
|
||||
"canonical": time.Date(2001, time.December, 15, 2, 59, 43, int(1*time.Millisecond), time.UTC),
|
||||
"iso8601": time.Date(2001, time.December, 14, 21, 59, 43, int(10*time.Millisecond), time.FixedZone("", -5*3600)),
|
||||
"spaced": time.Date(2001, time.December, 14, 21, 59, 43, int(10*time.Millisecond), time.FixedZone("", -5*3600)),
|
||||
"date": time.Date(2002, time.December, 14, 0, 0, 0, 0, time.UTC),
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
Context("Tags", func() {
|
||||
It("Respects tags", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_23_non_date.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]string)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]string{
|
||||
"not-date": "2002-04-28",
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("handles non-specific tags", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
not_parsed: ! 123
|
||||
`))
|
||||
v := make(map[string]int)
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]int{"not_parsed": 123}))
|
||||
})
|
||||
|
||||
It("handles non-specific tags", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
? a complex key
|
||||
: ! "123"
|
||||
`))
|
||||
v := make(map[string]string)
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]string{"a complex key": "123"}))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Decodes binary/base64", func() {
|
||||
It("to []byte", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_23_picture.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string][]byte)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string][]byte{
|
||||
"picture": []byte{0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x0c, 0x00,
|
||||
0x0c, 0x00, 0x84, 0x00, 0x00, 0xff, 0xff, 0xf7, 0xf5, 0xf5, 0xee,
|
||||
0xe9, 0xe9, 0xe5, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0xe7, 0xe7,
|
||||
0xe7, 0x5e, 0x5e, 0x5e, 0xf3, 0xf3, 0xed, 0x8e, 0x8e, 0x8e, 0xe0,
|
||||
0xe0, 0xe0, 0x9f, 0x9f, 0x9f, 0x93, 0x93, 0x93, 0xa7, 0xa7, 0xa7,
|
||||
0x9e, 0x9e, 0x9e, 0x69, 0x5e, 0x10, 0x27, 0x20, 0x82, 0x0a, 0x01,
|
||||
0x00, 0x3b},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("to string", func() {
|
||||
d := NewDecoder(strings.NewReader("!binary YWJjZGVmZw=="))
|
||||
var v string
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal("abcdefg"))
|
||||
})
|
||||
|
||||
It("to string via alternate form", func() {
|
||||
d := NewDecoder(strings.NewReader("!!binary YWJjZGVmZw=="))
|
||||
var v string
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal("abcdefg"))
|
||||
})
|
||||
|
||||
It("to interface", func() {
|
||||
d := NewDecoder(strings.NewReader("!binary YWJjZGVmZw=="))
|
||||
var v interface{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal([]byte("abcdefg")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Aliases", func() {
|
||||
Context("to known types", func() {
|
||||
It("aliases scalars", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_10.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string][]string)
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string][]string{
|
||||
"hr": {"Mark McGwire", "Sammy Sosa"},
|
||||
"rbi": {"Sammy Sosa", "Ken Griffey"},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("aliases sequences", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
hr: &ss
|
||||
- MG
|
||||
- SS
|
||||
rbi: *ss
|
||||
`))
|
||||
v := make(map[string][]string)
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string][]string{
|
||||
"hr": {"MG", "SS"},
|
||||
"rbi": {"MG", "SS"},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("aliases maps", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
hr: &ss
|
||||
MG : SS
|
||||
rbi: *ss
|
||||
`))
|
||||
v := make(map[string]map[string]string)
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]map[string]string{
|
||||
"hr": {"MG": "SS"},
|
||||
"rbi": {"MG": "SS"},
|
||||
}))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
It("aliases to different types", func() {
|
||||
type S struct {
|
||||
A map[string]int
|
||||
C map[string]string
|
||||
}
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
a: &map
|
||||
b : 1
|
||||
c: *map
|
||||
`))
|
||||
var s S
|
||||
err := d.Decode(&s)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(s).To(Equal(S{
|
||||
A: map[string]int{"b": 1},
|
||||
C: map[string]string{"b": "1"},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("fails if an anchor is undefined", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
a: *missing
|
||||
`))
|
||||
m := make(map[string]string)
|
||||
err := d.Decode(&m)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(MatchRegexp("missing anchor.*line.*column.*"))
|
||||
})
|
||||
|
||||
Context("to Interface", func() {
|
||||
It("aliases scalars", func() {
|
||||
f, _ := os.Open("fixtures/specification/example2_10.yaml")
|
||||
d := NewDecoder(f)
|
||||
v := make(map[string]interface{})
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"hr": []interface{}{"Mark McGwire", "Sammy Sosa"},
|
||||
"rbi": []interface{}{"Sammy Sosa", "Ken Griffey"},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("aliases sequences", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
hr: &ss
|
||||
- MG
|
||||
- SS
|
||||
rbi: *ss
|
||||
`))
|
||||
v := make(map[string]interface{})
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"hr": []interface{}{"MG", "SS"},
|
||||
"rbi": []interface{}{"MG", "SS"},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("aliases maps", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
hr: &ss
|
||||
MG : SS
|
||||
rbi: *ss
|
||||
`))
|
||||
v := make(map[string]interface{})
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"hr": map[interface{}]interface{}{"MG": "SS"},
|
||||
"rbi": map[interface{}]interface{}{"MG": "SS"},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("supports duplicate aliases", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
a: &a
|
||||
b: 1
|
||||
x: *a
|
||||
y: *a
|
||||
`))
|
||||
v := make(map[string]interface{})
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"a": map[interface{}]interface{}{"b": int64(1)},
|
||||
"x": map[interface{}]interface{}{"b": int64(1)},
|
||||
"y": map[interface{}]interface{}{"b": int64(1)},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("supports overriden anchors", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
First occurrence: &anchor Foo
|
||||
Second occurrence: *anchor
|
||||
Override anchor: &anchor Bar
|
||||
Reuse anchor: *anchor
|
||||
`))
|
||||
v := make(map[string]interface{})
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"First occurrence": "Foo",
|
||||
"Second occurrence": "Foo",
|
||||
"Override anchor": "Bar",
|
||||
"Reuse anchor": "Bar",
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("fails if an anchor is undefined", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
a: *missing
|
||||
`))
|
||||
var i interface{}
|
||||
err := d.Decode(&i)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(MatchRegexp("missing anchor.*line.*column.*"))
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
It("supports composing aliases", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
a: &a b
|
||||
x: &b
|
||||
d: *a
|
||||
z: *b
|
||||
`))
|
||||
v := make(map[string]interface{})
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"a": "b",
|
||||
"x": map[interface{}]interface{}{"d": "b"},
|
||||
"z": map[interface{}]interface{}{"d": "b"},
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("redefinition while composing aliases", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
a: &a b
|
||||
x: &c
|
||||
d : &a 1
|
||||
y: *a
|
||||
`))
|
||||
v := make(map[string]interface{})
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(map[string]interface{}{
|
||||
"a": "b",
|
||||
"x": map[interface{}]interface{}{"d": int64(1)},
|
||||
"y": int64(1),
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
It("can parse nested anchors", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
a:
|
||||
aa: &x
|
||||
aaa: 1
|
||||
ab:
|
||||
aba: &y
|
||||
abaa:
|
||||
abaaa: *x
|
||||
b:
|
||||
- ba:
|
||||
baa: *y
|
||||
`))
|
||||
v := make(map[string]interface{})
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
Context("When decoding fails", func() {
|
||||
It("returns an error", func() {
|
||||
f, _ := os.Open("fixtures/specification/example_empty.yaml")
|
||||
d := NewDecoder(f)
|
||||
var v interface{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Expected document start at line 0, column 0"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Unmarshaler support", func() {
|
||||
Context("Receiver is a value", func() {
|
||||
It("the Marshaler interface is not used", func() {
|
||||
d := NewDecoder(strings.NewReader("abc\n"))
|
||||
v := hasMarshaler{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v.Value).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
Context("Receiver is a pointer", func() {
|
||||
It("uses the Marshaler interface when a pointer", func() {
|
||||
d := NewDecoder(strings.NewReader("abc\n"))
|
||||
v := hasPtrMarshaler{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("marshals a scalar", func() {
|
||||
d := NewDecoder(strings.NewReader("abc\n"))
|
||||
v := hasPtrMarshaler{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v.Tag).To(Equal(yaml_STR_TAG))
|
||||
Expect(v.Value).To(Equal("abc"))
|
||||
})
|
||||
|
||||
It("marshals a sequence", func() {
|
||||
d := NewDecoder(strings.NewReader("[abc, def]\n"))
|
||||
v := hasPtrMarshaler{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v.Tag).To(Equal(yaml_SEQ_TAG))
|
||||
Expect(v.Value).To(Equal([]interface{}{"abc", "def"}))
|
||||
})
|
||||
|
||||
It("marshals a map", func() {
|
||||
d := NewDecoder(strings.NewReader("{ a: bc}\n"))
|
||||
v := hasPtrMarshaler{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v.Tag).To(Equal(yaml_MAP_TAG))
|
||||
Expect(v.Value).To(Equal(map[interface{}]interface{}{"a": "bc"}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("Marshals into a Number", func() {
|
||||
It("when the number is an int", func() {
|
||||
d := NewDecoder(strings.NewReader("123\n"))
|
||||
d.UseNumber()
|
||||
var v Number
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v.String()).To(Equal("123"))
|
||||
})
|
||||
|
||||
It("when the number is an float", func() {
|
||||
d := NewDecoder(strings.NewReader("1.23\n"))
|
||||
d.UseNumber()
|
||||
var v Number
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v.String()).To(Equal("1.23"))
|
||||
})
|
||||
|
||||
It("it fails when its a non-Number", func() {
|
||||
d := NewDecoder(strings.NewReader("on\n"))
|
||||
d.UseNumber()
|
||||
var v Number
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(MatchRegexp("Not a number: 'on' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("returns a Number", func() {
|
||||
d := NewDecoder(strings.NewReader("123\n"))
|
||||
d.UseNumber()
|
||||
var v interface{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(BeAssignableToTypeOf(Number("")))
|
||||
|
||||
n := v.(Number)
|
||||
Expect(n.String()).To(Equal("123"))
|
||||
})
|
||||
})
|
||||
Context("When there are special characters", func() {
|
||||
It("returns an error", func() {
|
||||
d := NewDecoder(strings.NewReader(`
|
||||
---
|
||||
applications:
|
||||
- name: m
|
||||
services:
|
||||
- !@#
|
||||
`))
|
||||
var v interface{}
|
||||
|
||||
err := d.Decode(&v)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(MatchRegexp("yaml.*did not find.*line.*column.*"))
|
||||
})
|
||||
})
|
||||
})
|
||||
2072
vendor/github.com/cloudfoundry-incubator/candiedyaml/emitter.go
generated
vendored
Normal file
2072
vendor/github.com/cloudfoundry-incubator/candiedyaml/emitter.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
395
vendor/github.com/cloudfoundry-incubator/candiedyaml/encode.go
generated
vendored
Normal file
395
vendor/github.com/cloudfoundry-incubator/candiedyaml/encode.go
generated
vendored
Normal file
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"math"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
timeTimeType = reflect.TypeOf(time.Time{})
|
||||
marshalerType = reflect.TypeOf(new(Marshaler)).Elem()
|
||||
numberType = reflect.TypeOf(Number(""))
|
||||
nonPrintable = regexp.MustCompile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFD]")
|
||||
multiline = regexp.MustCompile("\n|\u0085|\u2028|\u2029")
|
||||
|
||||
shortTags = map[string]string{
|
||||
yaml_NULL_TAG: "!!null",
|
||||
yaml_BOOL_TAG: "!!bool",
|
||||
yaml_STR_TAG: "!!str",
|
||||
yaml_INT_TAG: "!!int",
|
||||
yaml_FLOAT_TAG: "!!float",
|
||||
yaml_TIMESTAMP_TAG: "!!timestamp",
|
||||
yaml_SEQ_TAG: "!!seq",
|
||||
yaml_MAP_TAG: "!!map",
|
||||
yaml_BINARY_TAG: "!!binary",
|
||||
}
|
||||
)
|
||||
|
||||
type Marshaler interface {
|
||||
MarshalYAML() (tag string, value interface{}, err error)
|
||||
}
|
||||
|
||||
// An Encoder writes JSON objects to an output stream.
|
||||
type Encoder struct {
|
||||
w io.Writer
|
||||
emitter yaml_emitter_t
|
||||
event yaml_event_t
|
||||
flow bool
|
||||
err error
|
||||
}
|
||||
|
||||
func Marshal(v interface{}) ([]byte, error) {
|
||||
b := bytes.Buffer{}
|
||||
e := NewEncoder(&b)
|
||||
err := e.Encode(v)
|
||||
return b.Bytes(), err
|
||||
}
|
||||
|
||||
// NewEncoder returns a new encoder that writes to w.
|
||||
func NewEncoder(w io.Writer) *Encoder {
|
||||
e := &Encoder{w: w}
|
||||
yaml_emitter_initialize(&e.emitter)
|
||||
yaml_emitter_set_output_writer(&e.emitter, e.w)
|
||||
yaml_stream_start_event_initialize(&e.event, yaml_UTF8_ENCODING)
|
||||
e.emit()
|
||||
yaml_document_start_event_initialize(&e.event, nil, nil, true)
|
||||
e.emit()
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Encoder) Encode(v interface{}) (err error) {
|
||||
defer recovery(&err)
|
||||
|
||||
if e.err != nil {
|
||||
return e.err
|
||||
}
|
||||
|
||||
e.marshal("", reflect.ValueOf(v), true)
|
||||
|
||||
yaml_document_end_event_initialize(&e.event, true)
|
||||
e.emit()
|
||||
e.emitter.open_ended = false
|
||||
yaml_stream_end_event_initialize(&e.event)
|
||||
e.emit()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Encoder) emit() {
|
||||
if !yaml_emitter_emit(&e.emitter, &e.event) {
|
||||
panic("bad emit")
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Encoder) marshal(tag string, v reflect.Value, allowAddr bool) {
|
||||
vt := v.Type()
|
||||
|
||||
if vt.Implements(marshalerType) {
|
||||
e.emitMarshaler(tag, v)
|
||||
return
|
||||
}
|
||||
|
||||
if vt.Kind() != reflect.Ptr && allowAddr {
|
||||
if reflect.PtrTo(vt).Implements(marshalerType) {
|
||||
e.emitAddrMarshaler(tag, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
switch v.Kind() {
|
||||
case reflect.Interface:
|
||||
if v.IsNil() {
|
||||
e.emitNil()
|
||||
} else {
|
||||
e.marshal(tag, v.Elem(), allowAddr)
|
||||
}
|
||||
case reflect.Map:
|
||||
e.emitMap(tag, v)
|
||||
case reflect.Ptr:
|
||||
if v.IsNil() {
|
||||
e.emitNil()
|
||||
} else {
|
||||
e.marshal(tag, v.Elem(), true)
|
||||
}
|
||||
case reflect.Struct:
|
||||
e.emitStruct(tag, v)
|
||||
case reflect.Slice:
|
||||
e.emitSlice(tag, v)
|
||||
case reflect.String:
|
||||
e.emitString(tag, v)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
e.emitInt(tag, v)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
e.emitUint(tag, v)
|
||||
case reflect.Float32, reflect.Float64:
|
||||
e.emitFloat(tag, v)
|
||||
case reflect.Bool:
|
||||
e.emitBool(tag, v)
|
||||
default:
|
||||
panic("Can't marshal type yet: " + v.Type().String())
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Encoder) emitMap(tag string, v reflect.Value) {
|
||||
e.mapping(tag, func() {
|
||||
var keys stringValues = v.MapKeys()
|
||||
sort.Sort(keys)
|
||||
for _, k := range keys {
|
||||
e.marshal("", k, true)
|
||||
e.marshal("", v.MapIndex(k), true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Encoder) emitStruct(tag string, v reflect.Value) {
|
||||
if v.Type() == timeTimeType {
|
||||
e.emitTime(tag, v)
|
||||
return
|
||||
}
|
||||
|
||||
fields := cachedTypeFields(v.Type())
|
||||
|
||||
e.mapping(tag, func() {
|
||||
for _, f := range fields {
|
||||
fv := fieldByIndex(v, f.index)
|
||||
if !fv.IsValid() || f.omitEmpty && isEmptyValue(fv) {
|
||||
continue
|
||||
}
|
||||
|
||||
e.marshal("", reflect.ValueOf(f.name), true)
|
||||
e.flow = f.flow
|
||||
e.marshal("", fv, true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Encoder) emitTime(tag string, v reflect.Value) {
|
||||
t := v.Interface().(time.Time)
|
||||
bytes, _ := t.MarshalText()
|
||||
e.emitScalar(string(bytes), "", tag, yaml_PLAIN_SCALAR_STYLE)
|
||||
}
|
||||
|
||||
func isEmptyValue(v reflect.Value) bool {
|
||||
switch v.Kind() {
|
||||
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
|
||||
return v.Len() == 0
|
||||
case reflect.Bool:
|
||||
return !v.Bool()
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return v.Int() == 0
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return v.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return v.Float() == 0
|
||||
case reflect.Interface, reflect.Ptr:
|
||||
return v.IsNil()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e *Encoder) mapping(tag string, f func()) {
|
||||
implicit := tag == ""
|
||||
style := yaml_BLOCK_MAPPING_STYLE
|
||||
if e.flow {
|
||||
e.flow = false
|
||||
style = yaml_FLOW_MAPPING_STYLE
|
||||
}
|
||||
yaml_mapping_start_event_initialize(&e.event, nil, []byte(tag), implicit, style)
|
||||
e.emit()
|
||||
|
||||
f()
|
||||
|
||||
yaml_mapping_end_event_initialize(&e.event)
|
||||
e.emit()
|
||||
}
|
||||
|
||||
func (e *Encoder) emitSlice(tag string, v reflect.Value) {
|
||||
if v.Type() == byteSliceType {
|
||||
e.emitBase64(tag, v)
|
||||
return
|
||||
}
|
||||
|
||||
implicit := tag == ""
|
||||
style := yaml_BLOCK_SEQUENCE_STYLE
|
||||
if e.flow {
|
||||
e.flow = false
|
||||
style = yaml_FLOW_SEQUENCE_STYLE
|
||||
}
|
||||
yaml_sequence_start_event_initialize(&e.event, nil, []byte(tag), implicit, style)
|
||||
e.emit()
|
||||
|
||||
n := v.Len()
|
||||
for i := 0; i < n; i++ {
|
||||
e.marshal("", v.Index(i), true)
|
||||
}
|
||||
|
||||
yaml_sequence_end_event_initialize(&e.event)
|
||||
e.emit()
|
||||
}
|
||||
|
||||
func (e *Encoder) emitBase64(tag string, v reflect.Value) {
|
||||
if v.IsNil() {
|
||||
e.emitNil()
|
||||
return
|
||||
}
|
||||
|
||||
s := v.Bytes()
|
||||
|
||||
dst := make([]byte, base64.StdEncoding.EncodedLen(len(s)))
|
||||
|
||||
base64.StdEncoding.Encode(dst, s)
|
||||
e.emitScalar(string(dst), "", yaml_BINARY_TAG, yaml_DOUBLE_QUOTED_SCALAR_STYLE)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitString(tag string, v reflect.Value) {
|
||||
var style yaml_scalar_style_t
|
||||
s := v.String()
|
||||
|
||||
if nonPrintable.MatchString(s) {
|
||||
e.emitBase64(tag, v)
|
||||
return
|
||||
}
|
||||
|
||||
if v.Type() == numberType {
|
||||
style = yaml_PLAIN_SCALAR_STYLE
|
||||
} else {
|
||||
event := yaml_event_t{
|
||||
implicit: true,
|
||||
value: []byte(s),
|
||||
}
|
||||
|
||||
rtag, _ := resolveInterface(event, false)
|
||||
if tag == "" && rtag != yaml_STR_TAG {
|
||||
style = yaml_DOUBLE_QUOTED_SCALAR_STYLE
|
||||
} else if multiline.MatchString(s) {
|
||||
style = yaml_LITERAL_SCALAR_STYLE
|
||||
} else {
|
||||
style = yaml_PLAIN_SCALAR_STYLE
|
||||
}
|
||||
}
|
||||
|
||||
e.emitScalar(s, "", tag, style)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitBool(tag string, v reflect.Value) {
|
||||
s := strconv.FormatBool(v.Bool())
|
||||
e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitInt(tag string, v reflect.Value) {
|
||||
s := strconv.FormatInt(v.Int(), 10)
|
||||
e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitUint(tag string, v reflect.Value) {
|
||||
s := strconv.FormatUint(v.Uint(), 10)
|
||||
e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitFloat(tag string, v reflect.Value) {
|
||||
f := v.Float()
|
||||
|
||||
var s string
|
||||
switch {
|
||||
case math.IsNaN(f):
|
||||
s = ".nan"
|
||||
case math.IsInf(f, 1):
|
||||
s = "+.inf"
|
||||
case math.IsInf(f, -1):
|
||||
s = "-.inf"
|
||||
default:
|
||||
s = strconv.FormatFloat(f, 'g', -1, v.Type().Bits())
|
||||
}
|
||||
|
||||
e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitNil() {
|
||||
e.emitScalar("null", "", "", yaml_PLAIN_SCALAR_STYLE)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitScalar(value, anchor, tag string, style yaml_scalar_style_t) {
|
||||
implicit := tag == ""
|
||||
if !implicit {
|
||||
style = yaml_PLAIN_SCALAR_STYLE
|
||||
}
|
||||
|
||||
stag := shortTags[tag]
|
||||
if stag == "" {
|
||||
stag = tag
|
||||
}
|
||||
|
||||
yaml_scalar_event_initialize(&e.event, []byte(anchor), []byte(stag), []byte(value), implicit, implicit, style)
|
||||
e.emit()
|
||||
}
|
||||
|
||||
func (e *Encoder) emitMarshaler(tag string, v reflect.Value) {
|
||||
if v.Kind() == reflect.Ptr && v.IsNil() {
|
||||
e.emitNil()
|
||||
return
|
||||
}
|
||||
|
||||
m := v.Interface().(Marshaler)
|
||||
if m == nil {
|
||||
e.emitNil()
|
||||
return
|
||||
}
|
||||
t, val, err := m.MarshalYAML()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if val == nil {
|
||||
e.emitNil()
|
||||
return
|
||||
}
|
||||
|
||||
e.marshal(t, reflect.ValueOf(val), false)
|
||||
}
|
||||
|
||||
func (e *Encoder) emitAddrMarshaler(tag string, v reflect.Value) {
|
||||
if !v.CanAddr() {
|
||||
e.marshal(tag, v, false)
|
||||
return
|
||||
}
|
||||
|
||||
va := v.Addr()
|
||||
if va.IsNil() {
|
||||
e.emitNil()
|
||||
return
|
||||
}
|
||||
|
||||
m := v.Interface().(Marshaler)
|
||||
t, val, err := m.MarshalYAML()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if val == nil {
|
||||
e.emitNil()
|
||||
return
|
||||
}
|
||||
|
||||
e.marshal(t, reflect.ValueOf(val), false)
|
||||
}
|
||||
642
vendor/github.com/cloudfoundry-incubator/candiedyaml/encode_test.go
generated
vendored
Normal file
642
vendor/github.com/cloudfoundry-incubator/candiedyaml/encode_test.go
generated
vendored
Normal file
@@ -0,0 +1,642 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Encode", func() {
|
||||
var buf *bytes.Buffer
|
||||
var enc *Encoder
|
||||
|
||||
BeforeEach(func() {
|
||||
buf = &bytes.Buffer{}
|
||||
enc = NewEncoder(buf)
|
||||
})
|
||||
|
||||
Context("Scalars", func() {
|
||||
It("handles strings", func() {
|
||||
err := enc.Encode("abc")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`abc
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("handles really short strings", func() {
|
||||
err := enc.Encode(".")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`.
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("encodes strings with multilines", func() {
|
||||
err := enc.Encode("a\nc")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`|-
|
||||
a
|
||||
c
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("handles strings that match known scalars", func() {
|
||||
err := enc.Encode("true")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`"true"
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("handles strings that contain colons followed by whitespace", func() {
|
||||
err := enc.Encode("contains: colon")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`'contains: colon'
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
Context("handles ints", func() {
|
||||
It("handles ints", func() {
|
||||
err := enc.Encode(13)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("13\n"))
|
||||
})
|
||||
|
||||
It("handles uints", func() {
|
||||
err := enc.Encode(uint64(1))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("1\n"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("handles floats", func() {
|
||||
It("handles float32", func() {
|
||||
err := enc.Encode(float32(1.234))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("1.234\n"))
|
||||
|
||||
})
|
||||
|
||||
It("handles float64", func() {
|
||||
err := enc.Encode(float64(1.2e23))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("1.2e+23\n"))
|
||||
})
|
||||
|
||||
It("handles NaN", func() {
|
||||
err := enc.Encode(math.NaN())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(".nan\n"))
|
||||
})
|
||||
|
||||
It("handles infinity", func() {
|
||||
err := enc.Encode(math.Inf(-1))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("-.inf\n"))
|
||||
})
|
||||
})
|
||||
|
||||
It("handles bools", func() {
|
||||
err := enc.Encode(true)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("true\n"))
|
||||
})
|
||||
|
||||
It("handles time.Time", func() {
|
||||
t := time.Now()
|
||||
err := enc.Encode(t)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
bytes, _ := t.MarshalText()
|
||||
Expect(buf.String()).To(Equal(string(bytes) + "\n"))
|
||||
})
|
||||
|
||||
Context("Null", func() {
|
||||
It("fails on nil", func() {
|
||||
err := enc.Encode(nil)
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
It("handles []byte", func() {
|
||||
err := enc.Encode([]byte{'a', 'b', 'c'})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("!!binary YWJj\n"))
|
||||
})
|
||||
|
||||
Context("Ptrs", func() {
|
||||
It("handles ptr of a type", func() {
|
||||
p := new(int)
|
||||
*p = 10
|
||||
err := enc.Encode(p)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("10\n"))
|
||||
})
|
||||
|
||||
It("handles nil ptr", func() {
|
||||
var p *int
|
||||
err := enc.Encode(p)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("null\n"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Structs", func() {
|
||||
It("handles simple structs", func() {
|
||||
type batter struct {
|
||||
Name string
|
||||
HR int64
|
||||
AVG float64
|
||||
}
|
||||
|
||||
batters := []batter{
|
||||
batter{Name: "Mark McGwire", HR: 65, AVG: 0.278},
|
||||
batter{Name: "Sammy Sosa", HR: 63, AVG: 0.288},
|
||||
}
|
||||
err := enc.Encode(batters)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`- Name: Mark McGwire
|
||||
HR: 65
|
||||
AVG: 0.278
|
||||
- Name: Sammy Sosa
|
||||
HR: 63
|
||||
AVG: 0.288
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("handles tagged structs", func() {
|
||||
type batter struct {
|
||||
Name string `yaml:"name"`
|
||||
HR int64
|
||||
AVG float64 `yaml:"avg"`
|
||||
}
|
||||
|
||||
batters := []batter{
|
||||
batter{Name: "Mark McGwire", HR: 65, AVG: 0.278},
|
||||
batter{Name: "Sammy Sosa", HR: 63, AVG: 0.288},
|
||||
}
|
||||
err := enc.Encode(batters)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`- name: Mark McGwire
|
||||
HR: 65
|
||||
avg: 0.278
|
||||
- name: Sammy Sosa
|
||||
HR: 63
|
||||
avg: 0.288
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("handles nested structs", func() {
|
||||
type nestedConfig struct {
|
||||
AString string `yaml:"str"`
|
||||
Integer int `yaml:"int"`
|
||||
}
|
||||
type config struct {
|
||||
TopString string
|
||||
Nested nestedConfig
|
||||
}
|
||||
|
||||
cfg := config{
|
||||
TopString: "def",
|
||||
Nested: nestedConfig{
|
||||
AString: "abc",
|
||||
Integer: 123,
|
||||
},
|
||||
}
|
||||
|
||||
err := enc.Encode(cfg)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`TopString: def
|
||||
Nested:
|
||||
str: abc
|
||||
int: 123
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("handles inline structs", func() {
|
||||
type NestedConfig struct {
|
||||
AString string `yaml:"str"`
|
||||
Integer int `yaml:"int"`
|
||||
}
|
||||
type config struct {
|
||||
TopString string
|
||||
NestedConfig
|
||||
}
|
||||
|
||||
cfg := config{
|
||||
TopString: "def",
|
||||
NestedConfig: NestedConfig{
|
||||
AString: "abc",
|
||||
Integer: 123,
|
||||
},
|
||||
}
|
||||
|
||||
err := enc.Encode(cfg)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`TopString: def
|
||||
str: abc
|
||||
int: 123
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("handles inline structs with conflicts", func() {
|
||||
type NestedConfig struct {
|
||||
AString string `yaml:"str"`
|
||||
Integer int `yaml:"int"`
|
||||
}
|
||||
type config struct {
|
||||
AString string `yaml:"str"`
|
||||
NestedConfig
|
||||
}
|
||||
|
||||
cfg := config{
|
||||
AString: "def",
|
||||
NestedConfig: NestedConfig{
|
||||
AString: "abc",
|
||||
Integer: 123,
|
||||
},
|
||||
}
|
||||
|
||||
err := enc.Encode(cfg)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`str: def
|
||||
int: 123
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Context("Sequence", func() {
|
||||
It("handles slices", func() {
|
||||
val := []string{"a", "b", "c"}
|
||||
err := enc.Encode(val)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`- a
|
||||
- b
|
||||
- c
|
||||
`))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("Maps", func() {
|
||||
It("Encodes simple maps", func() {
|
||||
err := enc.Encode(&map[string]string{
|
||||
"name": "Mark McGwire",
|
||||
"hr": "65",
|
||||
"avg": "0.278",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`avg: "0.278"
|
||||
hr: "65"
|
||||
name: Mark McGwire
|
||||
`))
|
||||
})
|
||||
|
||||
It("sorts by key when strings otherwise by kind", func() {
|
||||
err := enc.Encode(&map[interface{}]string{
|
||||
1.2: "float",
|
||||
8: "integer",
|
||||
"name": "Mark McGwire",
|
||||
"hr": "65",
|
||||
"avg": "0.278",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`8: integer
|
||||
1.2: float
|
||||
avg: "0.278"
|
||||
hr: "65"
|
||||
name: Mark McGwire
|
||||
`))
|
||||
})
|
||||
|
||||
It("encodes mix types", func() {
|
||||
err := enc.Encode(&map[string]interface{}{
|
||||
"name": "Mark McGwire",
|
||||
"hr": 65,
|
||||
"avg": 0.278,
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`avg: 0.278
|
||||
hr: 65
|
||||
name: Mark McGwire
|
||||
`))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Sequence of Maps", func() {
|
||||
It("encodes", func() {
|
||||
err := enc.Encode([]map[string]interface{}{
|
||||
{"name": "Mark McGwire",
|
||||
"hr": 65,
|
||||
"avg": 0.278,
|
||||
},
|
||||
{"name": "Sammy Sosa",
|
||||
"hr": 63,
|
||||
"avg": 0.288,
|
||||
},
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`- avg: 0.278
|
||||
hr: 65
|
||||
name: Mark McGwire
|
||||
- avg: 0.288
|
||||
hr: 63
|
||||
name: Sammy Sosa
|
||||
`))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("Maps of Sequence", func() {
|
||||
It("encodes", func() {
|
||||
err := enc.Encode(map[string][]interface{}{
|
||||
"name": []interface{}{"Mark McGwire", "Sammy Sosa"},
|
||||
"hr": []interface{}{65, 63},
|
||||
"avg": []interface{}{0.278, 0.288},
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(buf.String()).To(Equal(`avg:
|
||||
- 0.278
|
||||
- 0.288
|
||||
hr:
|
||||
- 65
|
||||
- 63
|
||||
name:
|
||||
- Mark McGwire
|
||||
- Sammy Sosa
|
||||
`))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("Flow", func() {
|
||||
It("flows structs", func() {
|
||||
type i struct {
|
||||
A string
|
||||
}
|
||||
type o struct {
|
||||
I i `yaml:"i,flow"`
|
||||
}
|
||||
|
||||
err := enc.Encode(o{
|
||||
I: i{A: "abc"},
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`i: {A: abc}
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("flows sequences", func() {
|
||||
type i struct {
|
||||
A string
|
||||
}
|
||||
type o struct {
|
||||
I []i `yaml:"i,flow"`
|
||||
}
|
||||
|
||||
err := enc.Encode(o{
|
||||
I: []i{{A: "abc"}},
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`i: [{A: abc}]
|
||||
`))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("Omit empty", func() {
|
||||
It("omits nil ptrs", func() {
|
||||
type i struct {
|
||||
A *string `yaml:"a,omitempty"`
|
||||
}
|
||||
type o struct {
|
||||
I []i `yaml:"i,flow"`
|
||||
}
|
||||
|
||||
err := enc.Encode(o{
|
||||
I: []i{{A: nil}},
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`i: [{}]
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Context("Skip field", func() {
|
||||
It("does not include the field", func() {
|
||||
type a struct {
|
||||
B string `yaml:"-"`
|
||||
C string
|
||||
}
|
||||
|
||||
err := enc.Encode(a{B: "b", C: "c"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`C: c
|
||||
`))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("Marshaler support", func() {
|
||||
Context("Receiver is a value", func() {
|
||||
It("uses the Marshaler interface when a value", func() {
|
||||
err := enc.Encode(hasMarshaler{Value: 123})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("123\n"))
|
||||
})
|
||||
|
||||
It("uses the Marshaler interface when a pointer", func() {
|
||||
err := enc.Encode(&hasMarshaler{Value: "abc"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`abc
|
||||
`))
|
||||
})
|
||||
|
||||
Context("when it fails", func() {
|
||||
It("returns an error", func() {
|
||||
err := enc.Encode(&hasMarshaler{Value: "abc", Error: errors.New("fail")})
|
||||
Expect(err).To(MatchError("fail"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("Receiver is a pointer", func() {
|
||||
It("uses the Marshaler interface when a pointer", func() {
|
||||
err := enc.Encode(&hasPtrMarshaler{Value: map[string]string{"a": "b"}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`a: b
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("skips the Marshaler when its a value", func() {
|
||||
err := enc.Encode(hasPtrMarshaler{Value: map[string]string{"a": "b"}})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`Tag: ""
|
||||
Value:
|
||||
a: b
|
||||
Error: null
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
Context("the receiver is nil", func() {
|
||||
var ptr *hasPtrMarshaler
|
||||
|
||||
Context("when it fails", func() {
|
||||
It("returns an error", func() {
|
||||
err := enc.Encode(&hasPtrMarshaler{Value: "abc", Error: errors.New("fail")})
|
||||
Expect(err).To(MatchError("fail"))
|
||||
})
|
||||
})
|
||||
|
||||
It("returns a null", func() {
|
||||
err := enc.Encode(ptr)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`null
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("returns a null value for ptr types", func() {
|
||||
err := enc.Encode(map[string]*hasPtrMarshaler{"a": ptr})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`a: null
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("panics when used as a nil interface", func() {
|
||||
Expect(func() { enc.Encode(map[string]Marshaler{"a": ptr}) }).To(Panic())
|
||||
})
|
||||
})
|
||||
|
||||
Context("the receiver has a nil value", func() {
|
||||
ptr := &hasPtrMarshaler{Value: nil}
|
||||
|
||||
It("returns null", func() {
|
||||
err := enc.Encode(ptr)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`null
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
Context("in a map", func() {
|
||||
It("returns a null value for ptr types", func() {
|
||||
err := enc.Encode(map[string]*hasPtrMarshaler{"a": ptr})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`a: null
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("returns a null value for interface types", func() {
|
||||
err := enc.Encode(map[string]Marshaler{"a": ptr})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`a: null
|
||||
`))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Context("in a slice", func() {
|
||||
It("returns a null value for ptr types", func() {
|
||||
err := enc.Encode([]*hasPtrMarshaler{ptr})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`- null
|
||||
`))
|
||||
|
||||
})
|
||||
|
||||
It("returns a null value for interface types", func() {
|
||||
err := enc.Encode([]Marshaler{ptr})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal(`- null
|
||||
`))
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("Number type", func() {
|
||||
It("encodes as a number", func() {
|
||||
n := Number("12345")
|
||||
err := enc.Encode(n)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(buf.String()).To(Equal("12345\n"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
type hasMarshaler struct {
|
||||
Value interface{}
|
||||
Error error
|
||||
}
|
||||
|
||||
func (m hasMarshaler) MarshalYAML() (string, interface{}, error) {
|
||||
return "", m.Value, m.Error
|
||||
}
|
||||
|
||||
func (m hasMarshaler) UnmarshalYAML(tag string, value interface{}) error {
|
||||
m.Value = value
|
||||
return nil
|
||||
}
|
||||
|
||||
type hasPtrMarshaler struct {
|
||||
Tag string
|
||||
Value interface{}
|
||||
Error error
|
||||
}
|
||||
|
||||
func (m *hasPtrMarshaler) MarshalYAML() (string, interface{}, error) {
|
||||
return "", m.Value, m.Error
|
||||
}
|
||||
|
||||
func (m *hasPtrMarshaler) UnmarshalYAML(tag string, value interface{}) error {
|
||||
m.Tag = tag
|
||||
m.Value = value
|
||||
return nil
|
||||
}
|
||||
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_1.yaml
generated
vendored
Normal file
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_1.yaml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
- Mark McGwire
|
||||
- Sammy Sosa
|
||||
- Ken Griffey
|
||||
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_10.yaml
generated
vendored
Normal file
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_10.yaml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
hr:
|
||||
- Mark McGwire
|
||||
# Following node labeled SS
|
||||
- &SS Sammy Sosa
|
||||
rbi:
|
||||
- *SS # Subsequent occurrence
|
||||
- Ken Griffey
|
||||
9
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_11.yaml
generated
vendored
Normal file
9
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_11.yaml
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
? - Detroit Tigers
|
||||
- Chicago cubs
|
||||
:
|
||||
- 2001-07-23
|
||||
|
||||
? [ New York Yankees,
|
||||
Atlanta Braves ]
|
||||
: [ 2001-07-02, 2001-08-12,
|
||||
2001-08-14 ]
|
||||
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_12.yaml
generated
vendored
Normal file
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_12.yaml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
# products purchased
|
||||
- item : Super Hoop
|
||||
quantity: 1
|
||||
- item : Basketball
|
||||
quantity: 4
|
||||
- item : Big Shoes
|
||||
quantity: 1
|
||||
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_13.yaml
generated
vendored
Normal file
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_13.yaml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# ASCII Art
|
||||
--- |
|
||||
\//||\/||
|
||||
// || ||__
|
||||
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_14.yaml
generated
vendored
Normal file
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_14.yaml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
Mark McGwire's
|
||||
year was crippled
|
||||
by a knee injury.
|
||||
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_15.yaml
generated
vendored
Normal file
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_15.yaml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
>
|
||||
Sammy Sosa completed another
|
||||
fine season with great stats.
|
||||
|
||||
63 Home Runs
|
||||
0.288 Batting Average
|
||||
|
||||
What a year!
|
||||
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_15_dumped.yaml
generated
vendored
Normal file
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_15_dumped.yaml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
>
|
||||
Sammy Sosa completed another fine season with great stats.
|
||||
|
||||
63 Home Runs
|
||||
0.288 Batting Average
|
||||
|
||||
What a year!
|
||||
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_16.yaml
generated
vendored
Normal file
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_16.yaml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
name: Mark McGwire
|
||||
accomplishment: >
|
||||
Mark set a major league
|
||||
home run record in 1998.
|
||||
stats: |
|
||||
65 Home Runs
|
||||
0.278 Batting Average
|
||||
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17.yaml
generated
vendored
Normal file
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17.yaml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
unicode: "Sosa did fine.\u263A"
|
||||
control: "\b1998\t1999\t2000\n"
|
||||
hexesc: "\x0D\x0A is \r\n"
|
||||
|
||||
single: '"Howdy!" he cried.'
|
||||
quoted: ' # not a ''comment''.'
|
||||
tie-fighter: '|\-*-/|'
|
||||
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_control.yaml
generated
vendored
Normal file
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_control.yaml
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
control: "\b1998\t1999\t2000\n"
|
||||
|
||||
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_hexesc.yaml
generated
vendored
Normal file
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_hexesc.yaml
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
hexesc: "\x0D\x0A is \r\n"
|
||||
|
||||
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_quoted.yaml
generated
vendored
Normal file
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_quoted.yaml
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
quoted: ' # not a ''comment''.'
|
||||
|
||||
1
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_single.yaml
generated
vendored
Normal file
1
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_single.yaml
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
single: '"Howdy!" he cried.'
|
||||
1
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_tie_fighter.yaml
generated
vendored
Normal file
1
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_tie_fighter.yaml
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
tie-fighter: '|\-*-/|'
|
||||
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_unicode.yaml
generated
vendored
Normal file
2
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_17_unicode.yaml
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
unicode: "Sosa did fine.\u263A"
|
||||
|
||||
6
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_18.yaml
generated
vendored
Normal file
6
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_18.yaml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
plain:
|
||||
This unquoted scalar
|
||||
spans many lines.
|
||||
|
||||
quoted: "So does this
|
||||
quoted scalar.\n"
|
||||
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_19.yaml
generated
vendored
Normal file
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_19.yaml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
canonical: 12345
|
||||
decimal: +12_345
|
||||
octal: 014
|
||||
hexadecimal: 0xC
|
||||
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_2.yaml
generated
vendored
Normal file
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_2.yaml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
hr: 65 # Home runs
|
||||
avg: 0.278 # Batting average
|
||||
rbi: 147 # Runs Batted In
|
||||
5
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_20.yaml
generated
vendored
Normal file
5
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_20.yaml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
canonical: 1.23015e+3
|
||||
exponential: 12.3015e+02
|
||||
fixed: 1_230.15
|
||||
negative infinity: -.inf
|
||||
not a number: .NaN
|
||||
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_21.yaml
generated
vendored
Normal file
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_21.yaml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
null: ~
|
||||
true: yes
|
||||
false: no
|
||||
string: '12345'
|
||||
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_22.yaml
generated
vendored
Normal file
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_22.yaml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
canonical: 2001-12-15T02:59:43.1Z
|
||||
iso8601: 2001-12-14t21:59:43.10-05:00
|
||||
spaced: 2001-12-14 21:59:43.10 -5
|
||||
date: 2002-12-14
|
||||
14
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23.yaml
generated
vendored
Normal file
14
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23.yaml
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
not-date: !!str 2002-04-28
|
||||
|
||||
picture: !!binary "\
|
||||
R0lGODlhDAAMAIQAAP//9/X\
|
||||
17unp5WZmZgAAAOfn515eXv\
|
||||
Pz7Y6OjuDg4J+fn5OTk6enp\
|
||||
56enmleECcgggoBADs="
|
||||
|
||||
application specific tag: !something |
|
||||
The semantics of the tag
|
||||
above may be different for
|
||||
different documents.
|
||||
|
||||
5
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23_application.yaml
generated
vendored
Normal file
5
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23_application.yaml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
application specific tag: !something |
|
||||
The semantics of the tag
|
||||
above may be different for
|
||||
different documents.
|
||||
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23_non_date.yaml
generated
vendored
Normal file
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23_non_date.yaml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
not-date: !!str 2002-04-28
|
||||
|
||||
9
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23_picture.yaml
generated
vendored
Normal file
9
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_23_picture.yaml
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
picture: !!binary "\
|
||||
R0lGODlhDAAMAIQAAP//9/X\
|
||||
17unp5WZmZgAAAOfn515eXv\
|
||||
Pz7Y6OjuDg4J+fn5OTk6enp\
|
||||
56enmleECcgggoBADs="
|
||||
|
||||
|
||||
|
||||
14
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_24.yaml
generated
vendored
Normal file
14
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_24.yaml
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
%TAG ! tag:clarkevans.com,2002:
|
||||
--- !shape
|
||||
# Use the ! handle for presenting
|
||||
# tag:clarkevans.com,2002:circle
|
||||
- !circle
|
||||
center: &ORIGIN {x: 73, y: 129}
|
||||
radius: 7
|
||||
- !line
|
||||
start: *ORIGIN
|
||||
finish: { x: 89, y: 102 }
|
||||
- !label
|
||||
start: *ORIGIN
|
||||
color: 0xFFEEBB
|
||||
text: Pretty vector drawing.
|
||||
11
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_24_dumped.yaml
generated
vendored
Normal file
11
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_24_dumped.yaml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
!shape
|
||||
- !circle
|
||||
center: &id001 {x: 73, y: 129}
|
||||
radius: 7
|
||||
- !line
|
||||
finish: {x: 89, y: 102}
|
||||
start: *id001
|
||||
- !label
|
||||
color: 0xFFEEBB
|
||||
start: *id001
|
||||
text: Pretty vector drawing.
|
||||
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_25.yaml
generated
vendored
Normal file
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_25.yaml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# sets are represented as a
|
||||
# mapping where each key is
|
||||
# associated with the empty string
|
||||
--- !!set
|
||||
? Mark McGwire
|
||||
? Sammy Sosa
|
||||
? Ken Griff
|
||||
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_26.yaml
generated
vendored
Normal file
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_26.yaml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# ordered maps are represented as
|
||||
# a sequence of mappings, with
|
||||
# each mapping having one key
|
||||
--- !!omap
|
||||
- Mark McGwire: 65
|
||||
- Sammy Sosa: 63
|
||||
- Ken Griffy: 58
|
||||
29
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_27.yaml
generated
vendored
Normal file
29
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_27.yaml
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
--- !<tag:clarkevans.com,2002:invoice>
|
||||
invoice: 34843
|
||||
date : 2001-01-23
|
||||
billTo: &id001
|
||||
given : Chris
|
||||
family : Dumars
|
||||
address:
|
||||
lines: |
|
||||
458 Walkman Dr.
|
||||
Suite #292
|
||||
city : Royal Oak
|
||||
state : MI
|
||||
postal : 48046
|
||||
shipTo: *id001
|
||||
product:
|
||||
- sku : BL394D
|
||||
quantity : 4
|
||||
description : Basketball
|
||||
price : 450.00
|
||||
- sku : BL4438H
|
||||
quantity : 1
|
||||
description : Super Hoop
|
||||
price : 2392.00
|
||||
tax : 251.42
|
||||
total: 4443.52
|
||||
comments:
|
||||
Late afternoon is best.
|
||||
Backup contact is Nancy
|
||||
Billsmer @ 338-4338.
|
||||
20
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_27_dumped.yaml
generated
vendored
Normal file
20
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_27_dumped.yaml
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
!!org.yaml.snakeyaml.Invoice
|
||||
billTo: &id001
|
||||
address:
|
||||
city: Royal Oak
|
||||
lines: |
|
||||
458 Walkman Dr.
|
||||
Suite #292
|
||||
postal: '48046'
|
||||
state: MI
|
||||
family: Dumars
|
||||
given: Chris
|
||||
comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
|
||||
date: '2001-01-23'
|
||||
invoice: 34843
|
||||
product:
|
||||
- {description: Basketball, price: 450.0, quantity: 4, sku: BL394D}
|
||||
- {description: Super Hoop, price: 2392.0, quantity: 1, sku: BL4438H}
|
||||
shipTo: *id001
|
||||
tax: 251.42
|
||||
total: 4443.52
|
||||
29
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_28.yaml
generated
vendored
Normal file
29
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_28.yaml
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
Time: 2001-11-23 15:01:42 -5
|
||||
User: ed
|
||||
Warning:
|
||||
This is an error message
|
||||
for the log file
|
||||
---
|
||||
Time: 2001-11-23 15:02:31 -5
|
||||
User: ed
|
||||
Warning:
|
||||
A slightly different error
|
||||
message.
|
||||
---
|
||||
Date: 2001-11-23 15:03:17 -5
|
||||
User: ed
|
||||
Fatal:
|
||||
Unknown variable "bar"
|
||||
Stack:
|
||||
- file: TopClass.py
|
||||
line: 23
|
||||
code: |
|
||||
x = MoreObject("345\n")
|
||||
- file: MoreClass.py
|
||||
line: 58
|
||||
code: |-
|
||||
foo = bar
|
||||
|
||||
|
||||
|
||||
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_3.yaml
generated
vendored
Normal file
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_3.yaml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
american:
|
||||
- Boston Red Sox
|
||||
- Detroit Tigers
|
||||
- New York Yankees
|
||||
national:
|
||||
- New York Mets
|
||||
- Chicago Cubs
|
||||
- Atlanta Braves
|
||||
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_4.yaml
generated
vendored
Normal file
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_4.yaml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
-
|
||||
name: Mark McGwire
|
||||
hr: 65
|
||||
avg: 0.278
|
||||
-
|
||||
name: Sammy Sosa
|
||||
hr: 63
|
||||
avg: 0.288
|
||||
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_5.yaml
generated
vendored
Normal file
3
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_5.yaml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
- [name , hr, avg ]
|
||||
- [Mark McGwire, 65, 0.278]
|
||||
- [Sammy Sosa , 63, 0.288]
|
||||
5
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_6.yaml
generated
vendored
Normal file
5
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_6.yaml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
Mark McGwire: {hr: 65, avg: 0.278}
|
||||
Sammy Sosa: {
|
||||
hr: 63,
|
||||
avg: 0.288
|
||||
}
|
||||
10
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_7.yaml
generated
vendored
Normal file
10
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_7.yaml
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Ranking of 1998 home runs
|
||||
---
|
||||
- Mark McGwire
|
||||
- Sammy Sosa
|
||||
- Ken Griffey
|
||||
|
||||
# Team ranking
|
||||
---
|
||||
- Chicago Cubs
|
||||
- St Louis Cardinals
|
||||
10
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_8.yaml
generated
vendored
Normal file
10
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_8.yaml
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
time: 20:03:20
|
||||
player: Sammy Sosa
|
||||
action: strike (miss)
|
||||
...
|
||||
---
|
||||
time: 20:03:47
|
||||
player: Sammy Sosa
|
||||
action: grand slam
|
||||
...
|
||||
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_9.yaml
generated
vendored
Normal file
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example2_9.yaml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
hr: # 1998 hr ranking
|
||||
- Mark McGwire
|
||||
- Sammy Sosa
|
||||
rbi:
|
||||
# 1998 rbi ranking
|
||||
- Sammy Sosa
|
||||
- Ken Griffey
|
||||
0
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example_empty.yaml
generated
vendored
Normal file
0
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/example_empty.yaml
generated
vendored
Normal file
6
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/map.yaml
generated
vendored
Normal file
6
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/map.yaml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# Unordered set of key: value pairs.
|
||||
Block style: !!map
|
||||
Clark : Evans
|
||||
Brian : Ingerson
|
||||
Oren : Ben-Kiki
|
||||
Flow style: !!map { Clark: Evans, Brian: Ingerson, Oren: Ben-Kiki }
|
||||
6
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/map_mixed_tags.yaml
generated
vendored
Normal file
6
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/map_mixed_tags.yaml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# Unordered set of key: value pairs.
|
||||
Block style: !<tag:yaml.org,2002:map>
|
||||
Clark : Evans
|
||||
Brian : Ingerson
|
||||
Oren : Ben-Kiki
|
||||
Flow style: { Clark: Evans, Brian: Ingerson, Oren: Ben-Kiki }
|
||||
27
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/merge.yaml
generated
vendored
Normal file
27
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/merge.yaml
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
- &CENTER { x: 1, y: 2 }
|
||||
- &LEFT { x: 0, y: 2 }
|
||||
- &BIG { r: 10 }
|
||||
- &SMALL { r: 1 }
|
||||
|
||||
# All the following maps are equal:
|
||||
|
||||
- # Explicit keys
|
||||
x: 1
|
||||
y: 2
|
||||
r: 10
|
||||
label: center/big
|
||||
|
||||
- # Merge one map
|
||||
<< : *CENTER
|
||||
r: 10
|
||||
label: center/big
|
||||
|
||||
- # Merge multiple maps
|
||||
<< : [ *CENTER, *BIG ]
|
||||
label: center/big
|
||||
|
||||
- # Override
|
||||
<< : [ *BIG, *LEFT, *SMALL ]
|
||||
x: 1
|
||||
label: center/big
|
||||
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/omap.yaml
generated
vendored
Normal file
8
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/omap.yaml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Explicitly typed ordered map (dictionary).
|
||||
Bestiary: !!omap
|
||||
- aardvark: African pig-like ant eater. Ugly.
|
||||
- anteater: South-American ant eater. Two species.
|
||||
- anaconda: South-American constrictor snake. Scaly.
|
||||
# Etc.
|
||||
# Flow style
|
||||
Numbers: !!omap [ one: 1, two: 2, three : 3 ]
|
||||
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/pairs.yaml
generated
vendored
Normal file
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/pairs.yaml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Explicitly typed pairs.
|
||||
Block tasks: !!pairs
|
||||
- meeting: with team.
|
||||
- meeting: with boss.
|
||||
- break: lunch.
|
||||
- meeting: with client.
|
||||
Flow tasks: !!pairs [ meeting: with team, meeting: with boss ]
|
||||
14
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/seq.yaml
generated
vendored
Normal file
14
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/seq.yaml
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Ordered sequence of nodes
|
||||
Block style: !!seq
|
||||
- Mercury # Rotates - no light/dark sides.
|
||||
- Venus # Deadliest. Aptly named.
|
||||
- Earth # Mostly dirt.
|
||||
- Mars # Seems empty.
|
||||
- Jupiter # The king.
|
||||
- Saturn # Pretty.
|
||||
- Uranus # Where the sun hardly shines.
|
||||
- Neptune # Boring. No rings.
|
||||
- Pluto # You call this a planet?
|
||||
Flow style: !!seq [ Mercury, Venus, Earth, Mars, # Rocks
|
||||
Jupiter, Saturn, Uranus, Neptune, # Gas
|
||||
Pluto ] # Overrated
|
||||
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/set.yaml
generated
vendored
Normal file
7
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/set.yaml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Explicitly typed set.
|
||||
baseball players: !!set
|
||||
? Mark McGwire
|
||||
? Sammy Sosa
|
||||
? Ken Griffey
|
||||
# Flow style
|
||||
baseball teams: !!set { Boston Red Sox, Detroit Tigers, New York Yankees }
|
||||
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/v.yaml
generated
vendored
Normal file
4
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/v.yaml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
--- # New schema
|
||||
link with:
|
||||
- = : library1.dll
|
||||
version: 1.2
|
||||
10
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/value.yaml
generated
vendored
Normal file
10
vendor/github.com/cloudfoundry-incubator/candiedyaml/fixtures/specification/types/value.yaml
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
--- # Old schema
|
||||
link with:
|
||||
- library1.dll
|
||||
- library2.dll
|
||||
--- # New schema
|
||||
link with:
|
||||
- = : library1.dll
|
||||
version: 1.2
|
||||
- = : library2.dll
|
||||
version: 2.3
|
||||
19
vendor/github.com/cloudfoundry-incubator/candiedyaml/libyaml-LICENSE
generated
vendored
Normal file
19
vendor/github.com/cloudfoundry-incubator/candiedyaml/libyaml-LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2006 Kirill Simonov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1230
vendor/github.com/cloudfoundry-incubator/candiedyaml/parser.go
generated
vendored
Normal file
1230
vendor/github.com/cloudfoundry-incubator/candiedyaml/parser.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
81
vendor/github.com/cloudfoundry-incubator/candiedyaml/parser_test.go
generated
vendored
Normal file
81
vendor/github.com/cloudfoundry-incubator/candiedyaml/parser_test.go
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var parses = func(filename string) {
|
||||
It("parses "+filename, func() {
|
||||
file, err := os.Open(filename)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
parser := yaml_parser_t{}
|
||||
yaml_parser_initialize(&parser)
|
||||
yaml_parser_set_input_reader(&parser, file)
|
||||
|
||||
failed := false
|
||||
event := yaml_event_t{}
|
||||
|
||||
for {
|
||||
if !yaml_parser_parse(&parser, &event) {
|
||||
failed = true
|
||||
println("---", parser.error, parser.problem, parser.context, "line", parser.problem_mark.line, "col", parser.problem_mark.column)
|
||||
break
|
||||
}
|
||||
|
||||
if event.event_type == yaml_STREAM_END_EVENT {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
file.Close()
|
||||
|
||||
// msg := "SUCCESS"
|
||||
// if failed {
|
||||
// msg = "FAILED"
|
||||
// if parser.error != yaml_NO_ERROR {
|
||||
// m := parser.problem_mark
|
||||
// fmt.Printf("ERROR: (%s) %s @ line: %d col: %d\n",
|
||||
// parser.context, parser.problem, m.line, m.column)
|
||||
// }
|
||||
// }
|
||||
Expect(failed).To(BeFalse())
|
||||
})
|
||||
}
|
||||
|
||||
var parseYamls = func(dirname string) {
|
||||
fileInfos, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
for _, fileInfo := range fileInfos {
|
||||
if !fileInfo.IsDir() {
|
||||
parses(filepath.Join(dirname, fileInfo.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _ = Describe("Parser", func() {
|
||||
parseYamls("fixtures/specification")
|
||||
parseYamls("fixtures/specification/types")
|
||||
})
|
||||
465
vendor/github.com/cloudfoundry-incubator/candiedyaml/reader.go
generated
vendored
Normal file
465
vendor/github.com/cloudfoundry-incubator/candiedyaml/reader.go
generated
vendored
Normal file
@@ -0,0 +1,465 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
/*
|
||||
* Set the reader error and return 0.
|
||||
*/
|
||||
|
||||
func yaml_parser_set_reader_error(parser *yaml_parser_t, problem string,
|
||||
offset int, value int) bool {
|
||||
parser.error = yaml_READER_ERROR
|
||||
parser.problem = problem
|
||||
parser.problem_offset = offset
|
||||
parser.problem_value = value
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
* Byte order marks.
|
||||
*/
|
||||
const (
|
||||
BOM_UTF8 = "\xef\xbb\xbf"
|
||||
BOM_UTF16LE = "\xff\xfe"
|
||||
BOM_UTF16BE = "\xfe\xff"
|
||||
)
|
||||
|
||||
/*
|
||||
* Determine the input stream encoding by checking the BOM symbol. If no BOM is
|
||||
* found, the UTF-8 encoding is assumed. Return 1 on success, 0 on failure.
|
||||
*/
|
||||
|
||||
func yaml_parser_determine_encoding(parser *yaml_parser_t) bool {
|
||||
/* Ensure that we had enough bytes in the raw buffer. */
|
||||
for !parser.eof &&
|
||||
len(parser.raw_buffer)-parser.raw_buffer_pos < 3 {
|
||||
if !yaml_parser_update_raw_buffer(parser) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine the encoding. */
|
||||
raw := parser.raw_buffer
|
||||
pos := parser.raw_buffer_pos
|
||||
remaining := len(raw) - pos
|
||||
if remaining >= 2 &&
|
||||
raw[pos] == BOM_UTF16LE[0] && raw[pos+1] == BOM_UTF16LE[1] {
|
||||
parser.encoding = yaml_UTF16LE_ENCODING
|
||||
parser.raw_buffer_pos += 2
|
||||
parser.offset += 2
|
||||
} else if remaining >= 2 &&
|
||||
raw[pos] == BOM_UTF16BE[0] && raw[pos+1] == BOM_UTF16BE[1] {
|
||||
parser.encoding = yaml_UTF16BE_ENCODING
|
||||
parser.raw_buffer_pos += 2
|
||||
parser.offset += 2
|
||||
} else if remaining >= 3 &&
|
||||
raw[pos] == BOM_UTF8[0] && raw[pos+1] == BOM_UTF8[1] && raw[pos+2] == BOM_UTF8[2] {
|
||||
parser.encoding = yaml_UTF8_ENCODING
|
||||
parser.raw_buffer_pos += 3
|
||||
parser.offset += 3
|
||||
} else {
|
||||
parser.encoding = yaml_UTF8_ENCODING
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the raw buffer.
|
||||
*/
|
||||
|
||||
func yaml_parser_update_raw_buffer(parser *yaml_parser_t) bool {
|
||||
size_read := 0
|
||||
|
||||
/* Return if the raw buffer is full. */
|
||||
if parser.raw_buffer_pos == 0 && len(parser.raw_buffer) == cap(parser.raw_buffer) {
|
||||
return true
|
||||
}
|
||||
|
||||
/* Return on EOF. */
|
||||
|
||||
if parser.eof {
|
||||
return true
|
||||
}
|
||||
|
||||
/* Move the remaining bytes in the raw buffer to the beginning. */
|
||||
if parser.raw_buffer_pos > 0 && parser.raw_buffer_pos < len(parser.raw_buffer) {
|
||||
copy(parser.raw_buffer, parser.raw_buffer[parser.raw_buffer_pos:])
|
||||
}
|
||||
parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)-parser.raw_buffer_pos]
|
||||
parser.raw_buffer_pos = 0
|
||||
|
||||
/* Call the read handler to fill the buffer. */
|
||||
size_read, err := parser.read_handler(parser,
|
||||
parser.raw_buffer[len(parser.raw_buffer):cap(parser.raw_buffer)])
|
||||
parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)+size_read]
|
||||
|
||||
if err == io.EOF {
|
||||
parser.eof = true
|
||||
} else if err != nil {
|
||||
return yaml_parser_set_reader_error(parser, "input error: "+err.Error(),
|
||||
parser.offset, -1)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure that the buffer contains at least `length` characters.
|
||||
* Return 1 on success, 0 on failure.
|
||||
*
|
||||
* The length is supposed to be significantly less that the buffer size.
|
||||
*/
|
||||
|
||||
func yaml_parser_update_buffer(parser *yaml_parser_t, length int) bool {
|
||||
/* Read handler must be set. */
|
||||
if parser.read_handler == nil {
|
||||
panic("read handler must be set")
|
||||
}
|
||||
|
||||
/* If the EOF flag is set and the raw buffer is empty, do nothing. */
|
||||
|
||||
if parser.eof && parser.raw_buffer_pos == len(parser.raw_buffer) {
|
||||
return true
|
||||
}
|
||||
|
||||
/* Return if the buffer contains enough characters. */
|
||||
|
||||
if parser.unread >= length {
|
||||
return true
|
||||
}
|
||||
|
||||
/* Determine the input encoding if it is not known yet. */
|
||||
|
||||
if parser.encoding == yaml_ANY_ENCODING {
|
||||
if !yaml_parser_determine_encoding(parser) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/* Move the unread characters to the beginning of the buffer. */
|
||||
buffer_end := len(parser.buffer)
|
||||
if 0 < parser.buffer_pos &&
|
||||
parser.buffer_pos < buffer_end {
|
||||
copy(parser.buffer, parser.buffer[parser.buffer_pos:])
|
||||
buffer_end -= parser.buffer_pos
|
||||
parser.buffer_pos = 0
|
||||
} else if parser.buffer_pos == buffer_end {
|
||||
buffer_end = 0
|
||||
parser.buffer_pos = 0
|
||||
}
|
||||
|
||||
parser.buffer = parser.buffer[:cap(parser.buffer)]
|
||||
|
||||
/* Fill the buffer until it has enough characters. */
|
||||
first := true
|
||||
for parser.unread < length {
|
||||
/* Fill the raw buffer if necessary. */
|
||||
|
||||
if !first || parser.raw_buffer_pos == len(parser.raw_buffer) {
|
||||
if !yaml_parser_update_raw_buffer(parser) {
|
||||
parser.buffer = parser.buffer[:buffer_end]
|
||||
return false
|
||||
}
|
||||
}
|
||||
first = false
|
||||
|
||||
/* Decode the raw buffer. */
|
||||
for parser.raw_buffer_pos != len(parser.raw_buffer) {
|
||||
var value rune
|
||||
var w int
|
||||
|
||||
raw_unread := len(parser.raw_buffer) - parser.raw_buffer_pos
|
||||
incomplete := false
|
||||
|
||||
/* Decode the next character. */
|
||||
|
||||
switch parser.encoding {
|
||||
case yaml_UTF8_ENCODING:
|
||||
|
||||
/*
|
||||
* Decode a UTF-8 character. Check RFC 3629
|
||||
* (http://www.ietf.org/rfc/rfc3629.txt) for more details.
|
||||
*
|
||||
* The following table (taken from the RFC) is used for
|
||||
* decoding.
|
||||
*
|
||||
* Char. number range | UTF-8 octet sequence
|
||||
* (hexadecimal) | (binary)
|
||||
* --------------------+------------------------------------
|
||||
* 0000 0000-0000 007F | 0xxxxxxx
|
||||
* 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
|
||||
* 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
|
||||
* 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
*
|
||||
* Additionally, the characters in the range 0xD800-0xDFFF
|
||||
* are prohibited as they are reserved for use with UTF-16
|
||||
* surrogate pairs.
|
||||
*/
|
||||
|
||||
/* Determine the length of the UTF-8 sequence. */
|
||||
|
||||
octet := parser.raw_buffer[parser.raw_buffer_pos]
|
||||
w = width(octet)
|
||||
|
||||
/* Check if the leading octet is valid. */
|
||||
|
||||
if w == 0 {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"invalid leading UTF-8 octet",
|
||||
parser.offset, int(octet))
|
||||
}
|
||||
|
||||
/* Check if the raw buffer contains an incomplete character. */
|
||||
|
||||
if w > raw_unread {
|
||||
if parser.eof {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"incomplete UTF-8 octet sequence",
|
||||
parser.offset, -1)
|
||||
}
|
||||
incomplete = true
|
||||
break
|
||||
}
|
||||
|
||||
/* Decode the leading octet. */
|
||||
switch {
|
||||
case octet&0x80 == 0x00:
|
||||
value = rune(octet & 0x7F)
|
||||
case octet&0xE0 == 0xC0:
|
||||
value = rune(octet & 0x1F)
|
||||
case octet&0xF0 == 0xE0:
|
||||
value = rune(octet & 0x0F)
|
||||
case octet&0xF8 == 0xF0:
|
||||
value = rune(octet & 0x07)
|
||||
default:
|
||||
value = 0
|
||||
}
|
||||
|
||||
/* Check and decode the trailing octets. */
|
||||
|
||||
for k := 1; k < w; k++ {
|
||||
octet = parser.raw_buffer[parser.raw_buffer_pos+k]
|
||||
|
||||
/* Check if the octet is valid. */
|
||||
|
||||
if (octet & 0xC0) != 0x80 {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"invalid trailing UTF-8 octet",
|
||||
parser.offset+k, int(octet))
|
||||
}
|
||||
|
||||
/* Decode the octet. */
|
||||
|
||||
value = (value << 6) + rune(octet&0x3F)
|
||||
}
|
||||
|
||||
/* Check the length of the sequence against the value. */
|
||||
switch {
|
||||
case w == 1:
|
||||
case w == 2 && value >= 0x80:
|
||||
case w == 3 && value >= 0x800:
|
||||
case w == 4 && value >= 0x10000:
|
||||
default:
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"invalid length of a UTF-8 sequence",
|
||||
parser.offset, -1)
|
||||
}
|
||||
|
||||
/* Check the range of the value. */
|
||||
|
||||
if (value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"invalid Unicode character",
|
||||
parser.offset, int(value))
|
||||
}
|
||||
case yaml_UTF16LE_ENCODING,
|
||||
yaml_UTF16BE_ENCODING:
|
||||
|
||||
var low, high int
|
||||
if parser.encoding == yaml_UTF16LE_ENCODING {
|
||||
low, high = 0, 1
|
||||
} else {
|
||||
high, low = 1, 0
|
||||
}
|
||||
|
||||
/*
|
||||
* The UTF-16 encoding is not as simple as one might
|
||||
* naively think. Check RFC 2781
|
||||
* (http://www.ietf.org/rfc/rfc2781.txt).
|
||||
*
|
||||
* Normally, two subsequent bytes describe a Unicode
|
||||
* character. However a special technique (called a
|
||||
* surrogate pair) is used for specifying character
|
||||
* values larger than 0xFFFF.
|
||||
*
|
||||
* A surrogate pair consists of two pseudo-characters:
|
||||
* high surrogate area (0xD800-0xDBFF)
|
||||
* low surrogate area (0xDC00-0xDFFF)
|
||||
*
|
||||
* The following formulas are used for decoding
|
||||
* and encoding characters using surrogate pairs:
|
||||
*
|
||||
* U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF)
|
||||
* U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF)
|
||||
* W1 = 110110yyyyyyyyyy
|
||||
* W2 = 110111xxxxxxxxxx
|
||||
*
|
||||
* where U is the character value, W1 is the high surrogate
|
||||
* area, W2 is the low surrogate area.
|
||||
*/
|
||||
|
||||
/* Check for incomplete UTF-16 character. */
|
||||
|
||||
if raw_unread < 2 {
|
||||
if parser.eof {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"incomplete UTF-16 character",
|
||||
parser.offset, -1)
|
||||
}
|
||||
incomplete = true
|
||||
break
|
||||
}
|
||||
|
||||
/* Get the character. */
|
||||
value = rune(parser.raw_buffer[parser.raw_buffer_pos+low]) +
|
||||
(rune(parser.raw_buffer[parser.raw_buffer_pos+high]) << 8)
|
||||
|
||||
/* Check for unexpected low surrogate area. */
|
||||
|
||||
if (value & 0xFC00) == 0xDC00 {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"unexpected low surrogate area",
|
||||
parser.offset, int(value))
|
||||
}
|
||||
|
||||
/* Check for a high surrogate area. */
|
||||
|
||||
if (value & 0xFC00) == 0xD800 {
|
||||
|
||||
w = 4
|
||||
|
||||
/* Check for incomplete surrogate pair. */
|
||||
|
||||
if raw_unread < 4 {
|
||||
if parser.eof {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"incomplete UTF-16 surrogate pair",
|
||||
parser.offset, -1)
|
||||
}
|
||||
incomplete = true
|
||||
break
|
||||
}
|
||||
|
||||
/* Get the next character. */
|
||||
|
||||
value2 := rune(parser.raw_buffer[parser.raw_buffer_pos+low+2]) +
|
||||
(rune(parser.raw_buffer[parser.raw_buffer_pos+high+2]) << 8)
|
||||
|
||||
/* Check for a low surrogate area. */
|
||||
|
||||
if (value2 & 0xFC00) != 0xDC00 {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"expected low surrogate area",
|
||||
parser.offset+2, int(value2))
|
||||
}
|
||||
|
||||
/* Generate the value of the surrogate pair. */
|
||||
|
||||
value = 0x10000 + ((value & 0x3FF) << 10) + (value2 & 0x3FF)
|
||||
} else {
|
||||
w = 2
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
default:
|
||||
panic("Impossible") /* Impossible. */
|
||||
}
|
||||
|
||||
/* Check if the raw buffer contains enough bytes to form a character. */
|
||||
|
||||
if incomplete {
|
||||
break
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the character is in the allowed range:
|
||||
* #x9 | #xA | #xD | [#x20-#x7E] (8 bit)
|
||||
* | #x85 | [#xA0-#xD7FF] | [#xE000-#xFFFD] (16 bit)
|
||||
* | [#x10000-#x10FFFF] (32 bit)
|
||||
*/
|
||||
|
||||
if !(value == 0x09 || value == 0x0A || value == 0x0D ||
|
||||
(value >= 0x20 && value <= 0x7E) ||
|
||||
(value == 0x85) || (value >= 0xA0 && value <= 0xD7FF) ||
|
||||
(value >= 0xE000 && value <= 0xFFFD) ||
|
||||
(value >= 0x10000 && value <= 0x10FFFF)) {
|
||||
return yaml_parser_set_reader_error(parser,
|
||||
"control characters are not allowed",
|
||||
parser.offset, int(value))
|
||||
}
|
||||
|
||||
/* Move the raw pointers. */
|
||||
|
||||
parser.raw_buffer_pos += w
|
||||
parser.offset += w
|
||||
|
||||
/* Finally put the character into the buffer. */
|
||||
|
||||
/* 0000 0000-0000 007F . 0xxxxxxx */
|
||||
if value <= 0x7F {
|
||||
parser.buffer[buffer_end] = byte(value)
|
||||
} else if value <= 0x7FF {
|
||||
/* 0000 0080-0000 07FF . 110xxxxx 10xxxxxx */
|
||||
parser.buffer[buffer_end] = byte(0xC0 + (value >> 6))
|
||||
parser.buffer[buffer_end+1] = byte(0x80 + (value & 0x3F))
|
||||
} else if value <= 0xFFFF {
|
||||
/* 0000 0800-0000 FFFF . 1110xxxx 10xxxxxx 10xxxxxx */
|
||||
parser.buffer[buffer_end] = byte(0xE0 + (value >> 12))
|
||||
parser.buffer[buffer_end+1] = byte(0x80 + ((value >> 6) & 0x3F))
|
||||
parser.buffer[buffer_end+2] = byte(0x80 + (value & 0x3F))
|
||||
} else {
|
||||
/* 0001 0000-0010 FFFF . 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
|
||||
parser.buffer[buffer_end] = byte(0xF0 + (value >> 18))
|
||||
parser.buffer[buffer_end+1] = byte(0x80 + ((value >> 12) & 0x3F))
|
||||
parser.buffer[buffer_end+2] = byte(0x80 + ((value >> 6) & 0x3F))
|
||||
parser.buffer[buffer_end+3] = byte(0x80 + (value & 0x3F))
|
||||
}
|
||||
|
||||
buffer_end += w
|
||||
parser.unread++
|
||||
}
|
||||
|
||||
/* On EOF, put NUL into the buffer and return. */
|
||||
|
||||
if parser.eof {
|
||||
parser.buffer[buffer_end] = 0
|
||||
buffer_end++
|
||||
parser.buffer = parser.buffer[:buffer_end]
|
||||
parser.unread++
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parser.buffer = parser.buffer[:buffer_end]
|
||||
return true
|
||||
}
|
||||
291
vendor/github.com/cloudfoundry-incubator/candiedyaml/reader_test.go
generated
vendored
Normal file
291
vendor/github.com/cloudfoundry-incubator/candiedyaml/reader_test.go
generated
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
/*
|
||||
* Test cases are stolen from
|
||||
* http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
|
||||
*/
|
||||
|
||||
type test_case struct {
|
||||
title string
|
||||
test string
|
||||
result bool
|
||||
}
|
||||
|
||||
var _ = Describe("Reader", func() {
|
||||
LONG := 100000
|
||||
|
||||
Context("UTF8 Sequences", func() {
|
||||
utf8_sequences := []test_case{
|
||||
/* {"title", "test 1|test 2|...|test N!", (0 or 1)}, */
|
||||
|
||||
{"a simple test", "'test' is '\xd0\xbf\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\xd0\xba\xd0\xb0' in Russian!", true},
|
||||
|
||||
{"an empty line", "!", true},
|
||||
{"u-0 is a control character", "\x00!", false},
|
||||
{"u-80 is a control character", "\xc2\x80!", false},
|
||||
{"u-800 is valid", "\xe0\xa0\x80!", true},
|
||||
{"u-10000 is valid", "\xf0\x90\x80\x80!", true},
|
||||
{"5 bytes sequences are not allowed", "\xf8\x88\x80\x80\x80!", false},
|
||||
{"6 bytes sequences are not allowed", "\xfc\x84\x80\x80\x80\x80!", false},
|
||||
|
||||
{"u-7f is a control character", "\x7f!", false},
|
||||
{"u-7FF is valid", "\xdf\xbf!", true},
|
||||
{"u-FFFF is a control character", "\xef\xbf\xbf!", false},
|
||||
{"u-1FFFFF is too large", "\xf7\xbf\xbf\xbf!", false},
|
||||
{"u-3FFFFFF is 5 bytes", "\xfb\xbf\xbf\xbf\xbf!", false},
|
||||
{"u-7FFFFFFF is 6 bytes", "\xfd\xbf\xbf\xbf\xbf\xbf!", false},
|
||||
|
||||
{"u-D7FF", "\xed\x9f\xbf!", true},
|
||||
{"u-E000", "\xee\x80\x80!", true},
|
||||
{"u-FFFD", "\xef\xbf\xbd!", true},
|
||||
{"u-10FFFF", "\xf4\x8f\xbf\xbf!", true},
|
||||
{"u-110000", "\xf4\x90\x80\x80!", false},
|
||||
|
||||
{"first continuation byte", "\x80!", false},
|
||||
{"last continuation byte", "\xbf!", false},
|
||||
|
||||
{"2 continuation bytes", "\x80\xbf!", false},
|
||||
{"3 continuation bytes", "\x80\xbf\x80!", false},
|
||||
{"4 continuation bytes", "\x80\xbf\x80\xbf!", false},
|
||||
{"5 continuation bytes", "\x80\xbf\x80\xbf\x80!", false},
|
||||
{"6 continuation bytes", "\x80\xbf\x80\xbf\x80\xbf!", false},
|
||||
{"7 continuation bytes", "\x80\xbf\x80\xbf\x80\xbf\x80!", false},
|
||||
|
||||
{"sequence of all 64 possible continuation bytes",
|
||||
"\x80|\x81|\x82|\x83|\x84|\x85|\x86|\x87|\x88|\x89|\x8a|\x8b|\x8c|\x8d|\x8e|\x8f|" +
|
||||
"\x90|\x91|\x92|\x93|\x94|\x95|\x96|\x97|\x98|\x99|\x9a|\x9b|\x9c|\x9d|\x9e|\x9f|" +
|
||||
"\xa0|\xa1|\xa2|\xa3|\xa4|\xa5|\xa6|\xa7|\xa8|\xa9|\xaa|\xab|\xac|\xad|\xae|\xaf|" +
|
||||
"\xb0|\xb1|\xb2|\xb3|\xb4|\xb5|\xb6|\xb7|\xb8|\xb9|\xba|\xbb|\xbc|\xbd|\xbe|\xbf!", false},
|
||||
{"32 first bytes of 2-byte sequences {0xc0-0xdf}",
|
||||
"\xc0 |\xc1 |\xc2 |\xc3 |\xc4 |\xc5 |\xc6 |\xc7 |\xc8 |\xc9 |\xca |\xcb |\xcc |\xcd |\xce |\xcf |" +
|
||||
"\xd0 |\xd1 |\xd2 |\xd3 |\xd4 |\xd5 |\xd6 |\xd7 |\xd8 |\xd9 |\xda |\xdb |\xdc |\xdd |\xde |\xdf !", false},
|
||||
{"16 first bytes of 3-byte sequences {0xe0-0xef}",
|
||||
"\xe0 |\xe1 |\xe2 |\xe3 |\xe4 |\xe5 |\xe6 |\xe7 |\xe8 |\xe9 |\xea |\xeb |\xec |\xed |\xee |\xef !", false},
|
||||
{"8 first bytes of 4-byte sequences {0xf0-0xf7}", "\xf0 |\xf1 |\xf2 |\xf3 |\xf4 |\xf5 |\xf6 |\xf7 !", false},
|
||||
{"4 first bytes of 5-byte sequences {0xf8-0xfb}", "\xf8 |\xf9 |\xfa |\xfb !", false},
|
||||
{"2 first bytes of 6-byte sequences {0xfc-0xfd}", "\xfc |\xfd !", false},
|
||||
|
||||
{"sequences with last byte missing {u-0}",
|
||||
"\xc0|\xe0\x80|\xf0\x80\x80|\xf8\x80\x80\x80|\xfc\x80\x80\x80\x80!", false},
|
||||
{"sequences with last byte missing {u-...FF}",
|
||||
"\xdf|\xef\xbf|\xf7\xbf\xbf|\xfb\xbf\xbf\xbf|\xfd\xbf\xbf\xbf\xbf!", false},
|
||||
|
||||
{"impossible bytes", "\xfe|\xff|\xfe\xfe\xff\xff!", false},
|
||||
|
||||
{"overlong sequences {u-2f}",
|
||||
"\xc0\xaf|\xe0\x80\xaf|\xf0\x80\x80\xaf|\xf8\x80\x80\x80\xaf|\xfc\x80\x80\x80\x80\xaf!", false},
|
||||
|
||||
{"maximum overlong sequences",
|
||||
"\xc1\xbf|\xe0\x9f\xbf|\xf0\x8f\xbf\xbf|\xf8\x87\xbf\xbf\xbf|\xfc\x83\xbf\xbf\xbf\xbf!", false},
|
||||
|
||||
{"overlong representation of the NUL character",
|
||||
"\xc0\x80|\xe0\x80\x80|\xf0\x80\x80\x80|\xf8\x80\x80\x80\x80|\xfc\x80\x80\x80\x80\x80!", false},
|
||||
|
||||
{"single UTF-16 surrogates",
|
||||
"\xed\xa0\x80|\xed\xad\xbf|\xed\xae\x80|\xed\xaf\xbf|\xed\xb0\x80|\xed\xbe\x80|\xed\xbf\xbf!", false},
|
||||
|
||||
{"paired UTF-16 surrogates",
|
||||
"\xed\xa0\x80\xed\xb0\x80|\xed\xa0\x80\xed\xbf\xbf|\xed\xad\xbf\xed\xb0\x80|" +
|
||||
"\xed\xad\xbf\xed\xbf\xbf|\xed\xae\x80\xed\xb0\x80|\xed\xae\x80\xed\xbf\xbf|" +
|
||||
"\xed\xaf\xbf\xed\xb0\x80|\xed\xaf\xbf\xed\xbf\xbf!", false},
|
||||
|
||||
{"other illegal code positions", "\xef\xbf\xbe|\xef\xbf\xbf!", false},
|
||||
}
|
||||
|
||||
check_sequence := func(tc test_case) {
|
||||
It(tc.title, func() {
|
||||
start := 0
|
||||
end := start
|
||||
bytes := []byte(tc.test)
|
||||
|
||||
for {
|
||||
for bytes[end] != '|' && bytes[end] != '!' {
|
||||
end++
|
||||
}
|
||||
|
||||
parser := yaml_parser_t{}
|
||||
yaml_parser_initialize(&parser)
|
||||
yaml_parser_set_input_string(&parser, bytes)
|
||||
result := yaml_parser_update_buffer(&parser, end-start)
|
||||
Expect(result).To(Equal(tc.result))
|
||||
// outcome := '+'
|
||||
// if result != tc.result {
|
||||
// outcome = '-'
|
||||
// }
|
||||
// fmt.Printf("\t\t %c %s", outcome, tc.title)
|
||||
// if parser.error == yaml_NO_ERROR {
|
||||
// fmt.Printf("(no error)\n")
|
||||
// } else if parser.error == yaml_READER_ERROR {
|
||||
// if parser.problem_value != -1 {
|
||||
// fmt.Printf("(reader error: %s: #%X at %d)\n",
|
||||
// parser.problem, parser.problem_value, parser.problem_offset)
|
||||
// } else {
|
||||
// fmt.Printf("(reader error: %s: at %d)\n",
|
||||
// parser.problem, parser.problem_offset)
|
||||
// }
|
||||
// }
|
||||
|
||||
if bytes[end] == '!' {
|
||||
break
|
||||
}
|
||||
|
||||
end++
|
||||
start = end
|
||||
yaml_parser_delete(&parser)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for _, test := range utf8_sequences {
|
||||
check_sequence(test)
|
||||
}
|
||||
})
|
||||
|
||||
Context("BOMs", func() {
|
||||
boms := []test_case{
|
||||
/* {"title", "test!", lenth}, */
|
||||
{"no bom (utf-8)", "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", true},
|
||||
{"bom (utf-8)", "\xef\xbb\xbfHi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", true},
|
||||
{"bom (utf-16-le)", "\xff\xfeH\x00i\x00 \x00i\x00s\x00 \x00\x1f\x04@\x04" + "8\x04" + "2\x04" + "5\x04" + "B\x04!", true},
|
||||
{"bom (utf-16-be)", "\xfe\xff\x00H\x00i\x00 \x00i\x00s\x00 \x04\x1f\x04@\x04" + "8\x04" + "2\x04" + "5\x04" + "B!", true},
|
||||
}
|
||||
|
||||
check_bom := func(tc test_case) {
|
||||
It(tc.title, func() {
|
||||
start := 0
|
||||
end := start
|
||||
bytes := []byte(tc.test)
|
||||
|
||||
for bytes[end] != '!' {
|
||||
end++
|
||||
}
|
||||
|
||||
parser := yaml_parser_t{}
|
||||
yaml_parser_initialize(&parser)
|
||||
yaml_parser_set_input_string(&parser, bytes[:end-start])
|
||||
result := yaml_parser_update_buffer(&parser, end-start)
|
||||
Expect(result).To(Equal(tc.result))
|
||||
yaml_parser_delete(&parser)
|
||||
})
|
||||
}
|
||||
|
||||
for _, test := range boms {
|
||||
check_bom(test)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Context("Long UTF8", func() {
|
||||
It("parses properly", func() {
|
||||
buffer := make([]byte, 0, 3+LONG*2)
|
||||
buffer = append(buffer, '\xef', '\xbb', '\xbf')
|
||||
for j := 0; j < LONG; j++ {
|
||||
if j%2 == 1 {
|
||||
buffer = append(buffer, '\xd0', '\x90')
|
||||
} else {
|
||||
buffer = append(buffer, '\xd0', '\xaf')
|
||||
}
|
||||
}
|
||||
parser := yaml_parser_t{}
|
||||
yaml_parser_initialize(&parser)
|
||||
yaml_parser_set_input_string(&parser, buffer)
|
||||
|
||||
for k := 0; k < LONG; k++ {
|
||||
if parser.unread == 0 {
|
||||
updated := yaml_parser_update_buffer(&parser, 1)
|
||||
Expect(updated).To(BeTrue())
|
||||
// printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset);
|
||||
}
|
||||
Expect(parser.unread).NotTo(Equal(0))
|
||||
// printf("\tnot enough characters at %d\n", k);
|
||||
var ch0, ch1 byte
|
||||
if k%2 == 1 {
|
||||
ch0 = '\xd0'
|
||||
ch1 = '\x90'
|
||||
} else {
|
||||
ch0 = '\xd0'
|
||||
ch1 = '\xaf'
|
||||
}
|
||||
Expect(parser.buffer[parser.buffer_pos]).To(Equal(ch0))
|
||||
Expect(parser.buffer[parser.buffer_pos+1]).To(Equal(ch1))
|
||||
// printf("\tincorrect UTF-8 sequence: %X %X instead of %X %X\n",
|
||||
// (int)parser.buffer.pointer[0], (int)parser.buffer.pointer[1],
|
||||
// (int)ch0, (int)ch1);
|
||||
|
||||
parser.buffer_pos += 2
|
||||
parser.unread -= 1
|
||||
}
|
||||
updated := yaml_parser_update_buffer(&parser, 1)
|
||||
Expect(updated).To(BeTrue())
|
||||
// printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset);
|
||||
yaml_parser_delete(&parser)
|
||||
})
|
||||
})
|
||||
|
||||
Context("Long UTF16", func() {
|
||||
It("parses properly", func() {
|
||||
buffer := make([]byte, 0, 2+LONG*2)
|
||||
buffer = append(buffer, '\xff', '\xfe')
|
||||
for j := 0; j < LONG; j++ {
|
||||
if j%2 == 1 {
|
||||
buffer = append(buffer, '\x10', '\x04')
|
||||
} else {
|
||||
buffer = append(buffer, '/', '\x04')
|
||||
}
|
||||
}
|
||||
parser := yaml_parser_t{}
|
||||
yaml_parser_initialize(&parser)
|
||||
yaml_parser_set_input_string(&parser, buffer)
|
||||
|
||||
for k := 0; k < LONG; k++ {
|
||||
if parser.unread == 0 {
|
||||
updated := yaml_parser_update_buffer(&parser, 1)
|
||||
Expect(updated).To(BeTrue())
|
||||
// printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset);
|
||||
}
|
||||
Expect(parser.unread).NotTo(Equal(0))
|
||||
// printf("\tnot enough characters at %d\n", k);
|
||||
var ch0, ch1 byte
|
||||
if k%2 == 1 {
|
||||
ch0 = '\xd0'
|
||||
ch1 = '\x90'
|
||||
} else {
|
||||
ch0 = '\xd0'
|
||||
ch1 = '\xaf'
|
||||
}
|
||||
Expect(parser.buffer[parser.buffer_pos]).To(Equal(ch0))
|
||||
Expect(parser.buffer[parser.buffer_pos+1]).To(Equal(ch1))
|
||||
// printf("\tincorrect UTF-8 sequence: %X %X instead of %X %X\n",
|
||||
// (int)parser.buffer.pointer[0], (int)parser.buffer.pointer[1],
|
||||
// (int)ch0, (int)ch1);
|
||||
|
||||
parser.buffer_pos += 2
|
||||
parser.unread -= 1
|
||||
}
|
||||
updated := yaml_parser_update_buffer(&parser, 1)
|
||||
Expect(updated).To(BeTrue())
|
||||
// printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset);
|
||||
yaml_parser_delete(&parser)
|
||||
})
|
||||
})
|
||||
})
|
||||
449
vendor/github.com/cloudfoundry-incubator/candiedyaml/resolver.go
generated
vendored
Normal file
449
vendor/github.com/cloudfoundry-incubator/candiedyaml/resolver.go
generated
vendored
Normal file
@@ -0,0 +1,449 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var byteSliceType = reflect.TypeOf([]byte(nil))
|
||||
|
||||
var binary_tags = [][]byte{[]byte("!binary"), []byte(yaml_BINARY_TAG)}
|
||||
var bool_values map[string]bool
|
||||
var null_values map[string]bool
|
||||
|
||||
var signs = []byte{'-', '+'}
|
||||
var nulls = []byte{'~', 'n', 'N'}
|
||||
var bools = []byte{'t', 'T', 'f', 'F', 'y', 'Y', 'n', 'N', 'o', 'O'}
|
||||
|
||||
var timestamp_regexp *regexp.Regexp
|
||||
var ymd_regexp *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
bool_values = make(map[string]bool)
|
||||
bool_values["y"] = true
|
||||
bool_values["yes"] = true
|
||||
bool_values["n"] = false
|
||||
bool_values["no"] = false
|
||||
bool_values["true"] = true
|
||||
bool_values["false"] = false
|
||||
bool_values["on"] = true
|
||||
bool_values["off"] = false
|
||||
|
||||
null_values = make(map[string]bool)
|
||||
null_values["~"] = true
|
||||
null_values["null"] = true
|
||||
null_values["Null"] = true
|
||||
null_values["NULL"] = true
|
||||
|
||||
timestamp_regexp = regexp.MustCompile("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:(?:[Tt]|[ \t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \t]*(?:Z|([-+][0-9][0-9]?)(?::([0-9][0-9])?)?))?)?$")
|
||||
ymd_regexp = regexp.MustCompile("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)$")
|
||||
}
|
||||
|
||||
func resolve(event yaml_event_t, v reflect.Value, useNumber bool) (string, error) {
|
||||
val := string(event.value)
|
||||
|
||||
if null_values[val] {
|
||||
v.Set(reflect.Zero(v.Type()))
|
||||
return yaml_NULL_TAG, nil
|
||||
}
|
||||
|
||||
switch v.Kind() {
|
||||
case reflect.String:
|
||||
if useNumber && v.Type() == numberType {
|
||||
tag, i := resolveInterface(event, useNumber)
|
||||
if n, ok := i.(Number); ok {
|
||||
v.Set(reflect.ValueOf(n))
|
||||
return tag, nil
|
||||
}
|
||||
return "", fmt.Errorf("Not a number: '%s' at %s", event.value, event.start_mark)
|
||||
}
|
||||
|
||||
return resolve_string(val, v, event)
|
||||
case reflect.Bool:
|
||||
return resolve_bool(val, v, event)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return resolve_int(val, v, useNumber, event)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return resolve_uint(val, v, useNumber, event)
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return resolve_float(val, v, useNumber, event)
|
||||
case reflect.Interface:
|
||||
_, i := resolveInterface(event, useNumber)
|
||||
if i != nil {
|
||||
v.Set(reflect.ValueOf(i))
|
||||
} else {
|
||||
v.Set(reflect.Zero(v.Type()))
|
||||
}
|
||||
|
||||
case reflect.Struct:
|
||||
return resolve_time(val, v, event)
|
||||
case reflect.Slice:
|
||||
if v.Type() != byteSliceType {
|
||||
return "", fmt.Errorf("Cannot resolve %s into %s at %s", val, v.String(), event.start_mark)
|
||||
}
|
||||
b, err := decode_binary(event.value, event)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
v.Set(reflect.ValueOf(b))
|
||||
default:
|
||||
return "", fmt.Errorf("Unknown resolution for '%s' using %s at %s", val, v.String(), event.start_mark)
|
||||
}
|
||||
|
||||
return yaml_STR_TAG, nil
|
||||
}
|
||||
|
||||
func hasBinaryTag(event yaml_event_t) bool {
|
||||
for _, tag := range binary_tags {
|
||||
if bytes.Equal(event.tag, tag) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func decode_binary(value []byte, event yaml_event_t) ([]byte, error) {
|
||||
b := make([]byte, base64.StdEncoding.DecodedLen(len(value)))
|
||||
n, err := base64.StdEncoding.Decode(b, value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Invalid base64 text: '%s' at %s", string(b), event.start_mark)
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
|
||||
func resolve_string(val string, v reflect.Value, event yaml_event_t) (string, error) {
|
||||
if len(event.tag) > 0 {
|
||||
if hasBinaryTag(event) {
|
||||
b, err := decode_binary(event.value, event)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val = string(b)
|
||||
}
|
||||
}
|
||||
v.SetString(val)
|
||||
return yaml_STR_TAG, nil
|
||||
}
|
||||
|
||||
func resolve_bool(val string, v reflect.Value, event yaml_event_t) (string, error) {
|
||||
b, found := bool_values[strings.ToLower(val)]
|
||||
if !found {
|
||||
return "", fmt.Errorf("Invalid boolean: '%s' at %s", val, event.start_mark)
|
||||
}
|
||||
|
||||
v.SetBool(b)
|
||||
return yaml_BOOL_TAG, nil
|
||||
}
|
||||
|
||||
func resolve_int(val string, v reflect.Value, useNumber bool, event yaml_event_t) (string, error) {
|
||||
original := val
|
||||
val = strings.Replace(val, "_", "", -1)
|
||||
var value uint64
|
||||
|
||||
isNumberValue := v.Type() == numberType
|
||||
|
||||
sign := int64(1)
|
||||
if val[0] == '-' {
|
||||
sign = -1
|
||||
val = val[1:]
|
||||
} else if val[0] == '+' {
|
||||
val = val[1:]
|
||||
}
|
||||
|
||||
base := 0
|
||||
if val == "0" {
|
||||
if isNumberValue {
|
||||
v.SetString("0")
|
||||
} else {
|
||||
v.Set(reflect.Zero(v.Type()))
|
||||
}
|
||||
|
||||
return yaml_INT_TAG, nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(val, "0o") {
|
||||
base = 8
|
||||
val = val[2:]
|
||||
}
|
||||
|
||||
value, err := strconv.ParseUint(val, base, 64)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Invalid integer: '%s' at %s", original, event.start_mark)
|
||||
}
|
||||
|
||||
var val64 int64
|
||||
if value <= math.MaxInt64 {
|
||||
val64 = int64(value)
|
||||
if sign == -1 {
|
||||
val64 = -val64
|
||||
}
|
||||
} else if sign == -1 && value == uint64(math.MaxInt64)+1 {
|
||||
val64 = math.MinInt64
|
||||
} else {
|
||||
return "", fmt.Errorf("Invalid integer: '%s' at %s", original, event.start_mark)
|
||||
}
|
||||
|
||||
if isNumberValue {
|
||||
v.SetString(strconv.FormatInt(val64, 10))
|
||||
} else {
|
||||
if v.OverflowInt(val64) {
|
||||
return "", fmt.Errorf("Invalid integer: '%s' at %s", original, event.start_mark)
|
||||
}
|
||||
v.SetInt(val64)
|
||||
}
|
||||
|
||||
return yaml_INT_TAG, nil
|
||||
}
|
||||
|
||||
func resolve_uint(val string, v reflect.Value, useNumber bool, event yaml_event_t) (string, error) {
|
||||
original := val
|
||||
val = strings.Replace(val, "_", "", -1)
|
||||
var value uint64
|
||||
|
||||
isNumberValue := v.Type() == numberType
|
||||
|
||||
if val[0] == '-' {
|
||||
return "", fmt.Errorf("Unsigned int with negative value: '%s' at %s", original, event.start_mark)
|
||||
}
|
||||
|
||||
if val[0] == '+' {
|
||||
val = val[1:]
|
||||
}
|
||||
|
||||
base := 0
|
||||
if val == "0" {
|
||||
if isNumberValue {
|
||||
v.SetString("0")
|
||||
} else {
|
||||
v.Set(reflect.Zero(v.Type()))
|
||||
}
|
||||
|
||||
return yaml_INT_TAG, nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(val, "0o") {
|
||||
base = 8
|
||||
val = val[2:]
|
||||
}
|
||||
|
||||
value, err := strconv.ParseUint(val, base, 64)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Invalid unsigned integer: '%s' at %s", val, event.start_mark)
|
||||
}
|
||||
|
||||
if isNumberValue {
|
||||
v.SetString(strconv.FormatUint(value, 10))
|
||||
} else {
|
||||
if v.OverflowUint(value) {
|
||||
return "", fmt.Errorf("Invalid unsigned integer: '%s' at %s", val, event.start_mark)
|
||||
}
|
||||
|
||||
v.SetUint(value)
|
||||
}
|
||||
|
||||
return yaml_INT_TAG, nil
|
||||
}
|
||||
|
||||
func resolve_float(val string, v reflect.Value, useNumber bool, event yaml_event_t) (string, error) {
|
||||
val = strings.Replace(val, "_", "", -1)
|
||||
var value float64
|
||||
|
||||
isNumberValue := v.Type() == numberType
|
||||
typeBits := 64
|
||||
if !isNumberValue {
|
||||
typeBits = v.Type().Bits()
|
||||
}
|
||||
|
||||
sign := 1
|
||||
if val[0] == '-' {
|
||||
sign = -1
|
||||
val = val[1:]
|
||||
} else if val[0] == '+' {
|
||||
val = val[1:]
|
||||
}
|
||||
|
||||
valLower := strings.ToLower(val)
|
||||
if valLower == ".inf" {
|
||||
value = math.Inf(sign)
|
||||
} else if valLower == ".nan" {
|
||||
value = math.NaN()
|
||||
} else {
|
||||
var err error
|
||||
value, err = strconv.ParseFloat(val, typeBits)
|
||||
value *= float64(sign)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Invalid float: '%s' at %s", val, event.start_mark)
|
||||
}
|
||||
}
|
||||
|
||||
if isNumberValue {
|
||||
v.SetString(strconv.FormatFloat(value, 'g', -1, typeBits))
|
||||
} else {
|
||||
if v.OverflowFloat(value) {
|
||||
return "", fmt.Errorf("Invalid float: '%s' at %s", val, event.start_mark)
|
||||
}
|
||||
|
||||
v.SetFloat(value)
|
||||
}
|
||||
|
||||
return yaml_FLOAT_TAG, nil
|
||||
}
|
||||
|
||||
func resolve_time(val string, v reflect.Value, event yaml_event_t) (string, error) {
|
||||
var parsedTime time.Time
|
||||
matches := ymd_regexp.FindStringSubmatch(val)
|
||||
if len(matches) > 0 {
|
||||
year, _ := strconv.Atoi(matches[1])
|
||||
month, _ := strconv.Atoi(matches[2])
|
||||
day, _ := strconv.Atoi(matches[3])
|
||||
parsedTime = time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)
|
||||
} else {
|
||||
matches = timestamp_regexp.FindStringSubmatch(val)
|
||||
if len(matches) == 0 {
|
||||
return "", fmt.Errorf("Invalid timestamp: '%s' at %s", val, event.start_mark)
|
||||
}
|
||||
|
||||
year, _ := strconv.Atoi(matches[1])
|
||||
month, _ := strconv.Atoi(matches[2])
|
||||
day, _ := strconv.Atoi(matches[3])
|
||||
hour, _ := strconv.Atoi(matches[4])
|
||||
min, _ := strconv.Atoi(matches[5])
|
||||
sec, _ := strconv.Atoi(matches[6])
|
||||
|
||||
nsec := 0
|
||||
if matches[7] != "" {
|
||||
millis, _ := strconv.Atoi(matches[7])
|
||||
nsec = int(time.Duration(millis) * time.Millisecond)
|
||||
}
|
||||
|
||||
loc := time.UTC
|
||||
if matches[8] != "" {
|
||||
sign := matches[8][0]
|
||||
hr, _ := strconv.Atoi(matches[8][1:])
|
||||
min := 0
|
||||
if matches[9] != "" {
|
||||
min, _ = strconv.Atoi(matches[9])
|
||||
}
|
||||
|
||||
zoneOffset := (hr*60 + min) * 60
|
||||
if sign == '-' {
|
||||
zoneOffset = -zoneOffset
|
||||
}
|
||||
|
||||
loc = time.FixedZone("", zoneOffset)
|
||||
}
|
||||
parsedTime = time.Date(year, time.Month(month), day, hour, min, sec, nsec, loc)
|
||||
}
|
||||
|
||||
v.Set(reflect.ValueOf(parsedTime))
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func resolveInterface(event yaml_event_t, useNumber bool) (string, interface{}) {
|
||||
val := string(event.value)
|
||||
if len(event.tag) == 0 && !event.implicit {
|
||||
return "", val
|
||||
}
|
||||
|
||||
if len(val) == 0 {
|
||||
return yaml_NULL_TAG, nil
|
||||
}
|
||||
|
||||
var result interface{}
|
||||
|
||||
sign := false
|
||||
c := val[0]
|
||||
switch {
|
||||
case bytes.IndexByte(signs, c) != -1:
|
||||
sign = true
|
||||
fallthrough
|
||||
case c >= '0' && c <= '9':
|
||||
i := int64(0)
|
||||
result = &i
|
||||
if useNumber {
|
||||
var n Number
|
||||
result = &n
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(result).Elem()
|
||||
if _, err := resolve_int(val, v, useNumber, event); err == nil {
|
||||
return yaml_INT_TAG, v.Interface()
|
||||
}
|
||||
|
||||
f := float64(0)
|
||||
result = &f
|
||||
if useNumber {
|
||||
var n Number
|
||||
result = &n
|
||||
}
|
||||
|
||||
v = reflect.ValueOf(result).Elem()
|
||||
if _, err := resolve_float(val, v, useNumber, event); err == nil {
|
||||
return yaml_FLOAT_TAG, v.Interface()
|
||||
}
|
||||
|
||||
if !sign {
|
||||
t := time.Time{}
|
||||
if _, err := resolve_time(val, reflect.ValueOf(&t).Elem(), event); err == nil {
|
||||
return "", t
|
||||
}
|
||||
}
|
||||
case bytes.IndexByte(nulls, c) != -1:
|
||||
if null_values[val] {
|
||||
return yaml_NULL_TAG, nil
|
||||
}
|
||||
b := false
|
||||
if _, err := resolve_bool(val, reflect.ValueOf(&b).Elem(), event); err == nil {
|
||||
return yaml_BOOL_TAG, b
|
||||
}
|
||||
case c == '.':
|
||||
f := float64(0)
|
||||
result = &f
|
||||
if useNumber {
|
||||
var n Number
|
||||
result = &n
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(result).Elem()
|
||||
if _, err := resolve_float(val, v, useNumber, event); err == nil {
|
||||
return yaml_FLOAT_TAG, v.Interface()
|
||||
}
|
||||
case bytes.IndexByte(bools, c) != -1:
|
||||
b := false
|
||||
if _, err := resolve_bool(val, reflect.ValueOf(&b).Elem(), event); err == nil {
|
||||
return yaml_BOOL_TAG, b
|
||||
}
|
||||
}
|
||||
|
||||
if hasBinaryTag(event) {
|
||||
bytes, err := decode_binary(event.value, event)
|
||||
if err == nil {
|
||||
return yaml_BINARY_TAG, bytes
|
||||
}
|
||||
}
|
||||
|
||||
return yaml_STR_TAG, val
|
||||
}
|
||||
665
vendor/github.com/cloudfoundry-incubator/candiedyaml/resolver_test.go
generated
vendored
Normal file
665
vendor/github.com/cloudfoundry-incubator/candiedyaml/resolver_test.go
generated
vendored
Normal file
@@ -0,0 +1,665 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Resolver", func() {
|
||||
var event yaml_event_t
|
||||
|
||||
var nulls = []string{"~", "null", "Null", "NULL"}
|
||||
|
||||
BeforeEach(func() {
|
||||
event = yaml_event_t{}
|
||||
})
|
||||
|
||||
Context("Resolve", func() {
|
||||
Context("Implicit events", func() {
|
||||
checkNulls := func(f func()) {
|
||||
for _, null := range nulls {
|
||||
event = yaml_event_t{implicit: true}
|
||||
event.value = []byte(null)
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
event.implicit = true
|
||||
})
|
||||
|
||||
Context("String", func() {
|
||||
It("resolves a string", func() {
|
||||
aString := ""
|
||||
v := reflect.ValueOf(&aString)
|
||||
event.value = []byte("abc")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_STR_TAG))
|
||||
Expect(aString).To(Equal("abc"))
|
||||
})
|
||||
|
||||
It("resolves the empty string", func() {
|
||||
aString := "abc"
|
||||
v := reflect.ValueOf(&aString)
|
||||
event.value = []byte("")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_STR_TAG))
|
||||
Expect(aString).To(Equal(""))
|
||||
|
||||
})
|
||||
|
||||
It("resolves null", func() {
|
||||
checkNulls(func() {
|
||||
aString := "abc"
|
||||
v := reflect.ValueOf(&aString)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(aString).To(Equal(""))
|
||||
})
|
||||
})
|
||||
|
||||
It("resolves null pointers", func() {
|
||||
checkNulls(func() {
|
||||
aString := "abc"
|
||||
pString := &aString
|
||||
v := reflect.ValueOf(&pString)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(pString).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Context("Booleans", func() {
|
||||
match_bool := func(val string, expected bool) {
|
||||
b := !expected
|
||||
|
||||
v := reflect.ValueOf(&b)
|
||||
event.value = []byte(val)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_BOOL_TAG))
|
||||
Expect(b).To(Equal(expected))
|
||||
}
|
||||
|
||||
It("resolves on", func() {
|
||||
match_bool("on", true)
|
||||
match_bool("ON", true)
|
||||
})
|
||||
|
||||
It("resolves off", func() {
|
||||
match_bool("off", false)
|
||||
match_bool("OFF", false)
|
||||
})
|
||||
|
||||
It("resolves true", func() {
|
||||
match_bool("true", true)
|
||||
match_bool("TRUE", true)
|
||||
})
|
||||
|
||||
It("resolves false", func() {
|
||||
match_bool("false", false)
|
||||
match_bool("FALSE", false)
|
||||
})
|
||||
|
||||
It("resolves yes", func() {
|
||||
match_bool("yes", true)
|
||||
match_bool("YES", true)
|
||||
})
|
||||
|
||||
It("resolves no", func() {
|
||||
match_bool("no", false)
|
||||
match_bool("NO", false)
|
||||
})
|
||||
|
||||
It("reports an error otherwise", func() {
|
||||
b := true
|
||||
v := reflect.ValueOf(&b)
|
||||
event.value = []byte("fail")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Invalid boolean: 'fail' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("resolves null", func() {
|
||||
checkNulls(func() {
|
||||
b := true
|
||||
v := reflect.ValueOf(&b)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(b).To(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
It("resolves null pointers", func() {
|
||||
checkNulls(func() {
|
||||
b := true
|
||||
pb := &b
|
||||
v := reflect.ValueOf(&pb)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(pb).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("Ints", func() {
|
||||
It("simple ints", func() {
|
||||
i := 0
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("1234")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(1234))
|
||||
})
|
||||
|
||||
It("positive ints", func() {
|
||||
i := int16(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("+678")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(int16(678)))
|
||||
})
|
||||
|
||||
It("negative ints", func() {
|
||||
i := int32(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("-2345")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(int32(-2345)))
|
||||
})
|
||||
|
||||
It("base 8", func() {
|
||||
i := 0
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("0o12")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(10))
|
||||
})
|
||||
|
||||
It("base 16", func() {
|
||||
i := 0
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("0xff")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(255))
|
||||
})
|
||||
|
||||
It("fails on overflow", func() {
|
||||
i := int8(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("2345")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Invalid integer: '2345' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("fails on invalid int", func() {
|
||||
i := 0
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("234f")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Invalid integer: '234f' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("resolves null", func() {
|
||||
checkNulls(func() {
|
||||
i := 1
|
||||
v := reflect.ValueOf(&i)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(i).To(Equal(0))
|
||||
})
|
||||
})
|
||||
|
||||
It("resolves null pointers", func() {
|
||||
checkNulls(func() {
|
||||
i := 1
|
||||
pi := &i
|
||||
v := reflect.ValueOf(&pi)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(pi).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
It("returns a Number", func() {
|
||||
var i Number
|
||||
v := reflect.ValueOf(&i)
|
||||
|
||||
tag, err := resolve_int("12345", v.Elem(), true, event)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(Number("12345")))
|
||||
Expect(i.Int64()).To(Equal(int64(12345)))
|
||||
|
||||
event.value = []byte("1234")
|
||||
tag, err = resolve(event, v.Elem(), true)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(Number("1234")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("UInts", func() {
|
||||
It("resolves simple uints", func() {
|
||||
i := uint(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("1234")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(uint(1234)))
|
||||
})
|
||||
|
||||
It("resolves positive uints", func() {
|
||||
i := uint16(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("+678")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(uint16(678)))
|
||||
})
|
||||
|
||||
It("base 8", func() {
|
||||
i := uint(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("0o12")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(uint(10)))
|
||||
})
|
||||
|
||||
It("base 16", func() {
|
||||
i := uint(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("0xff")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(uint(255)))
|
||||
})
|
||||
|
||||
It("fails with negative ints", func() {
|
||||
i := uint(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("-2345")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Unsigned int with negative value: '-2345' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("fails on overflow", func() {
|
||||
i := uint8(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("2345")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Invalid unsigned integer: '2345' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("resolves null", func() {
|
||||
checkNulls(func() {
|
||||
i := uint(1)
|
||||
v := reflect.ValueOf(&i)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(i).To(Equal(uint(0)))
|
||||
})
|
||||
})
|
||||
|
||||
It("resolves null pointers", func() {
|
||||
checkNulls(func() {
|
||||
i := uint(1)
|
||||
pi := &i
|
||||
v := reflect.ValueOf(&pi)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(pi).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
It("returns a Number", func() {
|
||||
var i Number
|
||||
v := reflect.ValueOf(&i)
|
||||
|
||||
tag, err := resolve_uint("12345", v.Elem(), true, event)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(Number("12345")))
|
||||
|
||||
event.value = []byte("1234")
|
||||
tag, err = resolve(event, v.Elem(), true)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_INT_TAG))
|
||||
Expect(i).To(Equal(Number("1234")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Floats", func() {
|
||||
It("float32", func() {
|
||||
f := float32(0)
|
||||
v := reflect.ValueOf(&f)
|
||||
event.value = []byte("2345.01")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_FLOAT_TAG))
|
||||
Expect(f).To(Equal(float32(2345.01)))
|
||||
})
|
||||
|
||||
It("float64", func() {
|
||||
f := float64(0)
|
||||
v := reflect.ValueOf(&f)
|
||||
event.value = []byte("-456456.01")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_FLOAT_TAG))
|
||||
Expect(f).To(Equal(float64(-456456.01)))
|
||||
})
|
||||
|
||||
It("+inf", func() {
|
||||
f := float64(0)
|
||||
v := reflect.ValueOf(&f)
|
||||
event.value = []byte("+.inf")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_FLOAT_TAG))
|
||||
Expect(f).To(Equal(math.Inf(1)))
|
||||
})
|
||||
|
||||
It("-inf", func() {
|
||||
f := float32(0)
|
||||
v := reflect.ValueOf(&f)
|
||||
event.value = []byte("-.inf")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_FLOAT_TAG))
|
||||
Expect(f).To(Equal(float32(math.Inf(-1))))
|
||||
})
|
||||
|
||||
It("nan", func() {
|
||||
f := float64(0)
|
||||
v := reflect.ValueOf(&f)
|
||||
event.value = []byte(".NaN")
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_FLOAT_TAG))
|
||||
Expect(math.IsNaN(f)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("fails on overflow", func() {
|
||||
i := float32(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("123e10000")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Invalid float: '123e10000' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("fails on invalid float", func() {
|
||||
i := float32(0)
|
||||
v := reflect.ValueOf(&i)
|
||||
event.value = []byte("123e1a")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Invalid float: '123e1a' at line 0, column 0"))
|
||||
})
|
||||
|
||||
It("resolves null", func() {
|
||||
checkNulls(func() {
|
||||
f := float64(1)
|
||||
v := reflect.ValueOf(&f)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(f).To(Equal(0.0))
|
||||
})
|
||||
})
|
||||
|
||||
It("resolves null pointers", func() {
|
||||
checkNulls(func() {
|
||||
f := float64(1)
|
||||
pf := &f
|
||||
v := reflect.ValueOf(&pf)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(pf).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
It("returns a Number", func() {
|
||||
var i Number
|
||||
v := reflect.ValueOf(&i)
|
||||
|
||||
tag, err := resolve_float("12.345", v.Elem(), true, event)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_FLOAT_TAG))
|
||||
Expect(i).To(Equal(Number("12.345")))
|
||||
Expect(i.Float64()).To(Equal(12.345))
|
||||
|
||||
event.value = []byte("1.234")
|
||||
tag, err = resolve(event, v.Elem(), true)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_FLOAT_TAG))
|
||||
Expect(i).To(Equal(Number("1.234")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Timestamps", func() {
|
||||
parse_date := func(val string, date time.Time) {
|
||||
d := time.Now()
|
||||
v := reflect.ValueOf(&d)
|
||||
event.value = []byte(val)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(""))
|
||||
Expect(d).To(Equal(date))
|
||||
}
|
||||
|
||||
It("date", func() {
|
||||
parse_date("2002-12-14", time.Date(2002, time.December, 14, 0, 0, 0, 0, time.UTC))
|
||||
})
|
||||
|
||||
It("canonical", func() {
|
||||
parse_date("2001-12-15T02:59:43.1Z", time.Date(2001, time.December, 15, 2, 59, 43, int(1*time.Millisecond), time.UTC))
|
||||
})
|
||||
|
||||
It("iso8601", func() {
|
||||
parse_date("2001-12-14t21:59:43.10-05:00", time.Date(2001, time.December, 14, 21, 59, 43, int(10*time.Millisecond), time.FixedZone("", -5*3600)))
|
||||
})
|
||||
|
||||
It("space separated", func() {
|
||||
parse_date("2001-12-14 21:59:43.10 -5", time.Date(2001, time.December, 14, 21, 59, 43, int(10*time.Millisecond), time.FixedZone("", -5*3600)))
|
||||
})
|
||||
|
||||
It("no time zone", func() {
|
||||
parse_date("2001-12-15 2:59:43.10", time.Date(2001, time.December, 15, 2, 59, 43, int(10*time.Millisecond), time.UTC))
|
||||
})
|
||||
|
||||
It("resolves null", func() {
|
||||
checkNulls(func() {
|
||||
d := time.Now()
|
||||
v := reflect.ValueOf(&d)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(d).To(Equal(time.Time{}))
|
||||
})
|
||||
})
|
||||
|
||||
It("resolves null pointers", func() {
|
||||
checkNulls(func() {
|
||||
d := time.Now()
|
||||
pd := &d
|
||||
v := reflect.ValueOf(&pd)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_NULL_TAG))
|
||||
Expect(pd).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("Binary tag", func() {
|
||||
It("string", func() {
|
||||
checkNulls(func() {
|
||||
event.value = []byte("YWJjZGVmZw==")
|
||||
event.tag = []byte("!binary")
|
||||
aString := ""
|
||||
v := reflect.ValueOf(&aString)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_STR_TAG))
|
||||
Expect(aString).To(Equal("abcdefg"))
|
||||
})
|
||||
})
|
||||
|
||||
It("[]byte", func() {
|
||||
checkNulls(func() {
|
||||
event.value = []byte("YWJjZGVmZw==")
|
||||
event.tag = []byte("!binary")
|
||||
bytes := []byte(nil)
|
||||
v := reflect.ValueOf(&bytes)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_STR_TAG))
|
||||
Expect(bytes).To(Equal([]byte("abcdefg")))
|
||||
})
|
||||
})
|
||||
|
||||
It("returns a []byte when provided no hints", func() {
|
||||
checkNulls(func() {
|
||||
event.value = []byte("YWJjZGVmZw==")
|
||||
event.tag = []byte("!binary")
|
||||
var intf interface{}
|
||||
v := reflect.ValueOf(&intf)
|
||||
|
||||
tag, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(tag).To(Equal(yaml_STR_TAG))
|
||||
Expect(intf).To(Equal([]byte("abcdefg")))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
It("fails to resolve a pointer", func() {
|
||||
aString := ""
|
||||
pString := &aString
|
||||
v := reflect.ValueOf(&pString)
|
||||
event.value = []byte("abc")
|
||||
|
||||
_, err := resolve(event, v.Elem(), false)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("Unknown resolution for 'abc' using <*string Value> at line 0, column 0"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Not an implicit event && no tag", func() {
|
||||
It("bool returns a string", func() {
|
||||
event.value = []byte("on")
|
||||
|
||||
tag, result := resolveInterface(event, false)
|
||||
Expect(result).To(Equal("on"))
|
||||
Expect(tag).To(Equal(""))
|
||||
})
|
||||
|
||||
It("number returns a string", func() {
|
||||
event.value = []byte("1234")
|
||||
|
||||
tag, result := resolveInterface(event, false)
|
||||
Expect(result).To(Equal("1234"))
|
||||
Expect(tag).To(Equal(""))
|
||||
})
|
||||
|
||||
It("returns the empty string", func() {
|
||||
event.value = []byte("")
|
||||
// event.implicit = true
|
||||
|
||||
tag, result := resolveInterface(event, false)
|
||||
Expect(result).To(Equal(""))
|
||||
Expect(tag).To(Equal(""))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
62
vendor/github.com/cloudfoundry-incubator/candiedyaml/run_parser.go
generated
vendored
Normal file
62
vendor/github.com/cloudfoundry-incubator/candiedyaml/run_parser.go
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Run_parser(cmd string, args []string) {
|
||||
for i := 0; i < len(args); i++ {
|
||||
fmt.Printf("[%d] Scanning '%s'", i, args[i])
|
||||
file, err := os.Open(args[i])
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Invalid file '%s': %s", args[i], err.Error()))
|
||||
}
|
||||
|
||||
parser := yaml_parser_t{}
|
||||
yaml_parser_initialize(&parser)
|
||||
yaml_parser_set_input_reader(&parser, file)
|
||||
|
||||
failed := false
|
||||
token := yaml_token_t{}
|
||||
count := 0
|
||||
for {
|
||||
if !yaml_parser_scan(&parser, &token) {
|
||||
failed = true
|
||||
break
|
||||
}
|
||||
|
||||
if token.token_type == yaml_STREAM_END_TOKEN {
|
||||
break
|
||||
}
|
||||
count++
|
||||
}
|
||||
|
||||
file.Close()
|
||||
|
||||
msg := "SUCCESS"
|
||||
if failed {
|
||||
msg = "FAILED"
|
||||
if parser.error != yaml_NO_ERROR {
|
||||
m := parser.problem_mark
|
||||
fmt.Printf("ERROR: (%s) %s @ line: %d col: %d\n",
|
||||
parser.context, parser.problem, m.line, m.column)
|
||||
}
|
||||
}
|
||||
fmt.Printf("%s (%d tokens)\n", msg, count)
|
||||
}
|
||||
}
|
||||
3318
vendor/github.com/cloudfoundry-incubator/candiedyaml/scanner.go
generated
vendored
Normal file
3318
vendor/github.com/cloudfoundry-incubator/candiedyaml/scanner.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
80
vendor/github.com/cloudfoundry-incubator/candiedyaml/scanner_test.go
generated
vendored
Normal file
80
vendor/github.com/cloudfoundry-incubator/candiedyaml/scanner_test.go
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var scan = func(filename string) {
|
||||
It("scan "+filename, func() {
|
||||
file, err := os.Open(filename)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
parser := yaml_parser_t{}
|
||||
yaml_parser_initialize(&parser)
|
||||
yaml_parser_set_input_reader(&parser, file)
|
||||
|
||||
failed := false
|
||||
token := yaml_token_t{}
|
||||
|
||||
for {
|
||||
if !yaml_parser_scan(&parser, &token) {
|
||||
failed = true
|
||||
break
|
||||
}
|
||||
|
||||
if token.token_type == yaml_STREAM_END_TOKEN {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
file.Close()
|
||||
|
||||
// msg := "SUCCESS"
|
||||
// if failed {
|
||||
// msg = "FAILED"
|
||||
// if parser.error != yaml_NO_ERROR {
|
||||
// m := parser.problem_mark
|
||||
// fmt.Printf("ERROR: (%s) %s @ line: %d col: %d\n",
|
||||
// parser.context, parser.problem, m.line, m.column)
|
||||
// }
|
||||
// }
|
||||
Expect(failed).To(BeFalse())
|
||||
})
|
||||
}
|
||||
|
||||
var scanYamls = func(dirname string) {
|
||||
fileInfos, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
for _, fileInfo := range fileInfos {
|
||||
if !fileInfo.IsDir() {
|
||||
scan(filepath.Join(dirname, fileInfo.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _ = Describe("Scanner", func() {
|
||||
scanYamls("fixtures/specification")
|
||||
scanYamls("fixtures/specification/types")
|
||||
})
|
||||
360
vendor/github.com/cloudfoundry-incubator/candiedyaml/tags.go
generated
vendored
Normal file
360
vendor/github.com/cloudfoundry-incubator/candiedyaml/tags.go
generated
vendored
Normal file
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// A field represents a single field found in a struct.
|
||||
type field struct {
|
||||
name string
|
||||
tag bool
|
||||
index []int
|
||||
typ reflect.Type
|
||||
omitEmpty bool
|
||||
flow bool
|
||||
}
|
||||
|
||||
// byName sorts field by name, breaking ties with depth,
|
||||
// then breaking ties with "name came from json tag", then
|
||||
// breaking ties with index sequence.
|
||||
type byName []field
|
||||
|
||||
func (x byName) Len() int { return len(x) }
|
||||
|
||||
func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||
|
||||
func (x byName) Less(i, j int) bool {
|
||||
if x[i].name != x[j].name {
|
||||
return x[i].name < x[j].name
|
||||
}
|
||||
if len(x[i].index) != len(x[j].index) {
|
||||
return len(x[i].index) < len(x[j].index)
|
||||
}
|
||||
if x[i].tag != x[j].tag {
|
||||
return x[i].tag
|
||||
}
|
||||
return byIndex(x).Less(i, j)
|
||||
}
|
||||
|
||||
// byIndex sorts field by index sequence.
|
||||
type byIndex []field
|
||||
|
||||
func (x byIndex) Len() int { return len(x) }
|
||||
|
||||
func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||
|
||||
func (x byIndex) Less(i, j int) bool {
|
||||
for k, xik := range x[i].index {
|
||||
if k >= len(x[j].index) {
|
||||
return false
|
||||
}
|
||||
if xik != x[j].index[k] {
|
||||
return xik < x[j].index[k]
|
||||
}
|
||||
}
|
||||
return len(x[i].index) < len(x[j].index)
|
||||
}
|
||||
|
||||
// typeFields returns a list of fields that JSON should recognize for the given type.
|
||||
// The algorithm is breadth-first search over the set of structs to include - the top struct
|
||||
// and then any reachable anonymous structs.
|
||||
func typeFields(t reflect.Type) []field {
|
||||
// Anonymous fields to explore at the current level and the next.
|
||||
current := []field{}
|
||||
next := []field{{typ: t}}
|
||||
|
||||
// Count of queued names for current level and the next.
|
||||
count := map[reflect.Type]int{}
|
||||
nextCount := map[reflect.Type]int{}
|
||||
|
||||
// Types already visited at an earlier level.
|
||||
visited := map[reflect.Type]bool{}
|
||||
|
||||
// Fields found.
|
||||
var fields []field
|
||||
|
||||
for len(next) > 0 {
|
||||
current, next = next, current[:0]
|
||||
count, nextCount = nextCount, map[reflect.Type]int{}
|
||||
|
||||
for _, f := range current {
|
||||
if visited[f.typ] {
|
||||
continue
|
||||
}
|
||||
visited[f.typ] = true
|
||||
|
||||
// Scan f.typ for fields to include.
|
||||
for i := 0; i < f.typ.NumField(); i++ {
|
||||
sf := f.typ.Field(i)
|
||||
if sf.PkgPath != "" { // unexported
|
||||
continue
|
||||
}
|
||||
tag := sf.Tag.Get("yaml")
|
||||
if tag == "-" {
|
||||
continue
|
||||
}
|
||||
name, opts := parseTag(tag)
|
||||
if !isValidTag(name) {
|
||||
name = ""
|
||||
}
|
||||
index := make([]int, len(f.index)+1)
|
||||
copy(index, f.index)
|
||||
index[len(f.index)] = i
|
||||
|
||||
ft := sf.Type
|
||||
if ft.Name() == "" && ft.Kind() == reflect.Ptr {
|
||||
// Follow pointer.
|
||||
ft = ft.Elem()
|
||||
}
|
||||
|
||||
// Record found field and index sequence.
|
||||
if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct {
|
||||
tagged := name != ""
|
||||
if name == "" {
|
||||
name = sf.Name
|
||||
}
|
||||
fields = append(fields, field{name, tagged, index, ft,
|
||||
opts.Contains("omitempty"), opts.Contains("flow")})
|
||||
if count[f.typ] > 1 {
|
||||
// If there were multiple instances, add a second,
|
||||
// so that the annihilation code will see a duplicate.
|
||||
// It only cares about the distinction between 1 or 2,
|
||||
// so don't bother generating any more copies.
|
||||
fields = append(fields, fields[len(fields)-1])
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Record new anonymous struct to explore in next round.
|
||||
nextCount[ft]++
|
||||
if nextCount[ft] == 1 {
|
||||
next = append(next, field{name: ft.Name(), index: index, typ: ft})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(byName(fields))
|
||||
|
||||
// Delete all fields that are hidden by the Go rules for embedded fields,
|
||||
// except that fields with JSON tags are promoted.
|
||||
|
||||
// The fields are sorted in primary order of name, secondary order
|
||||
// of field index length. Loop over names; for each name, delete
|
||||
// hidden fields by choosing the one dominant field that survives.
|
||||
out := fields[:0]
|
||||
for advance, i := 0, 0; i < len(fields); i += advance {
|
||||
// One iteration per name.
|
||||
// Find the sequence of fields with the name of this first field.
|
||||
fi := fields[i]
|
||||
name := fi.name
|
||||
for advance = 1; i+advance < len(fields); advance++ {
|
||||
fj := fields[i+advance]
|
||||
if fj.name != name {
|
||||
break
|
||||
}
|
||||
}
|
||||
if advance == 1 { // Only one field with this name
|
||||
out = append(out, fi)
|
||||
continue
|
||||
}
|
||||
dominant, ok := dominantField(fields[i : i+advance])
|
||||
if ok {
|
||||
out = append(out, dominant)
|
||||
}
|
||||
}
|
||||
|
||||
fields = out
|
||||
sort.Sort(byIndex(fields))
|
||||
|
||||
return fields
|
||||
}
|
||||
|
||||
// dominantField looks through the fields, all of which are known to
|
||||
// have the same name, to find the single field that dominates the
|
||||
// others using Go's embedding rules, modified by the presence of
|
||||
// JSON tags. If there are multiple top-level fields, the boolean
|
||||
// will be false: This condition is an error in Go and we skip all
|
||||
// the fields.
|
||||
func dominantField(fields []field) (field, bool) {
|
||||
// The fields are sorted in increasing index-length order. The winner
|
||||
// must therefore be one with the shortest index length. Drop all
|
||||
// longer entries, which is easy: just truncate the slice.
|
||||
length := len(fields[0].index)
|
||||
tagged := -1 // Index of first tagged field.
|
||||
for i, f := range fields {
|
||||
if len(f.index) > length {
|
||||
fields = fields[:i]
|
||||
break
|
||||
}
|
||||
if f.tag {
|
||||
if tagged >= 0 {
|
||||
// Multiple tagged fields at the same level: conflict.
|
||||
// Return no field.
|
||||
return field{}, false
|
||||
}
|
||||
tagged = i
|
||||
}
|
||||
}
|
||||
if tagged >= 0 {
|
||||
return fields[tagged], true
|
||||
}
|
||||
// All remaining fields have the same length. If there's more than one,
|
||||
// we have a conflict (two fields named "X" at the same level) and we
|
||||
// return no field.
|
||||
if len(fields) > 1 {
|
||||
return field{}, false
|
||||
}
|
||||
return fields[0], true
|
||||
}
|
||||
|
||||
var fieldCache struct {
|
||||
sync.RWMutex
|
||||
m map[reflect.Type][]field
|
||||
}
|
||||
|
||||
// cachedTypeFields is like typeFields but uses a cache to avoid repeated work.
|
||||
func cachedTypeFields(t reflect.Type) []field {
|
||||
fieldCache.RLock()
|
||||
f := fieldCache.m[t]
|
||||
fieldCache.RUnlock()
|
||||
if f != nil {
|
||||
return f
|
||||
}
|
||||
|
||||
// Compute fields without lock.
|
||||
// Might duplicate effort but won't hold other computations back.
|
||||
f = typeFields(t)
|
||||
if f == nil {
|
||||
f = []field{}
|
||||
}
|
||||
|
||||
fieldCache.Lock()
|
||||
if fieldCache.m == nil {
|
||||
fieldCache.m = map[reflect.Type][]field{}
|
||||
}
|
||||
fieldCache.m[t] = f
|
||||
fieldCache.Unlock()
|
||||
return f
|
||||
}
|
||||
|
||||
// tagOptions is the string following a comma in a struct field's "json"
|
||||
// tag, or the empty string. It does not include the leading comma.
|
||||
type tagOptions string
|
||||
|
||||
func isValidTag(s string) bool {
|
||||
if s == "" {
|
||||
return false
|
||||
}
|
||||
for _, c := range s {
|
||||
switch {
|
||||
case strings.ContainsRune("!#$%&()*+-./:<=>?@[]^_{|}~ ", c):
|
||||
// Backslash and quote chars are reserved, but
|
||||
// otherwise any punctuation chars are allowed
|
||||
// in a tag name.
|
||||
default:
|
||||
if !unicode.IsLetter(c) && !unicode.IsDigit(c) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func fieldByIndex(v reflect.Value, index []int) reflect.Value {
|
||||
for _, i := range index {
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.IsNil() {
|
||||
return reflect.Value{}
|
||||
}
|
||||
v = v.Elem()
|
||||
}
|
||||
v = v.Field(i)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func typeByIndex(t reflect.Type, index []int) reflect.Type {
|
||||
for _, i := range index {
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
t = t.Field(i).Type
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// stringValues is a slice of reflect.Value holding *reflect.StringValue.
|
||||
// It implements the methods to sort by string.
|
||||
type stringValues []reflect.Value
|
||||
|
||||
func (sv stringValues) Len() int { return len(sv) }
|
||||
func (sv stringValues) Swap(i, j int) { sv[i], sv[j] = sv[j], sv[i] }
|
||||
func (sv stringValues) Less(i, j int) bool {
|
||||
av, ak := getElem(sv[i])
|
||||
bv, bk := getElem(sv[j])
|
||||
if ak == reflect.String && bk == reflect.String {
|
||||
return av.String() < bv.String()
|
||||
}
|
||||
|
||||
return ak < bk
|
||||
}
|
||||
|
||||
func getElem(v reflect.Value) (reflect.Value, reflect.Kind) {
|
||||
k := v.Kind()
|
||||
for k == reflect.Interface || k == reflect.Ptr && !v.IsNil() {
|
||||
v = v.Elem()
|
||||
k = v.Kind()
|
||||
}
|
||||
|
||||
return v, k
|
||||
}
|
||||
|
||||
// parseTag splits a struct field's json tag into its name and
|
||||
// comma-separated options.
|
||||
func parseTag(tag string) (string, tagOptions) {
|
||||
if idx := strings.Index(tag, ","); idx != -1 {
|
||||
return tag[:idx], tagOptions(tag[idx+1:])
|
||||
}
|
||||
return tag, tagOptions("")
|
||||
}
|
||||
|
||||
// Contains reports whether a comma-separated list of options
|
||||
// contains a particular substr flag. substr must be surrounded by a
|
||||
// string boundary or commas.
|
||||
func (o tagOptions) Contains(optionName 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 == optionName {
|
||||
return true
|
||||
}
|
||||
s = next
|
||||
}
|
||||
return false
|
||||
}
|
||||
128
vendor/github.com/cloudfoundry-incubator/candiedyaml/writer.go
generated
vendored
Normal file
128
vendor/github.com/cloudfoundry-incubator/candiedyaml/writer.go
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
/*
|
||||
* Set the writer error and return 0.
|
||||
*/
|
||||
|
||||
func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool {
|
||||
emitter.error = yaml_WRITER_ERROR
|
||||
emitter.problem = problem
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush the output buffer.
|
||||
*/
|
||||
|
||||
func yaml_emitter_flush(emitter *yaml_emitter_t) bool {
|
||||
if emitter.write_handler == nil {
|
||||
panic("Write handler must be set") /* Write handler must be set. */
|
||||
}
|
||||
if emitter.encoding == yaml_ANY_ENCODING {
|
||||
panic("Encoding must be set") /* Output encoding must be set. */
|
||||
}
|
||||
|
||||
/* Check if the buffer is empty. */
|
||||
|
||||
if emitter.buffer_pos == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
/* If the output encoding is UTF-8, we don't need to recode the buffer. */
|
||||
|
||||
if emitter.encoding == yaml_UTF8_ENCODING {
|
||||
if err := emitter.write_handler(emitter,
|
||||
emitter.buffer[:emitter.buffer_pos]); err != nil {
|
||||
return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error())
|
||||
}
|
||||
emitter.buffer_pos = 0
|
||||
return true
|
||||
}
|
||||
|
||||
/* Recode the buffer into the raw buffer. */
|
||||
|
||||
var low, high int
|
||||
if emitter.encoding == yaml_UTF16LE_ENCODING {
|
||||
low, high = 0, 1
|
||||
} else {
|
||||
high, low = 1, 0
|
||||
}
|
||||
|
||||
pos := 0
|
||||
for pos < emitter.buffer_pos {
|
||||
|
||||
/*
|
||||
* See the "reader.c" code for more details on UTF-8 encoding. Note
|
||||
* that we assume that the buffer contains a valid UTF-8 sequence.
|
||||
*/
|
||||
|
||||
/* Read the next UTF-8 character. */
|
||||
|
||||
octet := emitter.buffer[pos]
|
||||
|
||||
var w int
|
||||
var value rune
|
||||
switch {
|
||||
case octet&0x80 == 0x00:
|
||||
w, value = 1, rune(octet&0x7F)
|
||||
case octet&0xE0 == 0xC0:
|
||||
w, value = 2, rune(octet&0x1F)
|
||||
case octet&0xF0 == 0xE0:
|
||||
w, value = 3, rune(octet&0x0F)
|
||||
case octet&0xF8 == 0xF0:
|
||||
w, value = 4, rune(octet&0x07)
|
||||
}
|
||||
|
||||
for k := 1; k < w; k++ {
|
||||
octet = emitter.buffer[pos+k]
|
||||
value = (value << 6) + (rune(octet) & 0x3F)
|
||||
}
|
||||
|
||||
pos += w
|
||||
|
||||
/* Write the character. */
|
||||
|
||||
if value < 0x10000 {
|
||||
var b [2]byte
|
||||
b[high] = byte(value >> 8)
|
||||
b[low] = byte(value & 0xFF)
|
||||
emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1])
|
||||
} else {
|
||||
/* Write the character using a surrogate pair (check "reader.c"). */
|
||||
|
||||
var b [4]byte
|
||||
value -= 0x10000
|
||||
b[high] = byte(0xD8 + (value >> 18))
|
||||
b[low] = byte((value >> 10) & 0xFF)
|
||||
b[high+2] = byte(0xDC + ((value >> 8) & 0xFF))
|
||||
b[low+2] = byte(value & 0xFF)
|
||||
emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1], b[2], b[3])
|
||||
}
|
||||
}
|
||||
|
||||
/* Write the raw buffer. */
|
||||
|
||||
// Write the raw buffer.
|
||||
if err := emitter.write_handler(emitter, emitter.raw_buffer); err != nil {
|
||||
return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error())
|
||||
}
|
||||
|
||||
emitter.buffer_pos = 0
|
||||
emitter.raw_buffer = emitter.raw_buffer[:0]
|
||||
return true
|
||||
}
|
||||
22
vendor/github.com/cloudfoundry-incubator/candiedyaml/yaml_definesh.go
generated
vendored
Normal file
22
vendor/github.com/cloudfoundry-incubator/candiedyaml/yaml_definesh.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
const (
|
||||
yaml_VERSION_MAJOR = 0
|
||||
yaml_VERSION_MINOR = 1
|
||||
yaml_VERSION_PATCH = 6
|
||||
yaml_VERSION_STRING = "0.1.6"
|
||||
)
|
||||
891
vendor/github.com/cloudfoundry-incubator/candiedyaml/yaml_privateh.go
generated
vendored
Normal file
891
vendor/github.com/cloudfoundry-incubator/candiedyaml/yaml_privateh.go
generated
vendored
Normal file
@@ -0,0 +1,891 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
const (
|
||||
INPUT_RAW_BUFFER_SIZE = 1024
|
||||
|
||||
/*
|
||||
* The size of the input buffer.
|
||||
*
|
||||
* It should be possible to decode the whole raw buffer.
|
||||
*/
|
||||
INPUT_BUFFER_SIZE = (INPUT_RAW_BUFFER_SIZE * 3)
|
||||
|
||||
/*
|
||||
* The size of the output buffer.
|
||||
*/
|
||||
|
||||
OUTPUT_BUFFER_SIZE = 512
|
||||
|
||||
/*
|
||||
* The size of the output raw buffer.
|
||||
*
|
||||
* It should be possible to encode the whole output buffer.
|
||||
*/
|
||||
|
||||
OUTPUT_RAW_BUFFER_SIZE = (OUTPUT_BUFFER_SIZE*2 + 2)
|
||||
|
||||
INITIAL_STACK_SIZE = 16
|
||||
INITIAL_QUEUE_SIZE = 16
|
||||
)
|
||||
|
||||
func width(b byte) int {
|
||||
if b&0x80 == 0 {
|
||||
return 1
|
||||
}
|
||||
|
||||
if b&0xE0 == 0xC0 {
|
||||
return 2
|
||||
}
|
||||
|
||||
if b&0xF0 == 0xE0 {
|
||||
return 3
|
||||
}
|
||||
|
||||
if b&0xF8 == 0xF0 {
|
||||
return 4
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func copy_bytes(dest []byte, dest_pos *int, src []byte, src_pos *int) {
|
||||
w := width(src[*src_pos])
|
||||
switch w {
|
||||
case 4:
|
||||
dest[*dest_pos+3] = src[*src_pos+3]
|
||||
fallthrough
|
||||
case 3:
|
||||
dest[*dest_pos+2] = src[*src_pos+2]
|
||||
fallthrough
|
||||
case 2:
|
||||
dest[*dest_pos+1] = src[*src_pos+1]
|
||||
fallthrough
|
||||
case 1:
|
||||
dest[*dest_pos] = src[*src_pos]
|
||||
default:
|
||||
panic("invalid width")
|
||||
}
|
||||
*dest_pos += w
|
||||
*src_pos += w
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is an alphabetical
|
||||
// * character, a digit, '_', or '-'.
|
||||
// */
|
||||
|
||||
func is_alpha(b byte) bool {
|
||||
return (b >= '0' && b <= '9') ||
|
||||
(b >= 'A' && b <= 'Z') ||
|
||||
(b >= 'a' && b <= 'z') ||
|
||||
b == '_' || b == '-'
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is a digit.
|
||||
// */
|
||||
//
|
||||
func is_digit(b byte) bool {
|
||||
return b >= '0' && b <= '9'
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Get the value of a digit.
|
||||
// */
|
||||
//
|
||||
func as_digit(b byte) int {
|
||||
return int(b) - '0'
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is a hex-digit.
|
||||
// */
|
||||
//
|
||||
func is_hex(b byte) bool {
|
||||
return (b >= '0' && b <= '9') ||
|
||||
(b >= 'A' && b <= 'F') ||
|
||||
(b >= 'a' && b <= 'f')
|
||||
}
|
||||
|
||||
//
|
||||
// /*
|
||||
// * Get the value of a hex-digit.
|
||||
// */
|
||||
//
|
||||
func as_hex(b byte) int {
|
||||
if b >= 'A' && b <= 'F' {
|
||||
return int(b) - 'A' + 10
|
||||
} else if b >= 'a' && b <= 'f' {
|
||||
return int(b) - 'a' + 10
|
||||
}
|
||||
return int(b) - '0'
|
||||
}
|
||||
|
||||
// #define AS_HEX_AT(string,offset) \
|
||||
// (((string).pointer[offset] >= (yaml_char_t) 'A' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'F') ? \
|
||||
// ((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \
|
||||
// ((string).pointer[offset] >= (yaml_char_t) 'a' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'f') ? \
|
||||
// ((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \
|
||||
// ((string).pointer[offset] - (yaml_char_t) '0'))
|
||||
|
||||
// /*
|
||||
// * Check if the character is a line break, space, tab, or NUL.
|
||||
// */
|
||||
func is_blankz_at(b []byte, i int) bool {
|
||||
return is_blank(b[i]) || is_breakz_at(b, i)
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is a line break.
|
||||
// */
|
||||
func is_break_at(b []byte, i int) bool {
|
||||
return b[i] == '\r' || /* CR (#xD)*/
|
||||
b[i] == '\n' || /* LF (#xA) */
|
||||
(b[i] == 0xC2 && b[i+1] == 0x85) || /* NEL (#x85) */
|
||||
(b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8) || /* LS (#x2028) */
|
||||
(b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9) /* PS (#x2029) */
|
||||
}
|
||||
|
||||
func is_breakz_at(b []byte, i int) bool {
|
||||
return is_break_at(b, i) || is_z(b[i])
|
||||
}
|
||||
|
||||
func is_crlf_at(b []byte, i int) bool {
|
||||
return b[i] == '\r' && b[i+1] == '\n'
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is NUL.
|
||||
// */
|
||||
func is_z(b byte) bool {
|
||||
return b == 0x0
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is space.
|
||||
// */
|
||||
func is_space(b byte) bool {
|
||||
return b == ' '
|
||||
}
|
||||
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is tab.
|
||||
// */
|
||||
func is_tab(b byte) bool {
|
||||
return b == '\t'
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is blank (space or tab).
|
||||
// */
|
||||
func is_blank(b byte) bool {
|
||||
return is_space(b) || is_tab(b)
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character is ASCII.
|
||||
// */
|
||||
func is_ascii(b byte) bool {
|
||||
return b <= '\x7f'
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character can be printed unescaped.
|
||||
// */
|
||||
func is_printable_at(b []byte, i int) bool {
|
||||
return ((b[i] == 0x0A) || /* . == #x0A */
|
||||
(b[i] >= 0x20 && b[i] <= 0x7E) || /* #x20 <= . <= #x7E */
|
||||
(b[i] == 0xC2 && b[i+1] >= 0xA0) || /* #0xA0 <= . <= #xD7FF */
|
||||
(b[i] > 0xC2 && b[i] < 0xED) ||
|
||||
(b[i] == 0xED && b[i+1] < 0xA0) ||
|
||||
(b[i] == 0xEE) ||
|
||||
(b[i] == 0xEF && /* && . != #xFEFF */
|
||||
!(b[i+1] == 0xBB && b[i+2] == 0xBF) &&
|
||||
!(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF))))
|
||||
}
|
||||
|
||||
func insert_token(parser *yaml_parser_t, pos int, token *yaml_token_t) {
|
||||
// collapse the slice
|
||||
if parser.tokens_head > 0 && len(parser.tokens) == cap(parser.tokens) {
|
||||
if parser.tokens_head != len(parser.tokens) {
|
||||
// move the tokens down
|
||||
copy(parser.tokens, parser.tokens[parser.tokens_head:])
|
||||
}
|
||||
// readjust the length
|
||||
parser.tokens = parser.tokens[:len(parser.tokens)-parser.tokens_head]
|
||||
parser.tokens_head = 0
|
||||
}
|
||||
|
||||
parser.tokens = append(parser.tokens, *token)
|
||||
if pos < 0 {
|
||||
return
|
||||
}
|
||||
copy(parser.tokens[parser.tokens_head+pos+1:], parser.tokens[parser.tokens_head+pos:])
|
||||
parser.tokens[parser.tokens_head+pos] = *token
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Check if the character at the specified position is BOM.
|
||||
// */
|
||||
//
|
||||
func is_bom_at(b []byte, i int) bool {
|
||||
return b[i] == 0xEF && b[i+1] == 0xBB && b[i+2] == 0xBF
|
||||
}
|
||||
|
||||
//
|
||||
// #ifdef HAVE_CONFIG_H
|
||||
// #include <config.h>
|
||||
// #endif
|
||||
//
|
||||
// #include "./yaml.h"
|
||||
//
|
||||
// #include <assert.h>
|
||||
// #include <limits.h>
|
||||
//
|
||||
// /*
|
||||
// * Memory management.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(void *)
|
||||
// yaml_malloc(size_t size);
|
||||
//
|
||||
// yaml_DECLARE(void *)
|
||||
// yaml_realloc(void *ptr, size_t size);
|
||||
//
|
||||
// yaml_DECLARE(void)
|
||||
// yaml_free(void *ptr);
|
||||
//
|
||||
// yaml_DECLARE(yaml_char_t *)
|
||||
// yaml_strdup(const yaml_char_t *);
|
||||
//
|
||||
// /*
|
||||
// * Reader: Ensure that the buffer contains at least `length` characters.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
|
||||
//
|
||||
// /*
|
||||
// * Scanner: Ensure that the token stack contains at least one token ready.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
|
||||
//
|
||||
// /*
|
||||
// * The size of the input raw buffer.
|
||||
// */
|
||||
//
|
||||
// #define INPUT_RAW_BUFFER_SIZE 16384
|
||||
//
|
||||
// /*
|
||||
// * The size of the input buffer.
|
||||
// *
|
||||
// * It should be possible to decode the whole raw buffer.
|
||||
// */
|
||||
//
|
||||
// #define INPUT_BUFFER_SIZE (INPUT_RAW_BUFFER_SIZE*3)
|
||||
//
|
||||
// /*
|
||||
// * The size of the output buffer.
|
||||
// */
|
||||
//
|
||||
// #define OUTPUT_BUFFER_SIZE 16384
|
||||
//
|
||||
// /*
|
||||
// * The size of the output raw buffer.
|
||||
// *
|
||||
// * It should be possible to encode the whole output buffer.
|
||||
// */
|
||||
//
|
||||
// #define OUTPUT_RAW_BUFFER_SIZE (OUTPUT_BUFFER_SIZE*2+2)
|
||||
//
|
||||
// /*
|
||||
// * The size of other stacks and queues.
|
||||
// */
|
||||
//
|
||||
// #define INITIAL_STACK_SIZE 16
|
||||
// #define INITIAL_QUEUE_SIZE 16
|
||||
// #define INITIAL_STRING_SIZE 16
|
||||
//
|
||||
// /*
|
||||
// * Buffer management.
|
||||
// */
|
||||
//
|
||||
// #define BUFFER_INIT(context,buffer,size) \
|
||||
// (((buffer).start = yaml_malloc(size)) ? \
|
||||
// ((buffer).last = (buffer).pointer = (buffer).start, \
|
||||
// (buffer).end = (buffer).start+(size), \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// #define BUFFER_DEL(context,buffer) \
|
||||
// (yaml_free((buffer).start), \
|
||||
// (buffer).start = (buffer).pointer = (buffer).end = 0)
|
||||
//
|
||||
// /*
|
||||
// * String management.
|
||||
// */
|
||||
//
|
||||
// typedef struct {
|
||||
// yaml_char_t *start;
|
||||
// yaml_char_t *end;
|
||||
// yaml_char_t *pointer;
|
||||
// } yaml_string_t;
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_string_extend(yaml_char_t **start,
|
||||
// yaml_char_t **pointer, yaml_char_t **end);
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_string_join(
|
||||
// yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
|
||||
// yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
|
||||
//
|
||||
// #define NULL_STRING { NULL, NULL, NULL }
|
||||
//
|
||||
// #define STRING(string,length) { (string), (string)+(length), (string) }
|
||||
//
|
||||
// #define STRING_ASSIGN(value,string,length) \
|
||||
// ((value).start = (string), \
|
||||
// (value).end = (string)+(length), \
|
||||
// (value).pointer = (string))
|
||||
//
|
||||
// #define STRING_INIT(context,string,size) \
|
||||
// (((string).start = yaml_malloc(size)) ? \
|
||||
// ((string).pointer = (string).start, \
|
||||
// (string).end = (string).start+(size), \
|
||||
// memset((string).start, 0, (size)), \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// #define STRING_DEL(context,string) \
|
||||
// (yaml_free((string).start), \
|
||||
// (string).start = (string).pointer = (string).end = 0)
|
||||
//
|
||||
// #define STRING_EXTEND(context,string) \
|
||||
// (((string).pointer+5 < (string).end) \
|
||||
// || yaml_string_extend(&(string).start, \
|
||||
// &(string).pointer, &(string).end))
|
||||
//
|
||||
// #define CLEAR(context,string) \
|
||||
// ((string).pointer = (string).start, \
|
||||
// memset((string).start, 0, (string).end-(string).start))
|
||||
//
|
||||
// #define JOIN(context,string_a,string_b) \
|
||||
// ((yaml_string_join(&(string_a).start, &(string_a).pointer, \
|
||||
// &(string_a).end, &(string_b).start, \
|
||||
// &(string_b).pointer, &(string_b).end)) ? \
|
||||
// ((string_b).pointer = (string_b).start, \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// /*
|
||||
// * String check operations.
|
||||
// */
|
||||
//
|
||||
// /*
|
||||
// * Check the octet at the specified position.
|
||||
// */
|
||||
//
|
||||
// #define CHECK_AT(string,octet,offset) \
|
||||
// ((string).pointer[offset] == (yaml_char_t)(octet))
|
||||
//
|
||||
// /*
|
||||
// * Check the current octet in the buffer.
|
||||
// */
|
||||
//
|
||||
// #define CHECK(string,octet) CHECK_AT((string),(octet),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is an alphabetical
|
||||
// * character, a digit, '_', or '-'.
|
||||
// */
|
||||
//
|
||||
// #define IS_ALPHA_AT(string,offset) \
|
||||
// (((string).pointer[offset] >= (yaml_char_t) '0' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) '9') || \
|
||||
// ((string).pointer[offset] >= (yaml_char_t) 'A' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'Z') || \
|
||||
// ((string).pointer[offset] >= (yaml_char_t) 'a' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'z') || \
|
||||
// (string).pointer[offset] == '_' || \
|
||||
// (string).pointer[offset] == '-')
|
||||
//
|
||||
// #define IS_ALPHA(string) IS_ALPHA_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is a digit.
|
||||
// */
|
||||
//
|
||||
// #define IS_DIGIT_AT(string,offset) \
|
||||
// (((string).pointer[offset] >= (yaml_char_t) '0' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) '9'))
|
||||
//
|
||||
// #define IS_DIGIT(string) IS_DIGIT_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Get the value of a digit.
|
||||
// */
|
||||
//
|
||||
// #define AS_DIGIT_AT(string,offset) \
|
||||
// ((string).pointer[offset] - (yaml_char_t) '0')
|
||||
//
|
||||
// #define AS_DIGIT(string) AS_DIGIT_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is a hex-digit.
|
||||
// */
|
||||
//
|
||||
// #define IS_HEX_AT(string,offset) \
|
||||
// (((string).pointer[offset] >= (yaml_char_t) '0' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) '9') || \
|
||||
// ((string).pointer[offset] >= (yaml_char_t) 'A' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'F') || \
|
||||
// ((string).pointer[offset] >= (yaml_char_t) 'a' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'f'))
|
||||
//
|
||||
// #define IS_HEX(string) IS_HEX_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Get the value of a hex-digit.
|
||||
// */
|
||||
//
|
||||
// #define AS_HEX_AT(string,offset) \
|
||||
// (((string).pointer[offset] >= (yaml_char_t) 'A' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'F') ? \
|
||||
// ((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \
|
||||
// ((string).pointer[offset] >= (yaml_char_t) 'a' && \
|
||||
// (string).pointer[offset] <= (yaml_char_t) 'f') ? \
|
||||
// ((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \
|
||||
// ((string).pointer[offset] - (yaml_char_t) '0'))
|
||||
//
|
||||
// #define AS_HEX(string) AS_HEX_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character is ASCII.
|
||||
// */
|
||||
//
|
||||
// #define IS_ASCII_AT(string,offset) \
|
||||
// ((string).pointer[offset] <= (yaml_char_t) '\x7F')
|
||||
//
|
||||
// #define IS_ASCII(string) IS_ASCII_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character can be printed unescaped.
|
||||
// */
|
||||
//
|
||||
// #define IS_PRINTABLE_AT(string,offset) \
|
||||
// (((string).pointer[offset] == 0x0A) /* . == #x0A */ \
|
||||
// || ((string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */ \
|
||||
// && (string).pointer[offset] <= 0x7E) \
|
||||
// || ((string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */ \
|
||||
// && (string).pointer[offset+1] >= 0xA0) \
|
||||
// || ((string).pointer[offset] > 0xC2 \
|
||||
// && (string).pointer[offset] < 0xED) \
|
||||
// || ((string).pointer[offset] == 0xED \
|
||||
// && (string).pointer[offset+1] < 0xA0) \
|
||||
// || ((string).pointer[offset] == 0xEE) \
|
||||
// || ((string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */ \
|
||||
// && !((string).pointer[offset+1] == 0xBB /* && . != #xFEFF */ \
|
||||
// && (string).pointer[offset+2] == 0xBF) \
|
||||
// && !((string).pointer[offset+1] == 0xBF \
|
||||
// && ((string).pointer[offset+2] == 0xBE \
|
||||
// || (string).pointer[offset+2] == 0xBF))))
|
||||
//
|
||||
// #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is NUL.
|
||||
// */
|
||||
//
|
||||
// #define IS_Z_AT(string,offset) CHECK_AT((string),'\0',(offset))
|
||||
//
|
||||
// #define IS_Z(string) IS_Z_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is BOM.
|
||||
// */
|
||||
//
|
||||
// #define IS_BOM_AT(string,offset) \
|
||||
// (CHECK_AT((string),'\xEF',(offset)) \
|
||||
// && CHECK_AT((string),'\xBB',(offset)+1) \
|
||||
// && CHECK_AT((string),'\xBF',(offset)+2)) /* BOM (#xFEFF) */
|
||||
//
|
||||
// #define IS_BOM(string) IS_BOM_AT(string,0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is space.
|
||||
// */
|
||||
//
|
||||
// #define IS_SPACE_AT(string,offset) CHECK_AT((string),' ',(offset))
|
||||
//
|
||||
// #define IS_SPACE(string) IS_SPACE_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is tab.
|
||||
// */
|
||||
//
|
||||
// #define IS_TAB_AT(string,offset) CHECK_AT((string),'\t',(offset))
|
||||
//
|
||||
// #define IS_TAB(string) IS_TAB_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is blank (space or tab).
|
||||
// */
|
||||
//
|
||||
// #define IS_BLANK_AT(string,offset) \
|
||||
// (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset)))
|
||||
//
|
||||
// #define IS_BLANK(string) IS_BLANK_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character at the specified position is a line break.
|
||||
// */
|
||||
//
|
||||
// #define IS_BREAK_AT(string,offset) \
|
||||
// (CHECK_AT((string),'\r',(offset)) /* CR (#xD)*/ \
|
||||
// || CHECK_AT((string),'\n',(offset)) /* LF (#xA) */ \
|
||||
// || (CHECK_AT((string),'\xC2',(offset)) \
|
||||
// && CHECK_AT((string),'\x85',(offset)+1)) /* NEL (#x85) */ \
|
||||
// || (CHECK_AT((string),'\xE2',(offset)) \
|
||||
// && CHECK_AT((string),'\x80',(offset)+1) \
|
||||
// && CHECK_AT((string),'\xA8',(offset)+2)) /* LS (#x2028) */ \
|
||||
// || (CHECK_AT((string),'\xE2',(offset)) \
|
||||
// && CHECK_AT((string),'\x80',(offset)+1) \
|
||||
// && CHECK_AT((string),'\xA9',(offset)+2))) /* PS (#x2029) */
|
||||
//
|
||||
// #define IS_BREAK(string) IS_BREAK_AT((string),0)
|
||||
//
|
||||
// #define IS_CRLF_AT(string,offset) \
|
||||
// (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))
|
||||
//
|
||||
// #define IS_CRLF(string) IS_CRLF_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character is a line break or NUL.
|
||||
// */
|
||||
//
|
||||
// #define IS_BREAKZ_AT(string,offset) \
|
||||
// (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset)))
|
||||
//
|
||||
// #define IS_BREAKZ(string) IS_BREAKZ_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character is a line break, space, or NUL.
|
||||
// */
|
||||
//
|
||||
// #define IS_SPACEZ_AT(string,offset) \
|
||||
// (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
|
||||
//
|
||||
// #define IS_SPACEZ(string) IS_SPACEZ_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Check if the character is a line break, space, tab, or NUL.
|
||||
// */
|
||||
//
|
||||
// #define IS_BLANKZ_AT(string,offset) \
|
||||
// (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
|
||||
//
|
||||
// #define IS_BLANKZ(string) IS_BLANKZ_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Determine the width of the character.
|
||||
// */
|
||||
//
|
||||
// #define WIDTH_AT(string,offset) \
|
||||
// (((string).pointer[offset] & 0x80) == 0x00 ? 1 : \
|
||||
// ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 : \
|
||||
// ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 : \
|
||||
// ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
|
||||
//
|
||||
// #define WIDTH(string) WIDTH_AT((string),0)
|
||||
//
|
||||
// /*
|
||||
// * Move the string pointer to the next character.
|
||||
// */
|
||||
//
|
||||
// #define MOVE(string) ((string).pointer += WIDTH((string)))
|
||||
//
|
||||
// /*
|
||||
// * Copy a character and move the pointers of both strings.
|
||||
// */
|
||||
//
|
||||
// #define COPY(string_a,string_b) \
|
||||
// ((*(string_b).pointer & 0x80) == 0x00 ? \
|
||||
// (*((string_a).pointer++) = *((string_b).pointer++)) : \
|
||||
// (*(string_b).pointer & 0xE0) == 0xC0 ? \
|
||||
// (*((string_a).pointer++) = *((string_b).pointer++), \
|
||||
// *((string_a).pointer++) = *((string_b).pointer++)) : \
|
||||
// (*(string_b).pointer & 0xF0) == 0xE0 ? \
|
||||
// (*((string_a).pointer++) = *((string_b).pointer++), \
|
||||
// *((string_a).pointer++) = *((string_b).pointer++), \
|
||||
// *((string_a).pointer++) = *((string_b).pointer++)) : \
|
||||
// (*(string_b).pointer & 0xF8) == 0xF0 ? \
|
||||
// (*((string_a).pointer++) = *((string_b).pointer++), \
|
||||
// *((string_a).pointer++) = *((string_b).pointer++), \
|
||||
// *((string_a).pointer++) = *((string_b).pointer++), \
|
||||
// *((string_a).pointer++) = *((string_b).pointer++)) : 0)
|
||||
//
|
||||
// /*
|
||||
// * Stack and queue management.
|
||||
// */
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_stack_extend(void **start, void **top, void **end);
|
||||
//
|
||||
// yaml_DECLARE(int)
|
||||
// yaml_queue_extend(void **start, void **head, void **tail, void **end);
|
||||
//
|
||||
// #define STACK_INIT(context,stack,size) \
|
||||
// (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ? \
|
||||
// ((stack).top = (stack).start, \
|
||||
// (stack).end = (stack).start+(size), \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// #define STACK_DEL(context,stack) \
|
||||
// (yaml_free((stack).start), \
|
||||
// (stack).start = (stack).top = (stack).end = 0)
|
||||
//
|
||||
// #define STACK_EMPTY(context,stack) \
|
||||
// ((stack).start == (stack).top)
|
||||
//
|
||||
// #define PUSH(context,stack,value) \
|
||||
// (((stack).top != (stack).end \
|
||||
// || yaml_stack_extend((void **)&(stack).start, \
|
||||
// (void **)&(stack).top, (void **)&(stack).end)) ? \
|
||||
// (*((stack).top++) = value, \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// #define POP(context,stack) \
|
||||
// (*(--(stack).top))
|
||||
//
|
||||
// #define QUEUE_INIT(context,queue,size) \
|
||||
// (((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ? \
|
||||
// ((queue).head = (queue).tail = (queue).start, \
|
||||
// (queue).end = (queue).start+(size), \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// #define QUEUE_DEL(context,queue) \
|
||||
// (yaml_free((queue).start), \
|
||||
// (queue).start = (queue).head = (queue).tail = (queue).end = 0)
|
||||
//
|
||||
// #define QUEUE_EMPTY(context,queue) \
|
||||
// ((queue).head == (queue).tail)
|
||||
//
|
||||
// #define ENQUEUE(context,queue,value) \
|
||||
// (((queue).tail != (queue).end \
|
||||
// || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
|
||||
// (void **)&(queue).tail, (void **)&(queue).end)) ? \
|
||||
// (*((queue).tail++) = value, \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// #define DEQUEUE(context,queue) \
|
||||
// (*((queue).head++))
|
||||
//
|
||||
// #define QUEUE_INSERT(context,queue,index,value) \
|
||||
// (((queue).tail != (queue).end \
|
||||
// || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
|
||||
// (void **)&(queue).tail, (void **)&(queue).end)) ? \
|
||||
// (memmove((queue).head+(index)+1,(queue).head+(index), \
|
||||
// ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)), \
|
||||
// *((queue).head+(index)) = value, \
|
||||
// (queue).tail++, \
|
||||
// 1) : \
|
||||
// ((context)->error = yaml_MEMORY_ERROR, \
|
||||
// 0))
|
||||
//
|
||||
// /*
|
||||
// * Token initializers.
|
||||
// */
|
||||
//
|
||||
// #define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark) \
|
||||
// (memset(&(token), 0, sizeof(yaml_token_t)), \
|
||||
// (token).type = (token_type), \
|
||||
// (token).start_mark = (token_start_mark), \
|
||||
// (token).end_mark = (token_end_mark))
|
||||
//
|
||||
// #define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_STREAM_START_TOKEN,(start_mark),(end_mark)), \
|
||||
// (token).data.stream_start.encoding = (token_encoding))
|
||||
//
|
||||
// #define STREAM_END_TOKEN_INIT(token,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_STREAM_END_TOKEN,(start_mark),(end_mark)))
|
||||
//
|
||||
// #define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_ALIAS_TOKEN,(start_mark),(end_mark)), \
|
||||
// (token).data.alias.value = (token_value))
|
||||
//
|
||||
// #define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_ANCHOR_TOKEN,(start_mark),(end_mark)), \
|
||||
// (token).data.anchor.value = (token_value))
|
||||
//
|
||||
// #define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_TAG_TOKEN,(start_mark),(end_mark)), \
|
||||
// (token).data.tag.handle = (token_handle), \
|
||||
// (token).data.tag.suffix = (token_suffix))
|
||||
//
|
||||
// #define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_SCALAR_TOKEN,(start_mark),(end_mark)), \
|
||||
// (token).data.scalar.value = (token_value), \
|
||||
// (token).data.scalar.length = (token_length), \
|
||||
// (token).data.scalar.style = (token_style))
|
||||
//
|
||||
// #define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
|
||||
// (token).data.version_directive.major = (token_major), \
|
||||
// (token).data.version_directive.minor = (token_minor))
|
||||
//
|
||||
// #define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark) \
|
||||
// (TOKEN_INIT((token),yaml_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
|
||||
// (token).data.tag_directive.handle = (token_handle), \
|
||||
// (token).data.tag_directive.prefix = (token_prefix))
|
||||
//
|
||||
// /*
|
||||
// * Event initializers.
|
||||
// */
|
||||
//
|
||||
// #define EVENT_INIT(event,event_type,event_start_mark,event_end_mark) \
|
||||
// (memset(&(event), 0, sizeof(yaml_event_t)), \
|
||||
// (event).type = (event_type), \
|
||||
// (event).start_mark = (event_start_mark), \
|
||||
// (event).end_mark = (event_end_mark))
|
||||
//
|
||||
// #define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_STREAM_START_EVENT,(start_mark),(end_mark)), \
|
||||
// (event).data.stream_start.encoding = (event_encoding))
|
||||
//
|
||||
// #define STREAM_END_EVENT_INIT(event,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_STREAM_END_EVENT,(start_mark),(end_mark)))
|
||||
//
|
||||
// #define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \
|
||||
// event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \
|
||||
// (event).data.document_start.version_directive = (event_version_directive), \
|
||||
// (event).data.document_start.tag_directives.start = (event_tag_directives_start), \
|
||||
// (event).data.document_start.tag_directives.end = (event_tag_directives_end), \
|
||||
// (event).data.document_start.implicit = (event_implicit))
|
||||
//
|
||||
// #define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \
|
||||
// (event).data.document_end.implicit = (event_implicit))
|
||||
//
|
||||
// #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_ALIAS_EVENT,(start_mark),(end_mark)), \
|
||||
// (event).data.alias.anchor = (event_anchor))
|
||||
//
|
||||
// #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length, \
|
||||
// event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_SCALAR_EVENT,(start_mark),(end_mark)), \
|
||||
// (event).data.scalar.anchor = (event_anchor), \
|
||||
// (event).data.scalar.tag = (event_tag), \
|
||||
// (event).data.scalar.value = (event_value), \
|
||||
// (event).data.scalar.length = (event_length), \
|
||||
// (event).data.scalar.plain_implicit = (event_plain_implicit), \
|
||||
// (event).data.scalar.quoted_implicit = (event_quoted_implicit), \
|
||||
// (event).data.scalar.style = (event_style))
|
||||
//
|
||||
// #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \
|
||||
// event_implicit,event_style,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \
|
||||
// (event).data.sequence_start.anchor = (event_anchor), \
|
||||
// (event).data.sequence_start.tag = (event_tag), \
|
||||
// (event).data.sequence_start.implicit = (event_implicit), \
|
||||
// (event).data.sequence_start.style = (event_style))
|
||||
//
|
||||
// #define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_SEQUENCE_END_EVENT,(start_mark),(end_mark)))
|
||||
//
|
||||
// #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \
|
||||
// event_implicit,event_style,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_MAPPING_START_EVENT,(start_mark),(end_mark)), \
|
||||
// (event).data.mapping_start.anchor = (event_anchor), \
|
||||
// (event).data.mapping_start.tag = (event_tag), \
|
||||
// (event).data.mapping_start.implicit = (event_implicit), \
|
||||
// (event).data.mapping_start.style = (event_style))
|
||||
//
|
||||
// #define MAPPING_END_EVENT_INIT(event,start_mark,end_mark) \
|
||||
// (EVENT_INIT((event),yaml_MAPPING_END_EVENT,(start_mark),(end_mark)))
|
||||
//
|
||||
// /*
|
||||
// * Document initializer.
|
||||
// */
|
||||
//
|
||||
// #define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end, \
|
||||
// document_version_directive,document_tag_directives_start, \
|
||||
// document_tag_directives_end,document_start_implicit, \
|
||||
// document_end_implicit,document_start_mark,document_end_mark) \
|
||||
// (memset(&(document), 0, sizeof(yaml_document_t)), \
|
||||
// (document).nodes.start = (document_nodes_start), \
|
||||
// (document).nodes.end = (document_nodes_end), \
|
||||
// (document).nodes.top = (document_nodes_start), \
|
||||
// (document).version_directive = (document_version_directive), \
|
||||
// (document).tag_directives.start = (document_tag_directives_start), \
|
||||
// (document).tag_directives.end = (document_tag_directives_end), \
|
||||
// (document).start_implicit = (document_start_implicit), \
|
||||
// (document).end_implicit = (document_end_implicit), \
|
||||
// (document).start_mark = (document_start_mark), \
|
||||
// (document).end_mark = (document_end_mark))
|
||||
//
|
||||
// /*
|
||||
// * Node initializers.
|
||||
// */
|
||||
//
|
||||
// #define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark) \
|
||||
// (memset(&(node), 0, sizeof(yaml_node_t)), \
|
||||
// (node).type = (node_type), \
|
||||
// (node).tag = (node_tag), \
|
||||
// (node).start_mark = (node_start_mark), \
|
||||
// (node).end_mark = (node_end_mark))
|
||||
//
|
||||
// #define SCALAR_NODE_INIT(node,node_tag,node_value,node_length, \
|
||||
// node_style,start_mark,end_mark) \
|
||||
// (NODE_INIT((node),yaml_SCALAR_NODE,(node_tag),(start_mark),(end_mark)), \
|
||||
// (node).data.scalar.value = (node_value), \
|
||||
// (node).data.scalar.length = (node_length), \
|
||||
// (node).data.scalar.style = (node_style))
|
||||
//
|
||||
// #define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end, \
|
||||
// node_style,start_mark,end_mark) \
|
||||
// (NODE_INIT((node),yaml_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)), \
|
||||
// (node).data.sequence.items.start = (node_items_start), \
|
||||
// (node).data.sequence.items.end = (node_items_end), \
|
||||
// (node).data.sequence.items.top = (node_items_start), \
|
||||
// (node).data.sequence.style = (node_style))
|
||||
//
|
||||
// #define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end, \
|
||||
// node_style,start_mark,end_mark) \
|
||||
// (NODE_INIT((node),yaml_MAPPING_NODE,(node_tag),(start_mark),(end_mark)), \
|
||||
// (node).data.mapping.pairs.start = (node_pairs_start), \
|
||||
// (node).data.mapping.pairs.end = (node_pairs_end), \
|
||||
// (node).data.mapping.pairs.top = (node_pairs_start), \
|
||||
// (node).data.mapping.style = (node_style))
|
||||
//
|
||||
953
vendor/github.com/cloudfoundry-incubator/candiedyaml/yamlh.go
generated
vendored
Normal file
953
vendor/github.com/cloudfoundry-incubator/candiedyaml/yamlh.go
generated
vendored
Normal file
@@ -0,0 +1,953 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package candiedyaml
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
/** The version directive data. */
|
||||
type yaml_version_directive_t struct {
|
||||
major int // The major version number
|
||||
minor int // The minor version number
|
||||
}
|
||||
|
||||
/** The tag directive data. */
|
||||
type yaml_tag_directive_t struct {
|
||||
handle []byte // The tag handle
|
||||
prefix []byte // The tag prefix
|
||||
}
|
||||
|
||||
/** The stream encoding. */
|
||||
type yaml_encoding_t int
|
||||
|
||||
const (
|
||||
/** Let the parser choose the encoding. */
|
||||
yaml_ANY_ENCODING yaml_encoding_t = iota
|
||||
/** The defau lt UTF-8 encoding. */
|
||||
yaml_UTF8_ENCODING
|
||||
/** The UTF-16-LE encoding with BOM. */
|
||||
yaml_UTF16LE_ENCODING
|
||||
/** The UTF-16-BE encoding with BOM. */
|
||||
yaml_UTF16BE_ENCODING
|
||||
)
|
||||
|
||||
/** Line break types. */
|
||||
type yaml_break_t int
|
||||
|
||||
const (
|
||||
yaml_ANY_BREAK yaml_break_t = iota /** Let the parser choose the break type. */
|
||||
yaml_CR_BREAK /** Use CR for line breaks (Mac style). */
|
||||
yaml_LN_BREAK /** Use LN for line breaks (Unix style). */
|
||||
yaml_CRLN_BREAK /** Use CR LN for line breaks (DOS style). */
|
||||
)
|
||||
|
||||
/** Many bad things could happen with the parser and emitter. */
|
||||
type YAML_error_type_t int
|
||||
|
||||
const (
|
||||
/** No error is produced. */
|
||||
yaml_NO_ERROR YAML_error_type_t = iota
|
||||
|
||||
/** Cannot allocate or reallocate a block of memory. */
|
||||
yaml_MEMORY_ERROR
|
||||
|
||||
/** Cannot read or decode the input stream. */
|
||||
yaml_READER_ERROR
|
||||
/** Cannot scan the input stream. */
|
||||
yaml_SCANNER_ERROR
|
||||
/** Cannot parse the input stream. */
|
||||
yaml_PARSER_ERROR
|
||||
/** Cannot compose a YAML document. */
|
||||
yaml_COMPOSER_ERROR
|
||||
|
||||
/** Cannot write to the output stream. */
|
||||
yaml_WRITER_ERROR
|
||||
/** Cannot emit a YAML stream. */
|
||||
yaml_EMITTER_ERROR
|
||||
)
|
||||
|
||||
/** The pointer position. */
|
||||
type YAML_mark_t struct {
|
||||
/** The position index. */
|
||||
index int
|
||||
|
||||
/** The position line. */
|
||||
line int
|
||||
|
||||
/** The position column. */
|
||||
column int
|
||||
}
|
||||
|
||||
func (m YAML_mark_t) String() string {
|
||||
return fmt.Sprintf("line %d, column %d", m.line, m.column)
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup styles Node Styles
|
||||
* @{
|
||||
*/
|
||||
|
||||
type yaml_style_t int
|
||||
|
||||
/** Scalar styles. */
|
||||
type yaml_scalar_style_t yaml_style_t
|
||||
|
||||
const (
|
||||
/** Let the emitter choose the style. */
|
||||
yaml_ANY_SCALAR_STYLE yaml_scalar_style_t = iota
|
||||
|
||||
/** The plain scalar style. */
|
||||
yaml_PLAIN_SCALAR_STYLE
|
||||
|
||||
/** The single-quoted scalar style. */
|
||||
yaml_SINGLE_QUOTED_SCALAR_STYLE
|
||||
/** The double-quoted scalar style. */
|
||||
yaml_DOUBLE_QUOTED_SCALAR_STYLE
|
||||
|
||||
/** The literal scalar style. */
|
||||
yaml_LITERAL_SCALAR_STYLE
|
||||
/** The folded scalar style. */
|
||||
yaml_FOLDED_SCALAR_STYLE
|
||||
)
|
||||
|
||||
/** Sequence styles. */
|
||||
type yaml_sequence_style_t yaml_style_t
|
||||
|
||||
const (
|
||||
/** Let the emitter choose the style. */
|
||||
yaml_ANY_SEQUENCE_STYLE yaml_sequence_style_t = iota
|
||||
|
||||
/** The block sequence style. */
|
||||
yaml_BLOCK_SEQUENCE_STYLE
|
||||
/** The flow sequence style. */
|
||||
yaml_FLOW_SEQUENCE_STYLE
|
||||
)
|
||||
|
||||
/** Mapping styles. */
|
||||
type yaml_mapping_style_t yaml_style_t
|
||||
|
||||
const (
|
||||
/** Let the emitter choose the style. */
|
||||
yaml_ANY_MAPPING_STYLE yaml_mapping_style_t = iota
|
||||
|
||||
/** The block mapping style. */
|
||||
yaml_BLOCK_MAPPING_STYLE
|
||||
/** The flow mapping style. */
|
||||
yaml_FLOW_MAPPING_STYLE
|
||||
|
||||
/* yaml_FLOW_SET_MAPPING_STYLE */
|
||||
)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup tokens Tokens
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Token types. */
|
||||
type yaml_token_type_t int
|
||||
|
||||
const (
|
||||
/** An empty token. */
|
||||
yaml_NO_TOKEN yaml_token_type_t = iota
|
||||
|
||||
/** A STREAM-START token. */
|
||||
yaml_STREAM_START_TOKEN
|
||||
/** A STREAM-END token. */
|
||||
yaml_STREAM_END_TOKEN
|
||||
|
||||
/** A VERSION-DIRECTIVE token. */
|
||||
yaml_VERSION_DIRECTIVE_TOKEN
|
||||
/** A TAG-DIRECTIVE token. */
|
||||
yaml_TAG_DIRECTIVE_TOKEN
|
||||
/** A DOCUMENT-START token. */
|
||||
yaml_DOCUMENT_START_TOKEN
|
||||
/** A DOCUMENT-END token. */
|
||||
yaml_DOCUMENT_END_TOKEN
|
||||
|
||||
/** A BLOCK-SEQUENCE-START token. */
|
||||
yaml_BLOCK_SEQUENCE_START_TOKEN
|
||||
/** A BLOCK-SEQUENCE-END token. */
|
||||
yaml_BLOCK_MAPPING_START_TOKEN
|
||||
/** A BLOCK-END token. */
|
||||
yaml_BLOCK_END_TOKEN
|
||||
|
||||
/** A FLOW-SEQUENCE-START token. */
|
||||
yaml_FLOW_SEQUENCE_START_TOKEN
|
||||
/** A FLOW-SEQUENCE-END token. */
|
||||
yaml_FLOW_SEQUENCE_END_TOKEN
|
||||
/** A FLOW-MAPPING-START token. */
|
||||
yaml_FLOW_MAPPING_START_TOKEN
|
||||
/** A FLOW-MAPPING-END token. */
|
||||
yaml_FLOW_MAPPING_END_TOKEN
|
||||
|
||||
/** A BLOCK-ENTRY token. */
|
||||
yaml_BLOCK_ENTRY_TOKEN
|
||||
/** A FLOW-ENTRY token. */
|
||||
yaml_FLOW_ENTRY_TOKEN
|
||||
/** A KEY token. */
|
||||
yaml_KEY_TOKEN
|
||||
/** A VALUE token. */
|
||||
yaml_VALUE_TOKEN
|
||||
|
||||
/** An ALIAS token. */
|
||||
yaml_ALIAS_TOKEN
|
||||
/** An ANCHOR token. */
|
||||
yaml_ANCHOR_TOKEN
|
||||
/** A TAG token. */
|
||||
yaml_TAG_TOKEN
|
||||
/** A SCALAR token. */
|
||||
yaml_SCALAR_TOKEN
|
||||
)
|
||||
|
||||
/** The token structure. */
|
||||
type yaml_token_t struct {
|
||||
|
||||
/** The token type. */
|
||||
token_type yaml_token_type_t
|
||||
|
||||
/** The token data. */
|
||||
/** The stream start (for @c yaml_STREAM_START_TOKEN). */
|
||||
encoding yaml_encoding_t
|
||||
|
||||
/** The alias (for @c yaml_ALIAS_TOKEN, yaml_ANCHOR_TOKEN, yaml_SCALAR_TOKEN,yaml_TAG_TOKEN ). */
|
||||
/** The anchor (for @c ). */
|
||||
/** The scalar value (for @c ). */
|
||||
value []byte
|
||||
|
||||
/** The tag suffix. */
|
||||
suffix []byte
|
||||
|
||||
/** The scalar value (for @c yaml_SCALAR_TOKEN). */
|
||||
/** The scalar style. */
|
||||
style yaml_scalar_style_t
|
||||
|
||||
/** The version directive (for @c yaml_VERSION_DIRECTIVE_TOKEN). */
|
||||
version_directive yaml_version_directive_t
|
||||
|
||||
/** The tag directive (for @c yaml_TAG_DIRECTIVE_TOKEN). */
|
||||
prefix []byte
|
||||
|
||||
/** The beginning of the token. */
|
||||
start_mark YAML_mark_t
|
||||
/** The end of the token. */
|
||||
end_mark YAML_mark_t
|
||||
|
||||
major, minor int
|
||||
}
|
||||
|
||||
/**
|
||||
* @defgroup events Events
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Event types. */
|
||||
type yaml_event_type_t int
|
||||
|
||||
const (
|
||||
/** An empty event. */
|
||||
yaml_NO_EVENT yaml_event_type_t = iota
|
||||
|
||||
/** A STREAM-START event. */
|
||||
yaml_STREAM_START_EVENT
|
||||
/** A STREAM-END event. */
|
||||
yaml_STREAM_END_EVENT
|
||||
|
||||
/** A DOCUMENT-START event. */
|
||||
yaml_DOCUMENT_START_EVENT
|
||||
/** A DOCUMENT-END event. */
|
||||
yaml_DOCUMENT_END_EVENT
|
||||
|
||||
/** An ALIAS event. */
|
||||
yaml_ALIAS_EVENT
|
||||
/** A SCALAR event. */
|
||||
yaml_SCALAR_EVENT
|
||||
|
||||
/** A SEQUENCE-START event. */
|
||||
yaml_SEQUENCE_START_EVENT
|
||||
/** A SEQUENCE-END event. */
|
||||
yaml_SEQUENCE_END_EVENT
|
||||
|
||||
/** A MAPPING-START event. */
|
||||
yaml_MAPPING_START_EVENT
|
||||
/** A MAPPING-END event. */
|
||||
yaml_MAPPING_END_EVENT
|
||||
)
|
||||
|
||||
/** The event structure. */
|
||||
type yaml_event_t struct {
|
||||
|
||||
/** The event type. */
|
||||
event_type yaml_event_type_t
|
||||
|
||||
/** The stream parameters (for @c yaml_STREAM_START_EVENT). */
|
||||
encoding yaml_encoding_t
|
||||
|
||||
/** The document parameters (for @c yaml_DOCUMENT_START_EVENT). */
|
||||
version_directive *yaml_version_directive_t
|
||||
|
||||
/** The beginning and end of the tag directives list. */
|
||||
tag_directives []yaml_tag_directive_t
|
||||
|
||||
/** The document parameters (for @c yaml_DOCUMENT_START_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_START_EVENT,yaml_MAPPING_START_EVENT). */
|
||||
/** Is the document indicator implicit? */
|
||||
implicit bool
|
||||
|
||||
/** The alias parameters (for @c yaml_ALIAS_EVENT,yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). */
|
||||
/** The anchor. */
|
||||
anchor []byte
|
||||
|
||||
/** The scalar parameters (for @c yaml_SCALAR_EVENT,yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). */
|
||||
/** The tag. */
|
||||
tag []byte
|
||||
/** The scalar value. */
|
||||
value []byte
|
||||
|
||||
/** Is the tag optional for the plain style? */
|
||||
plain_implicit bool
|
||||
/** Is the tag optional for any non-plain style? */
|
||||
quoted_implicit bool
|
||||
|
||||
/** The sequence parameters (for @c yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). */
|
||||
/** The sequence style. */
|
||||
/** The scalar style. */
|
||||
style yaml_style_t
|
||||
|
||||
/** The beginning of the event. */
|
||||
start_mark, end_mark YAML_mark_t
|
||||
}
|
||||
|
||||
/**
|
||||
* @defgroup nodes Nodes
|
||||
* @{
|
||||
*/
|
||||
|
||||
const (
|
||||
/** The tag @c !!null with the only possible value: @c null. */
|
||||
yaml_NULL_TAG = "tag:yaml.org,2002:null"
|
||||
/** The tag @c !!bool with the values: @c true and @c falce. */
|
||||
yaml_BOOL_TAG = "tag:yaml.org,2002:bool"
|
||||
/** The tag @c !!str for string values. */
|
||||
yaml_STR_TAG = "tag:yaml.org,2002:str"
|
||||
/** The tag @c !!int for integer values. */
|
||||
yaml_INT_TAG = "tag:yaml.org,2002:int"
|
||||
/** The tag @c !!float for float values. */
|
||||
yaml_FLOAT_TAG = "tag:yaml.org,2002:float"
|
||||
/** The tag @c !!timestamp for date and time values. */
|
||||
yaml_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp"
|
||||
|
||||
/** The tag @c !!seq is used to denote sequences. */
|
||||
yaml_SEQ_TAG = "tag:yaml.org,2002:seq"
|
||||
/** The tag @c !!map is used to denote mapping. */
|
||||
yaml_MAP_TAG = "tag:yaml.org,2002:map"
|
||||
|
||||
/** The default scalar tag is @c !!str. */
|
||||
yaml_DEFAULT_SCALAR_TAG = yaml_STR_TAG
|
||||
/** The default sequence tag is @c !!seq. */
|
||||
yaml_DEFAULT_SEQUENCE_TAG = yaml_SEQ_TAG
|
||||
/** The default mapping tag is @c !!map. */
|
||||
yaml_DEFAULT_MAPPING_TAG = yaml_MAP_TAG
|
||||
|
||||
yaml_BINARY_TAG = "tag:yaml.org,2002:binary"
|
||||
)
|
||||
|
||||
/** Node types. */
|
||||
type yaml_node_type_t int
|
||||
|
||||
const (
|
||||
/** An empty node. */
|
||||
yaml_NO_NODE yaml_node_type_t = iota
|
||||
|
||||
/** A scalar node. */
|
||||
yaml_SCALAR_NODE
|
||||
/** A sequence node. */
|
||||
yaml_SEQUENCE_NODE
|
||||
/** A mapping node. */
|
||||
yaml_MAPPING_NODE
|
||||
)
|
||||
|
||||
/** An element of a sequence node. */
|
||||
type yaml_node_item_t int
|
||||
|
||||
/** An element of a mapping node. */
|
||||
type yaml_node_pair_t struct {
|
||||
/** The key of the element. */
|
||||
key int
|
||||
/** The value of the element. */
|
||||
value int
|
||||
}
|
||||
|
||||
/** The node structure. */
|
||||
type yaml_node_t struct {
|
||||
|
||||
/** The node type. */
|
||||
node_type yaml_node_type_t
|
||||
|
||||
/** The node tag. */
|
||||
tag []byte
|
||||
|
||||
/** The scalar parameters (for @c yaml_SCALAR_NODE). */
|
||||
scalar struct {
|
||||
/** The scalar value. */
|
||||
value []byte
|
||||
/** The scalar style. */
|
||||
style yaml_scalar_style_t
|
||||
}
|
||||
|
||||
/** The sequence parameters (for @c yaml_SEQUENCE_NODE). */
|
||||
sequence struct {
|
||||
/** The stack of sequence items. */
|
||||
items []yaml_node_item_t
|
||||
/** The sequence style. */
|
||||
style yaml_sequence_style_t
|
||||
}
|
||||
|
||||
/** The mapping parameters (for @c yaml_MAPPING_NODE). */
|
||||
mapping struct {
|
||||
/** The stack of mapping pairs (key, value). */
|
||||
pairs []yaml_node_pair_t
|
||||
/** The mapping style. */
|
||||
style yaml_mapping_style_t
|
||||
}
|
||||
|
||||
/** The beginning of the node. */
|
||||
start_mark YAML_mark_t
|
||||
/** The end of the node. */
|
||||
end_mark YAML_mark_t
|
||||
}
|
||||
|
||||
/** The document structure. */
|
||||
type yaml_document_t struct {
|
||||
|
||||
/** The document nodes. */
|
||||
nodes []yaml_node_t
|
||||
|
||||
/** The version directive. */
|
||||
version_directive *yaml_version_directive_t
|
||||
|
||||
/** The list of tag directives. */
|
||||
tags []yaml_tag_directive_t
|
||||
|
||||
/** Is the document start indicator implicit? */
|
||||
start_implicit bool
|
||||
/** Is the document end indicator implicit? */
|
||||
end_implicit bool
|
||||
|
||||
/** The beginning of the document. */
|
||||
start_mark YAML_mark_t
|
||||
/** The end of the document. */
|
||||
end_mark YAML_mark_t
|
||||
}
|
||||
|
||||
/**
|
||||
* The prototype of a read handler.
|
||||
*
|
||||
* The read handler is called when the parser needs to read more bytes from the
|
||||
* source. The handler should write not more than @a size bytes to the @a
|
||||
* buffer. The number of written bytes should be set to the @a length variable.
|
||||
*
|
||||
* @param[in,out] data A pointer to an application data specified by
|
||||
* yaml_parser_set_input().
|
||||
* @param[out] buffer The buffer to write the data from the source.
|
||||
* @param[in] size The size of the buffer.
|
||||
* @param[out] size_read The actual number of bytes read from the source.
|
||||
*
|
||||
* @returns On success, the handler should return @c 1. If the handler failed,
|
||||
* the returned value should be @c 0. On EOF, the handler should set the
|
||||
* @a size_read to @c 0 and return @c 1.
|
||||
*/
|
||||
|
||||
type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error)
|
||||
|
||||
/**
|
||||
* This structure holds information about a potential simple key.
|
||||
*/
|
||||
|
||||
type yaml_simple_key_t struct {
|
||||
/** Is a simple key possible? */
|
||||
possible bool
|
||||
|
||||
/** Is a simple key required? */
|
||||
required bool
|
||||
|
||||
/** The number of the token. */
|
||||
token_number int
|
||||
|
||||
/** The position mark. */
|
||||
mark YAML_mark_t
|
||||
}
|
||||
|
||||
/**
|
||||
* The states of the parser.
|
||||
*/
|
||||
type yaml_parser_state_t int
|
||||
|
||||
const (
|
||||
/** Expect STREAM-START. */
|
||||
yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota
|
||||
/** Expect the beginning of an implicit document. */
|
||||
yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE
|
||||
/** Expect DOCUMENT-START. */
|
||||
yaml_PARSE_DOCUMENT_START_STATE
|
||||
/** Expect the content of a document. */
|
||||
yaml_PARSE_DOCUMENT_CONTENT_STATE
|
||||
/** Expect DOCUMENT-END. */
|
||||
yaml_PARSE_DOCUMENT_END_STATE
|
||||
/** Expect a block node. */
|
||||
yaml_PARSE_BLOCK_NODE_STATE
|
||||
/** Expect a block node or indentless sequence. */
|
||||
yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE
|
||||
/** Expect a flow node. */
|
||||
yaml_PARSE_FLOW_NODE_STATE
|
||||
/** Expect the first entry of a block sequence. */
|
||||
yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE
|
||||
/** Expect an entry of a block sequence. */
|
||||
yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE
|
||||
/** Expect an entry of an indentless sequence. */
|
||||
yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE
|
||||
/** Expect the first key of a block mapping. */
|
||||
yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE
|
||||
/** Expect a block mapping key. */
|
||||
yaml_PARSE_BLOCK_MAPPING_KEY_STATE
|
||||
/** Expect a block mapping value. */
|
||||
yaml_PARSE_BLOCK_MAPPING_VALUE_STATE
|
||||
/** Expect the first entry of a flow sequence. */
|
||||
yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE
|
||||
/** Expect an entry of a flow sequence. */
|
||||
yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE
|
||||
/** Expect a key of an ordered mapping. */
|
||||
yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE
|
||||
/** Expect a value of an ordered mapping. */
|
||||
yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE
|
||||
/** Expect the and of an ordered mapping entry. */
|
||||
yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE
|
||||
/** Expect the first key of a flow mapping. */
|
||||
yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE
|
||||
/** Expect a key of a flow mapping. */
|
||||
yaml_PARSE_FLOW_MAPPING_KEY_STATE
|
||||
/** Expect a value of a flow mapping. */
|
||||
yaml_PARSE_FLOW_MAPPING_VALUE_STATE
|
||||
/** Expect an empty value of a flow mapping. */
|
||||
yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE
|
||||
/** Expect nothing. */
|
||||
yaml_PARSE_END_STATE
|
||||
)
|
||||
|
||||
/**
|
||||
* This structure holds aliases data.
|
||||
*/
|
||||
|
||||
type yaml_alias_data_t struct {
|
||||
/** The anchor. */
|
||||
anchor []byte
|
||||
/** The node id. */
|
||||
index int
|
||||
/** The anchor mark. */
|
||||
mark YAML_mark_t
|
||||
}
|
||||
|
||||
/**
|
||||
* The parser structure.
|
||||
*
|
||||
* All members are internal. Manage the structure using the @c yaml_parser_
|
||||
* family of functions.
|
||||
*/
|
||||
|
||||
type yaml_parser_t struct {
|
||||
|
||||
/**
|
||||
* @name Error handling
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Error type. */
|
||||
error YAML_error_type_t
|
||||
/** Error description. */
|
||||
problem string
|
||||
/** The byte about which the problem occured. */
|
||||
problem_offset int
|
||||
/** The problematic value (@c -1 is none). */
|
||||
problem_value int
|
||||
/** The problem position. */
|
||||
problem_mark YAML_mark_t
|
||||
/** The error context. */
|
||||
context string
|
||||
/** The context position. */
|
||||
context_mark YAML_mark_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Reader stuff
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Read handler. */
|
||||
read_handler yaml_read_handler_t
|
||||
|
||||
/** Reader input data. */
|
||||
input_reader io.Reader
|
||||
input []byte
|
||||
input_pos int
|
||||
|
||||
/** EOF flag */
|
||||
eof bool
|
||||
|
||||
/** The working buffer. */
|
||||
buffer []byte
|
||||
buffer_pos int
|
||||
|
||||
/* The number of unread characters in the buffer. */
|
||||
unread int
|
||||
|
||||
/** The raw buffer. */
|
||||
raw_buffer []byte
|
||||
raw_buffer_pos int
|
||||
|
||||
/** The input encoding. */
|
||||
encoding yaml_encoding_t
|
||||
|
||||
/** The offset of the current position (in bytes). */
|
||||
offset int
|
||||
|
||||
/** The mark of the current position. */
|
||||
mark YAML_mark_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Scanner stuff
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Have we started to scan the input stream? */
|
||||
stream_start_produced bool
|
||||
|
||||
/** Have we reached the end of the input stream? */
|
||||
stream_end_produced bool
|
||||
|
||||
/** The number of unclosed '[' and '{' indicators. */
|
||||
flow_level int
|
||||
|
||||
/** The tokens queue. */
|
||||
tokens []yaml_token_t
|
||||
tokens_head int
|
||||
|
||||
/** The number of tokens fetched from the queue. */
|
||||
tokens_parsed int
|
||||
|
||||
/* Does the tokens queue contain a token ready for dequeueing. */
|
||||
token_available bool
|
||||
|
||||
/** The indentation levels stack. */
|
||||
indents []int
|
||||
|
||||
/** The current indentation level. */
|
||||
indent int
|
||||
|
||||
/** May a simple key occur at the current position? */
|
||||
simple_key_allowed bool
|
||||
|
||||
/** The stack of simple keys. */
|
||||
simple_keys []yaml_simple_key_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Parser stuff
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** The parser states stack. */
|
||||
states []yaml_parser_state_t
|
||||
|
||||
/** The current parser state. */
|
||||
state yaml_parser_state_t
|
||||
|
||||
/** The stack of marks. */
|
||||
marks []YAML_mark_t
|
||||
|
||||
/** The list of TAG directives. */
|
||||
tag_directives []yaml_tag_directive_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Dumper stuff
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** The alias data. */
|
||||
aliases []yaml_alias_data_t
|
||||
|
||||
/** The currently parsed document. */
|
||||
document *yaml_document_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The prototype of a write handler.
|
||||
*
|
||||
* The write handler is called when the emitter needs to flush the accumulated
|
||||
* characters to the output. The handler should write @a size bytes of the
|
||||
* @a buffer to the output.
|
||||
*
|
||||
* @param[in,out] data A pointer to an application data specified by
|
||||
* yaml_emitter_set_output().
|
||||
* @param[in] buffer The buffer with bytes to be written.
|
||||
* @param[in] size The size of the buffer.
|
||||
*
|
||||
* @returns On success, the handler should return @c 1. If the handler failed,
|
||||
* the returned value should be @c 0.
|
||||
*/
|
||||
|
||||
type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error
|
||||
|
||||
/** The emitter states. */
|
||||
type yaml_emitter_state_t int
|
||||
|
||||
const (
|
||||
/** Expect STREAM-START. */
|
||||
yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota
|
||||
/** Expect the first DOCUMENT-START or STREAM-END. */
|
||||
yaml_EMIT_FIRST_DOCUMENT_START_STATE
|
||||
/** Expect DOCUMENT-START or STREAM-END. */
|
||||
yaml_EMIT_DOCUMENT_START_STATE
|
||||
/** Expect the content of a document. */
|
||||
yaml_EMIT_DOCUMENT_CONTENT_STATE
|
||||
/** Expect DOCUMENT-END. */
|
||||
yaml_EMIT_DOCUMENT_END_STATE
|
||||
/** Expect the first item of a flow sequence. */
|
||||
yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE
|
||||
/** Expect an item of a flow sequence. */
|
||||
yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE
|
||||
/** Expect the first key of a flow mapping. */
|
||||
yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE
|
||||
/** Expect a key of a flow mapping. */
|
||||
yaml_EMIT_FLOW_MAPPING_KEY_STATE
|
||||
/** Expect a value for a simple key of a flow mapping. */
|
||||
yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE
|
||||
/** Expect a value of a flow mapping. */
|
||||
yaml_EMIT_FLOW_MAPPING_VALUE_STATE
|
||||
/** Expect the first item of a block sequence. */
|
||||
yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE
|
||||
/** Expect an item of a block sequence. */
|
||||
yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE
|
||||
/** Expect the first key of a block mapping. */
|
||||
yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE
|
||||
/** Expect the key of a block mapping. */
|
||||
yaml_EMIT_BLOCK_MAPPING_KEY_STATE
|
||||
/** Expect a value for a simple key of a block mapping. */
|
||||
yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE
|
||||
/** Expect a value of a block mapping. */
|
||||
yaml_EMIT_BLOCK_MAPPING_VALUE_STATE
|
||||
/** Expect nothing. */
|
||||
yaml_EMIT_END_STATE
|
||||
)
|
||||
|
||||
/**
|
||||
* The emitter structure.
|
||||
*
|
||||
* All members are internal. Manage the structure using the @c yaml_emitter_
|
||||
* family of functions.
|
||||
*/
|
||||
|
||||
type yaml_emitter_t struct {
|
||||
|
||||
/**
|
||||
* @name Error handling
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Error type. */
|
||||
error YAML_error_type_t
|
||||
/** Error description. */
|
||||
problem string
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Writer stuff
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Write handler. */
|
||||
write_handler yaml_write_handler_t
|
||||
|
||||
/** Standard (string or file) output data. */
|
||||
output_buffer *[]byte
|
||||
output_writer io.Writer
|
||||
|
||||
/** The working buffer. */
|
||||
buffer []byte
|
||||
buffer_pos int
|
||||
|
||||
/** The raw buffer. */
|
||||
raw_buffer []byte
|
||||
raw_buffer_pos int
|
||||
|
||||
/** The stream encoding. */
|
||||
encoding yaml_encoding_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Emitter stuff
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** If the output is in the canonical style? */
|
||||
canonical bool
|
||||
/** The number of indentation spaces. */
|
||||
best_indent int
|
||||
/** The preferred width of the output lines. */
|
||||
best_width int
|
||||
/** Allow unescaped non-ASCII characters? */
|
||||
unicode bool
|
||||
/** The preferred line break. */
|
||||
line_break yaml_break_t
|
||||
|
||||
/** The stack of states. */
|
||||
states []yaml_emitter_state_t
|
||||
|
||||
/** The current emitter state. */
|
||||
state yaml_emitter_state_t
|
||||
|
||||
/** The event queue. */
|
||||
events []yaml_event_t
|
||||
events_head int
|
||||
|
||||
/** The stack of indentation levels. */
|
||||
indents []int
|
||||
|
||||
/** The list of tag directives. */
|
||||
tag_directives []yaml_tag_directive_t
|
||||
|
||||
/** The current indentation level. */
|
||||
indent int
|
||||
|
||||
/** The current flow level. */
|
||||
flow_level int
|
||||
|
||||
/** Is it the document root context? */
|
||||
root_context bool
|
||||
/** Is it a sequence context? */
|
||||
sequence_context bool
|
||||
/** Is it a mapping context? */
|
||||
mapping_context bool
|
||||
/** Is it a simple mapping key context? */
|
||||
simple_key_context bool
|
||||
|
||||
/** The current line. */
|
||||
line int
|
||||
/** The current column. */
|
||||
column int
|
||||
/** If the last character was a whitespace? */
|
||||
whitespace bool
|
||||
/** If the last character was an indentation character (' ', '-', '?', ':')? */
|
||||
indention bool
|
||||
/** If an explicit document end is required? */
|
||||
open_ended bool
|
||||
|
||||
/** Anchor analysis. */
|
||||
anchor_data struct {
|
||||
/** The anchor value. */
|
||||
anchor []byte
|
||||
/** Is it an alias? */
|
||||
alias bool
|
||||
}
|
||||
|
||||
/** Tag analysis. */
|
||||
tag_data struct {
|
||||
/** The tag handle. */
|
||||
handle []byte
|
||||
/** The tag suffix. */
|
||||
suffix []byte
|
||||
}
|
||||
|
||||
/** Scalar analysis. */
|
||||
scalar_data struct {
|
||||
/** The scalar value. */
|
||||
value []byte
|
||||
/** Does the scalar contain line breaks? */
|
||||
multiline bool
|
||||
/** Can the scalar be expessed in the flow plain style? */
|
||||
flow_plain_allowed bool
|
||||
/** Can the scalar be expressed in the block plain style? */
|
||||
block_plain_allowed bool
|
||||
/** Can the scalar be expressed in the single quoted style? */
|
||||
single_quoted_allowed bool
|
||||
/** Can the scalar be expressed in the literal or folded styles? */
|
||||
block_allowed bool
|
||||
/** The output style. */
|
||||
style yaml_scalar_style_t
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Dumper stuff
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** If the stream was already opened? */
|
||||
opened bool
|
||||
/** If the stream was already closed? */
|
||||
closed bool
|
||||
|
||||
/** The information associated with the document nodes. */
|
||||
anchors *struct {
|
||||
/** The number of references. */
|
||||
references int
|
||||
/** The anchor id. */
|
||||
anchor int
|
||||
/** If the node has been emitted? */
|
||||
serialized bool
|
||||
}
|
||||
|
||||
/** The last assigned anchor id. */
|
||||
last_anchor_id int
|
||||
|
||||
/** The currently emitted document. */
|
||||
document *yaml_document_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user