This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9e1e779
commit c4eb1d5
Showing
12 changed files
with
191 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod number; | ||
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
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() | ||
} | ||
} |
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::token::number::format_number_token; | ||
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) | ||
format_number_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[ | ||
{ | ||
"integer": 1234567890, | ||
"real": -9876.543210, | ||
"e": 0.123456789e-12, | ||
"E": 1.234567890E+34, | ||
"": 23456789012E66, | ||
"zero": 0, | ||
"one": 1, | ||
" s p a c e d ": [ | ||
1, 2, 3, | ||
|
||
4, 5, 6, 7 | ||
] | ||
}, | ||
0.5, | ||
98.6, | ||
99.44, | ||
1066, | ||
1e1, | ||
0.1e1, | ||
1e-1, | ||
1, | ||
2, | ||
2, | ||
2.00000 | ||
] |
81 changes: 81 additions & 0 deletions
81
crates/rome_json_formatter/tests/specs/json/number.json.snap
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,81 @@ | ||
--- | ||
source: crates/rome_formatter_test/src/snapshot_builder.rs | ||
info: json/number.json | ||
--- | ||
|
||
# Input | ||
|
||
```json | ||
[ | ||
{ | ||
"integer": 1234567890, | ||
"real": -9876.543210, | ||
"e": 0.123456789e-12, | ||
"E": 1.234567890E+34, | ||
"": 23456789012E66, | ||
"zero": 0, | ||
"one": 1, | ||
" s p a c e d ": [ | ||
1, 2, 3, | ||
4, 5, 6, 7 | ||
] | ||
}, | ||
0.5, | ||
98.6, | ||
99.44, | ||
1066, | ||
1e1, | ||
0.1e1, | ||
1e-1, | ||
1, | ||
2, | ||
2, | ||
2.00000 | ||
] | ||
``` | ||
|
||
|
||
============================= | ||
|
||
# Outputs | ||
|
||
## Output 1 | ||
|
||
----- | ||
Indent style: Tab | ||
Line width: 80 | ||
----- | ||
|
||
```json | ||
[ | ||
{ | ||
"integer": 1234567890, | ||
"real": -9876.54321, | ||
"e": 0.123456789e-12, | ||
"E": 1.23456789e34, | ||
"": 23456789012e66, | ||
"zero": 0, | ||
"one": 1, | ||
" s p a c e d ": [ | ||
1, 2, 3, | ||
4, 5, 6, 7 | ||
] | ||
}, | ||
0.5, | ||
98.6, | ||
99.44, | ||
1066, | ||
1e1, | ||
0.1e1, | ||
1e-1, | ||
1, | ||
2, | ||
2, | ||
2.0 | ||
] | ||
``` | ||
|
||
|
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
Oops, something went wrong.