Advertisement
Python253

case_converter

May 14th, 2024
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.64 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: case_converter.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script converts strings from snake_case or kebab-case to PascalCase.
  9. It also provides help information about different naming conventions.
  10.  
  11. Requirements:
  12.    - Python 3.x
  13.  
  14. Functions:
  15.    - snake_or_kebab_to_pascal(string): Converts a snake_case or kebab-case string into PascalCase.
  16.    - display_help(): Displays definitions and examples of various style cases.
  17.    - main(): Main loop that handles user input and performs the appropriate actions.
  18.  
  19. Usage:
  20.    - Run the script and enter a string in snake_case or kebab-case format to convert it to PascalCase.
  21.    - Type 'h' or 'H' to display help information about various naming conventions.
  22.  
  23. Additional Notes:
  24.    - Ensure you have Python 3.x installed to run this script.
  25.    - This script handles both snake_case and kebab-case inputs and converts them to PascalCase.
  26.    - The help information provides definitions and examples for snake_case, kebab-case, camelCase, and PascalCase.
  27. """
  28.  
  29. import re
  30.  
  31. def snake_or_kebab_to_pascal(string):
  32.     """
  33.    Converts a snake_case or kebab-case string into PascalCase.
  34.    
  35.    Parameters:
  36.    string (str): A string in snake_case or kebab-case format.
  37.    
  38.    Returns:
  39.    str: The string converted to PascalCase.
  40.    """
  41.     words = re.split(r"[-_]", string)
  42.     # Capitalize the first letter of each word
  43.     return ''.join(word.capitalize() for word in words)
  44.  
  45. def display_help():
  46.     """
  47.    Displays definitions and examples of various style cases.
  48.    """
  49.     help_text = """
  50.    Style Case Definitions:
  51.    
  52.    1. Snake Case:
  53.       - Definition: Words are separated by underscores.
  54.       - Example:
  55.         'example_string_here'
  56.    
  57.    2. Kebab Case:
  58.       - Definition: Words are separated by dashes.
  59.       - Example:
  60.         'example-string-here'
  61.    
  62.    3. Camel Case:
  63.       - Definition: The first word is lowercase, and subsequent words have their first letter capitalized with no separators.
  64.       - Example:
  65.         'exampleStringHere'
  66.    
  67.    4. Pascal Case:
  68.       - Definition: Every word starts with a capital letter with no separators.
  69.       - Example:
  70.         'ExampleStringHere'
  71.    """
  72.     print(help_text)
  73.  
  74. def main():
  75.     while True:
  76.         user_input = input("Enter string in snake case or kebab case (or type 'h' for help): ")
  77.         if user_input.lower() == 'h':
  78.             display_help()
  79.             input("Press [ENTER] to continue...")
  80.         else:
  81.             print(snake_or_kebab_to_pascal(user_input))
  82.  
  83. if __name__ == "__main__":
  84.     main()
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement