forked from rome/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rome_json_formatter): JSON Formatting number rome#2570
- Loading branch information
1 parent
c20d6cf
commit f6b959a
Showing
10 changed files
with
85 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::borrow::Cow; | ||
|
||
pub trait ToAsciiLowercaseCow { | ||
/// Returns the same value as String::to_lowercase. The only difference | ||
/// is that this functions returns ```Cow``` and does not allocate | ||
/// if the string is already in lowercase. | ||
fn to_ascii_lowercase_cow(&self) -> Cow<str>; | ||
} | ||
|
||
impl ToAsciiLowercaseCow for str { | ||
fn to_ascii_lowercase_cow(&self) -> Cow<str> { | ||
debug_assert!(self.is_ascii()); | ||
|
||
let bytes = self.as_bytes(); | ||
|
||
for idx in 0..bytes.len() { | ||
let chr = bytes[idx]; | ||
if chr != chr.to_ascii_lowercase() { | ||
let mut s = bytes.to_vec(); | ||
for b in &mut s[idx..] { | ||
b.make_ascii_lowercase(); | ||
} | ||
return Cow::Owned(unsafe { String::from_utf8_unchecked(s) }); | ||
} | ||
} | ||
|
||
Cow::Borrowed(self) | ||
} | ||
} | ||
|
||
impl ToAsciiLowercaseCow for String { | ||
#[inline(always)] | ||
fn to_ascii_lowercase_cow(&self) -> Cow<str> { | ||
self.as_str().to_ascii_lowercase_cow() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
crates/rome_js_formatter/src/js/expressions/number_literal_expression.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
use crate::prelude::*; | ||
use rome_formatter::format_number::CleanedNumberLiteralText; | ||
use rome_json_syntax::JsonNumberValue; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatJsonNumberValue; | ||
|
||
impl FormatNodeRule<JsonNumberValue> for FormatJsonNumberValue { | ||
fn fmt_fields(&self, node: &JsonNumberValue, f: &mut JsonFormatter) -> FormatResult<()> { | ||
node.value_token()?.format().fmt(f) | ||
CleanedNumberLiteralText::from_number_literal_token(&node.value_token()?).fmt(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters