Use std::fs::read_to_file in fluent_messages macro
This commit is contained in:
parent
c1d3610ac1
commit
f24983222d
1 changed files with 3 additions and 11 deletions
|
@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fs::File,
|
fs::read_to_string,
|
||||||
io::Read,
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use syn::{parse_macro_input, Ident, LitStr};
|
use syn::{parse_macro_input, Ident, LitStr};
|
||||||
|
@ -95,8 +94,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
|
||||||
|
|
||||||
// As this macro also outputs an `include_str!` for this file, the macro will always be
|
// As this macro also outputs an `include_str!` for this file, the macro will always be
|
||||||
// re-executed when the file changes.
|
// re-executed when the file changes.
|
||||||
let mut resource_file = match File::open(absolute_ftl_path) {
|
let resource_contents = match read_to_string(absolute_ftl_path) {
|
||||||
Ok(resource_file) => resource_file,
|
Ok(resource_contents) => resource_contents,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
|
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
|
||||||
.note(e.to_string())
|
.note(e.to_string())
|
||||||
|
@ -104,13 +103,6 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
|
||||||
return failed(&crate_name);
|
return failed(&crate_name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut resource_contents = String::new();
|
|
||||||
if let Err(e) = resource_file.read_to_string(&mut resource_contents) {
|
|
||||||
Diagnostic::spanned(resource_span, Level::Error, "could not read Fluent resource")
|
|
||||||
.note(e.to_string())
|
|
||||||
.emit();
|
|
||||||
return failed(&crate_name);
|
|
||||||
}
|
|
||||||
let mut bad = false;
|
let mut bad = false;
|
||||||
for esc in ["\\n", "\\\"", "\\'"] {
|
for esc in ["\\n", "\\\"", "\\'"] {
|
||||||
for _ in resource_contents.matches(esc) {
|
for _ in resource_contents.matches(esc) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue