From df38b70754bbfd1fa42dc0207a34f8b043ae499a Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Mon, 18 Nov 2024 19:48:59 +0100 Subject: [PATCH] feat: Implement `TO_HEX` Text Function --- crates/gitql-std/src/text/mod.rs | 14 ++++++++++++++ docs/functions/string.md | 1 + 2 files changed, 15 insertions(+) diff --git a/crates/gitql-std/src/text/mod.rs b/crates/gitql-std/src/text/mod.rs index a0cbc6cf..8356bcd2 100644 --- a/crates/gitql-std/src/text/mod.rs +++ b/crates/gitql-std/src/text/mod.rs @@ -43,6 +43,7 @@ pub fn register_std_text_functions(map: &mut HashMap<&'static str, Function>) { map.insert("strcmp", text_strcmp); map.insert("quotename", text_quotename); map.insert("str", text_str); + map.insert("to_hex", text_to_hex); } #[inline(always)] @@ -276,6 +277,13 @@ pub fn register_std_text_function_signatures(map: &mut HashMap<&'static str, Sig return_type: Box::new(TextType), }, ); + map.insert( + "text_to_hex", + Signature { + parameters: vec![Box::new(IntType)], + return_type: Box::new(TextType), + }, + ); } pub fn text_bin(inputs: &[Box]) -> Box { @@ -658,3 +666,9 @@ pub fn text_str(inputs: &[Box]) -> Box { value: number_string.clone(), }) } + +pub fn text_to_hex(inputs: &[Box]) -> Box { + let number = inputs[0].as_int().unwrap(); + let value = format!("0x{}", number); + Box::new(TextValue { value }) +} diff --git a/docs/functions/string.md b/docs/functions/string.md index 74c0debb..266168a2 100644 --- a/docs/functions/string.md +++ b/docs/functions/string.md @@ -30,3 +30,4 @@ | STRCMP | Text , Text | Integer | Return 0 If string1 = string2, -1 if string1 < string2, this function returns -1, and 1 if string1 > string2 | | QUOTENAME | Text , Text | Text | Returns the string (first argument) with specified delimiters (second argument), defaulting to [] | | STR | Text, Integer?, Integer? | Text | Returns a number as a string with optionals length and decimals. | +| TO_HEX | Integer | Text | Returns a number as a string with hex decimal format. |