Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: case_converter.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script converts strings from snake_case or kebab-case to PascalCase.
- It also provides help information about different naming conventions.
- Requirements:
- - Python 3.x
- Functions:
- - snake_or_kebab_to_pascal(string): Converts a snake_case or kebab-case string into PascalCase.
- - display_help(): Displays definitions and examples of various style cases.
- - main(): Main loop that handles user input and performs the appropriate actions.
- Usage:
- - Run the script and enter a string in snake_case or kebab-case format to convert it to PascalCase.
- - Type 'h' or 'H' to display help information about various naming conventions.
- Additional Notes:
- - Ensure you have Python 3.x installed to run this script.
- - This script handles both snake_case and kebab-case inputs and converts them to PascalCase.
- - The help information provides definitions and examples for snake_case, kebab-case, camelCase, and PascalCase.
- """
- import re
- def snake_or_kebab_to_pascal(string):
- """
- Converts a snake_case or kebab-case string into PascalCase.
- Parameters:
- string (str): A string in snake_case or kebab-case format.
- Returns:
- str: The string converted to PascalCase.
- """
- words = re.split(r"[-_]", string)
- # Capitalize the first letter of each word
- return ''.join(word.capitalize() for word in words)
- def display_help():
- """
- Displays definitions and examples of various style cases.
- """
- help_text = """
- Style Case Definitions:
- 1. Snake Case:
- - Definition: Words are separated by underscores.
- - Example:
- 'example_string_here'
- 2. Kebab Case:
- - Definition: Words are separated by dashes.
- - Example:
- 'example-string-here'
- 3. Camel Case:
- - Definition: The first word is lowercase, and subsequent words have their first letter capitalized with no separators.
- - Example:
- 'exampleStringHere'
- 4. Pascal Case:
- - Definition: Every word starts with a capital letter with no separators.
- - Example:
- 'ExampleStringHere'
- """
- print(help_text)
- def main():
- while True:
- user_input = input("Enter string in snake case or kebab case (or type 'h' for help): ")
- if user_input.lower() == 'h':
- display_help()
- input("Press [ENTER] to continue...")
- else:
- print(snake_or_kebab_to_pascal(user_input))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement