mirror of
https://github.com/chatmail/core.git
synced 2026-05-14 20:36:30 +03:00
location: remove bitflags dependency
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1168,7 +1168,6 @@ dependencies = [
|
|||||||
"async_zip",
|
"async_zip",
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"base64 0.21.0",
|
"base64 0.21.0",
|
||||||
"bitflags 1.3.2",
|
|
||||||
"brotli",
|
"brotli",
|
||||||
"chrono",
|
"chrono",
|
||||||
"criterion",
|
"criterion",
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ async-smtp = { version = "0.9", default-features = false, features = ["runtime-t
|
|||||||
async_zip = { version = "0.0.12", default-features = false, features = ["deflate", "fs"] }
|
async_zip = { version = "0.0.12", default-features = false, features = ["deflate", "fs"] }
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
base64 = "0.21"
|
base64 = "0.21"
|
||||||
bitflags = "1.3"
|
|
||||||
brotli = "3.3"
|
brotli = "3.3"
|
||||||
chrono = { version = "0.4", default-features=false, features = ["clock", "std"] }
|
chrono = { version = "0.4", default-features=false, features = ["clock", "std"] }
|
||||||
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
|
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::{ensure, Context as _, Result};
|
use anyhow::{ensure, Context as _, Result};
|
||||||
use async_channel::Receiver;
|
use async_channel::Receiver;
|
||||||
use bitflags::bitflags;
|
|
||||||
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
|
|
||||||
@@ -78,16 +77,15 @@ pub struct Kml {
|
|||||||
pub curr: Location,
|
pub curr: Location,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||||
#[derive(Default)]
|
enum KmlTag {
|
||||||
struct KmlTag: i32 {
|
#[default]
|
||||||
const UNDEFINED = 0x00;
|
Undefined,
|
||||||
const PLACEMARK = 0x01;
|
Placemark,
|
||||||
const TIMESTAMP = 0x02;
|
PlacemarkTimestamp,
|
||||||
const WHEN = 0x04;
|
PlacemarkTimestampWhen,
|
||||||
const POINT = 0x08;
|
PlacemarkPoint,
|
||||||
const COORDINATES = 0x10;
|
PlacemarkPointCoordinates,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Kml {
|
impl Kml {
|
||||||
@@ -128,12 +126,14 @@ impl Kml {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn text_cb(&mut self, event: &BytesText) {
|
fn text_cb(&mut self, event: &BytesText) {
|
||||||
if self.tag.contains(KmlTag::WHEN) || self.tag.contains(KmlTag::COORDINATES) {
|
if self.tag == KmlTag::PlacemarkTimestampWhen
|
||||||
|
|| self.tag == KmlTag::PlacemarkPointCoordinates
|
||||||
|
{
|
||||||
let val = event.unescape().unwrap_or_default();
|
let val = event.unescape().unwrap_or_default();
|
||||||
|
|
||||||
let val = val.replace(['\n', '\r', '\t', ' '], "");
|
let val = val.replace(['\n', '\r', '\t', ' '], "");
|
||||||
|
|
||||||
if self.tag.contains(KmlTag::WHEN) && val.len() >= 19 {
|
if self.tag == KmlTag::PlacemarkTimestampWhen && val.len() >= 19 {
|
||||||
// YYYY-MM-DDTHH:MM:SSZ
|
// YYYY-MM-DDTHH:MM:SSZ
|
||||||
// 0 4 7 10 13 16 19
|
// 0 4 7 10 13 16 19
|
||||||
match chrono::NaiveDateTime::parse_from_str(&val, "%Y-%m-%dT%H:%M:%SZ") {
|
match chrono::NaiveDateTime::parse_from_str(&val, "%Y-%m-%dT%H:%M:%SZ") {
|
||||||
@@ -147,7 +147,7 @@ impl Kml {
|
|||||||
self.curr.timestamp = time();
|
self.curr.timestamp = time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if self.tag.contains(KmlTag::COORDINATES) {
|
} else if self.tag == KmlTag::PlacemarkPointCoordinates {
|
||||||
let parts = val.splitn(2, ',').collect::<Vec<_>>();
|
let parts = val.splitn(2, ',').collect::<Vec<_>>();
|
||||||
if let [longitude, latitude] = &parts[..] {
|
if let [longitude, latitude] = &parts[..] {
|
||||||
self.curr.longitude = longitude.parse().unwrap_or_default();
|
self.curr.longitude = longitude.parse().unwrap_or_default();
|
||||||
@@ -162,17 +162,41 @@ impl Kml {
|
|||||||
.trim()
|
.trim()
|
||||||
.to_lowercase();
|
.to_lowercase();
|
||||||
|
|
||||||
if tag == "placemark" {
|
match self.tag {
|
||||||
if self.tag.contains(KmlTag::PLACEMARK)
|
KmlTag::PlacemarkTimestampWhen => {
|
||||||
&& 0 != self.curr.timestamp
|
if tag == "when" {
|
||||||
&& 0. != self.curr.latitude
|
self.tag = KmlTag::PlacemarkTimestamp
|
||||||
&& 0. != self.curr.longitude
|
}
|
||||||
{
|
|
||||||
self.locations
|
|
||||||
.push(std::mem::replace(&mut self.curr, Location::new()));
|
|
||||||
}
|
}
|
||||||
self.tag = KmlTag::UNDEFINED;
|
KmlTag::PlacemarkTimestamp => {
|
||||||
};
|
if tag == "timestamp" {
|
||||||
|
self.tag = KmlTag::Placemark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KmlTag::PlacemarkPointCoordinates => {
|
||||||
|
if tag == "coordinates" {
|
||||||
|
self.tag = KmlTag::PlacemarkPoint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KmlTag::PlacemarkPoint => {
|
||||||
|
if tag == "point" {
|
||||||
|
self.tag = KmlTag::Placemark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KmlTag::Placemark => {
|
||||||
|
if tag == "placemark" {
|
||||||
|
if 0 != self.curr.timestamp
|
||||||
|
&& 0. != self.curr.latitude
|
||||||
|
&& 0. != self.curr.longitude
|
||||||
|
{
|
||||||
|
self.locations
|
||||||
|
.push(std::mem::replace(&mut self.curr, Location::new()));
|
||||||
|
}
|
||||||
|
self.tag = KmlTag::Undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KmlTag::Undefined => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn starttag_cb<B: std::io::BufRead>(
|
fn starttag_cb<B: std::io::BufRead>(
|
||||||
@@ -196,19 +220,19 @@ impl Kml {
|
|||||||
.map(|a| a.into_owned());
|
.map(|a| a.into_owned());
|
||||||
}
|
}
|
||||||
} else if tag == "placemark" {
|
} else if tag == "placemark" {
|
||||||
self.tag = KmlTag::PLACEMARK;
|
self.tag = KmlTag::Placemark;
|
||||||
self.curr.timestamp = 0;
|
self.curr.timestamp = 0;
|
||||||
self.curr.latitude = 0.0;
|
self.curr.latitude = 0.0;
|
||||||
self.curr.longitude = 0.0;
|
self.curr.longitude = 0.0;
|
||||||
self.curr.accuracy = 0.0
|
self.curr.accuracy = 0.0
|
||||||
} else if tag == "timestamp" && self.tag.contains(KmlTag::PLACEMARK) {
|
} else if tag == "timestamp" && self.tag == KmlTag::Placemark {
|
||||||
self.tag = KmlTag::PLACEMARK | KmlTag::TIMESTAMP
|
self.tag = KmlTag::PlacemarkTimestamp;
|
||||||
} else if tag == "when" && self.tag.contains(KmlTag::TIMESTAMP) {
|
} else if tag == "when" && self.tag == KmlTag::PlacemarkTimestamp {
|
||||||
self.tag = KmlTag::PLACEMARK | KmlTag::TIMESTAMP | KmlTag::WHEN
|
self.tag = KmlTag::PlacemarkTimestampWhen;
|
||||||
} else if tag == "point" && self.tag.contains(KmlTag::PLACEMARK) {
|
} else if tag == "point" && self.tag == KmlTag::Placemark {
|
||||||
self.tag = KmlTag::PLACEMARK | KmlTag::POINT
|
self.tag = KmlTag::PlacemarkPoint;
|
||||||
} else if tag == "coordinates" && self.tag.contains(KmlTag::POINT) {
|
} else if tag == "coordinates" && self.tag == KmlTag::PlacemarkPoint {
|
||||||
self.tag = KmlTag::PLACEMARK | KmlTag::POINT | KmlTag::COORDINATES;
|
self.tag = KmlTag::PlacemarkPointCoordinates;
|
||||||
if let Some(acc) = event.attributes().find(|attr| {
|
if let Some(acc) = event.attributes().find(|attr| {
|
||||||
attr.as_ref()
|
attr.as_ref()
|
||||||
.map(|a| {
|
.map(|a| {
|
||||||
|
|||||||
Reference in New Issue
Block a user