Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ Values are denoted as displayed in the following table.
|------------|---------|
| `Value::String` | `"abc"`, `""`, `"a\"b\\c"` |
| `Value::Boolean` | `true`, `false` |
| `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0x1e` |
| `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0X1e`, `$fe` |
| `Value::Float` | `3.`, `.35`, `1.00`, `0.5`, `123.554`, `23e4`, `-2e-3`, `3.54e+2` |
| `Value::Tuple` | `(3, 55.0, false, ())`, `(1, 2)` |
| `Value::Empty` | `()` |
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
//! |------------|---------|
//! | `Value::String` | `"abc"`, `""`, `"a\"b\\c"` |
//! | `Value::Boolean` | `true`, `false` |
//! | `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0x1e` |
//! | `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0X1e`, `$fe` |
//! | `Value::Float` | `3.`, `.35`, `1.00`, `0.5`, `123.554`, `23e4`, `-2e-3`, `3.54e+2` |
//! | `Value::Tuple` | `(3, 55.0, false, ())`, `(1, 2)` |
//! | `Value::Empty` | `()` |
Expand Down
6 changes: 5 additions & 1 deletion src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,11 @@ pub(crate) fn tokenize(string: &str) -> EvalexprResult<Vec<Token>> {
}

fn parse_dec_or_hex(literal: &str) -> Result<IntType, std::num::ParseIntError> {
if let Some(literal) = literal.strip_prefix("0x") {
if let Some(literal) = literal.strip_prefix("0x").or_else(|| {
literal
.strip_prefix("0X")
.or_else(|| literal.strip_prefix('$'))
}) {
IntType::from_str_radix(literal, 16)
} else {
IntType::from_str_radix(literal, 10)
Expand Down
3 changes: 3 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,9 @@ fn test_hex() {
assert_eq!(eval("0x3"), Ok(Value::Int(3)));
assert_eq!(eval("0xFF"), Ok(Value::Int(255)));
assert_eq!(eval("-0xFF"), Ok(Value::Int(-255)));
assert_eq!(eval("0XFF"), Ok(Value::Int(255)));
assert_eq!(eval("$fe"), Ok(Value::Int(254)));
assert!(eval("$xy").is_err());
assert_eq!(
eval("0x"),
// The "VariableIdentifierNotFound" error is what evalexpr currently returns,
Expand Down