<commit_before>// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at https://mozilla.org/MPL/2.0/.

use std::fmt;
use common::escape_string;

/// Represents a comment concerning the location/translation of a message
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Comment {
    /// File and line
    Source(String, usize)
}


/// Represents a message, with a string and a list of comments
/// corresponding to position in source file
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Message {
    pub comments: Vec<Comment>,
    pub msg: String,
}


impl Message {
    /// Creates a new message
    pub fn new<S:Into<String>>(msg: S) -> Message {
        Message {
            msg: msg.into(),
            comments: vec!(),
        }
    }

    /// Add a source location to a comment
    pub fn add_source<S:Into<String>>(&mut self, file: S, line: usize) -> &mut Self {
        self.comments.push(Comment::Source(file.into(), line));
        self
    }
}


impl fmt::Display for Message {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        try!(write!(f, "#:"));
        for comment in &self.comments {
            match *comment {
                Comment::Source(ref file, line) => try!(write!(f, " {}:{}", file, line)),
            }
        }
        writeln!(f, "
msgid \"{}\"
msgstr \"\"\n",
                 escape_string(self.msg.as_str()))
    }
}
<commit_msg>Use ? instead of try! in message.rs<commit_after>// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at https://mozilla.org/MPL/2.0/.

use std::fmt;
use common::escape_string;

/// Represents a comment concerning the location/translation of a message
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Comment {
    /// File and line
    Source(String, usize)
}


/// Represents a message, with a string and a list of comments
/// corresponding to position in source file
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Message {
    pub comments: Vec<Comment>,
    pub msg: String,
}


impl Message {
    /// Creates a new message
    pub fn new<S:Into<String>>(msg: S) -> Message {
        Message {
            msg: msg.into(),
            comments: vec!(),
        }
    }

    /// Add a source location to a comment
    pub fn add_source<S:Into<String>>(&mut self, file: S, line: usize) -> &mut Self {
        self.comments.push(Comment::Source(file.into(), line));
        self
    }
}


impl fmt::Display for Message {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "#:")?;
        for comment in &self.comments {
            match *comment {
                Comment::Source(ref file, line) => write!(f, " {}:{}", file, line)?,
            }
        }
        writeln!(f, "
msgid \"{}\"
msgstr \"\"\n",
                 escape_string(self.msg.as_str()))
    }
}

{'fraction_non_alphanumeric': 0.14411764705882352, 'fraction_numerical': 0.00261437908496732, 'mean_word_length': 2.401111111111111, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7007713', 'n_tokens_mistral': 928, 'n_tokens_neox': 916, 'n_words': 317}