Documentation ¶
Index ¶
- Variables
- func FixVarNameIncremental(variable_name string, keywords []string, min int, start int) (string, bool)
- func FixVariableName(variable_name string, keywords []string, min int, suffix string) (string, bool)
- func IsGenericsID(str string) (rune, error)
- func IsValidName(variable_name string, keywords []string) bool
- func MakeVariableName(type_name string) (string, error)
- func ParseFields(str string) (map[string]string, error)
- func ParseGenerics(str string) ([]rune, error)
- type Parser
Constants ¶
This section is empty.
Variables ¶
var ( // GoReservedKeywords is a list of Go reserved keywords. GoReservedKeywords []string )
Functions ¶
func FixVarNameIncremental ¶
func FixVarNameIncremental(variable_name string, keywords []string, min int, start int) (string, bool)
FixVarNameIncremental works like FixVariableName but it appends an incremental number to the variable name instead of a suffix.
Parameters:
- variable_name: The variable name to fix.
- keywords: The list of keywords to check against.
- min: The minimum length of the variable name. If less than 1, the function uses 1.
- start: The starting number to append to the variable name. If less than 0, the function uses 0.
Returns:
- string: The fixed variable name.
- bool: True if the variable name is not empty. False otherwise.
func FixVariableName ¶
func FixVariableName(variable_name string, keywords []string, min int, suffix string) (string, bool)
FixVariableName fixes the given variable name by checking whether or not the name trimmed to the minimum length is valid. If it is not valid, the function appends the given suffix to the name until a valid name is found.
Moreover, if the name is greater than the minimum length, the function first checks whether the name can be trimmed to the minimum length and still be valid. If it is not valid, the function tries the remaining characters one by one until a valid name is found. Finally, if it is still not valid, the function appends the given suffix to the name until a valid name is found.
Parameters:
- variable_name: The variable name to fix.
- keywords: The list of keywords to check against.
- min: The minimum length of the variable name. If less than 1, the function uses 1.
- suffix: The suffix to append to the variable name. If empty, the function uses "_".
Returns:
- string: The fixed variable name.
- bool: True if the variable name is not empty. False otherwise.
func IsGenericsID ¶
IsGenericsID checks if the input string is a valid single upper case letter and returns it as a rune.
Parameters:
- str: The input string to check.
Returns:
- rune: The valid single upper case letter.
- error: An error if the input string is not a valid single upper case letter.
func IsValidName ¶
IsValidName checks if the given variable name is valid.
This function checks if the variable name is not empty and if it is not a Go reserved keyword. It also checks if the variable name is not in the list of keywords.
Parameters:
- variable_name: The variable name to check.
- keywords: The list of keywords to check against.
Returns:
- bool: True if the variable name is valid. False otherwise.
func MakeVariableName ¶
MakeVariableName converts a type name to a variable name.
Parameters:
- type_name: The type name to convert.
Returns:
- string: The variable name.
- error: An error if the type name is invalid.
Errors:
- *common.ErrInvalidParameter: If the type name is empty.
- *common.ErrAt: If the type name is invalid at a specific position.
func ParseFields ¶
ParseFields parses the given string to extract fields and their types.
Parameters:
- str: The string containing fields to parse.
Returns:
- map[string]string: A map of field names to their corresponding types.
- error: An error if parsing encounters any issues.
func ParseGenerics ¶
ParseGenerics parses a string representing a list of generic types enclosed in square brackets.
Parameters:
- str: The string to parse.
Return types:
- []rune: An array of runes representing the parsed generic types.
- error: An error if the parsing fails.