summaryrefslogtreecommitdiff
path: root/crates/gipfel-core/src/hill.rs
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-11-10 09:12:35 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-11-10 09:12:35 +0100
commit0b0663e0c9dc664f35ffead3b395ffd2009fd98c (patch)
treef9e10437ebe7e13e527ce1a6a2b456c105bcc5c0 /crates/gipfel-core/src/hill.rs
parent02546370ec4458eef59a8f636fe05b57961d56ab (diff)
parent31a47fc4393856a0a0380b2fdcf79f9dac72ad56 (diff)
Merge branch 'wasm-spike'
# Conflicts: # crates/gipfel-core/src/metadata.rs
Diffstat (limited to 'crates/gipfel-core/src/hill.rs')
-rw-r--r--crates/gipfel-core/src/hill.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/gipfel-core/src/hill.rs b/crates/gipfel-core/src/hill.rs
index b40eb1d..254a9e4 100644
--- a/crates/gipfel-core/src/hill.rs
+++ b/crates/gipfel-core/src/hill.rs
@@ -2,9 +2,6 @@
//!
//! Faithful port of gipfel's `Hill.cxx`.
-use std::fs::File;
-use std::io::{BufRead, BufReader};
-
pub const FLAG_DUPLIC: u32 = 1 << 0;
pub const FLAG_KNOWN: u32 = 1 << 1;
pub const FLAG_HIDDEN: u32 = 1 << 2;
@@ -80,16 +77,20 @@ fn atof(s: &str) -> f64 {
0.0
}
-/// Load a hill database. Two line formats are accepted:
+/// Load a hill database from a file path.
+pub fn load(path: &str) -> std::io::Result<Vec<Hill>> {
+ load_from_bytes(&std::fs::read(path)?)
+}
+
+/// Load a hill database from raw bytes. Two line formats are accepted:
/// - `SHORT,NAME,DESC,LAT,LON,HEIGHT` (6 fields)
/// - `LAT,LON,HEIGHT` (3 fields, track point)
-pub fn load(path: &str) -> std::io::Result<Vec<Hill>> {
- let file = File::open(path)?;
+///
+/// Byte-oriented entry point (no filesystem): used by the WASM build and
+/// by tests. The database is Latin-1; bytes decode to Unicode code points.
+pub fn load_from_bytes(raw: &[u8]) -> std::io::Result<Vec<Hill>> {
let mut hills = Vec::new();
-
- // the database is Latin-1; decode to Unicode code points
- for line in BufReader::new(file).split(b'\n') {
- let raw = line?;
+ for raw in raw.split(|b| *b == b'\n') {
let line: String = raw.iter().map(|b| *b as char).collect();
// strsep() semantics: split into at most 10 fields, keeping empties
let vals: Vec<&str> = line.split(',').take(10).collect();
@@ -112,7 +113,6 @@ pub fn load(path: &str) -> std::io::Result<Vec<Hill>> {
hills.push(h);
}
}
-
Ok(hills)
}