Skip to content

Commit

Permalink
Add support for Dates to CLDRJsonDataProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
zbraniecki committed Sep 21, 2020
1 parent 6d85f62 commit 9265129
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 4 deletions.
2 changes: 2 additions & 0 deletions components/cldr-json-data-provider/src/cldr_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ pub struct CldrPaths {
/// Path to checkout of cldr-core:
/// https://github.com/unicode-cldr/cldr-core
pub cldr_core: Result<PathBuf, MissingSourceError>,
pub cldr_dates: Result<PathBuf, MissingSourceError>,
}

impl Default for CldrPaths {
fn default() -> CldrPaths {
CldrPaths {
cldr_core: Err(MissingSourceError { src: "cldr-core" }),
cldr_dates: Err(MissingSourceError { src: "cldr-dates" }),
}
}
}
13 changes: 12 additions & 1 deletion components/cldr-json-data-provider/src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
use crate::error::Error;
use std::fs;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

/// Helper function to open a file and return failures as a crate error.
pub fn open_reader(path: PathBuf) -> Result<BufReader<File>, Error> {
File::open(&path)
.map(BufReader::new)
.map_err(|e| Error::IoError(e, path))
}

pub fn get_subdirectories(root: &Path) -> Result<Vec<PathBuf>, Error> {
let mut result = vec![];
for entry in fs::read_dir(root).map_err(|e| Error::IoError(e, root.to_path_buf()))? {
let entry = entry.map_err(|e| Error::IoError(e, root.to_path_buf()))?;
let path = entry.path();
result.push(path);
}
Ok(result)
}
Loading

0 comments on commit 9265129

Please sign in to comment.