use crate::lib::{json, Value};
use crate::internal::{type_name};
pub fn x_capitalize_x(s: &str) -> String {
if s.is_empty() {
s.into()
} else if s.len() == 1 {
s.to_uppercase()
} else {
let mut ss = s.chars().next().unwrap().to_uppercase().to_string();
ss.push_str(&s[1..].to_lowercase());
ss
}
}
pub fn x_capitalize(s: &str) -> Value {
json!(x_capitalize_x(s))
}
pub fn capitalize_x(v: Value) -> String {
match v {
Value::Null => "".into(),
Value::Bool(b) => {
if b {
"True".into()
} else {
"False".into()
}
}
Value::String(s) => x_capitalize_x(&s),
Value::Number(n) => n.to_string(),
Value::Array(vec) => {
let mut iter = vec.into_iter();
match iter.next() {
Some(v) => {
let mut s = {
if v.is_null() {
"Null".into()
} else {
capitalize_x(v)
}
};
for v in iter {
s.push(',');
s.push_str(&crate::to_lower_x(v));
}
s
}
None => "".into(),
}
}
Value::Object(o) => x_capitalize_x(type_name(&o)),
}
}
pub fn capitalize(v: Value) -> Value {
Value::String(capitalize_x(v))
}
#[macro_export]
macro_rules! x_capitalize_x {
() => {
"".to_owned()
};
($a:expr $(,)*) => {
$crate::x_capitalize_x($a)
};
($a:expr, $($rest:tt)*) => {
$crate::x_capitalize_x($a)
};
}
#[macro_export]
macro_rules! x_capitalize {
() => {
json!("")
};
($a:expr $(,)*) => {
$crate::x_capitalize($a)
};
($a:expr, $($rest:tt)*) => {
$crate::x_capitalize($a)
};
}
#[macro_export]
macro_rules! capitalize_x {
() => {
"".to_owned()
};
($a:expr $(,)*) => {
$crate::capitalize_x($a)
};
($a:expr, $($rest:tt)*) => {
$crate::capitalize_x($a)
};
}
#[macro_export]
macro_rules! capitalize {
() => {
json!("")
};
($a:expr $(,)*) => {
$crate::capitalize($a)
};
($a:expr, $($rest:tt)*) => {
$crate::capitalize($a)
};
}