#![warn(missing_docs)]
extern crate encode_unicode;
extern crate indexmap;
extern crate lexical_core;
extern crate ryu_ecmascript;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate base64;
pub mod json;
pub mod value;
use std::cmp::Ordering;
use std::fmt;
#[derive(Clone, Copy, PartialEq, PartialOrd, Default, Serialize, Deserialize)]
pub struct LegacyF64(f64);
impl LegacyF64 {
pub fn from_f64(f: f64) -> Option<LegacyF64> {
if LegacyF64::is_valid(f) {
Some(LegacyF64(f))
} else {
None
}
}
pub unsafe fn from_f64_unchecked(f: f64) -> LegacyF64 {
debug_assert!(LegacyF64::is_valid(f));
LegacyF64(f)
}
pub fn is_valid(f: f64) -> bool {
if f == 0.0 {
f.is_sign_positive()
} else {
f.is_finite() && (f != 0.0)
}
}
}
impl fmt::Display for LegacyF64 {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.0.fmt(f)
}
}
impl fmt::Debug for LegacyF64 {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.0.fmt(f)
}
}
impl Eq for LegacyF64 {}
impl Ord for LegacyF64 {
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other).unwrap()
}
}
impl From<LegacyF64> for f64 {
fn from(f: LegacyF64) -> Self {
f.0
}
}
pub fn is_u64_valid(n: u64) -> bool {
n < 9007199254740992
}
pub fn is_i64_valid(n: i64) -> bool {
n < 9007199254740992 && n > -9007199254740992
}
pub struct WeirdEncodingIterator<'a>(std::iter::Map<std::str::EncodeUtf16<'a>, fn(u16) -> u8>);
impl<'a> Iterator for WeirdEncodingIterator<'a> {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}
pub fn to_weird_encoding<'a>(s: &'a str) -> WeirdEncodingIterator<'a> {
WeirdEncodingIterator(s.encode_utf16().map(|x| x as u8))
}
pub fn legacy_length(s: &str) -> usize {
let mut len = 0;
for c in s.chars() {
if c as u32 <= 0xFFFF {
len += 1;
} else {
len += 2;
}
}
len
}