Skip to content

Commit

Permalink
Adds support for CldrJSONDataProvider for Dates (based on #256) (#258)
Browse files Browse the repository at this point in the history
* Add support for Dates to CLDRJsonDataProvider

* Apply feedback
  • Loading branch information
zbraniecki authored Sep 23, 2020
1 parent ab00f54 commit 97e53be
Show file tree
Hide file tree
Showing 5 changed files with 1,065 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" }),
}
}
}
15 changes: 14 additions & 1 deletion components/cldr-json-data-provider/src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
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))
}

/// Helper function which returns a sorted list of subdirectories.
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);
}
result.sort();
Ok(result)
}
Loading

0 comments on commit 97e53be

Please sign in to comment.