|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "strutil" for Str
|
|
import "crypto" for Hash
|
|
|
|
System.print("=== String Utility Module Demo ===\n")
|
|
|
|
System.print("--- Case Conversion ---")
|
|
System.print("toLower('HELLO World'): " + Str.toLower("HELLO World"))
|
|
System.print("toUpper('hello world'): " + Str.toUpper("hello world"))
|
|
|
|
System.print("\n--- Hex Encoding ---")
|
|
var data = "ABC"
|
|
var hex = Str.hexEncode(data)
|
|
System.print("hexEncode('ABC'): " + hex)
|
|
System.print("hexDecode('" + hex + "'): " + Str.hexDecode(hex))
|
|
|
|
System.print("\n--- SHA256 Hash with Hex ---")
|
|
var hash = Hash.sha256("hello")
|
|
System.print("SHA256('hello'): " + Hash.toHex(hash))
|
|
|
|
System.print("\n--- String Repetition ---")
|
|
System.print("repeat('ab', 5): " + Str.repeat("ab", 5))
|
|
|
|
System.print("\n--- Padding ---")
|
|
System.print("padLeft('42', 5, '0'): " + Str.padLeft("42", 5, "0"))
|
|
System.print("padRight('x', 5, '-'): " + Str.padRight("x", 5, "-"))
|
|
|
|
System.print("\n--- HTML Escaping ---")
|
|
var html = "<script>alert('xss')</script>"
|
|
System.print("Original: " + html)
|
|
System.print("Escaped: " + Str.escapeHtml(html))
|
|
|
|
System.print("\n--- JSON Escaping ---")
|
|
var text = "Line 1\nLine 2\tTabbed"
|
|
System.print("Original: Line 1\\nLine 2\\tTabbed")
|
|
System.print("Escaped: " + Str.escapeJson(text))
|
|
|
|
System.print("\n--- URL Encoding ---")
|
|
var url = "hello world & more"
|
|
var encoded = Str.urlEncode(url)
|
|
System.print("Original: " + url)
|
|
System.print("Encoded: " + encoded)
|
|
System.print("Decoded: " + Str.urlDecode(encoded))
|