Skip to content

Instantly share code, notes, and snippets.

@w-e-w
w-e-w / replace_illegal_filename_characters.py
Last active May 6, 2025 17:38
Python replace illegal filename characters
import re
character_translation_table = str.maketrans('"*/:<>?\\|\t\n\v\f\r', '"*/:<>?\│ ')
leading_space_pattern = re.compile(r'^\s+')
def replace_illegal_filename_characters(input_filename: str):
r"""
Replace illegal characters with full-width variant
Table
golden_ratio = 0x9E3779B9
max_int = 2**32 - 1
def rotate_left_5(value):
return ((value << 5) | (value >> 27)) & max_int
def add_to_hash(hash_value, value):
return (golden_ratio * (rotate_left_5(hash_value) ^ value)) & max_int
def hash_simple(url):