mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Rename YAML emitter functions for clarity
This commit is contained in:
@@ -209,28 +209,28 @@ impl EmitYaml for File {
|
||||
|
||||
fn emit_yaml(&self, emitter: &mut YamlEmitter) {
|
||||
if self.is_scalar() {
|
||||
emitter.single_quoted_str(self.name.as_str());
|
||||
emitter.write_single_quoted_str(self.name.as_str());
|
||||
} else {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("name");
|
||||
emitter.single_quoted_str(self.name.as_str());
|
||||
emitter.write_map_key("name");
|
||||
emitter.write_single_quoted_str(self.name.as_str());
|
||||
|
||||
if let Some(display_name) = &self.display_name {
|
||||
emitter.map_key("display");
|
||||
emitter.single_quoted_str(display_name);
|
||||
emitter.write_map_key("display");
|
||||
emitter.write_single_quoted_str(display_name);
|
||||
}
|
||||
|
||||
emit_message_contents(&self.detail, emitter, "detail");
|
||||
|
||||
if let Some(condition) = &self.condition {
|
||||
emitter.map_key("condition");
|
||||
emitter.single_quoted_str(condition);
|
||||
emitter.write_map_key("condition");
|
||||
emitter.write_single_quoted_str(condition);
|
||||
}
|
||||
|
||||
if let Some(constraint) = &self.constraint {
|
||||
emitter.map_key("constraint");
|
||||
emitter.single_quoted_str(constraint);
|
||||
emitter.write_map_key("constraint");
|
||||
emitter.write_single_quoted_str(constraint);
|
||||
}
|
||||
|
||||
emitter.end_map();
|
||||
|
||||
@@ -94,20 +94,20 @@ impl EmitYaml for Group {
|
||||
fn emit_yaml(&self, emitter: &mut YamlEmitter) {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("name");
|
||||
emitter.single_quoted_str(&self.name);
|
||||
emitter.write_map_key("name");
|
||||
emitter.write_single_quoted_str(&self.name);
|
||||
|
||||
if let Some(description) = &self.description {
|
||||
emitter.map_key("description");
|
||||
emitter.single_quoted_str(description);
|
||||
emitter.write_map_key("description");
|
||||
emitter.write_single_quoted_str(description);
|
||||
}
|
||||
|
||||
if !self.after_groups.is_empty() {
|
||||
emitter.map_key("after");
|
||||
emitter.write_map_key("after");
|
||||
emitter.begin_array();
|
||||
|
||||
for after in &self.after_groups {
|
||||
emitter.unquoted_str(after);
|
||||
emitter.write_unquoted_str(after);
|
||||
}
|
||||
|
||||
emitter.end_array();
|
||||
|
||||
@@ -84,15 +84,15 @@ impl EmitYaml for Location {
|
||||
if let Some(name) = &self.name {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("link");
|
||||
emitter.single_quoted_str(&self.url);
|
||||
emitter.write_map_key("link");
|
||||
emitter.write_single_quoted_str(&self.url);
|
||||
|
||||
emitter.map_key("name");
|
||||
emitter.single_quoted_str(name);
|
||||
emitter.write_map_key("name");
|
||||
emitter.write_single_quoted_str(name);
|
||||
|
||||
emitter.end_map();
|
||||
} else {
|
||||
emitter.single_quoted_str(&self.url);
|
||||
emitter.write_single_quoted_str(&self.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -390,11 +390,11 @@ impl EmitYaml for MessageContent {
|
||||
fn emit_yaml(&self, emitter: &mut YamlEmitter) {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("lang");
|
||||
emitter.unquoted_str(&self.language);
|
||||
emitter.write_map_key("lang");
|
||||
emitter.write_unquoted_str(&self.language);
|
||||
|
||||
emitter.map_key("text");
|
||||
emitter.single_quoted_str(&self.text);
|
||||
emitter.write_map_key("text");
|
||||
emitter.write_single_quoted_str(&self.text);
|
||||
|
||||
emitter.end_map();
|
||||
}
|
||||
@@ -408,11 +408,11 @@ pub(super) fn emit_message_contents(
|
||||
match slice {
|
||||
[] => {}
|
||||
[detail] => {
|
||||
emitter.map_key(key);
|
||||
emitter.single_quoted_str(detail.text());
|
||||
emitter.write_map_key(key);
|
||||
emitter.write_single_quoted_str(detail.text());
|
||||
}
|
||||
details => {
|
||||
emitter.map_key(key);
|
||||
emitter.write_map_key(key);
|
||||
|
||||
details.emit_yaml(emitter);
|
||||
}
|
||||
@@ -423,14 +423,14 @@ impl EmitYaml for Message {
|
||||
fn emit_yaml(&self, emitter: &mut YamlEmitter) {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("type");
|
||||
emitter.unquoted_str(&self.level.to_string());
|
||||
emitter.write_map_key("type");
|
||||
emitter.write_unquoted_str(&self.level.to_string());
|
||||
|
||||
emit_message_contents(&self.content, emitter, "content");
|
||||
|
||||
if let Some(condition) = &self.condition {
|
||||
emitter.map_key("condition");
|
||||
emitter.single_quoted_str(condition);
|
||||
emitter.write_map_key("condition");
|
||||
emitter.write_single_quoted_str(condition);
|
||||
}
|
||||
|
||||
emitter.end_map();
|
||||
|
||||
@@ -234,29 +234,29 @@ impl MetadataDocument {
|
||||
emitter.begin_map();
|
||||
|
||||
if !self.bash_tags.is_empty() {
|
||||
emitter.map_key("bash_tags");
|
||||
emitter.write_map_key("bash_tags");
|
||||
|
||||
emitter.begin_array();
|
||||
|
||||
for tag in &self.bash_tags {
|
||||
emitter.unquoted_str(tag);
|
||||
emitter.write_unquoted_str(tag);
|
||||
}
|
||||
|
||||
emitter.end_array();
|
||||
}
|
||||
|
||||
if self.groups.len() > 1 {
|
||||
emitter.map_key("groups");
|
||||
emitter.write_map_key("groups");
|
||||
self.groups.emit_yaml(&mut emitter);
|
||||
}
|
||||
|
||||
if !self.messages.is_empty() {
|
||||
emitter.map_key("globals");
|
||||
emitter.write_map_key("globals");
|
||||
self.messages.emit_yaml(&mut emitter);
|
||||
}
|
||||
|
||||
if !self.plugins.is_empty() || !self.regex_plugins.is_empty() {
|
||||
emitter.map_key("plugins");
|
||||
emitter.write_map_key("plugins");
|
||||
|
||||
emitter.begin_array();
|
||||
|
||||
|
||||
@@ -151,25 +151,25 @@ impl EmitYaml for PluginCleaningData {
|
||||
fn emit_yaml(&self, emitter: &mut YamlEmitter) {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("crc");
|
||||
emitter.unquoted_str(&format!("0x{:08X}", self.crc));
|
||||
emitter.write_map_key("crc");
|
||||
emitter.write_unquoted_str(&format!("0x{:08X}", self.crc));
|
||||
|
||||
emitter.map_key("util");
|
||||
emitter.single_quoted_str(&self.cleaning_utility);
|
||||
emitter.write_map_key("util");
|
||||
emitter.write_single_quoted_str(&self.cleaning_utility);
|
||||
|
||||
if self.itm_count > 0 {
|
||||
emitter.map_key("itm");
|
||||
emitter.u32(self.itm_count);
|
||||
emitter.write_map_key("itm");
|
||||
emitter.write_u32(self.itm_count);
|
||||
}
|
||||
|
||||
if self.deleted_reference_count > 0 {
|
||||
emitter.map_key("udr");
|
||||
emitter.u32(self.deleted_reference_count);
|
||||
emitter.write_map_key("udr");
|
||||
emitter.write_u32(self.deleted_reference_count);
|
||||
}
|
||||
|
||||
if self.deleted_navmesh_count > 0 {
|
||||
emitter.map_key("nav");
|
||||
emitter.u32(self.deleted_navmesh_count);
|
||||
emitter.write_map_key("nav");
|
||||
emitter.write_u32(self.deleted_navmesh_count);
|
||||
}
|
||||
|
||||
emit_message_contents(&self.detail, emitter, "detail");
|
||||
|
||||
@@ -450,51 +450,51 @@ impl EmitYaml for PluginMetadata {
|
||||
fn emit_yaml(&self, emitter: &mut YamlEmitter) {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("name");
|
||||
emitter.single_quoted_str(self.name());
|
||||
emitter.write_map_key("name");
|
||||
emitter.write_single_quoted_str(self.name());
|
||||
|
||||
if !self.locations.is_empty() {
|
||||
emitter.map_key("url");
|
||||
emitter.write_map_key("url");
|
||||
self.locations.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
if let Some(group) = &self.group {
|
||||
emitter.map_key("group");
|
||||
emitter.single_quoted_str(group);
|
||||
emitter.write_map_key("group");
|
||||
emitter.write_single_quoted_str(group);
|
||||
}
|
||||
|
||||
if !self.load_after.is_empty() {
|
||||
emitter.map_key("after");
|
||||
emitter.write_map_key("after");
|
||||
self.load_after.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
if !self.requirements.is_empty() {
|
||||
emitter.map_key("req");
|
||||
emitter.write_map_key("req");
|
||||
self.requirements.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
if !self.incompatibilities.is_empty() {
|
||||
emitter.map_key("inc");
|
||||
emitter.write_map_key("inc");
|
||||
self.incompatibilities.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
if !self.messages.is_empty() {
|
||||
emitter.map_key("msg");
|
||||
emitter.write_map_key("msg");
|
||||
self.messages.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
if !self.tags.is_empty() {
|
||||
emitter.map_key("tag");
|
||||
emitter.write_map_key("tag");
|
||||
self.tags.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
if !self.dirty_info.is_empty() {
|
||||
emitter.map_key("dirty");
|
||||
emitter.write_map_key("dirty");
|
||||
self.dirty_info.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
if !self.clean_info.is_empty() {
|
||||
emitter.map_key("clean");
|
||||
emitter.write_map_key("clean");
|
||||
self.clean_info.emit_yaml(emitter);
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -109,21 +109,21 @@ impl EmitYaml for Tag {
|
||||
if let Some(condition) = &self.condition {
|
||||
emitter.begin_map();
|
||||
|
||||
emitter.map_key("name");
|
||||
emitter.write_map_key("name");
|
||||
if self.is_addition() {
|
||||
emitter.unquoted_str(&self.name);
|
||||
emitter.write_unquoted_str(&self.name);
|
||||
} else {
|
||||
emitter.unquoted_str(&format!("-{}", self.name));
|
||||
emitter.write_unquoted_str(&format!("-{}", self.name));
|
||||
}
|
||||
|
||||
emitter.map_key("condition");
|
||||
emitter.single_quoted_str(condition);
|
||||
emitter.write_map_key("condition");
|
||||
emitter.write_single_quoted_str(condition);
|
||||
|
||||
emitter.end_map();
|
||||
} else if self.is_addition() {
|
||||
emitter.unquoted_str(&self.name);
|
||||
emitter.write_unquoted_str(&self.name);
|
||||
} else {
|
||||
emitter.unquoted_str(&format!("-{}", self.name));
|
||||
emitter.write_unquoted_str(&format!("-{}", self.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -52,11 +52,11 @@ impl YamlEmitter {
|
||||
self.buffer
|
||||
}
|
||||
|
||||
pub(in crate::metadata) fn unquoted_str(&mut self, value: &str) {
|
||||
pub(in crate::metadata) fn write_unquoted_str(&mut self, value: &str) {
|
||||
self.write_string(value, true);
|
||||
}
|
||||
|
||||
pub(in crate::metadata) fn single_quoted_str(&mut self, value: &str) {
|
||||
pub(in crate::metadata) fn write_single_quoted_str(&mut self, value: &str) {
|
||||
self.write_string(value, false);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ impl YamlEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::metadata) fn u32(&mut self, value: u32) {
|
||||
pub(in crate::metadata) fn write_u32(&mut self, value: u32) {
|
||||
self.write_prefix();
|
||||
|
||||
self.write(&value.to_string());
|
||||
@@ -99,9 +99,9 @@ impl YamlEmitter {
|
||||
/// This assumes that the given key is valid to be written as an unquoted
|
||||
/// string, and expects a string literal so that it's obvious that a given
|
||||
/// value is valid.
|
||||
pub(in crate::metadata) fn map_key(&mut self, key: &'static str) {
|
||||
pub(in crate::metadata) fn write_map_key(&mut self, key: &'static str) {
|
||||
if !self.is_first_line_of_map {
|
||||
self.end_line();
|
||||
self.write_end_of_line();
|
||||
self.write_indent();
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ impl YamlEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
fn end_line(&mut self) {
|
||||
fn write_end_of_line(&mut self) {
|
||||
self.write("\n");
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ impl YamlEmitter {
|
||||
|
||||
fn write_array_element_prefix(&mut self) {
|
||||
if self.style == YamlStyle::Block {
|
||||
self.end_line();
|
||||
self.write_end_of_line();
|
||||
self.write_indent();
|
||||
self.write(Self::ARRAY_ELEMENT_PREFIX);
|
||||
}
|
||||
@@ -344,12 +344,12 @@ mod tests {
|
||||
mod yaml_emitter {
|
||||
use super::*;
|
||||
|
||||
mod unquoted_str {
|
||||
mod write_unquoted_str {
|
||||
use super::*;
|
||||
|
||||
fn emit(str: &str) -> String {
|
||||
let mut emitter = YamlEmitter::new();
|
||||
emitter.unquoted_str(str);
|
||||
emitter.write_unquoted_str(str);
|
||||
emitter.into_string()
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ mod tests {
|
||||
fn emit_flow(str: &str) -> String {
|
||||
let mut emitter = YamlEmitter::new();
|
||||
emitter.set_style(YamlStyle::Flow);
|
||||
emitter.unquoted_str(str);
|
||||
emitter.write_unquoted_str(str);
|
||||
emitter.into_string()
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod single_quoted_str {
|
||||
mod write_single_quoted_str {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -535,7 +535,7 @@ mod tests {
|
||||
{
|
||||
let value = "hello 'world'";
|
||||
let mut emitter = YamlEmitter::new();
|
||||
emitter.single_quoted_str(value);
|
||||
emitter.write_single_quoted_str(value);
|
||||
|
||||
assert_eq!("'hello ''world'''", emitter.into_string());
|
||||
}
|
||||
@@ -545,7 +545,7 @@ mod tests {
|
||||
{
|
||||
let value = "\x1B[1mhello world\x1B[0m";
|
||||
let mut emitter = YamlEmitter::new();
|
||||
emitter.single_quoted_str(value);
|
||||
emitter.write_single_quoted_str(value);
|
||||
|
||||
assert_eq!("\"\\e[1mhello world\\e[0m\"", emitter.into_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user