mirror of
https://github.com/simonask/libyaml-safer
synced 2025-02-16 20:38:30 +00:00
Rustify constants
This commit is contained in:
parent
b394312eda
commit
b65896d04b
5 changed files with 26 additions and 28 deletions
|
@ -5,7 +5,7 @@ use crate::yaml::{EventData, NodeData};
|
|||
use crate::{
|
||||
Break, Document, Emitter, EmitterState, Encoding, Event, MappingStyle, Mark, Node, NodePair,
|
||||
Parser, ParserState, ScalarStyle, SequenceStyle, TagDirective, VersionDirective,
|
||||
YAML_DEFAULT_MAPPING_TAG, YAML_DEFAULT_SCALAR_TAG, YAML_DEFAULT_SEQUENCE_TAG,
|
||||
DEFAULT_MAPPING_TAG, DEFAULT_SCALAR_TAG, DEFAULT_SEQUENCE_TAG,
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
|
@ -405,7 +405,7 @@ pub fn yaml_document_add_scalar(
|
|||
line: 0_u64,
|
||||
column: 0_u64,
|
||||
};
|
||||
let tag = tag.unwrap_or(YAML_DEFAULT_SCALAR_TAG);
|
||||
let tag = tag.unwrap_or(DEFAULT_SCALAR_TAG);
|
||||
let tag_copy = String::from(tag);
|
||||
let value_copy = String::from(value);
|
||||
let node = Node {
|
||||
|
@ -439,7 +439,7 @@ pub fn yaml_document_add_sequence(
|
|||
};
|
||||
|
||||
let items = Vec::with_capacity(16);
|
||||
let tag = tag.unwrap_or(YAML_DEFAULT_SEQUENCE_TAG);
|
||||
let tag = tag.unwrap_or(DEFAULT_SEQUENCE_TAG);
|
||||
let tag_copy = String::from(tag);
|
||||
let node = Node {
|
||||
data: NodeData::Sequence { items, style },
|
||||
|
@ -468,7 +468,7 @@ pub fn yaml_document_add_mapping(
|
|||
column: 0_u64,
|
||||
};
|
||||
let pairs = Vec::with_capacity(16);
|
||||
let tag = tag.unwrap_or(YAML_DEFAULT_MAPPING_TAG);
|
||||
let tag = tag.unwrap_or(DEFAULT_MAPPING_TAG);
|
||||
let tag_copy = String::from(tag);
|
||||
|
||||
let node = Node {
|
||||
|
|
|
@ -5,8 +5,7 @@ use alloc::vec;
|
|||
|
||||
use crate::yaml::{Anchors, Any, Document, Emitter, Event, EventData, Node, NodeData};
|
||||
use crate::{
|
||||
yaml_emitter_emit, EmitterError, YAML_DEFAULT_MAPPING_TAG, YAML_DEFAULT_SCALAR_TAG,
|
||||
YAML_DEFAULT_SEQUENCE_TAG,
|
||||
yaml_emitter_emit, EmitterError, DEFAULT_MAPPING_TAG, DEFAULT_SCALAR_TAG, DEFAULT_SEQUENCE_TAG,
|
||||
};
|
||||
|
||||
/// Start a YAML stream.
|
||||
|
@ -162,8 +161,8 @@ fn yaml_emitter_dump_scalar(
|
|||
node: Node,
|
||||
anchor: Option<String>,
|
||||
) -> Result<(), EmitterError> {
|
||||
let plain_implicit = node.tag.as_deref() == Some(YAML_DEFAULT_SCALAR_TAG);
|
||||
let quoted_implicit = node.tag.as_deref() == Some(YAML_DEFAULT_SCALAR_TAG); // TODO: Why compare twice?! (even the C code does this)
|
||||
let plain_implicit = node.tag.as_deref() == Some(DEFAULT_SCALAR_TAG);
|
||||
let quoted_implicit = node.tag.as_deref() == Some(DEFAULT_SCALAR_TAG); // TODO: Why compare twice?! (even the C code does this)
|
||||
|
||||
if let NodeData::Scalar { value, style } = node.data {
|
||||
let event = Event {
|
||||
|
@ -189,7 +188,7 @@ fn yaml_emitter_dump_sequence(
|
|||
node: Node,
|
||||
anchor: Option<String>,
|
||||
) -> Result<(), EmitterError> {
|
||||
let implicit = node.tag.as_deref() == Some(YAML_DEFAULT_SEQUENCE_TAG);
|
||||
let implicit = node.tag.as_deref() == Some(DEFAULT_SEQUENCE_TAG);
|
||||
|
||||
if let NodeData::Sequence { items, style } = node.data {
|
||||
let event = Event {
|
||||
|
@ -222,7 +221,7 @@ fn yaml_emitter_dump_mapping(
|
|||
node: Node,
|
||||
anchor: Option<String>,
|
||||
) -> Result<(), EmitterError> {
|
||||
let implicit = node.tag.as_deref() == Some(YAML_DEFAULT_MAPPING_TAG);
|
||||
let implicit = node.tag.as_deref() == Some(DEFAULT_MAPPING_TAG);
|
||||
|
||||
if let NodeData::Mapping { pairs, style } = node.data {
|
||||
let event = Event {
|
||||
|
|
|
@ -77,9 +77,8 @@ pub use crate::yaml::{
|
|||
};
|
||||
#[doc(hidden)]
|
||||
pub use crate::yaml::{
|
||||
YAML_BOOL_TAG, YAML_DEFAULT_MAPPING_TAG, YAML_DEFAULT_SCALAR_TAG, YAML_DEFAULT_SEQUENCE_TAG,
|
||||
YAML_FLOAT_TAG, YAML_INT_TAG, YAML_MAP_TAG, YAML_NULL_TAG, YAML_SEQ_TAG, YAML_STR_TAG,
|
||||
YAML_TIMESTAMP_TAG,
|
||||
BOOL_TAG, DEFAULT_MAPPING_TAG, DEFAULT_SCALAR_TAG, DEFAULT_SEQUENCE_TAG, FLOAT_TAG, INT_TAG,
|
||||
MAP_TAG, NULL_TAG, SEQ_TAG, STR_TAG, TIMESTAMP_TAG,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -4,7 +4,7 @@ use alloc::{vec, vec::Vec};
|
|||
use crate::yaml::{EventData, NodeData};
|
||||
use crate::{
|
||||
yaml_document_new, yaml_parser_parse, AliasData, ComposerError, Document, Event, Mark, Node,
|
||||
NodePair, Parser, YAML_DEFAULT_MAPPING_TAG, YAML_DEFAULT_SCALAR_TAG, YAML_DEFAULT_SEQUENCE_TAG,
|
||||
NodePair, Parser, DEFAULT_MAPPING_TAG, DEFAULT_SCALAR_TAG, DEFAULT_SEQUENCE_TAG,
|
||||
};
|
||||
|
||||
/// Parse the input stream and produce the next YAML document.
|
||||
|
@ -264,7 +264,7 @@ fn yaml_parser_load_scalar(
|
|||
};
|
||||
|
||||
if tag.is_none() || tag.as_deref() == Some("!") {
|
||||
tag = Some(String::from(YAML_DEFAULT_SCALAR_TAG));
|
||||
tag = Some(String::from(DEFAULT_SCALAR_TAG));
|
||||
}
|
||||
let node = Node {
|
||||
data: NodeData::Scalar { value, style },
|
||||
|
@ -297,7 +297,7 @@ fn yaml_parser_load_sequence(
|
|||
let mut items = Vec::with_capacity(16);
|
||||
|
||||
if tag.is_none() || tag.as_deref() == Some("!") {
|
||||
tag = Some(String::from(YAML_DEFAULT_SEQUENCE_TAG));
|
||||
tag = Some(String::from(DEFAULT_SEQUENCE_TAG));
|
||||
}
|
||||
|
||||
let node = Node {
|
||||
|
@ -354,7 +354,7 @@ fn yaml_parser_load_mapping(
|
|||
let mut pairs = Vec::with_capacity(16);
|
||||
|
||||
if tag.is_none() || tag.as_deref() == Some("!") {
|
||||
tag = Some(String::from(YAML_DEFAULT_MAPPING_TAG));
|
||||
tag = Some(String::from(DEFAULT_MAPPING_TAG));
|
||||
}
|
||||
let node = Node {
|
||||
data: NodeData::Mapping {
|
||||
|
|
22
src/yaml.rs
22
src/yaml.rs
|
@ -7,29 +7,29 @@ use crate::{api::yaml_parser_new, yaml_emitter_new};
|
|||
pub use self::Encoding::*;
|
||||
|
||||
/// The tag @c !!null with the only possible value: @c null.
|
||||
pub const YAML_NULL_TAG: &str = "tag:yaml.org,2002:null";
|
||||
pub const NULL_TAG: &str = "tag:yaml.org,2002:null";
|
||||
/// The tag @c !!bool with the values: @c true and @c false.
|
||||
pub const YAML_BOOL_TAG: &str = "tag:yaml.org,2002:bool";
|
||||
pub const BOOL_TAG: &str = "tag:yaml.org,2002:bool";
|
||||
/// The tag @c !!str for string values.
|
||||
pub const YAML_STR_TAG: &str = "tag:yaml.org,2002:str";
|
||||
pub const STR_TAG: &str = "tag:yaml.org,2002:str";
|
||||
/// The tag @c !!int for integer values.
|
||||
pub const YAML_INT_TAG: &str = "tag:yaml.org,2002:int";
|
||||
pub const INT_TAG: &str = "tag:yaml.org,2002:int";
|
||||
/// The tag @c !!float for float values.
|
||||
pub const YAML_FLOAT_TAG: &str = "tag:yaml.org,2002:float";
|
||||
pub const FLOAT_TAG: &str = "tag:yaml.org,2002:float";
|
||||
/// The tag @c !!timestamp for date and time values.
|
||||
pub const YAML_TIMESTAMP_TAG: &str = "tag:yaml.org,2002:timestamp";
|
||||
pub const TIMESTAMP_TAG: &str = "tag:yaml.org,2002:timestamp";
|
||||
|
||||
/// The tag @c !!seq is used to denote sequences.
|
||||
pub const YAML_SEQ_TAG: &str = "tag:yaml.org,2002:seq";
|
||||
pub const SEQ_TAG: &str = "tag:yaml.org,2002:seq";
|
||||
/// The tag @c !!map is used to denote mapping.
|
||||
pub const YAML_MAP_TAG: &str = "tag:yaml.org,2002:map";
|
||||
pub const MAP_TAG: &str = "tag:yaml.org,2002:map";
|
||||
|
||||
/// The default scalar tag is @c !!str.
|
||||
pub const YAML_DEFAULT_SCALAR_TAG: &str = YAML_STR_TAG;
|
||||
pub const DEFAULT_SCALAR_TAG: &str = STR_TAG;
|
||||
/// The default sequence tag is @c !!seq.
|
||||
pub const YAML_DEFAULT_SEQUENCE_TAG: &str = YAML_SEQ_TAG;
|
||||
pub const DEFAULT_SEQUENCE_TAG: &str = SEQ_TAG;
|
||||
/// The default mapping tag is @c !!map.
|
||||
pub const YAML_DEFAULT_MAPPING_TAG: &str = YAML_MAP_TAG;
|
||||
pub const DEFAULT_MAPPING_TAG: &str = MAP_TAG;
|
||||
|
||||
/// The version directive data.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
Loading…
Add table
Reference in a new issue